From 941f247d30c447903107aa614ea46fb1e4019698 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 8 Apr 2019 21:50:48 +0000 Subject: [RuntimeDyld] Decouple RuntimeDyldChecker from RuntimeDyld. This will allow RuntimeDyldChecker (and rtdyld-check tests) to test a new JIT linker: JITLink (https://reviews.llvm.org/D58704). llvm-svn: 357947 --- .../ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp | 86 +++++++++++++++------- 1 file changed, 60 insertions(+), 26 deletions(-) (limited to 'llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp') diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index 589cdcbcb0d..dee8ecda13a 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -12,7 +12,6 @@ #include "llvm/ExecutionEngine/RuntimeDyld.h" #include "RuntimeDyldCOFF.h" -#include "RuntimeDyldCheckerImpl.h" #include "RuntimeDyldELF.h" #include "RuntimeDyldImpl.h" #include "RuntimeDyldMachO.h" @@ -375,10 +374,34 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) { else return IOrErr.takeError(); - // If there is an attached checker, notify it about the stubs for this - // section so that they can be verified. - if (Checker) - Checker->registerStubMap(Obj.getFileName(), SectionID, Stubs); + // If there is a NotifyStubEmitted callback set, call it to register any + // stubs created for this section. + if (NotifyStubEmitted) { + StringRef FileName = Obj.getFileName(); + StringRef SectionName = Sections[SectionID].getName(); + for (auto &KV : Stubs) { + + auto &VR = KV.first; + uint64_t StubAddr = KV.second; + + // If this is a named stub, just call NotifyStubEmitted. + if (VR.SymbolName) { + NotifyStubEmitted(FileName, SectionName, VR.SymbolName, StubAddr); + continue; + } + + // Otherwise we will have to try a reverse lookup on the globla symbol table. + for (auto &GSTMapEntry : GlobalSymbolTable) { + StringRef SymbolName = GSTMapEntry.first(); + auto &GSTEntry = GSTMapEntry.second; + if (GSTEntry.getSectionID() == VR.SectionID && + GSTEntry.getOffset() == VR.Offset) { + NotifyStubEmitted(FileName, SectionName, SymbolName, StubAddr); + break; + } + } + } + } } // Process remaining sections @@ -721,9 +744,6 @@ Error RuntimeDyldImpl::emitCommonSymbols(const ObjectFile &Obj, Addr += Size; } - if (Checker) - Checker->registerSection(Obj.getFileName(), SectionID); - return Error::success(); } @@ -840,9 +860,6 @@ RuntimeDyldImpl::emitSection(const ObjectFile &Obj, if (!IsRequired) Sections.back().setLoadAddress(0); - if (Checker) - Checker->registerSection(Obj.getFileName(), SectionID); - return SectionID; } @@ -1225,42 +1242,43 @@ RuntimeDyld::RuntimeDyld(RuntimeDyld::MemoryManager &MemMgr, // permissions are applied. Dyld = nullptr; ProcessAllSections = false; - Checker = nullptr; } RuntimeDyld::~RuntimeDyld() {} static std::unique_ptr -createRuntimeDyldCOFF(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, - JITSymbolResolver &Resolver, bool ProcessAllSections, - RuntimeDyldCheckerImpl *Checker) { +createRuntimeDyldCOFF( + Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, + JITSymbolResolver &Resolver, bool ProcessAllSections, + RuntimeDyld::NotifyStubEmittedFunction NotifyStubEmitted) { std::unique_ptr Dyld = RuntimeDyldCOFF::create(Arch, MM, Resolver); Dyld->setProcessAllSections(ProcessAllSections); - Dyld->setRuntimeDyldChecker(Checker); + Dyld->setNotifyStubEmitted(std::move(NotifyStubEmitted)); return Dyld; } static std::unique_ptr createRuntimeDyldELF(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver, bool ProcessAllSections, - RuntimeDyldCheckerImpl *Checker) { + RuntimeDyld::NotifyStubEmittedFunction NotifyStubEmitted) { std::unique_ptr Dyld = RuntimeDyldELF::create(Arch, MM, Resolver); Dyld->setProcessAllSections(ProcessAllSections); - Dyld->setRuntimeDyldChecker(Checker); + Dyld->setNotifyStubEmitted(std::move(NotifyStubEmitted)); return Dyld; } static std::unique_ptr -createRuntimeDyldMachO(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, - JITSymbolResolver &Resolver, - bool ProcessAllSections, - RuntimeDyldCheckerImpl *Checker) { +createRuntimeDyldMachO( + Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, + JITSymbolResolver &Resolver, + bool ProcessAllSections, + RuntimeDyld::NotifyStubEmittedFunction NotifyStubEmitted) { std::unique_ptr Dyld = RuntimeDyldMachO::create(Arch, MM, Resolver); Dyld->setProcessAllSections(ProcessAllSections); - Dyld->setRuntimeDyldChecker(Checker); + Dyld->setNotifyStubEmitted(std::move(NotifyStubEmitted)); return Dyld; } @@ -1270,15 +1288,16 @@ RuntimeDyld::loadObject(const ObjectFile &Obj) { if (Obj.isELF()) Dyld = createRuntimeDyldELF(static_cast(Obj.getArch()), - MemMgr, Resolver, ProcessAllSections, Checker); + MemMgr, Resolver, ProcessAllSections, + std::move(NotifyStubEmitted)); else if (Obj.isMachO()) Dyld = createRuntimeDyldMachO( static_cast(Obj.getArch()), MemMgr, Resolver, - ProcessAllSections, Checker); + ProcessAllSections, std::move(NotifyStubEmitted)); else if (Obj.isCOFF()) Dyld = createRuntimeDyldCOFF( static_cast(Obj.getArch()), MemMgr, Resolver, - ProcessAllSections, Checker); + ProcessAllSections, std::move(NotifyStubEmitted)); else report_fatal_error("Incompatible object format!"); } @@ -1297,6 +1316,11 @@ void *RuntimeDyld::getSymbolLocalAddress(StringRef Name) const { return Dyld->getSymbolLocalAddress(Name); } +unsigned RuntimeDyld::getSymbolSectionID(StringRef Name) const { + assert(Dyld && "No RuntimeDyld instance attached"); + return Dyld->getSymbolSectionID(Name); +} + JITEvaluatedSymbol RuntimeDyld::getSymbol(StringRef Name) const { if (!Dyld) return nullptr; @@ -1335,6 +1359,16 @@ void RuntimeDyld::finalizeWithMemoryManagerLocking() { } } +StringRef RuntimeDyld::getSectionContent(unsigned SectionID) const { + assert(Dyld && "No Dyld instance attached"); + return Dyld->getSectionContent(SectionID); +} + +uint64_t RuntimeDyld::getSectionLoadAddress(unsigned SectionID) const { + assert(Dyld && "No Dyld instance attached"); + return Dyld->getSectionLoadAddress(SectionID); +} + void RuntimeDyld::registerEHFrames() { if (Dyld) Dyld->registerEHFrames(); -- cgit v1.2.3