mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-29 10:25:12 +00:00
[MCJIT] Make sure eh-frame fixups use the target's pointer type, not the host's.
If the wrong pointer type is used it can cause corruption of the frame description entries. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217124 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -128,8 +128,37 @@ bool RuntimeDyldMachO::isCompatibleFile(const object::ObjectFile *Obj) const {
|
|||||||
return Obj->isMachO();
|
return Obj->isMachO();
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *processFDE(unsigned char *P, intptr_t DeltaForText,
|
template <typename Impl>
|
||||||
intptr_t DeltaForEH) {
|
void RuntimeDyldMachOCRTPBase<Impl>::finalizeLoad(ObjectImage &ObjImg,
|
||||||
|
ObjSectionToIDMap &SectionMap) {
|
||||||
|
unsigned EHFrameSID = RTDYLD_INVALID_SECTION_ID;
|
||||||
|
unsigned TextSID = RTDYLD_INVALID_SECTION_ID;
|
||||||
|
unsigned ExceptTabSID = RTDYLD_INVALID_SECTION_ID;
|
||||||
|
ObjSectionToIDMap::iterator i, e;
|
||||||
|
|
||||||
|
for (i = SectionMap.begin(), e = SectionMap.end(); i != e; ++i) {
|
||||||
|
const SectionRef &Section = i->first;
|
||||||
|
StringRef Name;
|
||||||
|
Section.getName(Name);
|
||||||
|
if (Name == "__eh_frame")
|
||||||
|
EHFrameSID = i->second;
|
||||||
|
else if (Name == "__text")
|
||||||
|
TextSID = i->second;
|
||||||
|
else if (Name == "__gcc_except_tab")
|
||||||
|
ExceptTabSID = i->second;
|
||||||
|
else
|
||||||
|
impl().finalizeSection(ObjImg, i->second, Section);
|
||||||
|
}
|
||||||
|
UnregisteredEHFrameSections.push_back(
|
||||||
|
EHFrameRelatedSections(EHFrameSID, TextSID, ExceptTabSID));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Impl>
|
||||||
|
unsigned char *RuntimeDyldMachOCRTPBase<Impl>::processFDE(unsigned char *P,
|
||||||
|
int64_t DeltaForText,
|
||||||
|
int64_t DeltaForEH) {
|
||||||
|
typedef typename Impl::TargetPtrT TargetPtrT;
|
||||||
|
|
||||||
DEBUG(dbgs() << "Processing FDE: Delta for text: " << DeltaForText
|
DEBUG(dbgs() << "Processing FDE: Delta for text: " << DeltaForText
|
||||||
<< ", Delta for EH: " << DeltaForEH << "\n");
|
<< ", Delta for EH: " << DeltaForEH << "\n");
|
||||||
uint32_t Length = *((uint32_t *)P);
|
uint32_t Length = *((uint32_t *)P);
|
||||||
@@ -140,32 +169,33 @@ static unsigned char *processFDE(unsigned char *P, intptr_t DeltaForText,
|
|||||||
return Ret;
|
return Ret;
|
||||||
|
|
||||||
P += 4;
|
P += 4;
|
||||||
intptr_t FDELocation = *((intptr_t *)P);
|
TargetPtrT FDELocation = *((TargetPtrT*)P);
|
||||||
intptr_t NewLocation = FDELocation - DeltaForText;
|
TargetPtrT NewLocation = FDELocation - DeltaForText;
|
||||||
*((intptr_t *)P) = NewLocation;
|
*((TargetPtrT*)P) = NewLocation;
|
||||||
P += sizeof(intptr_t);
|
P += sizeof(TargetPtrT);
|
||||||
|
|
||||||
// Skip the FDE address range
|
// Skip the FDE address range
|
||||||
P += sizeof(intptr_t);
|
P += sizeof(TargetPtrT);
|
||||||
|
|
||||||
uint8_t Augmentationsize = *P;
|
uint8_t Augmentationsize = *P;
|
||||||
P += 1;
|
P += 1;
|
||||||
if (Augmentationsize != 0) {
|
if (Augmentationsize != 0) {
|
||||||
intptr_t LSDA = *((intptr_t *)P);
|
TargetPtrT LSDA = *((TargetPtrT *)P);
|
||||||
intptr_t NewLSDA = LSDA - DeltaForEH;
|
TargetPtrT NewLSDA = LSDA - DeltaForEH;
|
||||||
*((intptr_t *)P) = NewLSDA;
|
*((TargetPtrT *)P) = NewLSDA;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static intptr_t computeDelta(SectionEntry *A, SectionEntry *B) {
|
static int64_t computeDelta(SectionEntry *A, SectionEntry *B) {
|
||||||
intptr_t ObjDistance = A->ObjAddress - B->ObjAddress;
|
int64_t ObjDistance = A->ObjAddress - B->ObjAddress;
|
||||||
intptr_t MemDistance = A->LoadAddress - B->LoadAddress;
|
int64_t MemDistance = A->LoadAddress - B->LoadAddress;
|
||||||
return ObjDistance - MemDistance;
|
return ObjDistance - MemDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RuntimeDyldMachO::registerEHFrames() {
|
template <typename Impl>
|
||||||
|
void RuntimeDyldMachOCRTPBase<Impl>::registerEHFrames() {
|
||||||
|
|
||||||
if (!MemMgr)
|
if (!MemMgr)
|
||||||
return;
|
return;
|
||||||
@@ -180,8 +210,8 @@ void RuntimeDyldMachO::registerEHFrames() {
|
|||||||
if (SectionInfo.ExceptTabSID != RTDYLD_INVALID_SECTION_ID)
|
if (SectionInfo.ExceptTabSID != RTDYLD_INVALID_SECTION_ID)
|
||||||
ExceptTab = &Sections[SectionInfo.ExceptTabSID];
|
ExceptTab = &Sections[SectionInfo.ExceptTabSID];
|
||||||
|
|
||||||
intptr_t DeltaForText = computeDelta(Text, EHFrame);
|
int64_t DeltaForText = computeDelta(Text, EHFrame);
|
||||||
intptr_t DeltaForEH = 0;
|
int64_t DeltaForEH = 0;
|
||||||
if (ExceptTab)
|
if (ExceptTab)
|
||||||
DeltaForEH = computeDelta(ExceptTab, EHFrame);
|
DeltaForEH = computeDelta(ExceptTab, EHFrame);
|
||||||
|
|
||||||
|
@@ -122,7 +122,6 @@ public:
|
|||||||
|
|
||||||
bool isCompatibleFormat(const ObjectBuffer *Buffer) const override;
|
bool isCompatibleFormat(const ObjectBuffer *Buffer) const override;
|
||||||
bool isCompatibleFile(const object::ObjectFile *Obj) const override;
|
bool isCompatibleFile(const object::ObjectFile *Obj) const override;
|
||||||
void registerEHFrames() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// RuntimeDyldMachOTarget - Templated base class for generic MachO linker
|
/// RuntimeDyldMachOTarget - Templated base class for generic MachO linker
|
||||||
@@ -138,32 +137,15 @@ private:
|
|||||||
Impl &impl() { return static_cast<Impl &>(*this); }
|
Impl &impl() { return static_cast<Impl &>(*this); }
|
||||||
const Impl &impl() const { return static_cast<const Impl &>(*this); }
|
const Impl &impl() const { return static_cast<const Impl &>(*this); }
|
||||||
|
|
||||||
|
unsigned char *processFDE(unsigned char *P, int64_t DeltaForText,
|
||||||
|
int64_t DeltaForEH);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RuntimeDyldMachOCRTPBase(RTDyldMemoryManager *mm) : RuntimeDyldMachO(mm) {}
|
RuntimeDyldMachOCRTPBase(RTDyldMemoryManager *mm) : RuntimeDyldMachO(mm) {}
|
||||||
|
|
||||||
void finalizeLoad(ObjectImage &ObjImg,
|
void finalizeLoad(ObjectImage &ObjImg,
|
||||||
ObjSectionToIDMap &SectionMap) override {
|
ObjSectionToIDMap &SectionMap) override;
|
||||||
unsigned EHFrameSID = RTDYLD_INVALID_SECTION_ID;
|
void registerEHFrames() override;
|
||||||
unsigned TextSID = RTDYLD_INVALID_SECTION_ID;
|
|
||||||
unsigned ExceptTabSID = RTDYLD_INVALID_SECTION_ID;
|
|
||||||
ObjSectionToIDMap::iterator i, e;
|
|
||||||
|
|
||||||
for (i = SectionMap.begin(), e = SectionMap.end(); i != e; ++i) {
|
|
||||||
const SectionRef &Section = i->first;
|
|
||||||
StringRef Name;
|
|
||||||
Section.getName(Name);
|
|
||||||
if (Name == "__eh_frame")
|
|
||||||
EHFrameSID = i->second;
|
|
||||||
else if (Name == "__text")
|
|
||||||
TextSID = i->second;
|
|
||||||
else if (Name == "__gcc_except_tab")
|
|
||||||
ExceptTabSID = i->second;
|
|
||||||
else
|
|
||||||
impl().finalizeSection(ObjImg, i->second, Section);
|
|
||||||
}
|
|
||||||
UnregisteredEHFrameSections.push_back(
|
|
||||||
EHFrameRelatedSections(EHFrameSID, TextSID, ExceptTabSID));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
@@ -20,6 +20,9 @@ namespace llvm {
|
|||||||
class RuntimeDyldMachOAArch64
|
class RuntimeDyldMachOAArch64
|
||||||
: public RuntimeDyldMachOCRTPBase<RuntimeDyldMachOAArch64> {
|
: public RuntimeDyldMachOCRTPBase<RuntimeDyldMachOAArch64> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef uint64_t TargetPtrT;
|
||||||
|
|
||||||
RuntimeDyldMachOAArch64(RTDyldMemoryManager *MM)
|
RuntimeDyldMachOAArch64(RTDyldMemoryManager *MM)
|
||||||
: RuntimeDyldMachOCRTPBase(MM) {}
|
: RuntimeDyldMachOCRTPBase(MM) {}
|
||||||
|
|
||||||
|
@@ -22,6 +22,9 @@ private:
|
|||||||
typedef RuntimeDyldMachOCRTPBase<RuntimeDyldMachOARM> ParentT;
|
typedef RuntimeDyldMachOCRTPBase<RuntimeDyldMachOARM> ParentT;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef uint32_t TargetPtrT;
|
||||||
|
|
||||||
RuntimeDyldMachOARM(RTDyldMemoryManager *MM) : RuntimeDyldMachOCRTPBase(MM) {}
|
RuntimeDyldMachOARM(RTDyldMemoryManager *MM) : RuntimeDyldMachOCRTPBase(MM) {}
|
||||||
|
|
||||||
unsigned getMaxStubSize() override { return 8; }
|
unsigned getMaxStubSize() override { return 8; }
|
||||||
|
@@ -19,6 +19,9 @@ namespace llvm {
|
|||||||
class RuntimeDyldMachOI386
|
class RuntimeDyldMachOI386
|
||||||
: public RuntimeDyldMachOCRTPBase<RuntimeDyldMachOI386> {
|
: public RuntimeDyldMachOCRTPBase<RuntimeDyldMachOI386> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef uint32_t TargetPtrT;
|
||||||
|
|
||||||
RuntimeDyldMachOI386(RTDyldMemoryManager *MM)
|
RuntimeDyldMachOI386(RTDyldMemoryManager *MM)
|
||||||
: RuntimeDyldMachOCRTPBase(MM) {}
|
: RuntimeDyldMachOCRTPBase(MM) {}
|
||||||
|
|
||||||
|
@@ -19,6 +19,9 @@ namespace llvm {
|
|||||||
class RuntimeDyldMachOX86_64
|
class RuntimeDyldMachOX86_64
|
||||||
: public RuntimeDyldMachOCRTPBase<RuntimeDyldMachOX86_64> {
|
: public RuntimeDyldMachOCRTPBase<RuntimeDyldMachOX86_64> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef uint64_t TargetPtrT;
|
||||||
|
|
||||||
RuntimeDyldMachOX86_64(RTDyldMemoryManager *MM)
|
RuntimeDyldMachOX86_64(RTDyldMemoryManager *MM)
|
||||||
: RuntimeDyldMachOCRTPBase(MM) {}
|
: RuntimeDyldMachOCRTPBase(MM) {}
|
||||||
|
|
||||||
|
30
test/ExecutionEngine/RuntimeDyld/X86/MachO_i386_eh_frame.s
Normal file
30
test/ExecutionEngine/RuntimeDyld/X86/MachO_i386_eh_frame.s
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# RUN: llvm-mc -triple=i386-apple-macosx10.4 -relocation-model=dynamic-no-pic -filetype=obj -o %T/MachO_i386_eh_frame.o %s
|
||||||
|
# RUN: llvm-rtdyld -triple=i386-apple-macosx10.4 -verify -map-section MachO_i386_eh_frame.o,__text=0x2000 -check=%s %/T/MachO_i386_eh_frame.o
|
||||||
|
|
||||||
|
# rtdyld-check: *{4}(section_addr(MachO_i386_eh_frame.o, __eh_frame) + 0x20) = (main - (section_addr(MachO_i386_eh_frame.o, __eh_frame) + 0x20))[31:0]
|
||||||
|
# rtdyld-check: *{4}(section_addr(MachO_i386_eh_frame.o, __eh_frame) + 0x24) = 0x9
|
||||||
|
|
||||||
|
.section __TEXT,__text,regular,pure_instructions
|
||||||
|
|
||||||
|
.globl bar
|
||||||
|
.align 4, 0x90
|
||||||
|
bar:
|
||||||
|
retl
|
||||||
|
|
||||||
|
.globl main
|
||||||
|
.align 4, 0x90
|
||||||
|
main:
|
||||||
|
.cfi_startproc
|
||||||
|
pushl %ebp
|
||||||
|
Ltmp0:
|
||||||
|
.cfi_def_cfa_offset 8
|
||||||
|
Ltmp1:
|
||||||
|
.cfi_offset %ebp, -8
|
||||||
|
movl %esp, %ebp
|
||||||
|
Ltmp2:
|
||||||
|
.cfi_def_cfa_register %ebp
|
||||||
|
popl %ebp
|
||||||
|
jmp bar
|
||||||
|
.cfi_endproc
|
||||||
|
|
||||||
|
.subsections_via_symbols
|
Reference in New Issue
Block a user