[llvm] [Support][Cygwin] Fix handling of Process symbol lookup. (PR #143072)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 5 23:08:04 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: None (jeremyd2019)

<details>
<summary>Changes</summary>

In Unix/DynamicLibrary.inc, it was already known that Cygwin required use of `RTLD_DEFAULT` as the `Handle` parameter to `DLSym` to search all modules for a symbol.  Unfortunately, RTLD_DEFAULT is defined as NULL, so the existing checks of the `Process` handle meant `DLSym` would never be called on Cygwin.  Add a `bool` member to indicate whether the Process handle was set instead.

---
Full diff: https://github.com/llvm/llvm-project/pull/143072.diff


1 Files Affected:

- (modified) llvm/lib/Support/DynamicLibrary.cpp (+4-2) 


``````````diff
diff --git a/llvm/lib/Support/DynamicLibrary.cpp b/llvm/lib/Support/DynamicLibrary.cpp
index 531c035ab9266..34c2dc2e56227 100644
--- a/llvm/lib/Support/DynamicLibrary.cpp
+++ b/llvm/lib/Support/DynamicLibrary.cpp
@@ -26,6 +26,7 @@ class DynamicLibrary::HandleSet {
   typedef std::vector<void *> HandleList;
   HandleList Handles;
   void *Process = nullptr;
+  bool ProcessAdded = false;
 
 public:
   static void *DLOpen(const char *Filename, std::string *Err);
@@ -66,6 +67,7 @@ class DynamicLibrary::HandleSet {
       }
 #endif
       Process = Handle;
+      ProcessAdded = true;
     }
     return true;
   }
@@ -97,11 +99,11 @@ class DynamicLibrary::HandleSet {
     assert(!((Order & SO_LoadedFirst) && (Order & SO_LoadedLast)) &&
            "Invalid Ordering");
 
-    if (!Process || (Order & SO_LoadedFirst)) {
+    if (!ProcessAdded || (Order & SO_LoadedFirst)) {
       if (void *Ptr = LibLookup(Symbol, Order))
         return Ptr;
     }
-    if (Process) {
+    if (ProcessAdded) {
       // Use OS facilities to search the current binary and all loaded libs.
       if (void *Ptr = DLSym(Process, Symbol))
         return Ptr;

``````````

</details>


https://github.com/llvm/llvm-project/pull/143072


More information about the llvm-commits mailing list