jrprice / Oclgrind

An OpenCL device simulator and debugger
Other
346 stars 63 forks source link

Dynamic linking to LLVM8 doesn't work #170

Open dextorious opened 5 years ago

dextorious commented 5 years ago

Following the workaround given in #164 I changed the CMakeLists.txt file on the latest master commit of Oclgrind to link to LLVM dynamically on Manjaro Linux (which is basically Arch). Unfortunately, it doesn't compile:

[  9%] Built target OPENCL_C_HEADERS
[ 47%] Built target oclgrind
[ 52%] Built target oclgrind-rt-icd
[ 58%] Built target oclgrind-rt
[ 61%] Built target oclgrind-exe
[ 63%] Linking CXX executable oclgrind-kernel
/usr/bin/ld: CMakeFiles/oclgrind-kernel.dir/src/kernel/Simulation.cpp.o: undefined reference to symbol '_ZN4llvm24DisableABIBreakingChecksE@@LLVM_8'
/usr/bin/ld: /usr/lib/libLLVM-8.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/oclgrind-kernel.dir/build.make:100: oclgrind-kernel] Error 1
make[1]: *** [CMakeFiles/Makefile2:290: CMakeFiles/oclgrind-kernel.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

Is there any reasonable workaround for this, or is it a case of ABI incompatibility that needs to be addressed?

jrprice commented 4 years ago

Apologies for the delay - finally had a chance to look at this today.

To fix this we need to make LLVM part of the the PUBLIC interface in CMake, so that LLVM gets linked into the executables as well. Here's the patch I used to get this building on a Manjaro Docker image:


index df4323d..41815e1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -216,8 +216,9 @@ add_library(oclgrind ${CORE_LIB_TYPE}
 target_link_libraries(oclgrind PRIVATE ${CORE_EXTRA_LIBS}
   clangCodeGen clangFrontend clangSerialization clangDriver
   clangParse clangSema clangAnalysis clangEdit clangAST clangASTMatchers
-  clangLex clangBasic
-  ${LLVM_LIBS})
+  clangLex clangBasic)
+
+target_link_libraries(oclgrind PUBLIC LLVM)

 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
   target_link_libraries(oclgrind PRIVATE Version)```
robstewart57 commented 4 years ago

@jrprice I was also affected by https://github.com/jrprice/Oclgrind/issues/164#issuecomment-477168536 .

Linux, Fedora 31.

This change fixed it for me also:

-  clangLex clangBasic
-  ${LLVM_LIBS})
+  clangLex clangBasic)
+
+target_link_libraries(oclgrind PUBLIC LLVM)