[llvm] 2bf87a4 - [ORC][MachO] Fix MachOPlatform after 9189a26664b.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 17 18:27:02 PDT 2022


Author: Lang Hames
Date: 2022-08-17T18:18:48-07:00
New Revision: 2bf87a4946b2dd0b94bfaa01f306a779066f30e7

URL: https://github.com/llvm/llvm-project/commit/2bf87a4946b2dd0b94bfaa01f306a779066f30e7
DIFF: https://github.com/llvm/llvm-project/commit/2bf87a4946b2dd0b94bfaa01f306a779066f30e7.diff

LOG: [ORC][MachO] Fix MachOPlatform after 9189a26664b.

Commit 9189a26664b caused llvm-jitlink to create bare JITDylibs to wrap real
dylibs loaded via -preload. This exposed a bug in MachOPlatform where we
assumed that all JITDylibs had been registered with the platform through
MachOPlatform::setupJITDylib (bare JITDylibs are _not_ run through this
function), and errored out where this was not the case.
This bug in MachOPlatform was causing test failures in compilert-rt:

Failed Tests (2):
  ORC-x86_64-darwin :: TestCases/Darwin/x86-64/trivial-objc-methods.S
  ORC-x86_64-darwin :: TestCases/Darwin/x86-64/trivial-swift-types-section.S

This commit fixes the issue by skipping JITDylibs that haven't been registered
with the platform via MachOPlatform::setupJITDylib.

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index d5274b06a76ff..b9c064dd4b34a 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -440,24 +440,17 @@ void MachOPlatform::pushInitializersLoop(
   if (NewInitSymbols.empty()) {
 
     // To make the list intelligible to the runtime we need to convert all
-    // JITDylib pointers to their header addresses.
+    // JITDylib pointers to their header addresses. Only include JITDylibs
+    // that appear in the JITDylibToHeaderAddr map (i.e. those that have been
+    // through setupJITDylib) -- bare JITDylibs aren't managed by the platform.
     DenseMap<JITDylib *, ExecutorAddr> HeaderAddrs;
     HeaderAddrs.reserve(JDDepMap.size());
     {
       std::lock_guard<std::mutex> Lock(PlatformMutex);
       for (auto &KV : JDDepMap) {
         auto I = JITDylibToHeaderAddr.find(KV.first);
-        if (I == JITDylibToHeaderAddr.end()) {
-          // The header address should have been materialized by the previous
-          // round, but we need to handle the pathalogical case where someone
-          // removes the symbol on another thread while we're running.
-          SendResult(
-              make_error<StringError>("JITDylib " + KV.first->getName() +
-                                          " has no registered header address",
-                                      inconvertibleErrorCode()));
-          return;
-        }
-        HeaderAddrs[KV.first] = I->second;
+        if (I != JITDylibToHeaderAddr.end())
+          HeaderAddrs[KV.first] = I->second;
       }
     }
 
@@ -465,12 +458,16 @@ void MachOPlatform::pushInitializersLoop(
     MachOJITDylibDepInfoMap DIM;
     DIM.reserve(JDDepMap.size());
     for (auto &KV : JDDepMap) {
-      assert(HeaderAddrs.count(KV.first) && "Missing header addr");
-      auto H = HeaderAddrs[KV.first];
+      auto HI = HeaderAddrs.find(KV.first);
+      // Skip unmanaged JITDylibs.
+      if (HI == HeaderAddrs.end())
+        continue;
+      auto H = HI->second;
       MachOJITDylibDepInfo DepInfo;
       for (auto &Dep : KV.second) {
-        assert(HeaderAddrs.count(Dep) && "Missing header addr");
-        DepInfo.DepHeaders.push_back(HeaderAddrs[Dep]);
+        auto HJ = HeaderAddrs.find(Dep);
+        if (HJ != HeaderAddrs.end())
+          DepInfo.DepHeaders.push_back(HJ->second);
       }
       DIM.push_back(std::make_pair(H, std::move(DepInfo)));
     }


        


More information about the llvm-commits mailing list