[PATCH] D36211: [cmake] Expose the dependencies of ExecutionEngine as PUBLIC

Michał Górny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 1 23:12:04 PDT 2017


mgorny created this revision.

Expose the dependencies of LLVMExecutionEngine library as PUBLIC rather
than PRIVATE when building a shared library. This is necessary because
the library is not contained but exposes API of other LLVM libraries via
its headers.

This causes other libraries to fail to link if the linker verifies for
correctness of -l flags (i.e. fails on indirect dependencies). This e.g.
happens when building LLDB against shared LLVM:

  lib64/liblldbExpression.a(IRExecutionUnit.cpp.o):(.data.rel.ro._ZTIN4llvm18MCJITMemoryManagerE[_ZTIN4llvm18MCJITMemoryManagerE]+0x10): undefined reference to `typeinfo for llvm::RuntimeDyld::MemoryManager'
  lib64/liblldbExpression.a(IRExecutionUnit.cpp.o):(.data.rel.ro._ZTVN4llvm18MCJITMemoryManagerE[_ZTVN4llvm18MCJITMemoryManagerE]+0x60): undefined reference to `llvm::RuntimeDyld::MemoryManager::anchor()'
  lib64/liblldbExpression.a(IRExecutionUnit.cpp.o):(.data.rel.ro._ZTVN12lldb_private15IRExecutionUnit13MemoryManagerE[_ZTVN12lldb_private15IRExecutionUnit13MemoryManagerE]+0x48): undefined reference to `llvm::RTDyldMemoryManager::deregisterEHFrames()'
  lib64/liblldbExpression.a(IRExecutionUnit.cpp.o):(.data.rel.ro._ZTVN12lldb_private15IRExecutionUnit13MemoryManagerE[_ZTVN12lldb_private15IRExecutionUnit13MemoryManagerE]+0x60): undefined reference to `llvm::RuntimeDyld::MemoryManager::anchor()'
  lib64/liblldbExpression.a(IRExecutionUnit.cpp.o):(.data.rel.ro._ZTVN12lldb_private15IRExecutionUnit13MemoryManagerE[_ZTVN12lldb_private15IRExecutionUnit13MemoryManagerE]+0xd0): undefined reference to `llvm::JITSymbolResolver::anchor()'
  collect2: error: ld returned 1 exit status

Declaring the dependencies as PUBLIC guarantees that any package using
the ExecutionEngine library will also get explicit -l flags for
the dependent libraries guaranteeing that the symbols exposed in headers
could be resolved.

The patch was originally written for me by @beanz but it seems that he
never submitted it.


Repository:
  rL LLVM

https://reviews.llvm.org/D36211

Files:
  cmake/modules/AddLLVM.cmake
  lib/ExecutionEngine/CMakeLists.txt


Index: lib/ExecutionEngine/CMakeLists.txt
===================================================================
--- lib/ExecutionEngine/CMakeLists.txt
+++ lib/ExecutionEngine/CMakeLists.txt
@@ -1,4 +1,9 @@
-
+# Execution engine is not neat and contained like other LLVM libraries. To work
+# around this if BUILD_SHARED_LIBS is set we need to force the linkage type of
+# LLVMExecutionEngine's dependencies to PUBLIC.
+if(BUILD_SHARED_LIBS)
+  set(dependency_hack DEPENDENCY_LINK_TYPE PUBLIC)
+endif()
 
 add_llvm_library(LLVMExecutionEngine
   ExecutionEngine.cpp
@@ -12,6 +17,7 @@
 
   DEPENDS
   intrinsics_gen
+  ${dependency_hack}
   )
 
 add_subdirectory(Interpreter)
Index: cmake/modules/AddLLVM.cmake
===================================================================
--- cmake/modules/AddLLVM.cmake
+++ cmake/modules/AddLLVM.cmake
@@ -358,7 +358,7 @@
 function(llvm_add_library name)
   cmake_parse_arguments(ARG
     "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME"
-    "OUTPUT_NAME;PLUGIN_TOOL"
+    "OUTPUT_NAME;PLUGIN_TOOL;DEPENDENCY_LINK_TYPE"
     "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
     ${ARGN})
   list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
@@ -536,14 +536,16 @@
     get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
   endif()
 
-  if(ARG_STATIC)
-    set(libtype INTERFACE)
-  else()
-    # We can use PRIVATE since SO knows its dependent libs.
-    set(libtype PRIVATE)
+  if(NOT ARG_DEPENDENCY_LINK_TYPE)
+    if(ARG_STATIC)
+      set(ARG_DEPENDENCY_LINK_TYPE INTERFACE)
+    else()
+      # We can use PRIVATE since SO knows its dependent libs.
+      set(ARG_DEPENDENCY_LINK_TYPE PRIVATE)
+    endif()
   endif()
 
-  target_link_libraries(${name} ${libtype}
+  target_link_libraries(${name} ${ARG_DEPENDENCY_LINK_TYPE}
       ${ARG_LINK_LIBS}
       ${lib_deps}
       ${llvm_libs}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36211.109276.patch
Type: text/x-patch
Size: 1874 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170802/1d5b45f2/attachment.bin>


More information about the llvm-commits mailing list