[llvm] r332796 - Fix build warning compiling TestPlugin on Windows and disable Passes plugin stuff on Windows since it fundamentally can't work

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Fri May 18 20:05:30 PDT 2018


Author: nico
Date: Fri May 18 20:05:30 2018
New Revision: 332796

URL: http://llvm.org/viewvc/llvm-project?rev=332796&view=rev
Log:
Fix build warning compiling TestPlugin on Windows and disable Passes plugin stuff on Windows since it fundamentally can't work

Aaron Ballman reported that TestPlugin warned about it using exception handling
without /EHsc flag, and that llvmGetPassInfo() had conflicting export
attributes (dllimport in the header, dllexport in the source file).

/EHsc is because TestPlugin didn't use the llvm_ cmake functions, so
llvm_update_compile_flags didn't get called for the target
(llvm_update_compile_flags explicitly passes /Ehs-c-, which fixes the warning).
Use add_llvm_loadable_module instead of add_library(... MODULE) to fix this.
This also has the side effect of not building the plugin on Windows. That's not
a big problem, since before the plugin was built on Windows, but the test
didn't attempt to load it, due to -DLLVM_ENABLE_PLUGIN not being passed to
PluginsTests.cpp during compilation on Windows. This makes the plugin behavior
consistent with e.g. lib/Transforms/Hello/CMakeLists.txt. (This also
automatically sets LTDL_SHLIB_EXT correctly.)

The dllimport/dllexport warning is more serious: Since LLVM doesn't generally
use export annotations for its code, the only way the plugin could link was by
linking in some LLVM libraries both into the test and the dll, so the plugin
would call the llvm code in the dll instead of the copy in the main executable.
This means globals weren't shared, and things generally can't work. (I think
there's a build config where you can build a LLVM.dll which might work, but
that wasn't how the test was configured. If that config is used, the dll should
still be built, but I haven't checked).

Now that add_llvm_loadable_module is used, LLVM_LINK_COMPONENTS got linked into
both executable and plugin on posix too, so unset it after the executable so
that the plugin doesn't end up with a 2nd copy of things on posix.

https://reviews.llvm.org/D47082

Modified:
    llvm/trunk/include/llvm/Demangle/Compiler.h
    llvm/trunk/include/llvm/Passes/PassPlugin.h
    llvm/trunk/unittests/Passes/CMakeLists.txt
    llvm/trunk/unittests/Passes/TestPlugin.cpp

Modified: llvm/trunk/include/llvm/Demangle/Compiler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Demangle/Compiler.h?rev=332796&r1=332795&r2=332796&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Demangle/Compiler.h (original)
+++ llvm/trunk/include/llvm/Demangle/Compiler.h Fri May 18 20:05:30 2018
@@ -503,22 +503,4 @@ void AnnotateIgnoreWritesEnd(const char
 #define LLVM_ENABLE_EXCEPTIONS 1
 #endif
 
-/// \macro LLVM_PLUGIN_IMPORT
-/// Used to import the well-known entry point for registering loaded pass
-/// plugins
-#ifdef WIN32
-#define LLVM_PLUGIN_IMPORT __declspec(dllimport)
-#else
-#define LLVM_PLUGIN_IMPORT
-#endif
-
-/// \macro LLVM_PLUGIN_EXPORT
-/// Used to export the well-known entry point for registering loaded pass
-/// plugins
-#ifdef WIN32
-#define LLVM_PLUGIN_EXPORT __declspec(dllexport)
-#else
-#define LLVM_PLUGIN_EXPORT
-#endif
-
 #endif

Modified: llvm/trunk/include/llvm/Passes/PassPlugin.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Passes/PassPlugin.h?rev=332796&r1=332795&r2=332796&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Passes/PassPlugin.h (original)
+++ llvm/trunk/include/llvm/Passes/PassPlugin.h Fri May 18 20:05:30 2018
@@ -102,13 +102,13 @@ private:
 ///
 /// ```
 /// extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
-/// LLVM_PLUGIN_EXPORT llvmGetPassPluginInfo() {
+/// llvmGetPassPluginInfo() {
 ///   return {
 ///     LLVM_PLUGIN_API_VERSION, "MyPlugin", "v0.1", [](PassBuilder &PB) { ... }
 ///   };
 /// }
 /// ```
-extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK LLVM_PLUGIN_IMPORT
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
 llvmGetPassPluginInfo();
 
 #endif /* LLVM_PASSES_PASSPLUGIN_H */

Modified: llvm/trunk/unittests/Passes/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Passes/CMakeLists.txt?rev=332796&r1=332795&r2=332796&view=diff
==============================================================================
--- llvm/trunk/unittests/Passes/CMakeLists.txt (original)
+++ llvm/trunk/unittests/Passes/CMakeLists.txt Fri May 18 20:05:30 2018
@@ -1,7 +1,5 @@
 # Needed by LLVM's CMake checks because this file defines multiple targets.
-set(LLVM_OPTIONAL_SOURCES TestPlugin.cpp)
-
-set(LLVM_LINK_COMPONENTS Support Passes Core)
+set(LLVM_OPTIONAL_SOURCES PluginsTest.cpp TestPlugin.cpp)
 
 # If plugins are disabled, this test will disable itself at runtime. Otherwise,
 # reconfiguring with plugins disabled will leave behind a stale executable.
@@ -9,30 +7,23 @@ if (LLVM_ENABLE_PLUGINS)
   add_definitions(-DLLVM_ENABLE_PLUGINS)
 endif()
 
+set(LLVM_LINK_COMPONENTS Support Passes Core)
 add_llvm_unittest(PluginsTests
   PluginsTest.cpp
   )
 export_executable_symbols(PluginsTests)
 
-add_library(TestPlugin MODULE
+set(LLVM_LINK_COMPONENTS)
+add_llvm_loadable_module(TestPlugin
   TestPlugin.cpp
   )
 
+# Put plugin next to the unit test executable.
 set_output_directory(TestPlugin
   BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
   LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
   )
-
-set_target_properties(TestPlugin
-  PROPERTIES PREFIX ""
-  SUFFIX ${LTDL_SHLIB_EXT}
-  )
 set_target_properties(TestPlugin PROPERTIES FOLDER "Tests")
 
-if (WIN32 OR CYGWIN OR LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)
-  llvm_map_components_to_libnames(LLVM_DEPS ${LLVM_LINK_COMPONENTS})
-  target_link_libraries(TestPlugin ${LLVM_DEPS})
-endif()
-
 add_dependencies(TestPlugin intrinsics_gen)
 add_dependencies(PluginsTests TestPlugin)

Modified: llvm/trunk/unittests/Passes/TestPlugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Passes/TestPlugin.cpp?rev=332796&r1=332795&r2=332796&view=diff
==============================================================================
--- llvm/trunk/unittests/Passes/TestPlugin.cpp (original)
+++ llvm/trunk/unittests/Passes/TestPlugin.cpp Fri May 18 20:05:30 2018
@@ -32,7 +32,7 @@ void registerCallbacks(PassBuilder &PB)
       });
 }
 
-extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK LLVM_PLUGIN_EXPORT
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
 llvmGetPassPluginInfo() {
   return {LLVM_PLUGIN_API_VERSION, TEST_PLUGIN_NAME, TEST_PLUGIN_VERSION,
           registerCallbacks};




More information about the llvm-commits mailing list