mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-13 23:25:06 +00:00
Template MachOObjectFile over endianness too.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179179 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -289,34 +289,41 @@ private:
|
|||||||
const SymtabLoadCommand *SymtabLoadCmd) const;
|
const SymtabLoadCommand *SymtabLoadCmd) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
struct MachOObjectFileHelperCommon {
|
struct MachOObjectFileHelperCommon;
|
||||||
typedef MachOFormat::SegmentLoadCommand<MachOType<support::little, is64Bits> >
|
|
||||||
|
template<endianness TargetEndianness, bool Is64Bits>
|
||||||
|
struct MachOObjectFileHelperCommon<MachOType<TargetEndianness, Is64Bits> > {
|
||||||
|
typedef
|
||||||
|
MachOFormat::SegmentLoadCommand<MachOType<TargetEndianness, Is64Bits> >
|
||||||
SegmentLoadCommand;
|
SegmentLoadCommand;
|
||||||
typedef MachOFormat::SymbolTableEntry<MachOType<support::little, is64Bits> >
|
typedef MachOFormat::SymbolTableEntry<MachOType<TargetEndianness, Is64Bits> >
|
||||||
SymbolTableEntry;
|
SymbolTableEntry;
|
||||||
typedef MachOFormat::Section<MachOType<support::little, is64Bits> > Section;
|
typedef MachOFormat::Section<MachOType<TargetEndianness, Is64Bits> > Section;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
struct MachOObjectFileHelper;
|
struct MachOObjectFileHelper;
|
||||||
|
|
||||||
template<>
|
template<endianness TargetEndianness>
|
||||||
struct MachOObjectFileHelper<false> :
|
struct MachOObjectFileHelper<MachOType<TargetEndianness, false> > :
|
||||||
public MachOObjectFileHelperCommon<false> {
|
public MachOObjectFileHelperCommon<MachOType<TargetEndianness, false> > {
|
||||||
static const macho::LoadCommandType SegmentLoadType = macho::LCT_Segment;
|
static const macho::LoadCommandType SegmentLoadType = macho::LCT_Segment;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<endianness TargetEndianness>
|
||||||
struct MachOObjectFileHelper<true> :
|
struct MachOObjectFileHelper<MachOType<TargetEndianness, true> > :
|
||||||
public MachOObjectFileHelperCommon<true> {
|
public MachOObjectFileHelperCommon<MachOType<TargetEndianness, true> > {
|
||||||
static const macho::LoadCommandType SegmentLoadType = macho::LCT_Segment64;
|
static const macho::LoadCommandType SegmentLoadType = macho::LCT_Segment64;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
class MachOObjectFile : public MachOObjectFileBase {
|
class MachOObjectFile : public MachOObjectFileBase {
|
||||||
public:
|
public:
|
||||||
typedef MachOObjectFileHelper<is64Bits> Helper;
|
static const endianness TargetEndianness = MachOT::TargetEndianness;
|
||||||
|
static const bool Is64Bits = MachOT::Is64Bits;
|
||||||
|
|
||||||
|
typedef MachOObjectFileHelper<MachOT> Helper;
|
||||||
static const macho::LoadCommandType SegmentLoadType = Helper::SegmentLoadType;
|
static const macho::LoadCommandType SegmentLoadType = Helper::SegmentLoadType;
|
||||||
typedef typename Helper::SegmentLoadCommand SegmentLoadCommand;
|
typedef typename Helper::SegmentLoadCommand SegmentLoadCommand;
|
||||||
typedef typename Helper::SymbolTableEntry SymbolTableEntry;
|
typedef typename Helper::SymbolTableEntry SymbolTableEntry;
|
||||||
@@ -357,10 +364,10 @@ public:
|
|||||||
void moveToNextSection(DataRefImpl &DRI) const;
|
void moveToNextSection(DataRefImpl &DRI) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
MachOObjectFile<is64Bits>::MachOObjectFile(MemoryBuffer *Object,
|
MachOObjectFile<MachOT>::MachOObjectFile(MemoryBuffer *Object,
|
||||||
error_code &ec) :
|
error_code &ec) :
|
||||||
MachOObjectFileBase(Object, is64Bits, ec) {
|
MachOObjectFileBase(Object, Is64Bits, ec) {
|
||||||
DataRefImpl DRI;
|
DataRefImpl DRI;
|
||||||
moveToNextSection(DRI);
|
moveToNextSection(DRI);
|
||||||
uint32_t LoadCommandCount = getHeader()->NumLoadCommands;
|
uint32_t LoadCommandCount = getHeader()->NumLoadCommands;
|
||||||
@@ -371,28 +378,28 @@ MachOObjectFile<is64Bits>::MachOObjectFile(MemoryBuffer *Object,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
bool MachOObjectFile<is64Bits>::classof(const Binary *v) {
|
bool MachOObjectFile<MachOT>::classof(const Binary *v) {
|
||||||
return v->getType() == getMachOType(true, is64Bits);
|
return v->getType() == getMachOType(true, Is64Bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
const typename MachOObjectFile<is64Bits>::Section *
|
const typename MachOObjectFile<MachOT>::Section *
|
||||||
MachOObjectFile<is64Bits>::getSection(DataRefImpl DRI) const {
|
MachOObjectFile<MachOT>::getSection(DataRefImpl DRI) const {
|
||||||
const SectionBase *Addr = getSectionBase(DRI);
|
const SectionBase *Addr = getSectionBase(DRI);
|
||||||
return reinterpret_cast<const Section*>(Addr);
|
return reinterpret_cast<const Section*>(Addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
const typename MachOObjectFile<is64Bits>::SymbolTableEntry *
|
const typename MachOObjectFile<MachOT>::SymbolTableEntry *
|
||||||
MachOObjectFile<is64Bits>::getSymbolTableEntry(DataRefImpl DRI) const {
|
MachOObjectFile<MachOT>::getSymbolTableEntry(DataRefImpl DRI) const {
|
||||||
const SymbolTableEntryBase *Base = getSymbolTableEntryBase(DRI);
|
const SymbolTableEntryBase *Base = getSymbolTableEntryBase(DRI);
|
||||||
return reinterpret_cast<const SymbolTableEntry*>(Base);
|
return reinterpret_cast<const SymbolTableEntry*>(Base);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
const typename MachOObjectFile<is64Bits>::RelocationEntry *
|
const typename MachOObjectFile<MachOT>::RelocationEntry *
|
||||||
MachOObjectFile<is64Bits>::getRelocation(DataRefImpl Rel) const {
|
MachOObjectFile<MachOT>::getRelocation(DataRefImpl Rel) const {
|
||||||
const Section *Sect = getSection(Sections[Rel.d.b]);
|
const Section *Sect = getSection(Sections[Rel.d.b]);
|
||||||
uint32_t RelOffset = Sect->RelocationTableOffset;
|
uint32_t RelOffset = Sect->RelocationTableOffset;
|
||||||
uint64_t Offset = RelOffset + Rel.d.a * sizeof(RelocationEntry);
|
uint64_t Offset = RelOffset + Rel.d.a * sizeof(RelocationEntry);
|
||||||
@@ -400,53 +407,53 @@ MachOObjectFile<is64Bits>::getRelocation(DataRefImpl Rel) const {
|
|||||||
return reinterpret_cast<const RelocationEntry*>(Data.data());
|
return reinterpret_cast<const RelocationEntry*>(Data.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::getSectionAddress(DataRefImpl Sec,
|
MachOObjectFile<MachOT>::getSectionAddress(DataRefImpl Sec,
|
||||||
uint64_t &Res) const {
|
uint64_t &Res) const {
|
||||||
const Section *Sect = getSection(Sec);
|
const Section *Sect = getSection(Sec);
|
||||||
Res = Sect->Address;
|
Res = Sect->Address;
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::getSectionSize(DataRefImpl Sec,
|
MachOObjectFile<MachOT>::getSectionSize(DataRefImpl Sec,
|
||||||
uint64_t &Res) const {
|
uint64_t &Res) const {
|
||||||
const Section *Sect = getSection(Sec);
|
const Section *Sect = getSection(Sec);
|
||||||
Res = Sect->Size;
|
Res = Sect->Size;
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::getSectionContents(DataRefImpl Sec,
|
MachOObjectFile<MachOT>::getSectionContents(DataRefImpl Sec,
|
||||||
StringRef &Res) const {
|
StringRef &Res) const {
|
||||||
const Section *Sect = getSection(Sec);
|
const Section *Sect = getSection(Sec);
|
||||||
Res = getData(Sect->Offset, Sect->Size);
|
Res = getData(Sect->Offset, Sect->Size);
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::getSectionAlignment(DataRefImpl Sec,
|
MachOObjectFile<MachOT>::getSectionAlignment(DataRefImpl Sec,
|
||||||
uint64_t &Res) const {
|
uint64_t &Res) const {
|
||||||
const Section *Sect = getSection(Sec);
|
const Section *Sect = getSection(Sec);
|
||||||
Res = uint64_t(1) << Sect->Align;
|
Res = uint64_t(1) << Sect->Align;
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::isSectionText(DataRefImpl Sec, bool &Res) const {
|
MachOObjectFile<MachOT>::isSectionText(DataRefImpl Sec, bool &Res) const {
|
||||||
const Section *Sect = getSection(Sec);
|
const Section *Sect = getSection(Sec);
|
||||||
Res = Sect->Flags & macho::SF_PureInstructions;
|
Res = Sect->Flags & macho::SF_PureInstructions;
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::isSectionZeroInit(DataRefImpl Sec, bool &Res) const {
|
MachOObjectFile<MachOT>::isSectionZeroInit(DataRefImpl Sec, bool &Res) const {
|
||||||
const Section *Sect = getSection(Sec);
|
const Section *Sect = getSection(Sec);
|
||||||
unsigned SectionType = Sect->Flags & MachO::SectionFlagMaskSectionType;
|
unsigned SectionType = Sect->Flags & MachO::SectionFlagMaskSectionType;
|
||||||
Res = SectionType == MachO::SectionTypeZeroFill ||
|
Res = SectionType == MachO::SectionTypeZeroFill ||
|
||||||
@@ -454,9 +461,9 @@ MachOObjectFile<is64Bits>::isSectionZeroInit(DataRefImpl Sec, bool &Res) const {
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
relocation_iterator
|
relocation_iterator
|
||||||
MachOObjectFile<is64Bits>::getSectionRelEnd(DataRefImpl Sec) const {
|
MachOObjectFile<MachOT>::getSectionRelEnd(DataRefImpl Sec) const {
|
||||||
const Section *Sect = getSection(Sec);
|
const Section *Sect = getSection(Sec);
|
||||||
uint32_t LastReloc = Sect->NumRelocationTableEntries;
|
uint32_t LastReloc = Sect->NumRelocationTableEntries;
|
||||||
DataRefImpl Ret;
|
DataRefImpl Ret;
|
||||||
@@ -465,9 +472,9 @@ MachOObjectFile<is64Bits>::getSectionRelEnd(DataRefImpl Sec) const {
|
|||||||
return relocation_iterator(RelocationRef(Ret, this));
|
return relocation_iterator(RelocationRef(Ret, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::getRelocationAddress(DataRefImpl Rel,
|
MachOObjectFile<MachOT>::getRelocationAddress(DataRefImpl Rel,
|
||||||
uint64_t &Res) const {
|
uint64_t &Res) const {
|
||||||
const Section *Sect = getSection(Sections[Rel.d.b]);
|
const Section *Sect = getSection(Sections[Rel.d.b]);
|
||||||
uint64_t SectAddress = Sect->Address;
|
uint64_t SectAddress = Sect->Address;
|
||||||
@@ -486,9 +493,9 @@ MachOObjectFile<is64Bits>::getRelocationAddress(DataRefImpl Rel,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::getRelocationOffset(DataRefImpl Rel,
|
MachOObjectFile<MachOT>::getRelocationOffset(DataRefImpl Rel,
|
||||||
uint64_t &Res) const {
|
uint64_t &Res) const {
|
||||||
const RelocationEntry *RE = getRelocation(Rel);
|
const RelocationEntry *RE = getRelocation(Rel);
|
||||||
|
|
||||||
@@ -502,9 +509,9 @@ MachOObjectFile<is64Bits>::getRelocationOffset(DataRefImpl Rel,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::getRelocationSymbol(DataRefImpl Rel,
|
MachOObjectFile<MachOT>::getRelocationSymbol(DataRefImpl Rel,
|
||||||
SymbolRef &Res) const {
|
SymbolRef &Res) const {
|
||||||
const RelocationEntry *RE = getRelocation(Rel);
|
const RelocationEntry *RE = getRelocation(Rel);
|
||||||
uint32_t SymbolIdx = RE->Word1 & 0xffffff;
|
uint32_t SymbolIdx = RE->Word1 & 0xffffff;
|
||||||
@@ -524,9 +531,9 @@ MachOObjectFile<is64Bits>::getRelocationSymbol(DataRefImpl Rel,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::getRelocationAdditionalInfo(DataRefImpl Rel,
|
MachOObjectFile<MachOT>::getRelocationAdditionalInfo(DataRefImpl Rel,
|
||||||
int64_t &Res) const {
|
int64_t &Res) const {
|
||||||
const RelocationEntry *RE = getRelocation(Rel);
|
const RelocationEntry *RE = getRelocation(Rel);
|
||||||
bool isExtern = (RE->Word1 >> 27) & 1;
|
bool isExtern = (RE->Word1 >> 27) & 1;
|
||||||
@@ -540,8 +547,8 @@ MachOObjectFile<is64Bits>::getRelocationAdditionalInfo(DataRefImpl Rel,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code MachOObjectFile<is64Bits>::getRelocationType(DataRefImpl Rel,
|
error_code MachOObjectFile<MachOT>::getRelocationType(DataRefImpl Rel,
|
||||||
uint64_t &Res) const {
|
uint64_t &Res) const {
|
||||||
const RelocationEntry *RE = getRelocation(Rel);
|
const RelocationEntry *RE = getRelocation(Rel);
|
||||||
Res = RE->Word0;
|
Res = RE->Word0;
|
||||||
@@ -550,9 +557,9 @@ error_code MachOObjectFile<is64Bits>::getRelocationType(DataRefImpl Rel,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::getRelocationTypeName(DataRefImpl Rel,
|
MachOObjectFile<MachOT>::getRelocationTypeName(DataRefImpl Rel,
|
||||||
SmallVectorImpl<char> &Result) const {
|
SmallVectorImpl<char> &Result) const {
|
||||||
// TODO: Support scattered relocations.
|
// TODO: Support scattered relocations.
|
||||||
StringRef res;
|
StringRef res;
|
||||||
@@ -652,9 +659,9 @@ MachOObjectFile<is64Bits>::getRelocationTypeName(DataRefImpl Rel,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::getRelocationValueString(DataRefImpl Rel,
|
MachOObjectFile<MachOT>::getRelocationValueString(DataRefImpl Rel,
|
||||||
SmallVectorImpl<char> &Result) const {
|
SmallVectorImpl<char> &Result) const {
|
||||||
const RelocationEntry *RE = getRelocation(Rel);
|
const RelocationEntry *RE = getRelocation(Rel);
|
||||||
|
|
||||||
@@ -864,9 +871,9 @@ MachOObjectFile<is64Bits>::getRelocationValueString(DataRefImpl Rel,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::getRelocationHidden(DataRefImpl Rel,
|
MachOObjectFile<MachOT>::getRelocationHidden(DataRefImpl Rel,
|
||||||
bool &Result) const {
|
bool &Result) const {
|
||||||
const RelocationEntry *RE = getRelocation(Rel);
|
const RelocationEntry *RE = getRelocation(Rel);
|
||||||
|
|
||||||
@@ -902,9 +909,9 @@ MachOObjectFile<is64Bits>::getRelocationHidden(DataRefImpl Rel,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::getSymbolFileOffset(DataRefImpl Symb,
|
MachOObjectFile<MachOT>::getSymbolFileOffset(DataRefImpl Symb,
|
||||||
uint64_t &Res) const {
|
uint64_t &Res) const {
|
||||||
const SymbolTableEntry *Entry = getSymbolTableEntry(Symb);
|
const SymbolTableEntry *Entry = getSymbolTableEntry(Symb);
|
||||||
Res = Entry->Value;
|
Res = Entry->Value;
|
||||||
@@ -916,9 +923,9 @@ MachOObjectFile<is64Bits>::getSymbolFileOffset(DataRefImpl Symb,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code
|
error_code
|
||||||
MachOObjectFile<is64Bits>::sectionContainsSymbol(DataRefImpl Sec,
|
MachOObjectFile<MachOT>::sectionContainsSymbol(DataRefImpl Sec,
|
||||||
DataRefImpl Symb,
|
DataRefImpl Symb,
|
||||||
bool &Result) const {
|
bool &Result) const {
|
||||||
SymbolRef::Type ST;
|
SymbolRef::Type ST;
|
||||||
@@ -940,16 +947,16 @@ MachOObjectFile<is64Bits>::sectionContainsSymbol(DataRefImpl Sec,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code MachOObjectFile<is64Bits>::getSymbolAddress(DataRefImpl Symb,
|
error_code MachOObjectFile<MachOT>::getSymbolAddress(DataRefImpl Symb,
|
||||||
uint64_t &Res) const {
|
uint64_t &Res) const {
|
||||||
const SymbolTableEntry *Entry = getSymbolTableEntry(Symb);
|
const SymbolTableEntry *Entry = getSymbolTableEntry(Symb);
|
||||||
Res = Entry->Value;
|
Res = Entry->Value;
|
||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code MachOObjectFile<is64Bits>::getSymbolSize(DataRefImpl DRI,
|
error_code MachOObjectFile<MachOT>::getSymbolSize(DataRefImpl DRI,
|
||||||
uint64_t &Result) const {
|
uint64_t &Result) const {
|
||||||
uint32_t LoadCommandCount = getHeader()->NumLoadCommands;
|
uint32_t LoadCommandCount = getHeader()->NumLoadCommands;
|
||||||
uint64_t BeginOffset;
|
uint64_t BeginOffset;
|
||||||
@@ -992,8 +999,8 @@ error_code MachOObjectFile<is64Bits>::getSymbolSize(DataRefImpl DRI,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
error_code MachOObjectFile<is64Bits>::getSectionNext(DataRefImpl Sec,
|
error_code MachOObjectFile<MachOT>::getSectionNext(DataRefImpl Sec,
|
||||||
SectionRef &Res) const {
|
SectionRef &Res) const {
|
||||||
Sec.d.b++;
|
Sec.d.b++;
|
||||||
moveToNextSection(Sec);
|
moveToNextSection(Sec);
|
||||||
@@ -1001,15 +1008,15 @@ error_code MachOObjectFile<is64Bits>::getSectionNext(DataRefImpl Sec,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
section_iterator MachOObjectFile<is64Bits>::begin_sections() const {
|
section_iterator MachOObjectFile<MachOT>::begin_sections() const {
|
||||||
DataRefImpl DRI;
|
DataRefImpl DRI;
|
||||||
moveToNextSection(DRI);
|
moveToNextSection(DRI);
|
||||||
return section_iterator(SectionRef(DRI, this));
|
return section_iterator(SectionRef(DRI, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool is64Bits>
|
template<class MachOT>
|
||||||
void MachOObjectFile<is64Bits>::moveToNextSection(DataRefImpl &DRI) const {
|
void MachOObjectFile<MachOT>::moveToNextSection(DataRefImpl &DRI) const {
|
||||||
uint32_t LoadCommandCount = getHeader()->NumLoadCommands;
|
uint32_t LoadCommandCount = getHeader()->NumLoadCommands;
|
||||||
while (DRI.d.a < LoadCommandCount) {
|
while (DRI.d.a < LoadCommandCount) {
|
||||||
const LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
|
const LoadCommand *Command = getLoadCommandInfo(DRI.d.a);
|
||||||
@@ -1025,6 +1032,10 @@ void MachOObjectFile<is64Bits>::moveToNextSection(DataRefImpl &DRI) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef MachOObjectFile<MachOType<support::little, false> >
|
||||||
|
MachOObjectFile32Le;
|
||||||
|
typedef MachOObjectFile<MachOType<support::little, true> >
|
||||||
|
MachOObjectFile64Le;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ MachOObjectFileBase::MachOObjectFileBase(MemoryBuffer *Object, bool Is64bits,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MachOObjectFileBase::is64Bit() const {
|
bool MachOObjectFileBase::is64Bit() const {
|
||||||
return isa<MachOObjectFile<true> >(this);
|
return isa<MachOObjectFile64Le>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
const MachOObjectFileBase::LoadCommand *
|
const MachOObjectFileBase::LoadCommand *
|
||||||
@@ -86,9 +86,9 @@ ObjectFile *ObjectFile::createMachOObjectFile(MemoryBuffer *Buffer) {
|
|||||||
bool Is64Bits = Magic == "\xFE\xED\xFA\xCF" || Magic == "\xCF\xFA\xED\xFE";
|
bool Is64Bits = Magic == "\xFE\xED\xFA\xCF" || Magic == "\xCF\xFA\xED\xFE";
|
||||||
ObjectFile *Ret;
|
ObjectFile *Ret;
|
||||||
if (Is64Bits)
|
if (Is64Bits)
|
||||||
Ret = new MachOObjectFile<true>(Buffer, ec);
|
Ret = new MachOObjectFile64Le(Buffer, ec);
|
||||||
else
|
else
|
||||||
Ret = new MachOObjectFile<false>(Buffer, ec);
|
Ret = new MachOObjectFile32Le(Buffer, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
return NULL;
|
return NULL;
|
||||||
return Ret;
|
return Ret;
|
||||||
@@ -127,8 +127,8 @@ MachOObjectFileBase::getSymbolTableEntryBase(DataRefImpl DRI,
|
|||||||
unsigned Index = DRI.d.b;
|
unsigned Index = DRI.d.b;
|
||||||
|
|
||||||
unsigned SymbolTableEntrySize = is64Bit() ?
|
unsigned SymbolTableEntrySize = is64Bit() ?
|
||||||
sizeof(MachOObjectFile<true>::SymbolTableEntry) :
|
sizeof(MachOObjectFile64Le::SymbolTableEntry) :
|
||||||
sizeof(MachOObjectFile<false>::SymbolTableEntry);
|
sizeof(MachOObjectFile32Le::SymbolTableEntry);
|
||||||
|
|
||||||
uint64_t Offset = SymbolTableOffset + Index * SymbolTableEntrySize;
|
uint64_t Offset = SymbolTableOffset + Index * SymbolTableEntrySize;
|
||||||
StringRef Data = getData(Offset, SymbolTableEntrySize);
|
StringRef Data = getData(Offset, SymbolTableEntrySize);
|
||||||
@@ -314,10 +314,10 @@ MachOObjectFileBase::getSectionBase(DataRefImpl DRI) const {
|
|||||||
|
|
||||||
bool Is64 = is64Bit();
|
bool Is64 = is64Bit();
|
||||||
unsigned SegmentLoadSize =
|
unsigned SegmentLoadSize =
|
||||||
Is64 ? sizeof(MachOObjectFile<true>::SegmentLoadCommand) :
|
Is64 ? sizeof(MachOObjectFile64Le::SegmentLoadCommand) :
|
||||||
sizeof(MachOObjectFile<false>::SegmentLoadCommand);
|
sizeof(MachOObjectFile32Le::SegmentLoadCommand);
|
||||||
unsigned SectionSize = Is64 ? sizeof(MachOObjectFile<true>::Section) :
|
unsigned SectionSize = Is64 ? sizeof(MachOObjectFile64Le::Section) :
|
||||||
sizeof(MachOObjectFile<false>::Section);
|
sizeof(MachOObjectFile32Le::Section);
|
||||||
|
|
||||||
uintptr_t SectionAddr = CommandAddr + SegmentLoadSize + DRI.d.b * SectionSize;
|
uintptr_t SectionAddr = CommandAddr + SegmentLoadSize + DRI.d.b * SectionSize;
|
||||||
return reinterpret_cast<const SectionBase*>(SectionAddr);
|
return reinterpret_cast<const SectionBase*>(SectionAddr);
|
||||||
|
@@ -160,8 +160,8 @@ namespace {
|
|||||||
static void getSection(const MachOObjectFileBase *Obj,
|
static void getSection(const MachOObjectFileBase *Obj,
|
||||||
DataRefImpl DRI,
|
DataRefImpl DRI,
|
||||||
MachOSection &Section) {
|
MachOSection &Section) {
|
||||||
if (const MachOObjectFile<true> *O = dyn_cast<MachOObjectFile<true> >(Obj)) {
|
if (const MachOObjectFile64Le *O = dyn_cast<MachOObjectFile64Le>(Obj)) {
|
||||||
const MachOObjectFile<true>::Section *Sect = O->getSection(DRI);
|
const MachOObjectFile64Le::Section *Sect = O->getSection(DRI);
|
||||||
|
|
||||||
Section.Address = Sect->Address;
|
Section.Address = Sect->Address;
|
||||||
Section.Size = Sect->Size;
|
Section.Size = Sect->Size;
|
||||||
@@ -173,8 +173,8 @@ static void getSection(const MachOObjectFileBase *Obj,
|
|||||||
Section.Reserved1 = Sect->Reserved1;
|
Section.Reserved1 = Sect->Reserved1;
|
||||||
Section.Reserved2 = Sect->Reserved2;
|
Section.Reserved2 = Sect->Reserved2;
|
||||||
} else {
|
} else {
|
||||||
const MachOObjectFile<false> *O2 = cast<MachOObjectFile<false> >(Obj);
|
const MachOObjectFile32Le *O2 = cast<MachOObjectFile32Le>(Obj);
|
||||||
const MachOObjectFile<false>::Section *Sect = O2->getSection(DRI);
|
const MachOObjectFile32Le::Section *Sect = O2->getSection(DRI);
|
||||||
|
|
||||||
Section.Address = Sect->Address;
|
Section.Address = Sect->Address;
|
||||||
Section.Size = Sect->Size;
|
Section.Size = Sect->Size;
|
||||||
@@ -191,8 +191,8 @@ static void getSection(const MachOObjectFileBase *Obj,
|
|||||||
static void getSymbol(const MachOObjectFileBase *Obj,
|
static void getSymbol(const MachOObjectFileBase *Obj,
|
||||||
DataRefImpl DRI,
|
DataRefImpl DRI,
|
||||||
MachOSymbol &Symbol) {
|
MachOSymbol &Symbol) {
|
||||||
if (const MachOObjectFile<true> *O = dyn_cast<MachOObjectFile<true> >(Obj)) {
|
if (const MachOObjectFile64Le *O = dyn_cast<MachOObjectFile64Le>(Obj)) {
|
||||||
const MachOObjectFile<true>::SymbolTableEntry *Entry =
|
const MachOObjectFile64Le::SymbolTableEntry *Entry =
|
||||||
O->getSymbolTableEntry(DRI);
|
O->getSymbolTableEntry(DRI);
|
||||||
Symbol.StringIndex = Entry->StringIndex;
|
Symbol.StringIndex = Entry->StringIndex;
|
||||||
Symbol.Type = Entry->Type;
|
Symbol.Type = Entry->Type;
|
||||||
@@ -200,8 +200,8 @@ static void getSymbol(const MachOObjectFileBase *Obj,
|
|||||||
Symbol.Flags = Entry->Flags;
|
Symbol.Flags = Entry->Flags;
|
||||||
Symbol.Value = Entry->Value;
|
Symbol.Value = Entry->Value;
|
||||||
} else {
|
} else {
|
||||||
const MachOObjectFile<false> *O2 = cast<MachOObjectFile<false> >(Obj);
|
const MachOObjectFile32Le *O2 = cast<MachOObjectFile32Le>(Obj);
|
||||||
const MachOObjectFile<false>::SymbolTableEntry *Entry =
|
const MachOObjectFile32Le::SymbolTableEntry *Entry =
|
||||||
O2->getSymbolTableEntry(DRI);
|
O2->getSymbolTableEntry(DRI);
|
||||||
Symbol.StringIndex = Entry->StringIndex;
|
Symbol.StringIndex = Entry->StringIndex;
|
||||||
Symbol.Type = Entry->Type;
|
Symbol.Type = Entry->Type;
|
||||||
|
Reference in New Issue
Block a user