Index: llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h =================================================================== --- llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h +++ llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h @@ -43,6 +43,10 @@ SID ExceptTabSID; }; + // Returns true if the FDE section includes absolute symbol relocations + // on this platform. + virtual bool doDwarfFDESymbolsUseAbsDiff() = 0; + // When a module is loaded we save the SectionID of the EH frame section // in a table until we receive a request to register all unregistered // EH frame sections with the memory manager. @@ -147,8 +151,8 @@ Impl &impl() { return static_cast(*this); } const Impl &impl() const { return static_cast(*this); } - unsigned char *processFDE(uint8_t *P, int64_t DeltaForText, - int64_t DeltaForEH); + unsigned char *patchFDERelocations(uint8_t *P, int64_t DeltaForText, + int64_t DeltaForEH); public: RuntimeDyldMachOCRTPBase(RuntimeDyld::MemoryManager &MemMgr, Index: llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp =================================================================== --- llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp +++ llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp @@ -272,9 +272,9 @@ } template -unsigned char *RuntimeDyldMachOCRTPBase::processFDE(uint8_t *P, - int64_t DeltaForText, - int64_t DeltaForEH) { +unsigned char *RuntimeDyldMachOCRTPBase::patchFDERelocations(uint8_t *P, + int64_t DeltaForText, + int64_t DeltaForEH) { typedef typename Impl::TargetPtrT TargetPtrT; LLVM_DEBUG(dbgs() << "Processing FDE: Delta for text: " << DeltaForText @@ -324,19 +324,24 @@ continue; SectionEntry *Text = &Sections[SectionInfo.TextSID]; SectionEntry *EHFrame = &Sections[SectionInfo.EHFrameSID]; - SectionEntry *ExceptTab = nullptr; - if (SectionInfo.ExceptTabSID != RTDYLD_INVALID_SECTION_ID) - ExceptTab = &Sections[SectionInfo.ExceptTabSID]; - - int64_t DeltaForText = computeDelta(Text, EHFrame); - int64_t DeltaForEH = 0; - if (ExceptTab) - DeltaForEH = computeDelta(ExceptTab, EHFrame); - - uint8_t *P = EHFrame->getAddress(); - uint8_t *End = P + EHFrame->getSize(); - while (P != End) { - P = processFDE(P, DeltaForText, DeltaForEH); + + // If the FDE includes absolute symbol relocations (not supported + // by RuntimeDyld), we need to manually patch-up the values + if (doDwarfFDESymbolsUseAbsDiff()) { + SectionEntry *ExceptTab = nullptr; + if (SectionInfo.ExceptTabSID != RTDYLD_INVALID_SECTION_ID) + ExceptTab = &Sections[SectionInfo.ExceptTabSID]; + + int64_t DeltaForText = computeDelta(Text, EHFrame); + int64_t DeltaForEH = 0; + if (ExceptTab) + DeltaForEH = computeDelta(ExceptTab, EHFrame); + + uint8_t *P = EHFrame->getAddress(); + uint8_t *End = P + EHFrame->getSize(); + while (P != End) { + P = patchFDERelocations(P, DeltaForText, DeltaForEH); + } } MemMgr.registerEHFrames(EHFrame->getAddress(), EHFrame->getLoadAddress(), Index: llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h =================================================================== --- llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h +++ llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h @@ -30,6 +30,8 @@ Align getStubAlignment() override { return Align(8); } + bool doDwarfFDESymbolsUseAbsDiff() override { return false; } + /// Extract the addend encoded in the instruction / memory location. Expected decodeAddend(const RelocationEntry &RE) const { const SectionEntry &Section = Sections[RE.SectionID]; Index: llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h =================================================================== --- llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h +++ llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h @@ -32,6 +32,8 @@ Align getStubAlignment() override { return Align(4); } + bool doDwarfFDESymbolsUseAbsDiff() override { return false; } + Expected getJITSymbolFlags(const SymbolRef &SR) override { auto Flags = RuntimeDyldImpl::getJITSymbolFlags(SR); if (!Flags) Index: llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h =================================================================== --- llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h +++ llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h @@ -29,6 +29,8 @@ Align getStubAlignment() override { return Align(1); } + bool doDwarfFDESymbolsUseAbsDiff() override { return true; } + Expected processRelocationRef(unsigned SectionID, relocation_iterator RelI, const ObjectFile &BaseObjT, Index: llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h =================================================================== --- llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h +++ llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h @@ -29,6 +29,8 @@ Align getStubAlignment() override { return Align(8); } + bool doDwarfFDESymbolsUseAbsDiff() override { return true; } + Expected processRelocationRef(unsigned SectionID, relocation_iterator RelI, const ObjectFile &BaseObjT,