llvm / llvm-project

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

llvm-debuginfod static link #89451

Open lateautumn233 opened 3 months ago

lateautumn233 commented 3 months ago

I tried to statically compile LLVM, but encountered some issues.

cmake -B /home/quqiu/dev/tc-build/build/llvm/final -G Ninja -S /home/quqiu/dev/tc-build/src/llvm-project/llvm -Wno-dev -DCLANG_ENABLE_ARCMT=OFF -DCLANG_ENABLE_STATIC_ANALYZER=OFF -DCLANG_PLUGIN_SUPPORT=OFF -DCLANG_TABLEGEN=/home/quqiu/dev/tc-build/build/llvm/bootstrap/bin/clang-tblgen -DCLANG_VENDOR=Lateautumn-20240420 -DCMAKE_AR=/home/quqiu/dev/tc-build/build/llvm/bootstrap/bin/llvm-ar -DCMAKE_BUILD_TYPE=Release '-DCMAKE_CXX_ARCHIVE_CREATE=<CMAKE_AR> DqcT <TARGET> <OBJECTS>' -DCMAKE_CXX_ARCHIVE_FINISH=true -DCMAKE_CXX_COMPILER=/home/quqiu/dev/tc-build/build/llvm/bootstrap/bin/clang++ -DCMAKE_CXX_FLAGS= -DCMAKE_C_COMPILER=/home/quqiu/dev/tc-build/build/llvm/bootstrap/bin/clang -DCMAKE_C_FLAGS= -DCMAKE_EXE_LINKER_FLAGS=-Wl,--emit-relocs -DCMAKE_INSTALL_PREFIX=/home/quqiu/dev/tc-build/installTmp -DCMAKE_RANLIB=/home/quqiu/dev/tc-build/build/llvm/bootstrap/bin/llvm-ranlib -DLLD_VENDOR=Lateautumn-20240420 -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-pc-linux-gnu '-DLLVM_DISTRIBUTION_COMPONENTS=llvm-ar;llvm-nm;llvm-objcopy;llvm-objdump;llvm-ranlib;llvm-readelf;llvm-strip;clang;clang-resource-headers;lld' -DLLVM_ENABLE_BINDINGS=OFF -DLLVM_ENABLE_CURL=OFF -DLLVM_ENABLE_OCAMLDOC=OFF '-DLLVM_ENABLE_PROJECTS=clang;lld;polly' -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_WARNINGS=OFF -DLLVM_ENABLE_ZSTD=OFF -DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR= -DLLVM_INCLUDE_DOCS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_PARALLEL_COMPILE_JOBS=16 -DLLVM_PARALLEL_LINK_JOBS=16 -DLLVM_TABLEGEN=/home/quqiu/dev/tc-build/build/llvm/bootstrap/bin/llvm-tblgen '-DLLVM_TARGETS_TO_BUILD=ARM;AArch64;X86' -DLLVM_TOOL_LLVM_DRIVER_BUILD=ON -DLLVM_USE_LINKER=/home/quqiu/dev/tc-build/build/llvm/bootstrap/bin/ld.lld -DZLIB_LIBRARY=/usr/lib/libz.a
ninja -C /home/quqiu/dev/tc-build/build/llvm/final
ninja: Entering directory `/home/quqiu/dev/tc-build/build/llvm/final'
[1/479] Linking CXX executable bin/llvm-debuginfod
FAILED: bin/llvm-debuginfod
: && /home/quqiu/dev/tc-build/build/llvm/bootstrap/bin/clang++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -w -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -Wl,--emit-relocs -fuse-ld=/home/quqiu/dev/tc-build/build/llvm/bootstrap/bin/ld.lld -Wl,--color-diagnostics    -Wl,--gc-sections tools/llvm-debuginfod/CMakeFiles/obj.llvm-debuginfod.dir/llvm-debuginfod.cpp.o tools/llvm-debuginfod/CMakeFiles/llvm-debuginfod.dir/llvm-debuginfod-driver.cpp.o -o bin/llvm-debuginfod  -Wl,-rpath,"\$ORIGIN/../lib:"  lib/libLLVMOption.a  lib/libLLVMSupport.a  -lrt  -ldl  -lm  /usr/lib/libz.a  lib/libLLVMDemangle.a && :
ld.lld: error: undefined symbol: llvm::HTTPClient::initialize()
>>> referenced by llvm-debuginfod.cpp
>>>               tools/llvm-debuginfod/CMakeFiles/obj.llvm-debuginfod.dir/llvm-debuginfod.cpp.o:(llvm_debuginfod_main(int, char**, llvm::ToolContext const&))

ld.lld: error: undefined symbol: llvm::DebuginfodCollection::DebuginfodCollection(llvm::ArrayRef<llvm::StringRef>, llvm::DebuginfodLog&, llvm::ThreadPoolInterface&, double)
>>> referenced by llvm-debuginfod.cpp
>>>               tools/llvm-debuginfod/CMakeFiles/obj.llvm-debuginfod.dir/llvm-debuginfod.cpp.o:(llvm_debuginfod_main(int, char**, llvm::ToolContext const&))

ld.lld: error: undefined symbol: llvm::DebuginfodServer::DebuginfodServer(llvm::DebuginfodLog&, llvm::DebuginfodCollection&)
>>> referenced by llvm-debuginfod.cpp
>>>               tools/llvm-debuginfod/CMakeFiles/obj.llvm-debuginfod.dir/llvm-debuginfod.cpp.o:(llvm_debuginfod_main(int, char**, llvm::ToolContext const&))

ld.lld: error: undefined symbol: llvm::HTTPServer::bind(char const*)
>>> referenced by llvm-debuginfod.cpp
>>>               tools/llvm-debuginfod/CMakeFiles/obj.llvm-debuginfod.dir/llvm-debuginfod.cpp.o:(llvm_debuginfod_main(int, char**, llvm::ToolContext const&))

ld.lld: error: undefined symbol: llvm::HTTPServer::bind(unsigned int, char const*)
>>> referenced by llvm-debuginfod.cpp
>>>               tools/llvm-debuginfod/CMakeFiles/obj.llvm-debuginfod.dir/llvm-debuginfod.cpp.o:(llvm_debuginfod_main(int, char**, llvm::ToolContext const&))

ld.lld: error: undefined symbol: llvm::DebuginfodLog::push(llvm::Twine const&)
>>> referenced by llvm-debuginfod.cpp
>>>               tools/llvm-debuginfod/CMakeFiles/obj.llvm-debuginfod.dir/llvm-debuginfod.cpp.o:(llvm_debuginfod_main(int, char**, llvm::ToolContext const&))

ld.lld: error: undefined symbol: llvm::DebuginfodCollection::updateForever(std::chrono::duration<long, std::ratio<1l, 1000l>>)
>>> referenced by llvm-debuginfod.cpp
>>>               tools/llvm-debuginfod/CMakeFiles/obj.llvm-debuginfod.dir/llvm-debuginfod.cpp.o:(llvm_debuginfod_main(int, char**, llvm::ToolContext const&))

ld.lld: error: undefined symbol: llvm::HTTPServer::listen()
>>> referenced by llvm-debuginfod.cpp
>>>               tools/llvm-debuginfod/CMakeFiles/obj.llvm-debuginfod.dir/llvm-debuginfod.cpp.o:(std::_Function_handler<void (), llvm_debuginfod_main(int, char**, llvm::ToolContext const&)::$_0>::_M_invoke(std::_Any_data const&))

ld.lld: error: undefined symbol: llvm::DebuginfodLog::pop()
>>> referenced by llvm-debuginfod.cpp
>>>               tools/llvm-debuginfod/CMakeFiles/obj.llvm-debuginfod.dir/llvm-debuginfod.cpp.o:(std::_Function_handler<void (), llvm_debuginfod_main(int, char**, llvm::ToolContext const&)::$_1>::_M_invoke(std::_Any_data const&))
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

May I ask what is the solution?

Andarwinux commented 3 months ago
    -DLLVM_TOOL_LLVM_DEBUGINFO_ANALYZER_BUILD=OFF
    -DLLVM_TOOL_LLVM_DEBUGINFOD_BUILD=OFF
    -DLLVM_TOOL_LLVM_DEBUGINFOD_FIND_BUILD=OFF

For static builds and especially LTO static builds, some llvm-tools usually fail to build or are extremely time-consuming, what I do is to look for their corresponding build options in CMakeCache and turn them off.

lateautumn233 commented 3 months ago

https://github.com/llvm/llvm-project/blob/03b1a0c2a72dd24943642ef15e6c046d982643c2/llvm/tools/llvm-debuginfod/CMakeLists.txt#L17

I don't understand why or how to do it