[PATCH] D18847: Fix Registry::import() crash on mingw when loading a DLL plugin

Rudy Pons via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 6 16:31:06 PDT 2016


Ilod created this revision.
Ilod added reviewers: chapuni, ehsan, Bigcheese.
Ilod added a subscriber: llvm-commits.

Fix support for importing and exporting Registry objects on Windows

On Windows, most compilers will produce a DLL with their own global Tail and Head variables, so we copy these variables returned from an exported function of the DLLs into the consumer Registry, but some (such as MinGW) shares it with the consumer (same as on other platforms).

Add a check before the copy to skip it if we detect the Head returned is the same as the consumer one, avoiding to copy it into itself, which is an infinite copy.
Also add null-check to avoid crash when exporting a DLL with no plugin registered.

Edit CMake rules to allow compiling example plugins on Windows.

http://reviews.llvm.org/D18847

Files:
  cmake/modules/HandleLLVMOptions.cmake
  include/llvm/Support/Registry.h

Index: include/llvm/Support/Registry.h
===================================================================
--- include/llvm/Support/Registry.h
+++ include/llvm/Support/Registry.h
@@ -135,12 +135,17 @@
         // current Registry.
         typedef std::pair<const node *, const node *> Info;
         Info *I = static_cast<Info *>(Getter());
-        iterator begin(I->first);
-        iterator end(I->second);
-        for (++end; begin != end; ++begin) {
-          // This Node object needs to remain alive for the
-          // duration of the program.
-          add_node(new node(*begin));
+        // We need to check I->first != Head for mingw, which build DLLs
+        // sharing extern symbols when using LLVM_BUILD_SHARED, so we don't
+        // copy the Registry in itself.
+        if (I->first != nullptr && I->first != Head) {
+          iterator begin(I->first);
+          iterator end(I->second);
+          for (++end; begin != end; ++begin) {
+            // This Node object needs to remain alive for the
+            // duration of the program.
+            add_node(new node(*begin));
+          }
         }
       }
     }
Index: cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -643,12 +643,4 @@
 
 # Plugin support
 # FIXME: Make this configurable.
-if(WIN32 OR CYGWIN)
-  if(BUILD_SHARED_LIBS)
-    set(LLVM_ENABLE_PLUGINS ON)
-  else()
-    set(LLVM_ENABLE_PLUGINS OFF)
-  endif()
-else()
-  set(LLVM_ENABLE_PLUGINS ON)
-endif()
+set(LLVM_ENABLE_PLUGINS ON)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18847.52866.patch
Type: text/x-patch
Size: 1633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160406/87b5e8e3/attachment.bin>


More information about the llvm-commits mailing list