mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-21 18:24:23 +00:00
Fix Addend computation for non external relocations on Macho.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180790 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -130,6 +130,7 @@ public:
|
|||||||
unsigned getAnyRelocationPCRel(const macho::RelocationEntry &RE) const;
|
unsigned getAnyRelocationPCRel(const macho::RelocationEntry &RE) const;
|
||||||
unsigned getAnyRelocationLength(const macho::RelocationEntry &RE) const;
|
unsigned getAnyRelocationLength(const macho::RelocationEntry &RE) const;
|
||||||
unsigned getAnyRelocationType(const macho::RelocationEntry &RE) const;
|
unsigned getAnyRelocationType(const macho::RelocationEntry &RE) const;
|
||||||
|
SectionRef getRelocationSection(const macho::RelocationEntry &RE) const;
|
||||||
|
|
||||||
// Walk load commands.
|
// Walk load commands.
|
||||||
LoadCommandInfo getFirstLoadCommandInfo() const;
|
LoadCommandInfo getFirstLoadCommandInfo() const;
|
||||||
|
@ -232,12 +232,12 @@ void RuntimeDyldMachO::processRelocationRef(unsigned SectionID,
|
|||||||
unsigned Size = MachO->getAnyRelocationLength(RE);
|
unsigned Size = MachO->getAnyRelocationLength(RE);
|
||||||
uint64_t Offset;
|
uint64_t Offset;
|
||||||
RelI.getOffset(Offset);
|
RelI.getOffset(Offset);
|
||||||
if (isExtern) {
|
uint8_t *LocalAddress = Section.Address + Offset;
|
||||||
uint8_t *LocalAddress = Section.Address + Offset;
|
unsigned NumBytes = 1 << Size;
|
||||||
unsigned NumBytes = 1 << Size;
|
uint64_t Addend = 0;
|
||||||
uint64_t Addend = 0;
|
memcpy(&Addend, LocalAddress, NumBytes);
|
||||||
memcpy(&Addend, LocalAddress, NumBytes);
|
|
||||||
|
|
||||||
|
if (isExtern) {
|
||||||
// Obtain the symbol name which is referenced in the relocation
|
// Obtain the symbol name which is referenced in the relocation
|
||||||
SymbolRef Symbol;
|
SymbolRef Symbol;
|
||||||
RelI.getSymbol(Symbol);
|
RelI.getSymbol(Symbol);
|
||||||
@ -260,29 +260,11 @@ void RuntimeDyldMachO::processRelocationRef(unsigned SectionID,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error_code err;
|
SectionRef Sec = MachO->getRelocationSection(RE);
|
||||||
uint8_t sectionIndex = static_cast<uint8_t>(RelType & 0xFF);
|
Value.SectionID = findOrEmitSection(Obj, Sec, true, ObjSectionToID);
|
||||||
section_iterator si = Obj.begin_sections(),
|
uint64_t Addr;
|
||||||
se = Obj.end_sections();
|
Sec.getAddress(Addr);
|
||||||
for (uint8_t i = 1; i < sectionIndex; i++) {
|
Value.Addend = Addend - Addr;
|
||||||
error_code err;
|
|
||||||
si.increment(err);
|
|
||||||
if (si == se)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
assert(si != se && "No section containing relocation!");
|
|
||||||
Value.SectionID = findOrEmitSection(Obj, *si, true, ObjSectionToID);
|
|
||||||
Value.Addend = 0;
|
|
||||||
// FIXME: The size and type of the relocation determines if we can
|
|
||||||
// encode an Addend in the target location itself, and if so, how many
|
|
||||||
// bytes we should read in order to get it. We don't yet support doing
|
|
||||||
// that, and just assuming it's sizeof(intptr_t) is blatantly wrong.
|
|
||||||
//Value.Addend = *(const intptr_t *)Target;
|
|
||||||
if (Value.Addend) {
|
|
||||||
// The MachO addend is an offset from the current section. We need it
|
|
||||||
// to be an offset from the destination section
|
|
||||||
Value.Addend += Section.ObjAddress - Sections[Value.SectionID].ObjAddress;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Arch == Triple::arm && (RelType & 0xf) == macho::RIT_ARM_Branch24Bit) {
|
if (Arch == Triple::arm && (RelType & 0xf) == macho::RIT_ARM_Branch24Bit) {
|
||||||
|
@ -1414,6 +1414,16 @@ MachOObjectFile::getAnyRelocationType(const macho::RelocationEntry &RE) const {
|
|||||||
return getPlainRelocationType(this, RE);
|
return getPlainRelocationType(this, RE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SectionRef
|
||||||
|
MachOObjectFile::getRelocationSection(const macho::RelocationEntry &RE) const {
|
||||||
|
if (isRelocationScattered(RE) || getPlainRelocationExternal(RE))
|
||||||
|
return *end_sections();
|
||||||
|
unsigned SecNum = getPlainRelocationSymbolNum(RE) - 1;
|
||||||
|
DataRefImpl DRI;
|
||||||
|
DRI.d.a = SecNum;
|
||||||
|
return SectionRef(DRI, this);
|
||||||
|
}
|
||||||
|
|
||||||
MachOObjectFile::LoadCommandInfo
|
MachOObjectFile::LoadCommandInfo
|
||||||
MachOObjectFile::getFirstLoadCommandInfo() const {
|
MachOObjectFile::getFirstLoadCommandInfo() const {
|
||||||
MachOObjectFile::LoadCommandInfo Load;
|
MachOObjectFile::LoadCommandInfo Load;
|
||||||
|
12
test/ExecutionEngine/MCJIT/non-extern-addend.ll
Normal file
12
test/ExecutionEngine/MCJIT/non-extern-addend.ll
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
; RUN: %lli_mcjit %s > /dev/null
|
||||||
|
|
||||||
|
define i32 @foo(i32 %X, i32 %Y, double %A) {
|
||||||
|
%cond212 = fcmp ueq double %A, 2.000000e+00 ; <i1> [#uses=1]
|
||||||
|
%cast110 = zext i1 %cond212 to i32 ; <i32> [#uses=1]
|
||||||
|
ret i32 %cast110
|
||||||
|
}
|
||||||
|
|
||||||
|
define i32 @main() {
|
||||||
|
%reg212 = call i32 @foo( i32 0, i32 1, double 1.000000e+00 ) ; <i32> [#uses=1]
|
||||||
|
ret i32 %reg212
|
||||||
|
}
|
Reference in New Issue
Block a user