elbywan / crystalline

A Language Server Protocol implementation for Crystal. 🔮
MIT License
424 stars 21 forks source link

Compilation error "Undefined symbols" in llvm including AtomicCmpXchgInst and buildModulesSummaryIndex #14

Closed hraftery closed 3 years ago

hraftery commented 3 years ago

For what it's worth, with latest everything (Crystal 0.35.1, macos 11.0.1, LLVM 11.0.0), crystalline seems to fail to build with this error:

$ env LLVM_CONFIG=/usr/local/opt/llvm/bin/llvm-config crystal build ./src/crystalline.cr  -o ./bin/crystalline --release --no-debug --progress -Dpreview_mt
Undefined symbols for architecture x86_64:      
  "llvm::AtomicCmpXchgInst::AtomicCmpXchgInst(llvm::Value*, llvm::Value*, llvm::Value*, llvm::AtomicOrdering, llvm::AtomicOrdering, unsigned char, llvm::Instruction*)", referenced from:
      llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>::CreateAtomicCmpXchg(llvm::Value*, llvm::Value*, llvm::Value*, llvm::AtomicOrdering, llvm::AtomicOrdering, unsigned char) in llvm_ext.o
  "llvm::buildModuleSummaryIndex(llvm::Module const&, std::__1::function<llvm::BlockFrequencyInfo* (llvm::Function const&)>, llvm::ProfileSummaryInfo*)", referenced from:
      _LLVMExtWriteBitcodeWithSummaryToFile in llvm_ext.o
     (maybe you meant: llvm::buildModuleSummaryIndex(llvm::Module const&, std::__1::function<llvm::BlockFrequencyInfo* (llvm::Function const&)>, llvm::ProfileSummaryInfo*, std::__1::function<llvm::StackSafetyInfo const* (llvm::Function const&)>))
  "llvm::DIBuilder::createCompileUnit(unsigned int, llvm::DIFile*, llvm::StringRef, bool, llvm::StringRef, unsigned int, llvm::StringRef, llvm::DICompileUnit::DebugEmissionKind, unsigned long long, bool, bool, llvm::DICompileUnit::DebugNameTableKind, bool)", referenced from:
      _LLVMExtDIBuilderCreateCompileUnit in llvm_ext.o
     (maybe you meant: llvm::DIBuilder::createCompileUnit(unsigned int, llvm::DIFile*, llvm::StringRef, bool, llvm::StringRef, unsigned int, llvm::StringRef, llvm::DICompileUnit::DebugEmissionKind, unsigned long long, bool, bool, llvm::DICompileUnit::DebugNameTableKind, bool, llvm::StringRef, llvm::StringRef))
ld: symbol(s) not found for architecture x86_64
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `/usr/local/opt/llvm/bin/clang "${@}" -o /Users/liteyear/Downloads/crystalline/bin/crystalline  -rdynamic -L/usr/local/Cellar/crystal/0.35.1_1/embedded/lib -L/usr/local/lib -L/usr/local/Cellar/libyaml/0.2.5/lib -lyaml -lz `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` /usr/local/Cellar/crystal/0.35.1_1/src/llvm/ext/llvm_ext.o `"/usr/local/opt/llvm/bin/llvm-config" --libs --system-libs --ldflags 2> /dev/null` -lstdc++ -lpcre -lgc -lpthread /usr/local/Cellar/crystal/0.35.1_1/src/ext/libcrystal.a -L/usr/local/Cellar/libevent/2.1.12/lib -levent_pthreads -levent -L/usr/local/Cellar/libevent/2.1.12/lib -levent -liconv -ldl`

Seems to be an LLVM change, but Homebrew doesn't have LLVM@10, so not sure if it's worth rolling back to another version?

elbywan commented 3 years ago

Hi @hraftery,

For what it's worth, with latest everything (Crystal 0.35.1, macos 11.0.1, LLVM 11.0.0), crystalline seems to fail to build with this error:

Yes this is an issue with crystal itself that does not support llvm 11. (see: https://github.com/crystal-lang/crystal/issues/9809).

Seems to be an LLVM change, but Homebrew doesn't have LLVM@10, so not sure if it's worth rolling back to another version?

Using the llvm@9 formula should be fine until the above issue is solved.

I'll close as a duplicate since there is another issue regarding LLVM.

hraftery commented 3 years ago

Yep, that did it! Embarrassingly enough I only had to add @9 to the build command, since it turns out I already had it installed. Somehow took me 19 days to verify though...

git clone https://github.com/elbywan/crystalline
cd crystalline
mkdir bin
shards install
env LLVM_CONFIG=/usr/local/opt/llvm@9/bin/llvm-config crystal build ./src/crystalline.cr  -o ./bin/crystalline --release --no-debug --progress -Dpreview_mt

Easy and mess free!