This is an archive of the discontinued LLVM Phabricator instance.

[clang] [unitttests] Fix linking Basic test to LLVMTestingSupport
ClosedPublic

Authored by mgorny on Dec 11 2021, 9:19 AM.

Details

Summary

Link BasicTests via explicit target_link_libraries() rather than
clang_target_link_libraries() in order to fix linking when building
clang against libclang. The latter requires all listed libraries
to be part of libclang and omits them if libclang is used. However,
LLVMTestingSupport is not part of libclang, so omitting it causes
undefined symbols. Link to the library explicitly to follow suit
with the 7 other unittest programs.

Diff Detail

Event Timeline

mgorny requested review of this revision.Dec 11 2021, 9:19 AM
mgorny created this revision.
mgorny added a reviewer: MaskRay.
MaskRay added a comment.EditedDec 13 2021, 1:10 PM

in order to fix linking when building clang against libclang

I am confused by building clang against libclang. libclang is the C API library (libclang.so on ELF platforms). Do you mean CLANG_LINK_CLANG_DYLIB libclang-cpp.so? What's your cmake command line to trigger a linker error?

Yes, I'm sorry, I meant libclang-cpp.

FAILED: unittests/Basic/BasicTests 
: && /usr/lib/ccache/bin/x86_64-pc-linux-gnu-g++ -m32 -march=znver2 --param l1-cache-size=32 --param l1-cache-line-size=64 -O2 -pipe -frecord-gcc-switches -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -Wimplicit-fallthrough -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -pedantic -Wno-long-long -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu    -Wl,--gc-sections unittests/Basic/CMakeFiles/BasicTests.dir/CharInfoTest.cpp.o unittests/Basic/CMakeFiles/BasicTests.dir/DarwinSDKInfoTest.cpp.o unittests/Basic/CMakeFiles/BasicTests.dir/DiagnosticTest.cpp.o unittests/Basic/CMakeFiles/BasicTests.dir/FileEntryTest.cpp.o unittests/Basic/CMakeFiles/BasicTests.dir/FileManagerTest.cpp.o unittests/Basic/CMakeFiles/BasicTests.dir/LineOffsetMappingTest.cpp.o unittests/Basic/CMakeFiles/BasicTests.dir/SanitizersTest.cpp.o unittests/Basic/CMakeFiles/BasicTests.dir/SourceManagerTest.cpp.o -o unittests/Basic/BasicTests -L/usr/lib/llvm/14/lib -Wl,-rpath,/usr/lib/llvm/14/lib:/var/tmp/portage/sys-devel/clang-14.0.0.9999/work/x/y/clang-abi_x86_32.x86/lib  lib/libgtest_main.a  lib/libgtest.a  lib/libclang-cpp.so.14git  -lpthread  /usr/lib/llvm/14/lib/libLLVM-14git.so && :
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: unittests/Basic/CMakeFiles/BasicTests.dir/FileManagerTest.cpp.o: in function `(anonymous namespace)::FileManagerTest_getBypassFile_Test::TestBody()':
FileManagerTest.cpp:(.text._ZN12_GLOBAL__N_134FileManagerTest_getBypassFile_Test8TestBodyEv+0x321): undefined reference to `llvm::detail::TakeError(llvm::Error)'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: FileManagerTest.cpp:(.text._ZN12_GLOBAL__N_134FileManagerTest_getBypassFile_Test8TestBodyEv+0x797): undefined reference to `llvm::detail::TakeError(llvm::Error)'
collect2: error: ld returned 1 exit status
MaskRay accepted this revision.Dec 13 2021, 1:44 PM

Thanks! Please update the commit message.

This revision is now accepted and ready to land.Dec 13 2021, 1:44 PM

Thanks! Done and merged.

This revision was landed with ongoing or failed builds.Dec 13 2021, 2:01 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2021, 2:01 PM