mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-12 03:32:10 +00:00
Don't use InMemoryStruct in getSection and getSection64.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178894 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5789a86f5c
commit
c1cd6aa7a4
@ -127,9 +127,8 @@ private:
|
|||||||
void getSymbol64TableEntry(DataRefImpl DRI,
|
void getSymbol64TableEntry(DataRefImpl DRI,
|
||||||
InMemoryStruct<macho::Symbol64TableEntry> &Res) const;
|
InMemoryStruct<macho::Symbol64TableEntry> &Res) const;
|
||||||
void moveToNextSymbol(DataRefImpl &DRI) const;
|
void moveToNextSymbol(DataRefImpl &DRI) const;
|
||||||
void getSection(DataRefImpl DRI, InMemoryStruct<macho::Section> &Res) const;
|
const macho::Section *getSection(DataRefImpl DRI) const;
|
||||||
void getSection64(DataRefImpl DRI,
|
const macho::Section64 *getSection64(DataRefImpl DRI) const;
|
||||||
InMemoryStruct<macho::Section64> &Res) const;
|
|
||||||
void getRelocation(DataRefImpl Rel,
|
void getRelocation(DataRefImpl Rel,
|
||||||
InMemoryStruct<macho::RelocationEntry> &Res) const;
|
InMemoryStruct<macho::RelocationEntry> &Res) const;
|
||||||
std::size_t getSectionIndex(DataRefImpl Sec) const;
|
std::size_t getSectionIndex(DataRefImpl Sec) const;
|
||||||
|
@ -138,8 +138,8 @@ error_code MachOObjectFile::getSymbolFileOffset(DataRefImpl DRI,
|
|||||||
getSymbol64TableEntry(DRI, Entry);
|
getSymbol64TableEntry(DRI, Entry);
|
||||||
Result = Entry->Value;
|
Result = Entry->Value;
|
||||||
if (Entry->SectionIndex) {
|
if (Entry->SectionIndex) {
|
||||||
InMemoryStruct<macho::Section64> Section;
|
const macho::Section64 *Section =
|
||||||
getSection64(Sections[Entry->SectionIndex-1], Section);
|
getSection64(Sections[Entry->SectionIndex-1]);
|
||||||
Result += Section->Offset - Section->Address;
|
Result += Section->Offset - Section->Address;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -147,8 +147,8 @@ error_code MachOObjectFile::getSymbolFileOffset(DataRefImpl DRI,
|
|||||||
getSymbolTableEntry(DRI, Entry);
|
getSymbolTableEntry(DRI, Entry);
|
||||||
Result = Entry->Value;
|
Result = Entry->Value;
|
||||||
if (Entry->SectionIndex) {
|
if (Entry->SectionIndex) {
|
||||||
InMemoryStruct<macho::Section> Section;
|
const macho::Section *Section =
|
||||||
getSection(Sections[Entry->SectionIndex-1], Section);
|
getSection(Sections[Entry->SectionIndex-1]);
|
||||||
Result += Section->Offset - Section->Address;
|
Result += Section->Offset - Section->Address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -444,11 +444,21 @@ error_code MachOObjectFile::getSectionNext(DataRefImpl DRI,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static bool is64BitLoadCommand(const MachOObject *MachOObj, DataRefImpl DRI) {
|
||||||
MachOObjectFile::getSection(DataRefImpl DRI,
|
|
||||||
InMemoryStruct<macho::Section> &Res) const {
|
|
||||||
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
|
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
|
||||||
MachOObj->ReadSection(LCI, DRI.d.b, Res);
|
if (LCI.Command.Type == macho::LCT_Segment64)
|
||||||
|
return true;
|
||||||
|
assert(LCI.Command.Type == macho::LCT_Segment && "Unexpected Type.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const macho::Section *MachOObjectFile::getSection(DataRefImpl DRI) const {
|
||||||
|
assert(!is64BitLoadCommand(MachOObj.get(), DRI));
|
||||||
|
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
|
||||||
|
unsigned SectionOffset = LCI.Offset + sizeof(macho::SegmentLoadCommand) +
|
||||||
|
DRI.d.b * sizeof(macho::Section);
|
||||||
|
StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section));
|
||||||
|
return reinterpret_cast<const macho::Section*>(Data.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t MachOObjectFile::getSectionIndex(DataRefImpl Sec) const {
|
std::size_t MachOObjectFile::getSectionIndex(DataRefImpl Sec) const {
|
||||||
@ -458,19 +468,14 @@ std::size_t MachOObjectFile::getSectionIndex(DataRefImpl Sec) const {
|
|||||||
return std::distance(Sections.begin(), loc);
|
return std::distance(Sections.begin(), loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
const macho::Section64 *
|
||||||
MachOObjectFile::getSection64(DataRefImpl DRI,
|
MachOObjectFile::getSection64(DataRefImpl DRI) const {
|
||||||
InMemoryStruct<macho::Section64> &Res) const {
|
assert(is64BitLoadCommand(MachOObj.get(), DRI));
|
||||||
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
|
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
|
||||||
MachOObj->ReadSection64(LCI, DRI.d.b, Res);
|
unsigned SectionOffset = LCI.Offset + sizeof(macho::Segment64LoadCommand) +
|
||||||
}
|
DRI.d.b * sizeof(macho::Section64);
|
||||||
|
StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section64));
|
||||||
static bool is64BitLoadCommand(const MachOObject *MachOObj, DataRefImpl DRI) {
|
return reinterpret_cast<const macho::Section64*>(Data.data());
|
||||||
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
|
|
||||||
if (LCI.Command.Type == macho::LCT_Segment64)
|
|
||||||
return true;
|
|
||||||
assert(LCI.Command.Type == macho::LCT_Segment && "Unexpected Type.");
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static StringRef parseSegmentOrSectionName(const char *P) {
|
static StringRef parseSegmentOrSectionName(const char *P) {
|
||||||
@ -483,21 +488,11 @@ static StringRef parseSegmentOrSectionName(const char *P) {
|
|||||||
|
|
||||||
ArrayRef<char> MachOObjectFile::getSectionRawName(DataRefImpl DRI) const {
|
ArrayRef<char> MachOObjectFile::getSectionRawName(DataRefImpl DRI) const {
|
||||||
if (is64BitLoadCommand(MachOObj.get(), DRI)) {
|
if (is64BitLoadCommand(MachOObj.get(), DRI)) {
|
||||||
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
|
const macho::Section64 *sec = getSection64(DRI);
|
||||||
unsigned SectionOffset = LCI.Offset + sizeof(macho::Segment64LoadCommand) +
|
return ArrayRef<char>(sec->Name);
|
||||||
DRI.d.b * sizeof(macho::Section64);
|
|
||||||
StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section64));
|
|
||||||
const macho::Section64 *sec =
|
|
||||||
reinterpret_cast<const macho::Section64*>(Data.data());
|
|
||||||
return ArrayRef<char>(sec->Name, 16);
|
|
||||||
} else {
|
} else {
|
||||||
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
|
const macho::Section *sec = getSection(DRI);
|
||||||
unsigned SectionOffset = LCI.Offset + sizeof(macho::SegmentLoadCommand) +
|
return ArrayRef<char>(sec->Name);
|
||||||
DRI.d.b * sizeof(macho::Section);
|
|
||||||
StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section));
|
|
||||||
const macho::Section *sec =
|
|
||||||
reinterpret_cast<const macho::Section*>(Data.data());
|
|
||||||
return ArrayRef<char>(sec->Name, 16);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -511,20 +506,10 @@ error_code MachOObjectFile::getSectionName(DataRefImpl DRI,
|
|||||||
ArrayRef<char>
|
ArrayRef<char>
|
||||||
MachOObjectFile::getSectionRawFinalSegmentName(DataRefImpl Sec) const {
|
MachOObjectFile::getSectionRawFinalSegmentName(DataRefImpl Sec) const {
|
||||||
if (is64BitLoadCommand(MachOObj.get(), Sec)) {
|
if (is64BitLoadCommand(MachOObj.get(), Sec)) {
|
||||||
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a);
|
const macho::Section64 *sec = getSection64(Sec);
|
||||||
unsigned SectionOffset = LCI.Offset + sizeof(macho::Segment64LoadCommand) +
|
|
||||||
Sec.d.b * sizeof(macho::Section64);
|
|
||||||
StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section64));
|
|
||||||
const macho::Section64 *sec =
|
|
||||||
reinterpret_cast<const macho::Section64*>(Data.data());
|
|
||||||
return ArrayRef<char>(sec->SegmentName, 16);
|
return ArrayRef<char>(sec->SegmentName, 16);
|
||||||
} else {
|
} else {
|
||||||
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a);
|
const macho::Section *sec = getSection(Sec);
|
||||||
unsigned SectionOffset = LCI.Offset + sizeof(macho::SegmentLoadCommand) +
|
|
||||||
Sec.d.b * sizeof(macho::Section);
|
|
||||||
StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section));
|
|
||||||
const macho::Section *sec =
|
|
||||||
reinterpret_cast<const macho::Section*>(Data.data());
|
|
||||||
return ArrayRef<char>(sec->SegmentName);
|
return ArrayRef<char>(sec->SegmentName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -537,12 +522,10 @@ StringRef MachOObjectFile::getSectionFinalSegmentName(DataRefImpl DRI) const {
|
|||||||
error_code MachOObjectFile::getSectionAddress(DataRefImpl DRI,
|
error_code MachOObjectFile::getSectionAddress(DataRefImpl DRI,
|
||||||
uint64_t &Result) const {
|
uint64_t &Result) const {
|
||||||
if (is64BitLoadCommand(MachOObj.get(), DRI)) {
|
if (is64BitLoadCommand(MachOObj.get(), DRI)) {
|
||||||
InMemoryStruct<macho::Section64> Sect;
|
const macho::Section64 *Sect = getSection64(DRI);
|
||||||
getSection64(DRI, Sect);
|
|
||||||
Result = Sect->Address;
|
Result = Sect->Address;
|
||||||
} else {
|
} else {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
const macho::Section *Sect = getSection(DRI);
|
||||||
getSection(DRI, Sect);
|
|
||||||
Result = Sect->Address;
|
Result = Sect->Address;
|
||||||
}
|
}
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
@ -551,12 +534,10 @@ error_code MachOObjectFile::getSectionAddress(DataRefImpl DRI,
|
|||||||
error_code MachOObjectFile::getSectionSize(DataRefImpl DRI,
|
error_code MachOObjectFile::getSectionSize(DataRefImpl DRI,
|
||||||
uint64_t &Result) const {
|
uint64_t &Result) const {
|
||||||
if (is64BitLoadCommand(MachOObj.get(), DRI)) {
|
if (is64BitLoadCommand(MachOObj.get(), DRI)) {
|
||||||
InMemoryStruct<macho::Section64> Sect;
|
const macho::Section64 *Sect = getSection64(DRI);
|
||||||
getSection64(DRI, Sect);
|
|
||||||
Result = Sect->Size;
|
Result = Sect->Size;
|
||||||
} else {
|
} else {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
const macho::Section *Sect = getSection(DRI);
|
||||||
getSection(DRI, Sect);
|
|
||||||
Result = Sect->Size;
|
Result = Sect->Size;
|
||||||
}
|
}
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
@ -565,12 +546,10 @@ error_code MachOObjectFile::getSectionSize(DataRefImpl DRI,
|
|||||||
error_code MachOObjectFile::getSectionContents(DataRefImpl DRI,
|
error_code MachOObjectFile::getSectionContents(DataRefImpl DRI,
|
||||||
StringRef &Result) const {
|
StringRef &Result) const {
|
||||||
if (is64BitLoadCommand(MachOObj.get(), DRI)) {
|
if (is64BitLoadCommand(MachOObj.get(), DRI)) {
|
||||||
InMemoryStruct<macho::Section64> Sect;
|
const macho::Section64 *Sect = getSection64(DRI);
|
||||||
getSection64(DRI, Sect);
|
|
||||||
Result = MachOObj->getData(Sect->Offset, Sect->Size);
|
Result = MachOObj->getData(Sect->Offset, Sect->Size);
|
||||||
} else {
|
} else {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
const macho::Section *Sect = getSection(DRI);
|
||||||
getSection(DRI, Sect);
|
|
||||||
Result = MachOObj->getData(Sect->Offset, Sect->Size);
|
Result = MachOObj->getData(Sect->Offset, Sect->Size);
|
||||||
}
|
}
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
@ -579,12 +558,10 @@ error_code MachOObjectFile::getSectionContents(DataRefImpl DRI,
|
|||||||
error_code MachOObjectFile::getSectionAlignment(DataRefImpl DRI,
|
error_code MachOObjectFile::getSectionAlignment(DataRefImpl DRI,
|
||||||
uint64_t &Result) const {
|
uint64_t &Result) const {
|
||||||
if (is64BitLoadCommand(MachOObj.get(), DRI)) {
|
if (is64BitLoadCommand(MachOObj.get(), DRI)) {
|
||||||
InMemoryStruct<macho::Section64> Sect;
|
const macho::Section64 *Sect = getSection64(DRI);
|
||||||
getSection64(DRI, Sect);
|
|
||||||
Result = uint64_t(1) << Sect->Align;
|
Result = uint64_t(1) << Sect->Align;
|
||||||
} else {
|
} else {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
const macho::Section *Sect = getSection(DRI);
|
||||||
getSection(DRI, Sect);
|
|
||||||
Result = uint64_t(1) << Sect->Align;
|
Result = uint64_t(1) << Sect->Align;
|
||||||
}
|
}
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
@ -593,12 +570,10 @@ error_code MachOObjectFile::getSectionAlignment(DataRefImpl DRI,
|
|||||||
error_code MachOObjectFile::isSectionText(DataRefImpl DRI,
|
error_code MachOObjectFile::isSectionText(DataRefImpl DRI,
|
||||||
bool &Result) const {
|
bool &Result) const {
|
||||||
if (is64BitLoadCommand(MachOObj.get(), DRI)) {
|
if (is64BitLoadCommand(MachOObj.get(), DRI)) {
|
||||||
InMemoryStruct<macho::Section64> Sect;
|
const macho::Section64 *Sect = getSection64(DRI);
|
||||||
getSection64(DRI, Sect);
|
|
||||||
Result = Sect->Flags & macho::SF_PureInstructions;
|
Result = Sect->Flags & macho::SF_PureInstructions;
|
||||||
} else {
|
} else {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
const macho::Section *Sect = getSection(DRI);
|
||||||
getSection(DRI, Sect);
|
|
||||||
Result = Sect->Flags & macho::SF_PureInstructions;
|
Result = Sect->Flags & macho::SF_PureInstructions;
|
||||||
}
|
}
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
@ -635,14 +610,12 @@ error_code MachOObjectFile::isSectionVirtual(DataRefImpl Sec,
|
|||||||
error_code MachOObjectFile::isSectionZeroInit(DataRefImpl DRI,
|
error_code MachOObjectFile::isSectionZeroInit(DataRefImpl DRI,
|
||||||
bool &Result) const {
|
bool &Result) const {
|
||||||
if (MachOObj->is64Bit()) {
|
if (MachOObj->is64Bit()) {
|
||||||
InMemoryStruct<macho::Section64> Sect;
|
const macho::Section64 *Sect = getSection64(DRI);
|
||||||
getSection64(DRI, Sect);
|
|
||||||
unsigned SectionType = Sect->Flags & MachO::SectionFlagMaskSectionType;
|
unsigned SectionType = Sect->Flags & MachO::SectionFlagMaskSectionType;
|
||||||
Result = (SectionType == MachO::SectionTypeZeroFill ||
|
Result = (SectionType == MachO::SectionTypeZeroFill ||
|
||||||
SectionType == MachO::SectionTypeZeroFillLarge);
|
SectionType == MachO::SectionTypeZeroFillLarge);
|
||||||
} else {
|
} else {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
const macho::Section *Sect = getSection(DRI);
|
||||||
getSection(DRI, Sect);
|
|
||||||
unsigned SectionType = Sect->Flags & MachO::SectionFlagMaskSectionType;
|
unsigned SectionType = Sect->Flags & MachO::SectionFlagMaskSectionType;
|
||||||
Result = (SectionType == MachO::SectionTypeZeroFill ||
|
Result = (SectionType == MachO::SectionTypeZeroFill ||
|
||||||
SectionType == MachO::SectionTypeZeroFillLarge);
|
SectionType == MachO::SectionTypeZeroFillLarge);
|
||||||
@ -700,12 +673,10 @@ relocation_iterator MachOObjectFile::getSectionRelBegin(DataRefImpl Sec) const {
|
|||||||
relocation_iterator MachOObjectFile::getSectionRelEnd(DataRefImpl Sec) const {
|
relocation_iterator MachOObjectFile::getSectionRelEnd(DataRefImpl Sec) const {
|
||||||
uint32_t last_reloc;
|
uint32_t last_reloc;
|
||||||
if (is64BitLoadCommand(MachOObj.get(), Sec)) {
|
if (is64BitLoadCommand(MachOObj.get(), Sec)) {
|
||||||
InMemoryStruct<macho::Section64> Sect;
|
const macho::Section64 *Sect = getSection64(Sec);
|
||||||
getSection64(Sec, Sect);
|
|
||||||
last_reloc = Sect->NumRelocationTableEntries;
|
last_reloc = Sect->NumRelocationTableEntries;
|
||||||
} else {
|
} else {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
const macho::Section *Sect = getSection(Sec);
|
||||||
getSection(Sec, Sect);
|
|
||||||
last_reloc = Sect->NumRelocationTableEntries;
|
last_reloc = Sect->NumRelocationTableEntries;
|
||||||
}
|
}
|
||||||
DataRefImpl ret;
|
DataRefImpl ret;
|
||||||
@ -733,12 +704,10 @@ getRelocation(DataRefImpl Rel,
|
|||||||
InMemoryStruct<macho::RelocationEntry> &Res) const {
|
InMemoryStruct<macho::RelocationEntry> &Res) const {
|
||||||
uint32_t relOffset;
|
uint32_t relOffset;
|
||||||
if (MachOObj->is64Bit()) {
|
if (MachOObj->is64Bit()) {
|
||||||
InMemoryStruct<macho::Section64> Sect;
|
const macho::Section64 *Sect = getSection64(Sections[Rel.d.b]);
|
||||||
getSection64(Sections[Rel.d.b], Sect);
|
|
||||||
relOffset = Sect->RelocationTableOffset;
|
relOffset = Sect->RelocationTableOffset;
|
||||||
} else {
|
} else {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
const macho::Section *Sect = getSection(Sections[Rel.d.b]);
|
||||||
getSection(Sections[Rel.d.b], Sect);
|
|
||||||
relOffset = Sect->RelocationTableOffset;
|
relOffset = Sect->RelocationTableOffset;
|
||||||
}
|
}
|
||||||
MachOObj->ReadRelocationEntry(relOffset, Rel.d.a, Res);
|
MachOObj->ReadRelocationEntry(relOffset, Rel.d.a, Res);
|
||||||
@ -753,12 +722,10 @@ error_code MachOObjectFile::getRelocationAddress(DataRefImpl Rel,
|
|||||||
uint64_t &Res) const {
|
uint64_t &Res) const {
|
||||||
const uint8_t* sectAddress = 0;
|
const uint8_t* sectAddress = 0;
|
||||||
if (MachOObj->is64Bit()) {
|
if (MachOObj->is64Bit()) {
|
||||||
InMemoryStruct<macho::Section64> Sect;
|
const macho::Section64 *Sect = getSection64(Sections[Rel.d.b]);
|
||||||
getSection64(Sections[Rel.d.b], Sect);
|
|
||||||
sectAddress += Sect->Address;
|
sectAddress += Sect->Address;
|
||||||
} else {
|
} else {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
const macho::Section *Sect = getSection(Sections[Rel.d.b]);
|
||||||
getSection(Sections[Rel.d.b], Sect);
|
|
||||||
sectAddress += Sect->Address;
|
sectAddress += Sect->Address;
|
||||||
}
|
}
|
||||||
InMemoryStruct<macho::RelocationEntry> RE;
|
InMemoryStruct<macho::RelocationEntry> RE;
|
||||||
@ -928,12 +895,10 @@ error_code MachOObjectFile::getRelocationAdditionalInfo(DataRefImpl Rel,
|
|||||||
if (!isExtern) {
|
if (!isExtern) {
|
||||||
const uint8_t* sectAddress = base();
|
const uint8_t* sectAddress = base();
|
||||||
if (MachOObj->is64Bit()) {
|
if (MachOObj->is64Bit()) {
|
||||||
InMemoryStruct<macho::Section64> Sect;
|
const macho::Section64 *Sect = getSection64(Sections[Rel.d.b]);
|
||||||
getSection64(Sections[Rel.d.b], Sect);
|
|
||||||
sectAddress += Sect->Offset;
|
sectAddress += Sect->Offset;
|
||||||
} else {
|
} else {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
const macho::Section *Sect = getSection(Sections[Rel.d.b]);
|
||||||
getSection(Sections[Rel.d.b], Sect);
|
|
||||||
sectAddress += Sect->Offset;
|
sectAddress += Sect->Offset;
|
||||||
}
|
}
|
||||||
Res = reinterpret_cast<uintptr_t>(sectAddress);
|
Res = reinterpret_cast<uintptr_t>(sectAddress);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user