Statically link to libllvm

Submitted by Rebecca N. Palmer on Jan. 6, 2019, 11:24 p.m.

Details

Message ID 84cdd6cd-d424-7285-4802-b1498b2de609@zoho.com
State New
Series "Statically link to libllvm"
Headers show

Commit Message

Rebecca N. Palmer Jan. 6, 2019, 11:24 p.m.
Dynamically linked LLVM crashes when two libraries using the same
LLVM version (e.g. Beignet and another OpenCL ICD) are dlopen()ed
in the same application, due to shared global state:

https://bugs.llvm.org/show_bug.cgi?id=30587
https://bugs.debian.org/852746

Signed-off-by: Rebecca N. Palmer <rebecca_palmer@zoho.com>

Patch hide | download patch | download mbox

--- a/CMake/FindLLVM.cmake
+++ b/CMake/FindLLVM.cmake
@@ -87,18 +87,34 @@  execute_process(
   OUTPUT_STRIP_TRAILING_WHITESPACE
 )
 
+if (LLVM_VERSION_NODOT VERSION_GREATER 38)
+execute_process(
+  COMMAND ${LLVM_CONFIG_EXECUTABLE} --libs --link-static
+  OUTPUT_VARIABLE LLVM_MODULE_LIBS
+  OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+else (LLVM_VERSION_NODOT VERSION_GREATER 38)
 execute_process(
   COMMAND ${LLVM_CONFIG_EXECUTABLE} --libs
   OUTPUT_VARIABLE LLVM_MODULE_LIBS
   OUTPUT_STRIP_TRAILING_WHITESPACE
 )
+endif (LLVM_VERSION_NODOT VERSION_GREATER 38)
 
 if (LLVM_VERSION_NODOT VERSION_GREATER 34)
+if (LLVM_VERSION_NODOT VERSION_GREATER 38)
+execute_process(
+  COMMAND ${LLVM_CONFIG_EXECUTABLE} --system-libs --link-static
+  OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_ORIG
+  OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+else (LLVM_VERSION_NODOT VERSION_GREATER 38)
 execute_process(
   COMMAND ${LLVM_CONFIG_EXECUTABLE} --system-libs
   OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_ORIG
   OUTPUT_STRIP_TRAILING_WHITESPACE
 )
+endif (LLVM_VERSION_NODOT VERSION_GREATER 38)
 if (LLVM_SYSTEM_LIBS_ORIG)
 string(REGEX REPLACE " *\n" "" LLVM_SYSTEM_LIBS ${LLVM_SYSTEM_LIBS_ORIG})
 endif (LLVM_SYSTEM_LIBS_ORIG)