undefined symbols during linking LLDB 4.0 RC1

Hello, I update my building scripts to build LLVM 4.0 RC1 (with clang, lldb, libc++, libc++abi, lld) on CentOS 6 and I got a lot of undefined symbols during linking LLDB.

I’m using clang-3.9 and this configuration:

-DLLVM_TARGETS_TO_BUILD=“X86”
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=/usr/bin/clang
-DCMAKE_CXX_COMPILER=/usr/bin/clang++
-DCMAKE_EXE_LINKER_FLAGS="-lc++abi -lc++"
-DCMAKE_EXE_LINKER_FLAGS="-lc++abi -lc++"
-DCMAKE_SHARED_LINKER_FLAGS="-lc++abi -lc++"
-DCMAKE_MODULE_LINKER_FLAGS="-lc++abi -lc++"
-DLLVM_ENABLE_LIBCXX=ON
-DLLVM_LIBDIR_SUFFIX=64
-DCMAKE_INSTALL_PREFIX=/usr
-DLLDB_DISABLE_PYTHON=1
-DTARGET_TRIPLE=“x86_64-pc-linux-gnu”
-DLIBCXX_INSTALL_EXPERIMENTAL_LIBRARY=ON
-DLLVM_ENABLE_LLD=ON

List of undefined symbols and invocation is next:

[ 89%] Linking CXX executable …/…/…/…/bin/lldb
cd /opt/bamboo-agent-01/xml-data/build-dir/CLANG-BFRH-JOB1/build/RELEASE_40_RC1/Linux/x86_64/llvm_build_phase1/tools/lldb/tools/driver && /usr/local/bin/cmake -E cmake_link_script CMakeFiles/lldb.dir/link.txt --verbose=1
/usr/bin/clang++ -stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -Werror=date-time -std=c++11 -ffunction-sections -fdata-sections -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -O3 -DNDEBUG -lc++abi -lc++ -stdlib=libc++ -fuse-ld=lld -Wl,-allow-shlib-undefined -Wl,-O3 -Wl,–gc-sections CMakeFiles/lldb.dir/Driver.cpp.o CMakeFiles/lldb.dir/Platform.cpp.o -o …/…/…/…/bin/lldb-4.0.0 …/…/…/…/lib64/libLLVMX86CodeGen.a …/…/…/…/lib64/libLLVMX86AsmPrinter.a …/…/…/…/lib64/libLLVMX86AsmParser.a …/…/…/…/lib64/libLLVMX86Desc.a …/…/…/…/lib64/libLLVMX86Info.a …/…/…/…/lib64/libLLVMX86Disassembler.a …/…/…/…/lib64/libLLVMInterpreter.a …/…/…/…/lib64/libLLVMAsmParser.a …/…/…/…/lib64/libLLVMBitReader.a …/…/…/…/lib64/libLLVMBitWriter.a …/…/…/…/lib64/libLLVMCodeGen.a …/…/…/…/lib64/libLLVMDemangle.a …/…/…/…/lib64/libLLVMipo.a …/…/…/…/lib64/libLLVMSelectionDAG.a …/…/…/…/lib64/libLLVMBitReader.a …/…/…/…/lib64/libLLVMMC.a …/…/…/…/lib64/libLLVMMCJIT.a …/…/…/…/lib64/libLLVMCore.a …/…/…/…/lib64/libLLVMMCDisassembler.a …/…/…/…/lib64/libLLVMExecutionEngine.a …/…/…/…/lib64/libLLVMRuntimeDyld.a …/…/…/…/lib64/libLLVMOption.a …/…/…/…/lib64/libLLVMSupport.a …/…/…/…/lib64/libLLVMCoverage.a …/…/…/…/lib64/libLLVMTarget.a -lpthread …/…/…/…/lib64/liblldb.so.4.0.0 …/…/…/…/lib64/libLLVMAsmPrinter.a …/…/…/…/lib64/libLLVMDebugInfoCodeView.a …/…/…/…/lib64/libLLVMDebugInfoMSF.a …/…/…/…/lib64/libLLVMGlobalISel.a …/…/…/…/lib64/libLLVMX86AsmPrinter.a …/…/…/…/lib64/libLLVMX86Utils.a …/…/…/…/lib64/libLLVMX86Info.a …/…/…/…/lib64/libLLVMCodeGen.a …/…/…/…/lib64/libLLVMBitWriter.a …/…/…/…/lib64/libLLVMScalarOpts.a …/…/…/…/lib64/libLLVMIRReader.a …/…/…/…/lib64/libLLVMAsmParser.a …/…/…/…/lib64/libLLVMInstCombine.a …/…/…/…/lib64/libLLVMInstrumentation.a …/…/…/…/lib64/libLLVMLinker.a …/…/…/…/lib64/libLLVMVectorize.a …/…/…/…/lib64/libLLVMTransformUtils.a …/…/…/…/lib64/libLLVMTarget.a …/…/…/…/lib64/libLLVMAnalysis.a …/…/…/…/lib64/libLLVMObject.a …/…/…/…/lib64/libLLVMBitReader.a …/…/…/…/lib64/libLLVMMCParser.a …/…/…/…/lib64/libLLVMMC.a …/…/…/…/lib64/libLLVMProfileData.a …/…/…/…/lib64/libLLVMCore.a …/…/…/…/lib64/libLLVMSupport.a …/…/…/…/lib64/libLLVMDemangle.a -lrt -ldl -ltinfo -lpthread -lz -lm -Wl,-rpath,"$ORIGIN/…/lib64"
undefined symbol: _ZN4lldb10SBDebugger10InitializeEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger11SetUseColorEb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger15GetInstanceNameEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger16GetVersionStringEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger16SetTerminalWidthEj in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger16SkipAppInitFilesEb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger17SkipLLDBInitFilesEb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger18GetErrorFileHandleEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger18SetCloseInputOnEOFEb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger18SetErrorFileHandleEP8_IO_FILEb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger18SetInputFileHandleEP8_IO_FILEb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger19GetOutputFileHandleEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger19SetOutputFileHandleEP8_IO_FILEb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger20GetScriptingLanguageEPKc in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger20SetUseExternalEditorEb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger21GetCommandInterpreterEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger21RunCommandInterpreterEbb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: ZN4lldb10SBDebugger21RunCommandInterpreterEbbRNS_30SBCommandInterpreterRunOptionsERiRbS4 in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger22DispatchInputInterruptEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger22GetDefaultArchitectureEPcm in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger22SaveInputTerminalStateEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger22SetDefaultArchitectureEPKc in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: ZN4lldb10SBDebugger24GetInternalVariableValueEPKcS2 in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger25RestoreInputTerminalStateEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger6CreateEb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: ZN4lldb10SBDebugger7DestroyERS0 in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger7RunREPLENS_12LanguageTypeEPKc in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger8GetAsyncEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger8SetAsyncEb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebugger9TerminateEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBDebuggerD1Ev in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBFileSpec19AppendPathComponentEPKc in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBFileSpec25ResolveExecutableLocationEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBFileSpecC1EPKc in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBFileSpecC1EPKcb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb10SBFileSpecD1Ev in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb12SBStringList16GetStringAtIndexEm in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb12SBStringListD1Ev in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb13SBBroadcasterC2EPKc in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb13SBBroadcasterD2Ev in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb17SBLanguageRuntime25GetLanguageTypeFromStringEPKc in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb20SBCommandInterpreter24GetArgumentTypeAsCStringENS_19CommandArgumentTypeE in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb20SBCommandInterpreter29SourceInitFileInHomeDirectoryERNS_21SBCommandReturnObjectE in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb20SBCommandInterpreterD1Ev in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb21SBCommandReturnObject8PutErrorEP8_IO_FILE in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb21SBCommandReturnObject9PutOutputEP8_IO_FILE in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb21SBCommandReturnObjectC1Ev in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb21SBCommandReturnObjectD1Ev in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb30SBCommandInterpreterRunOptions14SetStopOnCrashEb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb30SBCommandInterpreterRunOptions14SetStopOnErrorEb in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb30SBCommandInterpreterRunOptionsC1Ev in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb30SBCommandInterpreterRunOptionsD1Ev in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb7SBError24SetErrorStringWithFormatEPKcz in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb7SBErrorC1Ev in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb7SBErrorD1Ev in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb8SBHostOS13ThreadCreatedEPKc in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb8SBHostOS17GetLLDBPythonPathEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb8SBHostOS20GetUserHomeDirectoryEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb8SBStream6PrintfEPKcz in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb8SBStream7GetDataEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb8SBStream7GetSizeEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb8SBStreamC1Ev in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZN4lldb8SBStreamD1Ev in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZNK4lldb10SBFileSpec12GetDirectoryEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZNK4lldb10SBFileSpec6ExistsEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZNK4lldb10SBFileSpec7GetPathEPcm in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZNK4lldb10SBFileSpec7IsValidEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZNK4lldb12SBStringList7GetSizeEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZNK4lldb7SBError10GetCStringEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZNK4lldb7SBError4FailEv in CMakeFiles/lldb.dir/Driver.cpp.o
undefined symbol: _ZNK4lldb7SBError8GetErrorEv in CMakeFiles/lldb.dir/Driver.cpp.o
clang-3.9: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/lldb-4.0.0] Error 1
make[2]: Leaving directory /opt/bamboo-agent-01/xml-data/build-dir/CLANG-BFRH-JOB1/build/RELEASE_40_RC1/Linux/x86_64/llvm_build_phase1' make[1]: *** [tools/lldb/tools/driver/CMakeFiles/lldb.dir/all] Error 2 make[1]: Leaving directory /opt/bamboo-agent-01/xml-data/build-dir/CLANG-BFRH-JOB1/build/RELEASE_40_RC1/Linux/x86_64/llvm_build_phase1’
make: *** [all] Error 2

