[llvm] 8363ff0 - [ORC] Add some debugging output for initializers.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 4 12:38:54 PST 2020


Author: Lang Hames
Date: 2020-03-04T12:38:25-08:00
New Revision: 8363ff04afada01afb9c32a3daa6586e1bd4f2e4

URL: https://github.com/llvm/llvm-project/commit/8363ff04afada01afb9c32a3daa6586e1bd4f2e4
DIFF: https://github.com/llvm/llvm-project/commit/8363ff04afada01afb9c32a3daa6586e1bd4f2e4.diff

LOG: [ORC] Add some debugging output for initializers.

This output can be useful in tracking down initialization failures in the JIT.

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
    llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
    llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
    llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
index 0c42aa46ce79..2f3c21b15fca 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -21,6 +21,7 @@
 #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
 #include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
 #include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/ThreadPool.h"
 
 namespace llvm {
@@ -137,12 +138,20 @@ class LLJIT {
 
   /// Run the initializers for the given JITDylib.
   Error initialize(JITDylib &JD) {
+    DEBUG_WITH_TYPE("orc", {
+      dbgs() << "LLJIT running initializers for JITDylib \"" << JD.getName()
+             << "\"\n";
+    });
     assert(PS && "PlatformSupport must be set to run initializers.");
     return PS->initialize(JD);
   }
 
   /// Run the deinitializers for the given JITDylib.
   Error deinitialize(JITDylib &JD) {
+    DEBUG_WITH_TYPE("orc", {
+      dbgs() << "LLJIT running deinitializers for JITDylib \"" << JD.getName()
+             << "\"\n";
+    });
     assert(PS && "PlatformSupport must be set to run initializers.");
     return PS->deinitialize(JD);
   }

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
index 92c1a04921b8..0d07f53dd3fb 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
@@ -59,8 +59,6 @@ class MachOJITDylibInitializers {
   void registerObjCSelectors() const;
   Error registerObjCClasses() const;
 
-  void dump() const;
-
 private:
   using RawPointerSectionList = std::vector<SectionExtent>;
 

diff  --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index a9ec8c45c61c..2ff9e78f82e1 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -21,6 +21,8 @@
 
 #include <map>
 
+#define DEBUG_TYPE "orc"
+
 using namespace llvm;
 using namespace llvm::orc;
 
@@ -191,8 +193,17 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
   }
 
   Error initialize(JITDylib &JD) override {
+    LLVM_DEBUG({
+      dbgs() << "GenericLLVMIRPlatformSupport getting initializers to run\n";
+    });
     if (auto Initializers = getInitializers(JD)) {
+      LLVM_DEBUG(
+          { dbgs() << "GenericLLVMIRPlatformSupport running initializers\n"; });
       for (auto InitFnAddr : *Initializers) {
+        LLVM_DEBUG({
+          dbgs() << "  Running init " << formatv("{0:x16}", InitFnAddr)
+                 << "...\n";
+        });
         auto *InitFn = jitTargetAddressToFunction<void (*)()>(InitFnAddr);
         InitFn();
       }
@@ -202,8 +213,18 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
   }
 
   Error deinitialize(JITDylib &JD) override {
+    LLVM_DEBUG({
+      dbgs() << "GenericLLVMIRPlatformSupport getting deinitializers to run\n";
+    });
     if (auto Deinitializers = getDeinitializers(JD)) {
+      LLVM_DEBUG({
+        dbgs() << "GenericLLVMIRPlatformSupport running deinitializers\n";
+      });
       for (auto DeinitFnAddr : *Deinitializers) {
+        LLVM_DEBUG({
+          dbgs() << "  Running init " << formatv("{0:x16}", DeinitFnAddr)
+                 << "...\n";
+        });
         auto *DeinitFn = jitTargetAddressToFunction<void (*)()>(DeinitFnAddr);
         DeinitFn();
       }
@@ -239,6 +260,16 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
       }
     }
 
+    LLVM_DEBUG({
+      dbgs() << "JITDylib init order is [ ";
+      for (auto *JD : llvm::reverse(DFSLinkOrder))
+        dbgs() << "\"" << JD->getName() << "\" ";
+      dbgs() << "]\n";
+      dbgs() << "Looking up init functions:\n";
+      for (auto &KV : LookupSymbols)
+        dbgs() << "  \"" << KV.first->getName() << "\": " << KV.second << "\n";
+    });
+
     auto &ES = getExecutionSession();
     auto LookupResult = Platform::lookupInitSymbols(ES, LookupSymbols);
 
@@ -519,6 +550,11 @@ class MachOPlatformSupport : public LLJIT::PlatformSupport {
   }
 
   Error initialize(JITDylib &JD) override {
+    LLVM_DEBUG({
+      dbgs() << "MachOPlatformSupport initializing \"" << JD.getName()
+             << "\"\n";
+    });
+
     if (auto InitSeq = MP.getInitializerSequence(JD)) {
       for (auto &KV : *InitSeq) {
         KV.second.registerObjCSelectors();
@@ -1039,10 +1075,13 @@ Error LLJIT::applyDataLayout(Module &M) {
 }
 
 void setUpGenericLLVMIRPlatform(LLJIT &J) {
+  LLVM_DEBUG(
+      { dbgs() << "Setting up GenericLLVMIRPlatform support for LLJIT\n"; });
   J.setPlatformSupport(std::make_unique<GenericLLVMIRPlatformSupport>(J));
 }
 
 Error setUpMachOPlatform(LLJIT &J) {
+  LLVM_DEBUG({ dbgs() << "Setting up MachOPlatform support for LLJIT\n"; });
   auto MP = MachOPlatformSupport::Create(J, J.getMainJITDylib());
   if (!MP)
     return MP.takeError();

diff  --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index 4618d53315ef..b883a81e5d3f 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -10,6 +10,9 @@
 
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/Support/BinaryByteStream.h"
+#include "llvm/Support/Debug.h"
+
+#define DEBUG_TYPE "orc"
 
 namespace {
 
@@ -141,12 +144,6 @@ Error MachOJITDylibInitializers::registerObjCClasses() const {
   return Error::success();
 }
 
-void MachOJITDylibInitializers::dump() const {
-  for (auto &Extent : ModInitSections)
-    dbgs() << formatv("{0:x16}", Extent.Address) << " -- "
-           << formatv("{0:x16}", Extent.Address + 8 * Extent.NumPtrs) << "\n";
-}
-
 MachOPlatform::MachOPlatform(
     ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
     std::unique_ptr<MemoryBuffer> StandardSymbolsObject)
@@ -168,6 +165,10 @@ Error MachOPlatform::notifyAdding(JITDylib &JD, const MaterializationUnit &MU) {
 
   std::lock_guard<std::mutex> Lock(PlatformMutex);
   RegisteredInitSymbols[&JD].add(InitSym);
+  LLVM_DEBUG({
+    dbgs() << "MachOPlatform: Registered init symbol " << *InitSym << " for MU "
+           << MU.getName() << "\n";
+  });
   return Error::success();
 }
 
@@ -178,6 +179,11 @@ Error MachOPlatform::notifyRemoving(JITDylib &JD, VModuleKey K) {
 Expected<MachOPlatform::InitializerSequence>
 MachOPlatform::getInitializerSequence(JITDylib &JD) {
 
+  LLVM_DEBUG({
+    dbgs() << "MachOPlatform: Building initializer sequence for "
+           << JD.getName() << "\n";
+  });
+
   std::vector<JITDylib *> DFSLinkOrder;
 
   while (true) {
@@ -200,6 +206,13 @@ MachOPlatform::getInitializerSequence(JITDylib &JD) {
     if (NewInitSymbols.empty())
       break;
 
+    LLVM_DEBUG({
+      dbgs() << "MachOPlatform: Issuing lookups for new init symbols: "
+                "(lookup may require multiple rounds)\n";
+      for (auto &KV : NewInitSymbols)
+        dbgs() << "  \"" << KV.first->getName() << "\": " << KV.second << "\n";
+    });
+
     // Outside the lock, issue the lookup.
     if (auto R = lookupInitSymbols(JD.getExecutionSession(), NewInitSymbols))
       ; // Nothing to do in the success case.
@@ -207,11 +220,20 @@ MachOPlatform::getInitializerSequence(JITDylib &JD) {
       return R.takeError();
   }
 
+  LLVM_DEBUG({
+    dbgs() << "MachOPlatform: Init symbol lookup complete, building init "
+              "sequence\n";
+  });
+
   // Lock again to collect the initializers.
   InitializerSequence FullInitSeq;
   {
     std::lock_guard<std::mutex> Lock(PlatformMutex);
     for (auto *InitJD : reverse(DFSLinkOrder)) {
+      LLVM_DEBUG({
+        dbgs() << "MachOPlatform: Appending inits for \"" << InitJD->getName()
+               << "\" to sequence\n";
+      });
       auto ISItr = InitSeqs.find(InitJD);
       if (ISItr != InitSeqs.end()) {
         FullInitSeq.emplace_back(InitJD, std::move(ISItr->second));
@@ -345,6 +367,31 @@ void MachOPlatform::InitScraperPlugin::modifyPassConfig(
     else
       return ObjCClassListOrErr.takeError();
 
+    // Dump the scraped inits.
+    LLVM_DEBUG({
+      dbgs() << "MachOPlatform: Scraped " << G.getName() << " init sections:\n";
+      dbgs() << "  __objc_selrefs: ";
+      if (ObjCSelRefs.NumPtrs)
+        dbgs() << ObjCSelRefs.NumPtrs << " pointer(s) at "
+               << formatv("{0:x16}", ObjCSelRefs.Address) << "\n";
+      else
+        dbgs() << "none\n";
+
+      dbgs() << "  __objc_classlist: ";
+      if (ObjCClassList.NumPtrs)
+        dbgs() << ObjCClassList.NumPtrs << " pointer(s) at "
+               << formatv("{0:x16}", ObjCClassList.Address) << "\n";
+      else
+        dbgs() << "none\n";
+
+      dbgs() << "__mod_init_func: ";
+      if (ModInits.NumPtrs)
+        dbgs() << ModInits.NumPtrs << " pointer(s) at "
+               << formatv("{0:x16}", ModInits.Address) << "\n";
+      else
+        dbgs() << "none\n";
+    });
+
     MP.registerInitInfo(JD, ObjCImageInfoAddr, std::move(ModInits),
                         std::move(ObjCSelRefs), std::move(ObjCClassList));
 


        


More information about the llvm-commits mailing list