[PATCH] D33515: Fix the ManagedStatic list ordering when using DynamicLibrary::addPermanentLibrary.

Frederich Munch via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 25 12:34:39 PDT 2017


marsupial updated this revision to Diff 100280.
marsupial added a comment.

Perhaps we can try to close this one out before moving on to the larger problem?

I'm not trying to pass the buck here, this has in fact lead to finding two interesting bugs, but it certainly seems there's an API misuse/deficiency that super-cedes this issue.  Even if the ManagedStatic ordering is completely sorted out, how is Polly handling the **valid** is case of a user using **llvm_shutdown**.  That is once llvm_shutdown has been **GlobalExtensions** will have been cleared and the passes no longer available.


https://reviews.llvm.org/D33515

Files:
  lib/Support/DynamicLibrary.cpp


Index: lib/Support/DynamicLibrary.cpp
===================================================================
--- lib/Support/DynamicLibrary.cpp
+++ lib/Support/DynamicLibrary.cpp
@@ -127,10 +127,15 @@
 
 DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *FileName,
                                                    std::string *Err) {
-  SmartScopedLock<true> Lock(*SymbolsMutex);
+  // Force OpenedHandles to be added into the ManagedStatic list before any
+  // ManagedStatic can be added from static constructors in HandleSet::DLOpen.
+  HandleSet& HS = *OpenedHandles;
+
   void *Handle = HandleSet::DLOpen(FileName, Err);
-  if (Handle != &Invalid)
-    OpenedHandles->AddLibrary(Handle, /*IsProcess*/ FileName == nullptr);
+  if (Handle != &Invalid) {
+    SmartScopedLock<true> Lock(*SymbolsMutex);
+    HS.AddLibrary(Handle, /*IsProcess*/ FileName == nullptr);
+  }
 
   return DynamicLibrary(Handle);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33515.100280.patch
Type: text/x-patch
Size: 924 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170525/6261f096/attachment.bin>


More information about the llvm-commits mailing list