git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179051
91177308-0d34-0410-b5e6-
96231b3b80d8
namespace object {
namespace MachOFormat {
namespace object {
namespace MachOFormat {
+ template<bool is64Bits>
+ struct Section;
+
+ template<>
+ struct Section<false> {
char Name[16];
char SegmentName[16];
support::ulittle32_t Address;
char Name[16];
char SegmentName[16];
support::ulittle32_t Address;
support::ulittle32_t Reserved2;
};
support::ulittle32_t Reserved2;
};
+ template<>
+ struct Section<true> {
char Name[16];
char SegmentName[16];
support::ulittle64_t Address;
char Name[16];
char SegmentName[16];
support::ulittle64_t Address;
support::ulittle32_t Word1;
};
support::ulittle32_t Word1;
};
- struct SymbolTableEntry {
+ template<bool is64Bits>
+ struct SymbolTableEntry;
+
+ template<>
+ struct SymbolTableEntry<false> {
support::ulittle32_t StringIndex;
uint8_t Type;
uint8_t SectionIndex;
support::ulittle32_t StringIndex;
uint8_t Type;
uint8_t SectionIndex;
support::ulittle32_t Value;
};
support::ulittle32_t Value;
};
- struct Symbol64TableEntry {
+ template<>
+ struct SymbolTableEntry<true> {
support::ulittle32_t StringIndex;
uint8_t Type;
uint8_t SectionIndex;
support::ulittle32_t StringIndex;
uint8_t Type;
uint8_t SectionIndex;
support::ulittle32_t StringTableSize;
};
support::ulittle32_t StringTableSize;
};
- struct SegmentLoadCommand {
+ template<bool is64Bits>
+ struct SegmentLoadCommand;
+
+ template<>
+ struct SegmentLoadCommand<false> {
support::ulittle32_t Type;
support::ulittle32_t Size;
char Name[16];
support::ulittle32_t Type;
support::ulittle32_t Size;
char Name[16];
support::ulittle32_t Flags;
};
support::ulittle32_t Flags;
};
- struct Segment64LoadCommand {
+ template<>
+ struct SegmentLoadCommand<true> {
support::ulittle32_t Type;
support::ulittle32_t Size;
char Name[16];
support::ulittle32_t Type;
support::ulittle32_t Size;
char Name[16];
ArrayRef<char> getSectionRawName(DataRefImpl Sec) const;
ArrayRef<char>getSectionRawFinalSegmentName(DataRefImpl Sec) const;
ArrayRef<char> getSectionRawName(DataRefImpl Sec) const;
ArrayRef<char>getSectionRawFinalSegmentName(DataRefImpl Sec) const;
- const MachOFormat::Section64 *getSection64(DataRefImpl DRI) const;
- const MachOFormat::Section *getSection(DataRefImpl DRI) const;
- const MachOFormat::Symbol64TableEntry *
+ const MachOFormat::Section<true> *getSection64(DataRefImpl DRI) const;
+ const MachOFormat::Section<false> *getSection(DataRefImpl DRI) const;
+ const MachOFormat::SymbolTableEntry<true> *
getSymbol64TableEntry(DataRefImpl DRI) const;
getSymbol64TableEntry(DataRefImpl DRI) const;
- const MachOFormat::SymbolTableEntry *
+ const MachOFormat::SymbolTableEntry<false> *
getSymbolTableEntry(DataRefImpl DRI) const;
bool is64Bit() const;
const MachOFormat::LoadCommand *getLoadCommandInfo(unsigned Index) const;
getSymbolTableEntry(DataRefImpl DRI) const;
bool is64Bit() const;
const MachOFormat::LoadCommand *getLoadCommandInfo(unsigned Index) const;
void moveToNextSection(DataRefImpl &DRI) const;
void moveToNextSection(DataRefImpl &DRI) const;
- const MachOFormat::SymbolTableEntry *
+ const MachOFormat::SymbolTableEntry<false> *
getSymbolTableEntry(DataRefImpl DRI,
const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const;
getSymbolTableEntry(DataRefImpl DRI,
const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const;
- const MachOFormat::Symbol64TableEntry *
+ const MachOFormat::SymbolTableEntry<true> *
getSymbol64TableEntry(DataRefImpl DRI,
const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const;
getSymbol64TableEntry(DataRefImpl DRI,
const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const;
-const MachOFormat::SymbolTableEntry *
+const MachOFormat::SymbolTableEntry<false> *
MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI) const {
const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
const MachOFormat::SymtabLoadCommand *SymtabLoadCmd =
MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI) const {
const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
const MachOFormat::SymtabLoadCommand *SymtabLoadCmd =
return getSymbolTableEntry(DRI, SymtabLoadCmd);
}
return getSymbolTableEntry(DRI, SymtabLoadCmd);
}
-const MachOFormat::SymbolTableEntry *
+const MachOFormat::SymbolTableEntry<false> *
MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI,
const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const {
uint64_t SymbolTableOffset = SymtabLoadCmd->SymbolTableOffset;
unsigned Index = DRI.d.b;
uint64_t Offset = (SymbolTableOffset +
MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI,
const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const {
uint64_t SymbolTableOffset = SymtabLoadCmd->SymbolTableOffset;
unsigned Index = DRI.d.b;
uint64_t Offset = (SymbolTableOffset +
- Index * sizeof(macho::SymbolTableEntry));
- StringRef Data = getData(Offset, sizeof(MachOFormat::SymbolTableEntry));
- return reinterpret_cast<const MachOFormat::SymbolTableEntry*>(Data.data());
+ Index * sizeof(MachOFormat::SymbolTableEntry<false>));
+ StringRef Data =
+ getData(Offset, sizeof(MachOFormat::SymbolTableEntry<false>));
+ return
+ reinterpret_cast<const MachOFormat::SymbolTableEntry<false>*>(Data.data());
-const MachOFormat::Symbol64TableEntry*
+const MachOFormat::SymbolTableEntry<true>*
MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI) const {
const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
const MachOFormat::SymtabLoadCommand *SymtabLoadCmd =
MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI) const {
const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
const MachOFormat::SymtabLoadCommand *SymtabLoadCmd =
return getSymbol64TableEntry(DRI, SymtabLoadCmd);
}
return getSymbol64TableEntry(DRI, SymtabLoadCmd);
}
-const MachOFormat::Symbol64TableEntry*
+const MachOFormat::SymbolTableEntry<true>*
MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI,
const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const {
uint64_t SymbolTableOffset = SymtabLoadCmd->SymbolTableOffset;
unsigned Index = DRI.d.b;
uint64_t Offset = (SymbolTableOffset +
MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI,
const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const {
uint64_t SymbolTableOffset = SymtabLoadCmd->SymbolTableOffset;
unsigned Index = DRI.d.b;
uint64_t Offset = (SymbolTableOffset +
- Index * sizeof(macho::Symbol64TableEntry));
- StringRef Data = getData(Offset, sizeof(MachOFormat::Symbol64TableEntry));
- return reinterpret_cast<const MachOFormat::Symbol64TableEntry*>(Data.data());
+ Index * sizeof(MachOFormat::SymbolTableEntry<true>));
+ StringRef Data = getData(Offset, sizeof(MachOFormat::SymbolTableEntry<true>));
+ return
+ reinterpret_cast<const MachOFormat::SymbolTableEntry<true>*>(Data.data());
}
error_code MachOObjectFile::getSymbolNext(DataRefImpl DRI,
}
error_code MachOObjectFile::getSymbolNext(DataRefImpl DRI,
uint32_t StringIndex;
if (is64Bit()) {
uint32_t StringIndex;
if (is64Bit()) {
- const MachOFormat::Symbol64TableEntry *Entry =
+ const MachOFormat::SymbolTableEntry<true> *Entry =
getSymbol64TableEntry(DRI, SymtabLoadCmd);
StringIndex = Entry->StringIndex;
} else {
getSymbol64TableEntry(DRI, SymtabLoadCmd);
StringIndex = Entry->StringIndex;
} else {
- const MachOFormat::SymbolTableEntry *Entry =
+ const MachOFormat::SymbolTableEntry<false> *Entry =
getSymbolTableEntry(DRI, SymtabLoadCmd);
StringIndex = Entry->StringIndex;
}
getSymbolTableEntry(DRI, SymtabLoadCmd);
StringIndex = Entry->StringIndex;
}
error_code MachOObjectFile::getSymbolFileOffset(DataRefImpl DRI,
uint64_t &Result) const {
if (is64Bit()) {
error_code MachOObjectFile::getSymbolFileOffset(DataRefImpl DRI,
uint64_t &Result) const {
if (is64Bit()) {
- const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI);
+ const MachOFormat::SymbolTableEntry<true> *Entry =
+ getSymbol64TableEntry(DRI);
Result = Entry->Value;
if (Entry->SectionIndex) {
Result = Entry->Value;
if (Entry->SectionIndex) {
- const MachOFormat::Section64 *Section =
+ const MachOFormat::Section<true> *Section =
getSection64(Sections[Entry->SectionIndex-1]);
Result += Section->Offset - Section->Address;
}
} else {
getSection64(Sections[Entry->SectionIndex-1]);
Result += Section->Offset - Section->Address;
}
} else {
- const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
+ const MachOFormat::SymbolTableEntry<false> *Entry =
+ getSymbolTableEntry(DRI);
Result = Entry->Value;
if (Entry->SectionIndex) {
Result = Entry->Value;
if (Entry->SectionIndex) {
- const MachOFormat::Section *Section =
+ const MachOFormat::Section<false> *Section =
getSection(Sections[Entry->SectionIndex-1]);
Result += Section->Offset - Section->Address;
}
getSection(Sections[Entry->SectionIndex-1]);
Result += Section->Offset - Section->Address;
}
error_code MachOObjectFile::getSymbolAddress(DataRefImpl DRI,
uint64_t &Result) const {
if (is64Bit()) {
error_code MachOObjectFile::getSymbolAddress(DataRefImpl DRI,
uint64_t &Result) const {
if (is64Bit()) {
- const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI);
+ const MachOFormat::SymbolTableEntry<true> *Entry =
+ getSymbol64TableEntry(DRI);
Result = Entry->Value;
} else {
Result = Entry->Value;
} else {
- const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
+ const MachOFormat::SymbolTableEntry<false> *Entry =
+ getSymbolTableEntry(DRI);
Result = Entry->Value;
}
return object_error::success;
Result = Entry->Value;
}
return object_error::success;
uint64_t EndOffset = 0;
uint8_t SectionIndex;
if (is64Bit()) {
uint64_t EndOffset = 0;
uint8_t SectionIndex;
if (is64Bit()) {
- const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI);
+ const MachOFormat::SymbolTableEntry<true> *Entry =
+ getSymbol64TableEntry(DRI);
BeginOffset = Entry->Value;
SectionIndex = Entry->SectionIndex;
if (!SectionIndex) {
BeginOffset = Entry->Value;
SectionIndex = Entry->SectionIndex;
if (!SectionIndex) {
- const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
+ const MachOFormat::SymbolTableEntry<false> *Entry =
+ getSymbolTableEntry(DRI);
BeginOffset = Entry->Value;
SectionIndex = Entry->SectionIndex;
if (!SectionIndex) {
BeginOffset = Entry->Value;
SectionIndex = Entry->SectionIndex;
if (!SectionIndex) {
char &Result) const {
uint8_t Type, Flags;
if (is64Bit()) {
char &Result) const {
uint8_t Type, Flags;
if (is64Bit()) {
- const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI);
+ const MachOFormat::SymbolTableEntry<true> *Entry =
+ getSymbol64TableEntry(DRI);
Type = Entry->Type;
Flags = Entry->Flags;
} else {
Type = Entry->Type;
Flags = Entry->Flags;
} else {
- const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
+ const MachOFormat::SymbolTableEntry<false> *Entry =
+ getSymbolTableEntry(DRI);
Type = Entry->Type;
Flags = Entry->Flags;
}
Type = Entry->Type;
Flags = Entry->Flags;
}
uint16_t MachOFlags;
uint8_t MachOType;
if (is64Bit()) {
uint16_t MachOFlags;
uint8_t MachOType;
if (is64Bit()) {
- const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI);
+ const MachOFormat::SymbolTableEntry<true> *Entry =
+ getSymbol64TableEntry(DRI);
MachOFlags = Entry->Flags;
MachOType = Entry->Type;
} else {
MachOFlags = Entry->Flags;
MachOType = Entry->Type;
} else {
- const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
+ const MachOFormat::SymbolTableEntry<false> *Entry =
+ getSymbolTableEntry(DRI);
MachOFlags = Entry->Flags;
MachOType = Entry->Type;
}
MachOFlags = Entry->Flags;
MachOType = Entry->Type;
}
section_iterator &Res) const {
uint8_t index;
if (is64Bit()) {
section_iterator &Res) const {
uint8_t index;
if (is64Bit()) {
- const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(Symb);
+ const MachOFormat::SymbolTableEntry<true> *Entry =
+ getSymbol64TableEntry(Symb);
index = Entry->SectionIndex;
} else {
index = Entry->SectionIndex;
} else {
- const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(Symb);
+ const MachOFormat::SymbolTableEntry<false> *Entry =
+ getSymbolTableEntry(Symb);
index = Entry->SectionIndex;
}
index = Entry->SectionIndex;
}
SymbolRef::Type &Res) const {
uint8_t n_type;
if (is64Bit()) {
SymbolRef::Type &Res) const {
uint8_t n_type;
if (is64Bit()) {
- const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(Symb);
+ const MachOFormat::SymbolTableEntry<true> *Entry =
+ getSymbol64TableEntry(Symb);
n_type = Entry->Type;
} else {
n_type = Entry->Type;
} else {
- const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(Symb);
+ const MachOFormat::SymbolTableEntry<false> *Entry =
+ getSymbolTableEntry(Symb);
n_type = Entry->Type;
}
Res = SymbolRef::ST_Other;
n_type = Entry->Type;
}
Res = SymbolRef::ST_Other;
while (DRI.d.a < LoadCommandCount) {
const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
if (Command->Type == macho::LCT_Segment) {
while (DRI.d.a < LoadCommandCount) {
const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
if (Command->Type == macho::LCT_Segment) {
- const MachOFormat::SegmentLoadCommand *SegmentLoadCmd =
- reinterpret_cast<const MachOFormat::SegmentLoadCommand*>(Command);
+ const MachOFormat::SegmentLoadCommand<false> *SegmentLoadCmd =
+ reinterpret_cast<const MachOFormat::SegmentLoadCommand<false>*>(Command);
if (DRI.d.b < SegmentLoadCmd->NumSections)
return;
} else if (Command->Type == macho::LCT_Segment64) {
if (DRI.d.b < SegmentLoadCmd->NumSections)
return;
} else if (Command->Type == macho::LCT_Segment64) {
- const MachOFormat::Segment64LoadCommand *Segment64LoadCmd =
- reinterpret_cast<const MachOFormat::Segment64LoadCommand*>(Command);
- if (DRI.d.b < Segment64LoadCmd->NumSections)
+ const MachOFormat::SegmentLoadCommand<true> *SegmentLoadCmd =
+ reinterpret_cast<const MachOFormat::SegmentLoadCommand<true>*>(Command);
+ if (DRI.d.b < SegmentLoadCmd->NumSections)
return object_error::success;
}
return object_error::success;
}
-const MachOFormat::Section *MachOObjectFile::getSection(DataRefImpl DRI) const {
+const MachOFormat::Section<false> *
+MachOObjectFile::getSection(DataRefImpl DRI) const {
assert(!is64Bit());
const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
uintptr_t CommandAddr = reinterpret_cast<uintptr_t>(Command);
uintptr_t SectionAddr = CommandAddr + sizeof(macho::SegmentLoadCommand) +
assert(!is64Bit());
const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
uintptr_t CommandAddr = reinterpret_cast<uintptr_t>(Command);
uintptr_t SectionAddr = CommandAddr + sizeof(macho::SegmentLoadCommand) +
- DRI.d.b * sizeof(MachOFormat::Section);
- return reinterpret_cast<const MachOFormat::Section*>(SectionAddr);
+ 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 {
return std::distance(Sections.begin(), loc);
}
return std::distance(Sections.begin(), loc);
}
-const MachOFormat::Section64 *
+const MachOFormat::Section<true> *
MachOObjectFile::getSection64(DataRefImpl DRI) const {
assert(is64Bit());
const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
uintptr_t CommandAddr = reinterpret_cast<uintptr_t>(Command);
uintptr_t SectionAddr = CommandAddr + sizeof(macho::Segment64LoadCommand) +
MachOObjectFile::getSection64(DataRefImpl DRI) const {
assert(is64Bit());
const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
uintptr_t CommandAddr = reinterpret_cast<uintptr_t>(Command);
uintptr_t SectionAddr = CommandAddr + sizeof(macho::Segment64LoadCommand) +
- DRI.d.b * sizeof(MachOFormat::Section64);
- return reinterpret_cast<const MachOFormat::Section64*>(SectionAddr);
+ 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) {
ArrayRef<char> MachOObjectFile::getSectionRawName(DataRefImpl DRI) const {
if (is64Bit()) {
ArrayRef<char> MachOObjectFile::getSectionRawName(DataRefImpl DRI) const {
if (is64Bit()) {
- const MachOFormat::Section64 *sec = getSection64(DRI);
+ const MachOFormat::Section<true> *sec = getSection64(DRI);
return ArrayRef<char>(sec->Name);
} else {
return ArrayRef<char>(sec->Name);
} else {
- const MachOFormat::Section *sec = getSection(DRI);
+ const MachOFormat::Section<false> *sec = getSection(DRI);
return ArrayRef<char>(sec->Name);
}
}
return ArrayRef<char>(sec->Name);
}
}
ArrayRef<char>
MachOObjectFile::getSectionRawFinalSegmentName(DataRefImpl Sec) const {
if (is64Bit()) {
ArrayRef<char>
MachOObjectFile::getSectionRawFinalSegmentName(DataRefImpl Sec) const {
if (is64Bit()) {
- const MachOFormat::Section64 *sec = getSection64(Sec);
+ const MachOFormat::Section<true> *sec = getSection64(Sec);
return ArrayRef<char>(sec->SegmentName, 16);
} else {
return ArrayRef<char>(sec->SegmentName, 16);
} else {
- const MachOFormat::Section *sec = getSection(Sec);
+ const MachOFormat::Section<false> *sec = getSection(Sec);
return ArrayRef<char>(sec->SegmentName);
}
}
return ArrayRef<char>(sec->SegmentName);
}
}
error_code MachOObjectFile::getSectionAddress(DataRefImpl DRI,
uint64_t &Result) const {
if (is64Bit()) {
error_code MachOObjectFile::getSectionAddress(DataRefImpl DRI,
uint64_t &Result) const {
if (is64Bit()) {
- const MachOFormat::Section64 *Sect = getSection64(DRI);
+ const MachOFormat::Section<true> *Sect = getSection64(DRI);
Result = Sect->Address;
} else {
Result = Sect->Address;
} else {
- const MachOFormat::Section *Sect = getSection(DRI);
+ const MachOFormat::Section<false> *Sect = getSection(DRI);
Result = Sect->Address;
}
return object_error::success;
Result = Sect->Address;
}
return object_error::success;
error_code MachOObjectFile::getSectionSize(DataRefImpl DRI,
uint64_t &Result) const {
if (is64Bit()) {
error_code MachOObjectFile::getSectionSize(DataRefImpl DRI,
uint64_t &Result) const {
if (is64Bit()) {
- const MachOFormat::Section64 *Sect = getSection64(DRI);
+ const MachOFormat::Section<true> *Sect = getSection64(DRI);
Result = Sect->Size;
} else {
Result = Sect->Size;
} else {
- const MachOFormat::Section *Sect = getSection(DRI);
+ const MachOFormat::Section<false> *Sect = getSection(DRI);
Result = Sect->Size;
}
return object_error::success;
Result = Sect->Size;
}
return object_error::success;
error_code MachOObjectFile::getSectionContents(DataRefImpl DRI,
StringRef &Result) const {
if (is64Bit()) {
error_code MachOObjectFile::getSectionContents(DataRefImpl DRI,
StringRef &Result) const {
if (is64Bit()) {
- const MachOFormat::Section64 *Sect = getSection64(DRI);
+ const MachOFormat::Section<true> *Sect = getSection64(DRI);
Result = getData(Sect->Offset, Sect->Size);
} else {
Result = getData(Sect->Offset, Sect->Size);
} else {
- const MachOFormat::Section *Sect = getSection(DRI);
+ const MachOFormat::Section<false> *Sect = getSection(DRI);
Result = getData(Sect->Offset, Sect->Size);
}
return object_error::success;
Result = getData(Sect->Offset, Sect->Size);
}
return object_error::success;
error_code MachOObjectFile::getSectionAlignment(DataRefImpl DRI,
uint64_t &Result) const {
if (is64Bit()) {
error_code MachOObjectFile::getSectionAlignment(DataRefImpl DRI,
uint64_t &Result) const {
if (is64Bit()) {
- const MachOFormat::Section64 *Sect = getSection64(DRI);
+ const MachOFormat::Section<true> *Sect = getSection64(DRI);
Result = uint64_t(1) << Sect->Align;
} else {
Result = uint64_t(1) << Sect->Align;
} else {
- const MachOFormat::Section *Sect = getSection(DRI);
+ const MachOFormat::Section<false> *Sect = getSection(DRI);
Result = uint64_t(1) << Sect->Align;
}
return object_error::success;
Result = uint64_t(1) << Sect->Align;
}
return object_error::success;
error_code MachOObjectFile::isSectionText(DataRefImpl DRI,
bool &Result) const {
if (is64Bit()) {
error_code MachOObjectFile::isSectionText(DataRefImpl DRI,
bool &Result) const {
if (is64Bit()) {
- const MachOFormat::Section64 *Sect = getSection64(DRI);
+ const MachOFormat::Section<true> *Sect = getSection64(DRI);
Result = Sect->Flags & macho::SF_PureInstructions;
} else {
Result = Sect->Flags & macho::SF_PureInstructions;
} else {
- const MachOFormat::Section *Sect = getSection(DRI);
+ const MachOFormat::Section<false> *Sect = getSection(DRI);
Result = Sect->Flags & macho::SF_PureInstructions;
}
return object_error::success;
Result = Sect->Flags & macho::SF_PureInstructions;
}
return object_error::success;
error_code MachOObjectFile::isSectionZeroInit(DataRefImpl DRI,
bool &Result) const {
if (is64Bit()) {
error_code MachOObjectFile::isSectionZeroInit(DataRefImpl DRI,
bool &Result) const {
if (is64Bit()) {
- const MachOFormat::Section64 *Sect = getSection64(DRI);
+ const MachOFormat::Section<true> *Sect = getSection64(DRI);
unsigned SectionType = Sect->Flags & MachO::SectionFlagMaskSectionType;
Result = (SectionType == MachO::SectionTypeZeroFill ||
SectionType == MachO::SectionTypeZeroFillLarge);
} else {
unsigned SectionType = Sect->Flags & MachO::SectionFlagMaskSectionType;
Result = (SectionType == MachO::SectionTypeZeroFill ||
SectionType == MachO::SectionTypeZeroFillLarge);
} else {
- const MachOFormat::Section *Sect = getSection(DRI);
+ const MachOFormat::Section<false> *Sect = getSection(DRI);
unsigned SectionType = Sect->Flags & MachO::SectionFlagMaskSectionType;
Result = (SectionType == MachO::SectionTypeZeroFill ||
SectionType == MachO::SectionTypeZeroFillLarge);
unsigned SectionType = Sect->Flags & MachO::SectionFlagMaskSectionType;
Result = (SectionType == MachO::SectionTypeZeroFill ||
SectionType == MachO::SectionTypeZeroFillLarge);
SectEnd += SectBegin;
if (is64Bit()) {
SectEnd += SectBegin;
if (is64Bit()) {
- const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(Symb);
+ const MachOFormat::SymbolTableEntry<true> *Entry =
+ getSymbol64TableEntry(Symb);
uint64_t SymAddr= Entry->Value;
Result = (SymAddr >= SectBegin) && (SymAddr < SectEnd);
} else {
uint64_t SymAddr= Entry->Value;
Result = (SymAddr >= SectBegin) && (SymAddr < SectEnd);
} else {
- const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(Symb);
+ const MachOFormat::SymbolTableEntry<false> *Entry =
+ getSymbolTableEntry(Symb);
uint64_t SymAddr= Entry->Value;
Result = (SymAddr >= SectBegin) && (SymAddr < SectEnd);
}
uint64_t SymAddr= Entry->Value;
Result = (SymAddr >= SectBegin) && (SymAddr < SectEnd);
}
ret.d.b = getSectionIndex(Sec);
return relocation_iterator(RelocationRef(ret, this));
}
ret.d.b = getSectionIndex(Sec);
return relocation_iterator(RelocationRef(ret, this));
}
relocation_iterator MachOObjectFile::getSectionRelEnd(DataRefImpl Sec) const {
uint32_t last_reloc;
if (is64Bit()) {
relocation_iterator MachOObjectFile::getSectionRelEnd(DataRefImpl Sec) const {
uint32_t last_reloc;
if (is64Bit()) {
- const MachOFormat::Section64 *Sect = getSection64(Sec);
+ const MachOFormat::Section<true> *Sect = getSection64(Sec);
last_reloc = Sect->NumRelocationTableEntries;
} else {
last_reloc = Sect->NumRelocationTableEntries;
} else {
- const MachOFormat::Section *Sect = getSection(Sec);
+ const MachOFormat::Section<false> *Sect = getSection(Sec);
last_reloc = Sect->NumRelocationTableEntries;
}
DataRefImpl ret;
last_reloc = Sect->NumRelocationTableEntries;
}
DataRefImpl ret;
MachOObjectFile::getRelocation(DataRefImpl Rel) const {
uint32_t relOffset;
if (is64Bit()) {
MachOObjectFile::getRelocation(DataRefImpl Rel) const {
uint32_t relOffset;
if (is64Bit()) {
- const MachOFormat::Section64 *Sect = getSection64(Sections[Rel.d.b]);
+ const MachOFormat::Section<true> *Sect = getSection64(Sections[Rel.d.b]);
relOffset = Sect->RelocationTableOffset;
} else {
relOffset = Sect->RelocationTableOffset;
} else {
- const MachOFormat::Section *Sect = getSection(Sections[Rel.d.b]);
+ const MachOFormat::Section<false> *Sect = getSection(Sections[Rel.d.b]);
relOffset = Sect->RelocationTableOffset;
}
uint64_t Offset = relOffset + Rel.d.a * sizeof(MachOFormat::RelocationEntry);
relOffset = Sect->RelocationTableOffset;
}
uint64_t Offset = relOffset + Rel.d.a * sizeof(MachOFormat::RelocationEntry);
uint64_t &Res) const {
const uint8_t* sectAddress = 0;
if (is64Bit()) {
uint64_t &Res) const {
const uint8_t* sectAddress = 0;
if (is64Bit()) {
- const MachOFormat::Section64 *Sect = getSection64(Sections[Rel.d.b]);
+ const MachOFormat::Section<true> *Sect = getSection64(Sections[Rel.d.b]);
sectAddress += Sect->Address;
} else {
sectAddress += Sect->Address;
} else {
- const MachOFormat::Section *Sect = getSection(Sections[Rel.d.b]);
+ const MachOFormat::Section<false> *Sect = getSection(Sections[Rel.d.b]);
sectAddress += Sect->Address;
}
const MachOFormat::RelocationEntry *RE = getRelocation(Rel);
sectAddress += Sect->Address;
}
const MachOFormat::RelocationEntry *RE = getRelocation(Rel);
if (!isExtern) {
const uint8_t* sectAddress = base();
if (is64Bit()) {
if (!isExtern) {
const uint8_t* sectAddress = base();
if (is64Bit()) {
- const MachOFormat::Section64 *Sect = getSection64(Sections[Rel.d.b]);
+ const MachOFormat::Section<true> *Sect = getSection64(Sections[Rel.d.b]);
sectAddress += Sect->Offset;
} else {
sectAddress += Sect->Offset;
} else {
- const MachOFormat::Section *Sect = getSection(Sections[Rel.d.b]);
+ const MachOFormat::Section<false> *Sect = getSection(Sections[Rel.d.b]);
sectAddress += Sect->Offset;
}
Res = reinterpret_cast<uintptr_t>(sectAddress);
sectAddress += Sect->Offset;
}
Res = reinterpret_cast<uintptr_t>(sectAddress);
DataRefImpl DRI,
MachOSection &Section) {
if (Obj->is64Bit()) {
DataRefImpl DRI,
MachOSection &Section) {
if (Obj->is64Bit()) {
- const MachOFormat::Section64 *Sect = Obj->getSection64(DRI);
+ const MachOFormat::Section<true> *Sect = Obj->getSection64(DRI);
Section.Address = Sect->Address;
Section.Size = Sect->Size;
Section.Address = Sect->Address;
Section.Size = Sect->Size;
Section.Reserved1 = Sect->Reserved1;
Section.Reserved2 = Sect->Reserved2;
} else {
Section.Reserved1 = Sect->Reserved1;
Section.Reserved2 = Sect->Reserved2;
} else {
- const MachOFormat::Section *Sect = Obj->getSection(DRI);
+ const MachOFormat::Section<false> *Sect = Obj->getSection(DRI);
Section.Address = Sect->Address;
Section.Size = Sect->Size;
Section.Address = Sect->Address;
Section.Size = Sect->Size;
DataRefImpl DRI,
MachOSymbol &Symbol) {
if (Obj->is64Bit()) {
DataRefImpl DRI,
MachOSymbol &Symbol) {
if (Obj->is64Bit()) {
- const MachOFormat::Symbol64TableEntry *Entry =
- Obj->getSymbol64TableEntry( DRI);
+ const MachOFormat::SymbolTableEntry<true> *Entry =
+ Obj->getSymbol64TableEntry(DRI);
Symbol.StringIndex = Entry->StringIndex;
Symbol.Type = Entry->Type;
Symbol.SectionIndex = Entry->SectionIndex;
Symbol.Flags = Entry->Flags;
Symbol.Value = Entry->Value;
} else {
Symbol.StringIndex = Entry->StringIndex;
Symbol.Type = Entry->Type;
Symbol.SectionIndex = Entry->SectionIndex;
Symbol.Flags = Entry->Flags;
Symbol.Value = Entry->Value;
} else {
- const MachOFormat::SymbolTableEntry *Entry = Obj->getSymbolTableEntry(DRI);
+ const MachOFormat::SymbolTableEntry<false> *Entry =
+ Obj->getSymbolTableEntry(DRI);
Symbol.StringIndex = Entry->StringIndex;
Symbol.Type = Entry->Type;
Symbol.SectionIndex = Entry->SectionIndex;
Symbol.StringIndex = Entry->StringIndex;
Symbol.Type = Entry->Type;
Symbol.SectionIndex = Entry->SectionIndex;