Question on symbol lookup error (VersionTuple)

Hi,

i am currently working on an out-of-source pass to manipulate CUDA applications. Because since CUDA 9.2 the launch mechanism has changed, i check the CUDA SDK version from within my module pass. My pass fails when i use opt to run it on IR code:
`symbol lookup error: /opt/cuda-flux/lib/libcuda_flux_pass.so: undefined symbol: _ZN4llvmlsERNS_11raw_ostreamERKNS_12VersionTupleE`

This error does not happen when i register my pass with clang. When looking up the symbol tables with nm it shows me that the symbol is not found (which i expected from the error i got):

$ nm --dynamic /opt/cuda-flux/lib/libcuda_flux_pass.so | grep _ZN4llvmlsERNS_11raw_ostreamERKNS_12VersionTupleE
                  U _ZN4llvmlsERNS_11raw_ostreamERKNS_12VersionTupleE

When making the same lookup on the clang binary the symbol is found. However, it is not found when doing the lookup on the opt binary. Is this on purpose? If yes, what would be the best way to fix this? Linking the LLVMSupport lib does not really work because this will lead to command line option registered multiple times.

Here some additional info to give some context info:
- using llvm 10.0 tag from github
- cmake config:
cmake -DLLVM_ENABLE_PROJECTS="clang;openmp" -DCMAKE_INSTALL_PREFIX=/opt/llvm-10.0 -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_DOXYGEN=OFF -DLLVM_BUILD_DOCS=OFF -GNinja -DLLVM_INSTALL_BINUTILS_SYMLINKS=ON ../llvm

Best Regards
Lorenz

I was able to solve the problem by rebuilding llvm with the cmake flag BUILD_SHARED_LIBS=ON. I am not entirely sure why this works because i did not link against the LLVMSupport.so. For any readers that are trying to solve a similar problem, be aware that i am building my pass out-of-source.

Any additional comments on why excatly this works are very welcome :wink:

Best Regards
Lorenz

Hi @Lorenz_Braun1
After reading your Question and It’s solution I think that I am having a similar sort of problem

I have built LLVM using the following:
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=On -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PROJECTS=‘clang’ -DLLVM_ENABLE_RUNTIMES=‘libcxx;libcxxabi’ …/llvm_source/llvm-project/llvm

opt --version (outputs):
LLVM (http://llvm.org/):
LLVM version 16.0.0git
Optimized build.
Default target: x86_64-unknown-linux-gnu
Host CPU: skylake

I am trying to build the passes by example given at:

while the running the above specific pass:
$OPT_DIR/opt -load-pass-plugin ./libOpcodeCounter.so --passes=“print” -disable-output input_for_cc.bc

i get the following error:
/home/abkh/Downloads/BUILD_llvm/bin/opt: symbol lookup error: ./libOpcodeCounter.so: undefined symbol: ZN4llvm15AnalysisManagerINS_8FunctionEJEE13getResultImplEPNS_11AnalysisKeyERS1

My BUILD(llvm) folder is NOT inside the llvm_source and is present outside(in parallel)

Any queues on what I might be doing wrong?
Thankyou and Regards
abkh