mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Add support for 64 bit objects to MachOObjectFile.
- I don't see a better way than duplicating all the code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135229 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -70,6 +70,8 @@ private:
|
|||||||
InMemoryStruct<macho::SymbolTableEntry> &Res) const;
|
InMemoryStruct<macho::SymbolTableEntry> &Res) const;
|
||||||
void moveToNextSymbol(DataRefImpl &DRI) const;
|
void moveToNextSymbol(DataRefImpl &DRI) const;
|
||||||
void getSection(DataRefImpl DRI, InMemoryStruct<macho::Section> &Res) const;
|
void getSection(DataRefImpl DRI, InMemoryStruct<macho::Section> &Res) const;
|
||||||
|
void getSection64(DataRefImpl DRI,
|
||||||
|
InMemoryStruct<macho::Section64> &Res) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
ObjectFile *ObjectFile::createMachOObjectFile(MemoryBuffer *Buffer) {
|
ObjectFile *ObjectFile::createMachOObjectFile(MemoryBuffer *Buffer) {
|
||||||
@@ -234,51 +236,105 @@ MachOObjectFile::getSection(DataRefImpl DRI,
|
|||||||
MachOObj->ReadSection(LCI, DRI.d.b, Res);
|
MachOObj->ReadSection(LCI, DRI.d.b, Res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MachOObjectFile::getSection64(DataRefImpl DRI,
|
||||||
|
InMemoryStruct<macho::Section64> &Res) const {
|
||||||
|
InMemoryStruct<macho::Segment64LoadCommand> SLC;
|
||||||
|
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
|
||||||
|
MachOObj->ReadSegment64LoadCommand(LCI, SLC);
|
||||||
|
MachOObj->ReadSection64(LCI, DRI.d.b, Res);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is64BitLoadCommand(const MachOObject *MachOObj, DataRefImpl DRI) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
error_code MachOObjectFile::getSectionName(DataRefImpl DRI,
|
error_code MachOObjectFile::getSectionName(DataRefImpl DRI,
|
||||||
StringRef &Result) const {
|
StringRef &Result) const {
|
||||||
InMemoryStruct<macho::SegmentLoadCommand> SLC;
|
// FIXME: thread safety.
|
||||||
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
|
|
||||||
MachOObj->ReadSegmentLoadCommand(LCI, SLC);
|
|
||||||
InMemoryStruct<macho::Section> Sect;
|
|
||||||
MachOObj->ReadSection(LCI, DRI.d.b, Sect);
|
|
||||||
|
|
||||||
static char result[34];
|
static char result[34];
|
||||||
strcpy(result, SLC->Name);
|
if (is64BitLoadCommand(MachOObj, DRI)) {
|
||||||
strcat(result, ",");
|
InMemoryStruct<macho::Segment64LoadCommand> SLC;
|
||||||
strcat(result, Sect->Name);
|
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
|
||||||
|
MachOObj->ReadSegment64LoadCommand(LCI, SLC);
|
||||||
|
InMemoryStruct<macho::Section64> Sect;
|
||||||
|
MachOObj->ReadSection64(LCI, DRI.d.b, Sect);
|
||||||
|
|
||||||
|
strcpy(result, SLC->Name);
|
||||||
|
strcat(result, ",");
|
||||||
|
strcat(result, Sect->Name);
|
||||||
|
} else {
|
||||||
|
InMemoryStruct<macho::SegmentLoadCommand> SLC;
|
||||||
|
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
|
||||||
|
MachOObj->ReadSegmentLoadCommand(LCI, SLC);
|
||||||
|
InMemoryStruct<macho::Section> Sect;
|
||||||
|
MachOObj->ReadSection(LCI, DRI.d.b, Sect);
|
||||||
|
|
||||||
|
strcpy(result, SLC->Name);
|
||||||
|
strcat(result, ",");
|
||||||
|
strcat(result, Sect->Name);
|
||||||
|
}
|
||||||
Result = StringRef(result);
|
Result = StringRef(result);
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code MachOObjectFile::getSectionAddress(DataRefImpl DRI,
|
error_code MachOObjectFile::getSectionAddress(DataRefImpl DRI,
|
||||||
uint64_t &Result) const {
|
uint64_t &Result) const {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
if (is64BitLoadCommand(MachOObj, DRI)) {
|
||||||
getSection(DRI, Sect);
|
InMemoryStruct<macho::Section64> Sect;
|
||||||
Result = Sect->Address;
|
getSection64(DRI, Sect);
|
||||||
|
Result = Sect->Address;
|
||||||
|
} else {
|
||||||
|
InMemoryStruct<macho::Section> Sect;
|
||||||
|
getSection(DRI, Sect);
|
||||||
|
Result = Sect->Address;
|
||||||
|
}
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code MachOObjectFile::getSectionSize(DataRefImpl DRI,
|
error_code MachOObjectFile::getSectionSize(DataRefImpl DRI,
|
||||||
uint64_t &Result) const {
|
uint64_t &Result) const {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
if (is64BitLoadCommand(MachOObj, DRI)) {
|
||||||
getSection(DRI, Sect);
|
InMemoryStruct<macho::Section64> Sect;
|
||||||
Result = Sect->Size;
|
getSection64(DRI, Sect);
|
||||||
|
Result = Sect->Size;
|
||||||
|
} else {
|
||||||
|
InMemoryStruct<macho::Section> Sect;
|
||||||
|
getSection(DRI, Sect);
|
||||||
|
Result = Sect->Size;
|
||||||
|
}
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code MachOObjectFile::getSectionContents(DataRefImpl DRI,
|
error_code MachOObjectFile::getSectionContents(DataRefImpl DRI,
|
||||||
StringRef &Result) const {
|
StringRef &Result) const {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
if (is64BitLoadCommand(MachOObj, DRI)) {
|
||||||
getSection(DRI, Sect);
|
InMemoryStruct<macho::Section64> Sect;
|
||||||
Result = MachOObj->getData(Sect->Offset, Sect->Size);
|
getSection64(DRI, Sect);
|
||||||
|
Result = MachOObj->getData(Sect->Offset, Sect->Size);
|
||||||
|
} else {
|
||||||
|
InMemoryStruct<macho::Section> Sect;
|
||||||
|
getSection(DRI, Sect);
|
||||||
|
Result = MachOObj->getData(Sect->Offset, Sect->Size);
|
||||||
|
}
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code MachOObjectFile::isSectionText(DataRefImpl DRI,
|
error_code MachOObjectFile::isSectionText(DataRefImpl DRI,
|
||||||
bool &Result) const {
|
bool &Result) const {
|
||||||
InMemoryStruct<macho::Section> Sect;
|
if (is64BitLoadCommand(MachOObj, DRI)) {
|
||||||
getSection(DRI, Sect);
|
InMemoryStruct<macho::Section64> Sect;
|
||||||
Result = !strcmp(Sect->Name, "__text");
|
getSection64(DRI, Sect);
|
||||||
|
Result = !strcmp(Sect->Name, "__text");
|
||||||
|
} else {
|
||||||
|
InMemoryStruct<macho::Section> Sect;
|
||||||
|
getSection(DRI, Sect);
|
||||||
|
Result = !strcmp(Sect->Name, "__text");
|
||||||
|
}
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user