Open mscheong01 opened 6 months ago
The LLVM component transformutils
was added to the wrong library in the CMakeLists. I must have messed it up while merging changes from upstream...
Could you try editing the repo/src/lib/CMakeLists.txt
so that transformutils
is added to the library SCBackend
, and see if it works?
@strikef The error seems to persist after adding transformutils to SCBackend (Although I might have modified the setup incorrectly)
-llvm_map_components_to_libnames(backend_llvm_libs analysis scalaropts)
+llvm_map_components_to_libnames(backend_llvm_libs analysis scalaropts transformutils)
When you run
ls <llvm-install-dir>/lib | grep LLVMTransformUtils
, does it show you the .dylib file?
Yes, it does
add_library(SCBackend backend.cpp)
target_include_directories(SCBackend PRIVATE ${LLVM_INCLUDE_DIRS})
llvm_map_components_to_libnames(backend_llvm_libs analysis scalaropts transformutils)
target_link_libraries(SCBackend PRIVATE
SCPrintIR SCBackendAssembly SCBackendAnalysis
SCBackendEmitter SCBackendSymbol SCBackendFreezeElimPass
SCBackendConstExprElimPass SCBackendConstSplitPass SCBackendConstMap
SCBackendGEPElimPass SCBackendGVElimPass SCBackendAllocaElimPass
SCBackendGEPConstCombPass SCBackendPHIPreprocessPass SCBackendPoisonElimPass
SCBackendSextEliminatePass SCBackendTruncAdjustPass SCBackendUndefElimPass
SCBackendRegAllocPass ${backend_llvm_libs})
This is the setup that compiles & links without error in my Mac, and I don't see any difference between this and your fix. This is really puzzling...
Could you give me the full list of files (or libraries) that fail to link?
This is the full error log after adding transformutils to SCBackend:
[38/51] Linking CXX shared library src/lib/opt/libArithmeticPass.dylib
FAILED: src/lib/opt/libArithmeticPass.dylib
: && /Users/wjdalstn/llvm-18.1.0/bin/clang++ -O3 -DNDEBUG -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -mmacosx-version-min=14.4 -dynamiclib -Wl,-headerpad_max_install_names -fuse-ld=/Users/wjdalstn/llvm-18.1.0/bin/ld64.lld -o src/lib/opt/libArithmeticPass.dylib -install_name @rpath/libArithmeticPass.dylib src/lib/opt/CMakeFiles/ArithmeticPass.dir/arithmetic_pass.cpp.o -L/Users/wjdalstn/llvm-18.1.0/lib -Wl,-rpath,/Users/wjdalstn/llvm-18.1.0/lib /Users/wjdalstn/llvm-18.1.0/lib/libLLVMPasses.dylib /Users/wjdalstn/llvm-18.1.0/lib/libLLVMAnalysis.dylib /Users/wjdalstn/llvm-18.1.0/lib/libLLVMCore.dylib /Users/wjdalstn/llvm-18.1.0/lib/libLLVMSupport.dylib && :
ld64.lld: error: undefined symbol: llvm::ReplaceInstWithInst(llvm::Instruction*, llvm::Instruction*)
>>> referenced by src/lib/opt/CMakeFiles/ArithmeticPass.dir/arithmetic_pass.cpp.o:(symbol sc::opt::arithmetic_pass::ArithmeticPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&)+0x644)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
[43/51] Building CXX object src/lib/op...es/LoopToRcall.dir/loop_to_rcall.cpp.o
ninja: build stopped: subcommand failed.
You have to link the LLVM library component to each optimization pass you have implemented if you're using components other than the ones specified in src/lib/opt/CMakeLists.txt
.
You may add the component to all optimization passes
- llvm_map_components_to_libnames(pass_llvm_libs passes analysis core support)
+ llvm_map_components_to_libnames(pass_llvm_libs passes analysis core support transformutils)
, or add the component only to the passes that actually requires it.
add_opt_pass(ArithmeticPass arithmetic_pass.cpp)
+ llvm_map_components_to_libnames(arith_pass_llvm_libs transformutils)
+ target_link_libraries(ArithmeticPass PRIVATE ${arith_pass_llvm_libs})
Unlike backend, this is not something we can fix as we cannot predict the components to be used in advance, so there won't be any update to apply this fix.
@strikef adding the components for each pass explicitly didn't turn out to work for me (probably because I did something wrong). But adding these two lines to opt/CMakeLists.txt solved the error.
set(NO_RTTI "-fno-rtti")
add_definitions(${NO_RTTI})
reference: https://discourse.llvm.org/t/undefined-reference-to-typeinfo-for-llvm-genericoptionvalue/71526/3
The error message did not tell anything about type error, and LLVM built with the script we distributed actually has RTTI enabled. The fact that adding RTTI fixed the problem is quite surprising... (puzzled)
I've reported this in the former issue where this error came up
but the same error seems to persist on my setup even after the patch was updated to our team compiler 😢