diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -418,8 +418,10 @@ else() llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS}) endif() - if(ARG_ENABLE_PLUGINS) - set_property(GLOBAL APPEND PROPERTY LLVM_PLUGIN_TARGETS ${name}) + if(ARG_ENABLE_PLUGINS) + if(ARG_DISABLE_LLVM_LINK_LLVM_DYLIB OR NOT ARG_LLVM_LINK_LLVM_DYLIB) + set_property(GLOBAL APPEND PROPERTY LLVM_PLUGIN_TARGETS ${name}) + endif() endif() if(ARG_MODULE) @@ -840,7 +842,7 @@ # API for all shared libaries loaded by this executable. target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB}) endif() - if(ARG_ENABLE_PLUGINS) + if(ARG_ENABLE_PLUGINS AND NOT LLVM_LINK_LLVM_DYLIB) set_property(GLOBAL APPEND PROPERTY LLVM_PLUGIN_TARGETS ${name}) endif() diff --git a/llvm/lib/Passes/PassPlugin.cpp b/llvm/lib/Passes/PassPlugin.cpp --- a/llvm/lib/Passes/PassPlugin.cpp +++ b/llvm/lib/Passes/PassPlugin.cpp @@ -49,3 +49,15 @@ return P; } + +// Provide an anchor that pull statically linked plugin symbols. +#define HANDLE_EXTENSION(Ext) \ + llvm::PassPluginLibraryInfo get##Ext##PluginInfo(); +#include "llvm/Support/Extension.def" + +llvm::PassPluginLibraryInfo (*PluginsAnchor[])() = { +#define HANDLE_EXTENSION(Ext) \ + get##Ext##PluginInfo, +#include "llvm/Support/Extension.def" + nullptr +}; diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt b/llvm/tools/llvm-shlib/CMakeLists.txt --- a/llvm/tools/llvm-shlib/CMakeLists.txt +++ b/llvm/tools/llvm-shlib/CMakeLists.txt @@ -30,7 +30,7 @@ if (LLVM_LINK_LLVM_DYLIB) set(INSTALL_WITH_TOOLCHAIN INSTALL_WITH_TOOLCHAIN) endif() - add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${INSTALL_WITH_TOOLCHAIN} ${SOURCES}) + add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB ENABLE_PLUGINS SONAME ${INSTALL_WITH_TOOLCHAIN} ${SOURCES}) list(REMOVE_DUPLICATES LIB_NAMES) if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU) @@ -96,7 +96,7 @@ add_custom_target(libLLVMCExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE}) - add_llvm_library(LLVM-C SHARED ${SOURCES} INSTALL_WITH_TOOLCHAIN) + add_llvm_library(LLVM-C SHARED ${SOURCES} INSTALL_WITH_TOOLCHAIN ENABLE_PLUGINS) target_link_libraries(LLVM-C PUBLIC LLVM) add_dependencies(LLVM-C libLLVMCExports) @@ -170,6 +170,6 @@ VERBATIM ) # Finally link the target. - add_llvm_library(LLVM-C SHARED INSTALL_WITH_TOOLCHAIN ${SOURCES} DEPENDS intrinsics_gen) + add_llvm_library(LLVM-C SHARED INSTALL_WITH_TOOLCHAIN ENABLE_PLUGINS ${SOURCES} DEPENDS intrinsics_gen) endif() diff --git a/polly/lib/CMakeLists.txt b/polly/lib/CMakeLists.txt --- a/polly/lib/CMakeLists.txt +++ b/polly/lib/CMakeLists.txt @@ -106,15 +106,13 @@ llvm_map_components_to_libnames(nvptx_libs NVPTX) endif () -if (LLVM_LINK_LLVM_DYLIB) - # The shlib/dylib contains all the LLVM components - # (including NVPTX is enabled) already. Adding them to target_link_libraries - # would cause them being twice in the address space - # (their LLVM*.a/so and their copies in libLLVM.so) - # which results in errors when the two instances try to register the same - # command-line switches. - target_link_libraries(Polly PUBLIC LLVM) -else () +# The shlib/dylib contains all the LLVM components +# (including NVPTX is enabled) already. Adding them to target_link_libraries +# would cause them being twice in the address space +# (their LLVM*.a/so and their copies in libLLVM.so) +# which results in errors when the two instances try to register the same +# command-line switches. +if (NOT LLVM_LINK_LLVM_DYLIB) target_link_libraries(Polly PUBLIC LLVMSupport LLVMCore