Details
Diff Detail
Event Timeline
@gchatelet I made this into a patch and didn't just push it directly because my build succeeds without this patch even with -DBUILD_SHARED_LIBS=On. For reference this is my full cmake command for how I build libc:
$ cmake ../llvm -DLLVM_ENABLE_PROJECTS=libc -DLLVM_USE_SANITIZER='Address;Undefined' -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DLLVM_PARALLEL_LINK_JOBS=4 -DLLVM_USE_PERF=On -DBUILD_SHARED_LIBS=On -G Ninja $ cmake --version cmake version 3.16.20191110-ga9c0959
Does this change fix it for you? It works for me but it worked without too so I wanted to check with you before pushing this.
I have also switched to using add_llvm_library which is what UnitTest uses but it complains when I didn't specify any source files it looks like so I need to do it in this strange way.
I have the same observation as well. But, this change doesn't hurt anything so I am fine to land it. But, if you want, you may still wait for @gchatelet's acceptance to make sure that it is not in vain.
I have also switched to using add_llvm_library which is what UnitTest uses but it complains when I didn't specify any source files it looks like so I need to do it in this strange way.
Hmm it still doesn't seem to work
My command line:
cmake -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ -DCMAKE_BUILD_TYPE=Debug -LLVM_ENABLE_ASSERTIONS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DLLVM_USE_SPLIT_DWARF=ON -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PROJECTS=libc -DBUILD_SHARED_LIBS=ON -DLLVM_BUILD_TESTS=ON -DLLVM_ENABLE_WERROR=ON -DLLVM_ENABLE_LLD=ON -H/redacted/git/llvm-project/llvm -B/tmp/llvm-project_dbg_compiled-with-gcc -GNinja
FAILED: lib/libLibcUnitTest.so.11git : && /usr/bin/g++ -fPIC -fPIC -fvisibility-inlines-hidden -Werror -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -g -Wl,-z,defs -Wl,-z,nodelete -fuse-ld=lld -Wl,--color-diagnostics -shared -Wl,-soname,libLibcUnitTest.so.11git -o lib/libLibcUnitTest.so.11git projects/libc/utils/UnitTest/CMakeFiles/LibcUnitTest.dir/Test.cpp.o -Wl,-rpath,"\$ORIGIN/../lib" lib/libLLVMSupport.so.11git && : ld.lld: error: undefined symbol: __llvm_libc::testutils::invokeInSubprocess(__llvm_libc::testutils::FunctionCaller*) >>> referenced by Test.cpp:238 (/redacted/git/llvm-project/libc/utils/UnitTest/Test.cpp:238) >>> projects/libc/utils/UnitTest/CMakeFiles/LibcUnitTest.dir/Test.cpp.o:(__llvm_libc::testing::Test::testProcessKilled(__llvm_libc::testing::RunContext&, __llvm_libc::testutils::FunctionCaller*, int, char const*, char const*, char const*, unsigned long)) >>> referenced by Test.cpp:269 (/redacted/git/llvm-project/libc/utils/UnitTest/Test.cpp:269) >>> projects/libc/utils/UnitTest/CMakeFiles/LibcUnitTest.dir/Test.cpp.o:(__llvm_libc::testing::Test::testProcessExits(__llvm_libc::testing::RunContext&, __llvm_libc::testutils::FunctionCaller*, int, char const*, char const*, char const*, unsigned long)) ld.lld: error: undefined symbol: __llvm_libc::testutils::ProcessStatus::exitedNormally() >>> referenced by Test.cpp:240 (/redacted/git/llvm-project/libc/utils/UnitTest/Test.cpp:240) >>> projects/libc/utils/UnitTest/CMakeFiles/LibcUnitTest.dir/Test.cpp.o:(__llvm_libc::testing::Test::testProcessKilled(__llvm_libc::testing::RunContext&, __llvm_libc::testutils::FunctionCaller*, int, char const*, char const*, char const*, unsigned long)) >>> referenced by Test.cpp:271 (/redacted/git/llvm-project/libc/utils/UnitTest/Test.cpp:271) >>> projects/libc/utils/UnitTest/CMakeFiles/LibcUnitTest.dir/Test.cpp.o:(__llvm_libc::testing::Test::testProcessExits(__llvm_libc::testing::RunContext&, __llvm_libc::testutils::FunctionCaller*, int, char const*, char const*, char const*, unsigned long)) ld.lld: error: undefined symbol: __llvm_libc::testutils::ProcessStatus::getFatalSignal() >>> referenced by Test.cpp:248 (/redacted/git/llvm-project/libc/utils/UnitTest/Test.cpp:248) >>> projects/libc/utils/UnitTest/CMakeFiles/LibcUnitTest.dir/Test.cpp.o:(__llvm_libc::testing::Test::testProcessKilled(__llvm_libc::testing::RunContext&, __llvm_libc::testutils::FunctionCaller*, int, char const*, char const*, char const*, unsigned long)) ld.lld: error: undefined symbol: __llvm_libc::testutils::signalAsString(int) >>> referenced by Test.cpp:258 (/redacted/git/llvm-project/libc/utils/UnitTest/Test.cpp:258) >>> projects/libc/utils/UnitTest/CMakeFiles/LibcUnitTest.dir/Test.cpp.o:(__llvm_libc::testing::Test::testProcessKilled(__llvm_libc::testing::RunContext&, __llvm_libc::testutils::FunctionCaller*, int, char const*, char const*, char const*, unsigned long)) >>> referenced by Test.cpp:260 (/redacted/git/llvm-project/libc/utils/UnitTest/Test.cpp:260) >>> projects/libc/utils/UnitTest/CMakeFiles/LibcUnitTest.dir/Test.cpp.o:(__llvm_libc::testing::Test::testProcessKilled(__llvm_libc::testing::RunContext&, __llvm_libc::testutils::FunctionCaller*, int, char const*, char const*, char const*, unsigned long)) ld.lld: error: undefined symbol: __llvm_libc::testutils::ProcessStatus::getExitCode() >>> referenced by Test.cpp:280 (/redacted/git/llvm-project/libc/utils/UnitTest/Test.cpp:280) >>> projects/libc/utils/UnitTest/CMakeFiles/LibcUnitTest.dir/Test.cpp.o:(__llvm_libc::testing::Test::testProcessExits(__llvm_libc::testing::RunContext&, __llvm_libc::testutils::FunctionCaller*, int, char const*, char const*, char const*, unsigned long)) collect2: error: ld returned 1 exit status
We probably need to add the testutils library here: https://github.com/llvm/llvm-project/blob/master/libc/utils/UnitTest/CMakeLists.txt#L8
When I ran with the same command as you I got it to break. This one should work. I'm not sure which was the flag that made the difference here. I'll do some investigating report back :)
It looks like when you compile with -DLLVM_USE_SANITIZER it ends up adding a -Wl,-allow-shlib-undefined. I'll compile without that in the future to make sure it works :)