llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.01k stars 11.96k forks source link

[Clang][Unittests] - Linker failure in clang unittests for Clang driver #109328

Open bhandarkar-pranav opened 1 month ago

bhandarkar-pranav commented 1 month ago

I am getting the following build error

FAILED: tools/clang/unittests/Driver/ClangDriverTests
: && /usr/bin/c++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -Wl,--gc-sections tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/DistroTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/DXCModeTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/GCCVersionTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/ToolChainTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/ModuleCacheTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/MultilibBuilderTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/MultilibTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/SanitizerArgsTest.cpp.o -o tools/clang/unittests/Driver/ClangDriverTests  -Wl,-rpath,/home/prbhanda/git/bhandarkar-pranav/build/build-12Sep24/lib  lib/libLLVMX86CodeGen.so.20.0git  lib/libLLVMX86AsmParser.so.20.0git  lib/libLLVMX86Desc.so.20.0git  lib/libLLVMX86Disassembler.so.20.0git  lib/libLLVMX86Info.so.20.0git  lib/libLLVMAMDGPUCodeGen.so.20.0git  lib/libLLVMAMDGPUAsmParser.so.20.0git  lib/libLLVMAMDGPUDisassembler.so.20.0git  lib/libLLVMNVPTXCodeGen.so.20.0git  lib/libLLVMNVPTXDesc.so.20.0git  lib/libLLVMNVPTXInfo.so.20.0git  lib/libllvm_gtest_main.so.20.0git  lib/libllvm_gtest.so.20.0git  lib/libclangFrontend.so.20.0git  lib/libLLVMAMDGPUDesc.so.20.0git  lib/libLLVMAMDGPUInfo.so.20.0git  lib/libLLVMAMDGPUUtils.so.20.0git  lib/libclangDriver.so.20.0git  lib/libLLVMOption.so.20.0git  lib/libclangBasic.so.20.0git  lib/libLLVMMC.so.20.0git  lib/libLLVMTargetParser.so.20.0git  lib/libLLVMSupport.so.20.0git  -Wl,-rpath-link,/home/prbhanda/git/bhandarkar-pranav/build/build-12Sep24/lib && :
/usr/bin/ld: tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/ToolChainTest.cpp.o: undefined reference to symbol '_ZN5clang22PCHContainerOperationsC1Ev'
/usr/bin/ld: /home/prbhanda/git/bhandarkar-pranav/build/build-12Sep24/lib/libclangSerialization.so.20.0git: error adding symbols: DSO missing from command line

I build with BUILD_SHARED_LIBS=ON. It started with this commit https://github.com/llvm/llvm-project/commit/d1335fb86466221b0499db5fc8f158f1f64d9542

bhandarkar-pranav commented 1 month ago

The following change fixes the problem for me.

diff --git a/clang/unittests/Driver/CMakeLists.txt b/clang/unittests/Driver/CMakeLists.txt
index 752037f78fb1..efdd07ea2388 100644
--- a/clang/unittests/Driver/CMakeLists.txt
+++ b/clang/unittests/Driver/CMakeLists.txt
@@ -22,4 +22,5 @@ clang_target_link_libraries(ClangDriverTests
   clangDriver
   clangBasic
   clangFrontend # For TextDiagnosticPrinter.
+  clangSerialization
   )
shafik commented 1 month ago

CC @Prabhuk