Errors building LLVM for CIRCT

Hello,
I am trying to build https://github.com/llvm/circt (CIRCT, an llvm incubator project). Steps that I took as follows-

git clone git@github.com:circt/circt.git
cd circt
git submodule init
git submodule update
cd circt
mkdir llvm/build
cd llvm/build
cmake -DLLVM_ENABLE_PROJECTS=“mlir” -DLLVM_TARGETS_TO_BUILD=“X86” -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_LLD=ON -DLLVM_BUILD_TOOLS=OFF -DLLVM_ENABLE_UNWIND_TABLES=OFF -DLLVM_ENABLE_LTO=ON -DBUILD_SHARED_LIBS=ON -DLLVM_BUILD_LLVM_DYLIB=ON …/llvm
make

errors are-
ld.lld: error: undefined symbol: llvm::shouldOptimizeForSize(llvm::MachineBasicBlock const*, llvm::ProfileSummaryInfo*, llvm::MBFIWrapper*, llvm::PGSOQueryType)

referenced by ld-temp.o
lto.tmp:(llvm::BranchFolder::OptimizeFunction(llvm::MachineFunction&, llvm::TargetInstrInfo const*, llvm::TargetRegisterInfo const*, llvm::MachineLoopInfo*, bool))
referenced by ld-temp.o
lto.tmp:(llvm::BranchFolder::TryTailMergeBlocks(llvm::MachineBasicBlock*, llvm::MachineBasicBlock*, unsigned int))
referenced by ld-temp.o
lto.tmp:(llvm::BranchFolder::TryTailMergeBlocks(llvm::MachineBasicBlock*, llvm::MachineBasicBlock*, unsigned int))
referenced 3 more times

ld.lld: error: undefined symbol: llvm::shouldOptimizeForSize(llvm::MachineFunction const*, llvm::ProfileSummaryInfo*, llvm::MachineBlockFrequencyInfo const*, llvm::PGSOQueryType)

referenced by ld-temp.o
lto.tmp:((anonymous namespace)::MachineBlockPlacement::runOnMachineFunction(llvm::MachineFunction&))

ld.lld: error: undefined symbol: llvm::shouldOptimizeForSize(llvm::MachineBasicBlock const*, llvm::ProfileSummaryInfo*, llvm::MachineBlockFrequencyInfo const*, llvm::PGSOQueryType)

referenced by ld-temp.o
lto.tmp:((anonymous namespace)::MachineCombiner::runOnMachineFunction(llvm::MachineFunction&))

ld.lld: error: undefined symbol: llvm::makeVarLocBasedLiveDebugValues()

referenced by ld-temp.o
lto.tmp:(LiveDebugValues::runOnMachineFunction(llvm::MachineFunction&))
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/build.make:2933: lib/libLLVMCodeGen.so.12git] Error 1
make[1]: *** [CMakeFiles/Makefile2:13675: lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/all] Error 2
make: *** [Makefile:171: all] Error 2

CMakeOutput.log
CMakeError.log

I also tried second configuration of cmake as mention in documention of CIRCT.
cmake -G Ninja …/llvm
-DLLVM_ENABLE_PROJECTS=“mlir”
-DLLVM_TARGETS_TO_BUILD=“X86;RISCV”
-DLLVM_ENABLE_ASSERTIONS=ON
-DCMAKE_BUILD_TYPE=Release
ninja
but still have errors.

Someone know the reason for these errors or confirmed on their machine, please?

Hi Shivam,

Probably this is an error with BUILD_SHARED_LIBS=ON. However, in order to disable it you either need to remove your build directory completely, or explicitly specify BUILD_SHARED_LIBS=OFF in the second configuration of cmake.

Steve

Thanks, Steve for the help. LLVM and CIRCT both build correctly this time.

I started from a new directory with the same CMake option as given in the documentation. But this time run make single-threaded so I believe undefine symbol error occurs because linker is strated linking while compiler still compiling files for creating the archive.

Usually undefined symbols happen because library A includes library B and library B includes library C. When statically linking, it is sufficient to have A depend on B and B depend on C, but when using shared libraries, A needs to depend on B and C. I almost always build with shared libraries, but developers who build exclusively with static libraries can often create such situations. The solution is to add the correct library dependencies to the CMake files.

Yes, that should be correct reasoning.
Thanks.