mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Don't use InMemoryStruct in getRelocation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178943 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -55,6 +55,11 @@ namespace MachOFormat {
|
|||||||
support::ulittle32_t Reserved2;
|
support::ulittle32_t Reserved2;
|
||||||
support::ulittle32_t Reserved3;
|
support::ulittle32_t Reserved3;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RelocationEntry {
|
||||||
|
support::ulittle32_t Word0;
|
||||||
|
support::ulittle32_t Word1;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef MachOObject::LoadCommandInfo LoadCommandInfo;
|
typedef MachOObject::LoadCommandInfo LoadCommandInfo;
|
||||||
@@ -161,11 +166,10 @@ private:
|
|||||||
void moveToNextSymbol(DataRefImpl &DRI) const;
|
void moveToNextSymbol(DataRefImpl &DRI) const;
|
||||||
const MachOFormat::Section *getSection(DataRefImpl DRI) const;
|
const MachOFormat::Section *getSection(DataRefImpl DRI) const;
|
||||||
const MachOFormat::Section64 *getSection64(DataRefImpl DRI) const;
|
const MachOFormat::Section64 *getSection64(DataRefImpl DRI) const;
|
||||||
void getRelocation(DataRefImpl Rel,
|
const MachOFormat::RelocationEntry *getRelocation(DataRefImpl Rel) const;
|
||||||
InMemoryStruct<macho::RelocationEntry> &Res) const;
|
|
||||||
std::size_t getSectionIndex(DataRefImpl Sec) const;
|
std::size_t getSectionIndex(DataRefImpl Sec) const;
|
||||||
|
|
||||||
void printRelocationTargetName(InMemoryStruct<macho::RelocationEntry>& RE,
|
void printRelocationTargetName(const MachOFormat::RelocationEntry *RE,
|
||||||
raw_string_ostream &fmt) const;
|
raw_string_ostream &fmt) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -699,9 +699,8 @@ section_iterator MachOObjectFile::end_sections() const {
|
|||||||
|
|
||||||
/*===-- Relocations -------------------------------------------------------===*/
|
/*===-- Relocations -------------------------------------------------------===*/
|
||||||
|
|
||||||
void MachOObjectFile::
|
const MachOFormat::RelocationEntry *
|
||||||
getRelocation(DataRefImpl Rel,
|
MachOObjectFile::getRelocation(DataRefImpl Rel) const {
|
||||||
InMemoryStruct<macho::RelocationEntry> &Res) const {
|
|
||||||
uint32_t relOffset;
|
uint32_t relOffset;
|
||||||
if (MachOObj->is64Bit()) {
|
if (MachOObj->is64Bit()) {
|
||||||
const MachOFormat::Section64 *Sect = getSection64(Sections[Rel.d.b]);
|
const MachOFormat::Section64 *Sect = getSection64(Sections[Rel.d.b]);
|
||||||
@@ -710,8 +709,12 @@ getRelocation(DataRefImpl Rel,
|
|||||||
const MachOFormat::Section *Sect = getSection(Sections[Rel.d.b]);
|
const MachOFormat::Section *Sect = getSection(Sections[Rel.d.b]);
|
||||||
relOffset = Sect->RelocationTableOffset;
|
relOffset = Sect->RelocationTableOffset;
|
||||||
}
|
}
|
||||||
MachOObj->ReadRelocationEntry(relOffset, Rel.d.a, Res);
|
uint64_t Offset = relOffset + Rel.d.a * sizeof(MachOFormat::RelocationEntry);
|
||||||
|
StringRef Data =
|
||||||
|
MachOObj->getData(Offset, sizeof(MachOFormat::RelocationEntry));
|
||||||
|
return reinterpret_cast<const MachOFormat::RelocationEntry*>(Data.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code MachOObjectFile::getRelocationNext(DataRefImpl Rel,
|
error_code MachOObjectFile::getRelocationNext(DataRefImpl Rel,
|
||||||
RelocationRef &Res) const {
|
RelocationRef &Res) const {
|
||||||
++Rel.d.a;
|
++Rel.d.a;
|
||||||
@@ -728,8 +731,7 @@ error_code MachOObjectFile::getRelocationAddress(DataRefImpl Rel,
|
|||||||
const MachOFormat::Section *Sect = getSection(Sections[Rel.d.b]);
|
const MachOFormat::Section *Sect = getSection(Sections[Rel.d.b]);
|
||||||
sectAddress += Sect->Address;
|
sectAddress += Sect->Address;
|
||||||
}
|
}
|
||||||
InMemoryStruct<macho::RelocationEntry> RE;
|
const MachOFormat::RelocationEntry *RE = getRelocation(Rel);
|
||||||
getRelocation(Rel, RE);
|
|
||||||
|
|
||||||
unsigned Arch = getArch();
|
unsigned Arch = getArch();
|
||||||
bool isScattered = (Arch != Triple::x86_64) &&
|
bool isScattered = (Arch != Triple::x86_64) &&
|
||||||
@@ -745,8 +747,7 @@ error_code MachOObjectFile::getRelocationAddress(DataRefImpl Rel,
|
|||||||
}
|
}
|
||||||
error_code MachOObjectFile::getRelocationOffset(DataRefImpl Rel,
|
error_code MachOObjectFile::getRelocationOffset(DataRefImpl Rel,
|
||||||
uint64_t &Res) const {
|
uint64_t &Res) const {
|
||||||
InMemoryStruct<macho::RelocationEntry> RE;
|
const MachOFormat::RelocationEntry *RE = getRelocation(Rel);
|
||||||
getRelocation(Rel, RE);
|
|
||||||
|
|
||||||
unsigned Arch = getArch();
|
unsigned Arch = getArch();
|
||||||
bool isScattered = (Arch != Triple::x86_64) &&
|
bool isScattered = (Arch != Triple::x86_64) &&
|
||||||
@@ -759,8 +760,7 @@ error_code MachOObjectFile::getRelocationOffset(DataRefImpl Rel,
|
|||||||
}
|
}
|
||||||
error_code MachOObjectFile::getRelocationSymbol(DataRefImpl Rel,
|
error_code MachOObjectFile::getRelocationSymbol(DataRefImpl Rel,
|
||||||
SymbolRef &Res) const {
|
SymbolRef &Res) const {
|
||||||
InMemoryStruct<macho::RelocationEntry> RE;
|
const MachOFormat::RelocationEntry *RE = getRelocation(Rel);
|
||||||
getRelocation(Rel, RE);
|
|
||||||
uint32_t SymbolIdx = RE->Word1 & 0xffffff;
|
uint32_t SymbolIdx = RE->Word1 & 0xffffff;
|
||||||
bool isExtern = (RE->Word1 >> 27) & 1;
|
bool isExtern = (RE->Word1 >> 27) & 1;
|
||||||
|
|
||||||
@@ -779,8 +779,7 @@ error_code MachOObjectFile::getRelocationSymbol(DataRefImpl Rel,
|
|||||||
}
|
}
|
||||||
error_code MachOObjectFile::getRelocationType(DataRefImpl Rel,
|
error_code MachOObjectFile::getRelocationType(DataRefImpl Rel,
|
||||||
uint64_t &Res) const {
|
uint64_t &Res) const {
|
||||||
InMemoryStruct<macho::RelocationEntry> RE;
|
const MachOFormat::RelocationEntry *RE = getRelocation(Rel);
|
||||||
getRelocation(Rel, RE);
|
|
||||||
Res = RE->Word0;
|
Res = RE->Word0;
|
||||||
Res <<= 32;
|
Res <<= 32;
|
||||||
Res |= RE->Word1;
|
Res |= RE->Word1;
|
||||||
@@ -790,8 +789,7 @@ error_code MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
|
|||||||
SmallVectorImpl<char> &Result) const {
|
SmallVectorImpl<char> &Result) const {
|
||||||
// TODO: Support scattered relocations.
|
// TODO: Support scattered relocations.
|
||||||
StringRef res;
|
StringRef res;
|
||||||
InMemoryStruct<macho::RelocationEntry> RE;
|
const MachOFormat::RelocationEntry *RE = getRelocation(Rel);
|
||||||
getRelocation(Rel, RE);
|
|
||||||
|
|
||||||
unsigned Arch = getArch();
|
unsigned Arch = getArch();
|
||||||
bool isScattered = (Arch != Triple::x86_64) &&
|
bool isScattered = (Arch != Triple::x86_64) &&
|
||||||
@@ -888,8 +886,7 @@ error_code MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
|
|||||||
}
|
}
|
||||||
error_code MachOObjectFile::getRelocationAdditionalInfo(DataRefImpl Rel,
|
error_code MachOObjectFile::getRelocationAdditionalInfo(DataRefImpl Rel,
|
||||||
int64_t &Res) const {
|
int64_t &Res) const {
|
||||||
InMemoryStruct<macho::RelocationEntry> RE;
|
const MachOFormat::RelocationEntry *RE = getRelocation(Rel);
|
||||||
getRelocation(Rel, RE);
|
|
||||||
bool isExtern = (RE->Word1 >> 27) & 1;
|
bool isExtern = (RE->Word1 >> 27) & 1;
|
||||||
Res = 0;
|
Res = 0;
|
||||||
if (!isExtern) {
|
if (!isExtern) {
|
||||||
@@ -923,7 +920,7 @@ void advanceTo(T &it, size_t Val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MachOObjectFile::printRelocationTargetName(
|
void MachOObjectFile::printRelocationTargetName(
|
||||||
InMemoryStruct<macho::RelocationEntry>& RE,
|
const MachOFormat::RelocationEntry *RE,
|
||||||
raw_string_ostream &fmt) const {
|
raw_string_ostream &fmt) const {
|
||||||
unsigned Arch = getArch();
|
unsigned Arch = getArch();
|
||||||
bool isScattered = (Arch != Triple::x86_64) &&
|
bool isScattered = (Arch != Triple::x86_64) &&
|
||||||
@@ -994,8 +991,7 @@ void MachOObjectFile::printRelocationTargetName(
|
|||||||
|
|
||||||
error_code MachOObjectFile::getRelocationValueString(DataRefImpl Rel,
|
error_code MachOObjectFile::getRelocationValueString(DataRefImpl Rel,
|
||||||
SmallVectorImpl<char> &Result) const {
|
SmallVectorImpl<char> &Result) const {
|
||||||
InMemoryStruct<macho::RelocationEntry> RE;
|
const MachOFormat::RelocationEntry *RE = getRelocation(Rel);
|
||||||
getRelocation(Rel, RE);
|
|
||||||
|
|
||||||
unsigned Arch = getArch();
|
unsigned Arch = getArch();
|
||||||
bool isScattered = (Arch != Triple::x86_64) &&
|
bool isScattered = (Arch != Triple::x86_64) &&
|
||||||
@@ -1032,10 +1028,9 @@ error_code MachOObjectFile::getRelocationValueString(DataRefImpl Rel,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case macho::RIT_X86_64_Subtractor: { // X86_64_RELOC_SUBTRACTOR
|
case macho::RIT_X86_64_Subtractor: { // X86_64_RELOC_SUBTRACTOR
|
||||||
InMemoryStruct<macho::RelocationEntry> RENext;
|
|
||||||
DataRefImpl RelNext = Rel;
|
DataRefImpl RelNext = Rel;
|
||||||
RelNext.d.a++;
|
RelNext.d.a++;
|
||||||
getRelocation(RelNext, RENext);
|
const MachOFormat::RelocationEntry *RENext = getRelocation(RelNext);
|
||||||
|
|
||||||
// X86_64_SUBTRACTOR must be followed by a relocation of type
|
// X86_64_SUBTRACTOR must be followed by a relocation of type
|
||||||
// X86_64_RELOC_UNSIGNED.
|
// X86_64_RELOC_UNSIGNED.
|
||||||
@@ -1080,10 +1075,9 @@ error_code MachOObjectFile::getRelocationValueString(DataRefImpl Rel,
|
|||||||
case macho::RIT_Pair: // GENERIC_RELOC_PAIR - prints no info
|
case macho::RIT_Pair: // GENERIC_RELOC_PAIR - prints no info
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
case macho::RIT_Difference: { // GENERIC_RELOC_SECTDIFF
|
case macho::RIT_Difference: { // GENERIC_RELOC_SECTDIFF
|
||||||
InMemoryStruct<macho::RelocationEntry> RENext;
|
|
||||||
DataRefImpl RelNext = Rel;
|
DataRefImpl RelNext = Rel;
|
||||||
RelNext.d.a++;
|
RelNext.d.a++;
|
||||||
getRelocation(RelNext, RENext);
|
const MachOFormat::RelocationEntry *RENext = getRelocation(RelNext);
|
||||||
|
|
||||||
// X86 sect diff's must be followed by a relocation of type
|
// X86 sect diff's must be followed by a relocation of type
|
||||||
// GENERIC_RELOC_PAIR.
|
// GENERIC_RELOC_PAIR.
|
||||||
@@ -1110,10 +1104,9 @@ error_code MachOObjectFile::getRelocationValueString(DataRefImpl Rel,
|
|||||||
// handled in the generic code.
|
// handled in the generic code.
|
||||||
switch (Type) {
|
switch (Type) {
|
||||||
case macho::RIT_Generic_LocalDifference:{// GENERIC_RELOC_LOCAL_SECTDIFF
|
case macho::RIT_Generic_LocalDifference:{// GENERIC_RELOC_LOCAL_SECTDIFF
|
||||||
InMemoryStruct<macho::RelocationEntry> RENext;
|
|
||||||
DataRefImpl RelNext = Rel;
|
DataRefImpl RelNext = Rel;
|
||||||
RelNext.d.a++;
|
RelNext.d.a++;
|
||||||
getRelocation(RelNext, RENext);
|
const MachOFormat::RelocationEntry *RENext = getRelocation(RelNext);
|
||||||
|
|
||||||
// X86 sect diff's must be followed by a relocation of type
|
// X86 sect diff's must be followed by a relocation of type
|
||||||
// GENERIC_RELOC_PAIR.
|
// GENERIC_RELOC_PAIR.
|
||||||
@@ -1160,10 +1153,9 @@ error_code MachOObjectFile::getRelocationValueString(DataRefImpl Rel,
|
|||||||
fmt << ":lower16:(";
|
fmt << ":lower16:(";
|
||||||
printRelocationTargetName(RE, fmt);
|
printRelocationTargetName(RE, fmt);
|
||||||
|
|
||||||
InMemoryStruct<macho::RelocationEntry> RENext;
|
|
||||||
DataRefImpl RelNext = Rel;
|
DataRefImpl RelNext = Rel;
|
||||||
RelNext.d.a++;
|
RelNext.d.a++;
|
||||||
getRelocation(RelNext, RENext);
|
const MachOFormat::RelocationEntry *RENext = getRelocation(RelNext);
|
||||||
|
|
||||||
// ARM half relocs must be followed by a relocation of type
|
// ARM half relocs must be followed by a relocation of type
|
||||||
// ARM_RELOC_PAIR.
|
// ARM_RELOC_PAIR.
|
||||||
@@ -1209,8 +1201,7 @@ error_code MachOObjectFile::getRelocationValueString(DataRefImpl Rel,
|
|||||||
|
|
||||||
error_code MachOObjectFile::getRelocationHidden(DataRefImpl Rel,
|
error_code MachOObjectFile::getRelocationHidden(DataRefImpl Rel,
|
||||||
bool &Result) const {
|
bool &Result) const {
|
||||||
InMemoryStruct<macho::RelocationEntry> RE;
|
const MachOFormat::RelocationEntry *RE = getRelocation(Rel);
|
||||||
getRelocation(Rel, RE);
|
|
||||||
|
|
||||||
unsigned Arch = getArch();
|
unsigned Arch = getArch();
|
||||||
bool isScattered = (Arch != Triple::x86_64) &&
|
bool isScattered = (Arch != Triple::x86_64) &&
|
||||||
@@ -1233,8 +1224,7 @@ error_code MachOObjectFile::getRelocationHidden(DataRefImpl Rel,
|
|||||||
if (Type == macho::RIT_X86_64_Unsigned && Rel.d.a > 0) {
|
if (Type == macho::RIT_X86_64_Unsigned && Rel.d.a > 0) {
|
||||||
DataRefImpl RelPrev = Rel;
|
DataRefImpl RelPrev = Rel;
|
||||||
RelPrev.d.a--;
|
RelPrev.d.a--;
|
||||||
InMemoryStruct<macho::RelocationEntry> REPrev;
|
const MachOFormat::RelocationEntry *REPrev = getRelocation(RelPrev);
|
||||||
getRelocation(RelPrev, REPrev);
|
|
||||||
|
|
||||||
unsigned PrevType = (REPrev->Word1 >> 28) & 0xF;
|
unsigned PrevType = (REPrev->Word1 >> 28) & 0xF;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user