[libcxx-commits] [PATCH] D131037: [libc++] Simplify how we define the linker script for libc++

Dimitry Andric via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Aug 7 01:58:03 PDT 2022


dim added a comment.

So I've been trying again with the following diff applied on top of this one:

  diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
  index 9abf548abbb9..d6769e4a3e64 100644
  --- a/libcxx/src/CMakeLists.txt
  +++ b/libcxx/src/CMakeLists.txt
  @@ -244,7 +244,9 @@ if (LIBCXX_ENABLE_SHARED)
  
       set(imported_libname "$<TARGET_PROPERTY:libcxx-abi-shared,IMPORTED_LIBNAME>")
       set(output_name "$<TARGET_PROPERTY:libcxx-abi-shared,OUTPUT_NAME>")
  -    string(APPEND link_libraries "${CMAKE_LINK_LIBRARY_FLAG}$<IF:$<BOOL:${imported_libname}>,${imported_libname},${output_name}>")
  +    # NOTE: We cannot use the LOCATION target property, since that is forbidden by the CMP0026 policy.
  +    set(target_file "$<TARGET_FILE:libcxx-abi-shared>")
  +    string(APPEND link_libraries "$<IF:$<BOOL:${imported_libname}>,${CMAKE_LINK_LIBRARY_FLAG}${imported_libname},$<IF:$<BOOL:${output_name}>,${CMAKE_LINK_LIBRARY_FLAG}${output_name},${target_file}>>")
  
       # TODO: Move to the same approach as above for the unwind library
       if (LIBCXXABI_USE_LLVM_UNWINDER)

E.g. what this does is fall-back to `$<TARGET_FILE:libcxx-abi-shared>`, if both `IMPORTED_LIBNAME` and `OUTPUT_NAME` are unset, which turns out to be the case if `LIBCXX_CXX_ABI=libcxxrt`. That causes the linker script to look like:

  INPUT(libc++.so.1 /usr/lib/libcxxrt.so)

Which works up to a point, but then it turns out that during the runtime builds for some reason the line `target_compile_definitions(libcxx-abi-headers INTERFACE "-DLIBCXXRT")` (from `libcxx/cmake/Modules/HandleLibCXXABI.cmake`) isn't picked up. E.g. the whole of libc++ is then compiled _without_ the `-DLIBCXXRT` define necessary for supporting libcxxrt, and at the end the build still fails, but now with:

  FAILED: bin/llvm-tblgen
  : && /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/clang++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -Wl,--color-diagnostics    -Wl,-z,origin  -Wl,--gc-sections utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmWriterEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmWriterInst.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/Attributes.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/CallingConvEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeEmitterGen.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenDAGPatterns.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenHwModes.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenInstruction.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenMapTable.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenRegisters.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenSchedule.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenTarget.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherGen.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherOpt.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcher.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/DecoderEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/DFAEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/DFAPacketizerEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/DirectiveEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/DisassemblerEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/DXILEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/ExegesisEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/FastISelEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/GICombinerEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/GlobalISelEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/InfoByHwMode.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/InstrInfoEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/InstrDocsEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/IntrinsicEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/OptEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/OptParserEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/OptRSTEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/PredicateExpander.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/PseudoLoweringEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/CompressInstEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/RegisterBankEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/RegisterInfoEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/SDNodeProperties.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/SearchableTableEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/SubtargetEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/SubtargetFeatureInfo.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/TableGen.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/Types.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/VarLenCodeEmitterGen.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86DisassemblerTables.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86EVEX2VEXTablesEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86FoldTablesEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86MnemonicTables.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86ModRMFilters.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86RecognizableInstr.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/WebAssemblyDisassemblerEmitter.cpp.o utils/TableGen/CMakeFiles/llvm-tblgen.dir/CTagsEmitter.cpp.o -o bin/llvm-tblgen  -Wl,-rpath,"\$ORIGIN/../lib"  lib/libLLVMSupport.a  lib/libLLVMTableGen.a  -lpthread  lib/libLLVMTableGenGlobalISel.a  lib/libLLVMTableGen.a  lib/libLLVMSupport.a  -lrt  -lexecinfo  -lpthread  -lm  /usr/lib/libz.so  /usr/lib/libtinfo.so  lib/libLLVMDemangle.a && :
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to __cxa_uncaught_exceptions
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to std::logic_error::~logic_error()
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to std::logic_error::what() const
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to typeinfo for std::logic_error
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to typeinfo for std::overflow_error
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to std::overflow_error::~overflow_error()
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to vtable for std::overflow_error
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to vtable for std::logic_error
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to vtable for std::runtime_error
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to typeinfo for std::length_error
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to std::length_error::~length_error()
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to typeinfo for std::out_of_range
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to std::out_of_range::~out_of_range()
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to vtable for std::length_error
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to vtable for std::out_of_range
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to vtable for std::invalid_argument
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to typeinfo for std::invalid_argument
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to std::invalid_argument::~invalid_argument()
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to std::runtime_error::~runtime_error()
  ld: error: /home/dim/llvm/15.0.0/rc1/Phase1/Release/llvmCore-15.0.0-rc1.install/usr/local/bin/../lib/x86_64-unknown-freebsd12.3/libc++.so.1: undefined reference to std::runtime_error::what() const
  ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
  clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

The errors mean it was assuming it was being linked against libcxxabi instead.

At this point I'm inclined to just do the test builds with `LIBCXX_CXX_ABI` forced to `libcxxabi`, as the runtimes seem to be pretty much broken for anything other than libcxxabi. :-)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131037/new/

https://reviews.llvm.org/D131037



More information about the libcxx-commits mailing list