Loading llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h +9 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -137,12 +138,20 @@ public: /// 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); } Loading llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h +0 −2 Original line number Diff line number Diff line Loading @@ -59,8 +59,6 @@ public: void registerObjCSelectors() const; Error registerObjCClasses() const; void dump() const; private: using RawPointerSectionList = std::vector<SectionExtent>; Loading llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +39 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ #include <map> #define DEBUG_TYPE "orc" using namespace llvm; using namespace llvm::orc; Loading Loading @@ -191,8 +193,17 @@ public: } 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(); } Loading @@ -202,8 +213,18 @@ public: } 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(); } Loading Loading @@ -239,6 +260,16 @@ private: } } 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); Loading Loading @@ -519,6 +550,11 @@ public: } 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(); Loading Loading @@ -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(); Loading llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp +53 −6 Original line number Diff line number Diff line Loading @@ -10,6 +10,9 @@ #include "llvm/BinaryFormat/MachO.h" #include "llvm/Support/BinaryByteStream.h" #include "llvm/Support/Debug.h" #define DEBUG_TYPE "orc" namespace { Loading Loading @@ -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) Loading @@ -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(); } Loading @@ -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) { Loading @@ -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. Loading @@ -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)); Loading Loading @@ -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)); Loading Loading
llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h +9 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -137,12 +138,20 @@ public: /// 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); } Loading
llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h +0 −2 Original line number Diff line number Diff line Loading @@ -59,8 +59,6 @@ public: void registerObjCSelectors() const; Error registerObjCClasses() const; void dump() const; private: using RawPointerSectionList = std::vector<SectionExtent>; Loading
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +39 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ #include <map> #define DEBUG_TYPE "orc" using namespace llvm; using namespace llvm::orc; Loading Loading @@ -191,8 +193,17 @@ public: } 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(); } Loading @@ -202,8 +213,18 @@ public: } 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(); } Loading Loading @@ -239,6 +260,16 @@ private: } } 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); Loading Loading @@ -519,6 +550,11 @@ public: } 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(); Loading Loading @@ -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(); Loading
llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp +53 −6 Original line number Diff line number Diff line Loading @@ -10,6 +10,9 @@ #include "llvm/BinaryFormat/MachO.h" #include "llvm/Support/BinaryByteStream.h" #include "llvm/Support/Debug.h" #define DEBUG_TYPE "orc" namespace { Loading Loading @@ -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) Loading @@ -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(); } Loading @@ -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) { Loading @@ -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. Loading @@ -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)); Loading Loading @@ -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)); Loading