mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-07 14:33:15 +00:00
Add a SectionBase struct.
Use it to share code and when we don't need to know if we have a 32 or 64 bit Section. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179072 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0a9b452aa4
commit
3388589fc1
@ -27,6 +27,11 @@ namespace llvm {
|
|||||||
namespace object {
|
namespace object {
|
||||||
|
|
||||||
namespace MachOFormat {
|
namespace MachOFormat {
|
||||||
|
struct SectionBase {
|
||||||
|
char Name[16];
|
||||||
|
char SegmentName[16];
|
||||||
|
};
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<bool is64Bits>
|
||||||
struct Section;
|
struct Section;
|
||||||
|
|
||||||
@ -254,6 +259,7 @@ private:
|
|||||||
typedef SmallVector<DataRefImpl, 1> SectionList;
|
typedef SmallVector<DataRefImpl, 1> SectionList;
|
||||||
SectionList Sections;
|
SectionList Sections;
|
||||||
|
|
||||||
|
const MachOFormat::SectionBase *getSectionBase(DataRefImpl DRI) const;
|
||||||
|
|
||||||
void moveToNextSection(DataRefImpl &DRI) const;
|
void moveToNextSection(DataRefImpl &DRI) const;
|
||||||
|
|
||||||
|
@ -509,11 +509,8 @@ error_code MachOObjectFile::getSectionNext(DataRefImpl DRI,
|
|||||||
const MachOFormat::Section<false> *
|
const MachOFormat::Section<false> *
|
||||||
MachOObjectFile::getSection(DataRefImpl DRI) const {
|
MachOObjectFile::getSection(DataRefImpl DRI) const {
|
||||||
assert(!is64Bit());
|
assert(!is64Bit());
|
||||||
const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
|
const MachOFormat::SectionBase *Addr = getSectionBase(DRI);
|
||||||
uintptr_t CommandAddr = reinterpret_cast<uintptr_t>(Command);
|
return reinterpret_cast<const MachOFormat::Section<false>*>(Addr);
|
||||||
uintptr_t SectionAddr = CommandAddr + sizeof(macho::SegmentLoadCommand) +
|
|
||||||
DRI.d.b * sizeof(MachOFormat::Section<false>);
|
|
||||||
return reinterpret_cast<const MachOFormat::Section<false>*>(SectionAddr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t MachOObjectFile::getSectionIndex(DataRefImpl Sec) const {
|
std::size_t MachOObjectFile::getSectionIndex(DataRefImpl Sec) const {
|
||||||
@ -523,14 +520,27 @@ std::size_t MachOObjectFile::getSectionIndex(DataRefImpl Sec) const {
|
|||||||
return std::distance(Sections.begin(), loc);
|
return std::distance(Sections.begin(), loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MachOFormat::SectionBase*
|
||||||
|
MachOObjectFile::getSectionBase(DataRefImpl DRI) const {
|
||||||
|
const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
|
||||||
|
uintptr_t CommandAddr = reinterpret_cast<uintptr_t>(Command);
|
||||||
|
|
||||||
|
bool Is64 = is64Bit();
|
||||||
|
unsigned SegmentLoadSize =
|
||||||
|
Is64 ? sizeof(MachOFormat::SegmentLoadCommand<true>) :
|
||||||
|
sizeof(MachOFormat::SegmentLoadCommand<false>);
|
||||||
|
unsigned SectionSize = Is64 ? sizeof(MachOFormat::Section<true>) :
|
||||||
|
sizeof(MachOFormat::Section<false>);
|
||||||
|
|
||||||
|
uintptr_t SectionAddr = CommandAddr + SegmentLoadSize + DRI.d.b * SectionSize;
|
||||||
|
return reinterpret_cast<const MachOFormat::SectionBase*>(SectionAddr);
|
||||||
|
}
|
||||||
|
|
||||||
const MachOFormat::Section<true> *
|
const MachOFormat::Section<true> *
|
||||||
MachOObjectFile::getSection64(DataRefImpl DRI) const {
|
MachOObjectFile::getSection64(DataRefImpl DRI) const {
|
||||||
assert(is64Bit());
|
assert(is64Bit());
|
||||||
const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
|
const MachOFormat::SectionBase *Addr = getSectionBase(DRI);
|
||||||
uintptr_t CommandAddr = reinterpret_cast<uintptr_t>(Command);
|
return reinterpret_cast<const MachOFormat::Section<true>*>(Addr);
|
||||||
uintptr_t SectionAddr = CommandAddr + sizeof(macho::Segment64LoadCommand) +
|
|
||||||
DRI.d.b * sizeof(MachOFormat::Section<true>);
|
|
||||||
return reinterpret_cast<const MachOFormat::Section<true>*>(SectionAddr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static StringRef parseSegmentOrSectionName(const char *P) {
|
static StringRef parseSegmentOrSectionName(const char *P) {
|
||||||
@ -542,13 +552,8 @@ static StringRef parseSegmentOrSectionName(const char *P) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArrayRef<char> MachOObjectFile::getSectionRawName(DataRefImpl DRI) const {
|
ArrayRef<char> MachOObjectFile::getSectionRawName(DataRefImpl DRI) const {
|
||||||
if (is64Bit()) {
|
const MachOFormat::SectionBase *Base = getSectionBase(DRI);
|
||||||
const MachOFormat::Section<true> *sec = getSection64(DRI);
|
return ArrayRef<char>(Base->Name);
|
||||||
return ArrayRef<char>(sec->Name);
|
|
||||||
} else {
|
|
||||||
const MachOFormat::Section<false> *sec = getSection(DRI);
|
|
||||||
return ArrayRef<char>(sec->Name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code MachOObjectFile::getSectionName(DataRefImpl DRI,
|
error_code MachOObjectFile::getSectionName(DataRefImpl DRI,
|
||||||
@ -560,13 +565,8 @@ error_code MachOObjectFile::getSectionName(DataRefImpl DRI,
|
|||||||
|
|
||||||
ArrayRef<char>
|
ArrayRef<char>
|
||||||
MachOObjectFile::getSectionRawFinalSegmentName(DataRefImpl Sec) const {
|
MachOObjectFile::getSectionRawFinalSegmentName(DataRefImpl Sec) const {
|
||||||
if (is64Bit()) {
|
const MachOFormat::SectionBase *Base = getSectionBase(Sec);
|
||||||
const MachOFormat::Section<true> *sec = getSection64(Sec);
|
return ArrayRef<char>(Base->SegmentName);
|
||||||
return ArrayRef<char>(sec->SegmentName, 16);
|
|
||||||
} else {
|
|
||||||
const MachOFormat::Section<false> *sec = getSection(Sec);
|
|
||||||
return ArrayRef<char>(sec->SegmentName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StringRef MachOObjectFile::getSectionFinalSegmentName(DataRefImpl DRI) const {
|
StringRef MachOObjectFile::getSectionFinalSegmentName(DataRefImpl DRI) const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user