Hi Hana,

these are all symbols that should be exposed by liblldb (which is
present on your link line), so I am not sure what could be the problem
here.

Could you inspect the symbols exposed by liblldb (objdump -T
lib64/liblldb.so) to see if the symbols are present there?

Also, to help us narrow down the problem could you prune the list of
cmake flags you are configuring the build with (i.e. remove everything
libc++ and lld related) and try to rebuild that way?

thanks,
pavel

Hi Pavel,

thank you for you response.

objdump -T showed that there are no symbols defined in liblldb.so.

After few compilations I found that problem is with linking with LLD (-DLLVM_ENABLE_LLD=ON) without the directive everything is ok.

Hana

This is interesting. I am not sure why LLD should have a problem with
linking liblldb.so.

I guess it has something to do with the version script we use to
restrict the exported API, but I am not sure whether that is an lld
bug, or a bug in how we are setting it up.

Adding Ruiu, in case he has any insight.

cheers,
pl

I looked and only liblldb.so library is using add_llvm_symbol_exports function from cmake/modules/AddLLVM.cmake.

Maybe there is a problem with calling lld somehow with version script. The problem can be there for long time 4.0RC1 is my first build with LLD previous ones was with GOLD.

H.

libclang does the same thing as well, however it does it indirectly by
setting the LLVM_EXPORTED_SYMBOL_FILE variable. I am not sure why
would that make any difference, but maybe you can try if linking
liblldb that way fixes anything (or indeed, checking whether libclang
exports the expected symbols).

Apart from that, I don't really have any good idea.