[PATCH] D76642: Make static linking for LLVM plugins more reliable.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 23 15:16:32 PDT 2020


efriedma created this revision.
efriedma added reviewers: Meinersbur, serge-sans-paille, mehdi_amini, beanz.
Herald added a subscriber: mgorny.
Herald added a project: LLVM.

Linking a static library into a binary doesn't do anything if none of the symbols are used. For some combinations of plugin/host binary, we apparently get lucky (I think due to inline definitions from headers). But in general, it won't work.

To make sure this works properly, use an object library from CMake.

This is a bit hacky; suggestions welcome for a better way to solve the issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76642

Files:
  llvm/cmake/modules/AddLLVM.cmake


Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -925,6 +925,7 @@
     get_property(llvm_plugin_targets GLOBAL PROPERTY LLVM_PLUGIN_TARGETS)
     foreach(llvm_plugin_target ${llvm_plugin_targets})
       set_property(TARGET ${llvm_plugin_target} APPEND PROPERTY LINK_LIBRARIES ${llvm_extension})
+      set_property(TARGET ${llvm_plugin_target} APPEND PROPERTY LINK_LIBRARIES "obj.${llvm_extension}")
       set_property(TARGET ${llvm_plugin_target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${llvm_extension})
     endforeach()
   endforeach()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76642.252149.patch
Type: text/x-patch
Size: 680 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200323/9ffbde11/attachment.bin>


More information about the llvm-commits mailing list