This is an archive of the discontinued LLVM Phabricator instance.

[libc] Fix build when -DBUILD_SHARED_LIBS=On
ClosedPublic

Authored by abrachet on Feb 25 2020, 12:54 PM.

Diff Detail

Event Timeline

abrachet created this revision.Feb 25 2020, 12:54 PM
sivachandra accepted this revision.Feb 25 2020, 1:01 PM
This revision is now accepted and ready to land.Feb 25 2020, 1:01 PM

@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.

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 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
abrachet updated this revision to Diff 246722.Feb 26 2020, 7:33 AM

Add libc_test_utils dependency to UnitTest

abrachet updated this revision to Diff 246735.Feb 26 2020, 7:58 AM

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 :)

gchatelet accepted this revision.Feb 26 2020, 8:26 AM

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 :)

Ha nice ! Good to know :)

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 26 2020, 9:21 AM