summaryrefslogtreecommitdiff
path: root/include/llvm/Object/MachO.h
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-04-11 17:46:10 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-04-11 17:46:10 +0000
commit59a8b5a8f09ae4c4f3b0e3d8025c6b4cf3ca1f1a (patch)
treeca0f4e97518092abe898964097539a8ccc364b06 /include/llvm/Object/MachO.h
parent6b281800d2bd2419d3f1c4e282c7c07dd54058f5 (diff)
downloadllvm-59a8b5a8f09ae4c4f3b0e3d8025c6b4cf3ca1f1a.tar.gz
llvm-59a8b5a8f09ae4c4f3b0e3d8025c6b4cf3ca1f1a.tar.bz2
llvm-59a8b5a8f09ae4c4f3b0e3d8025c6b4cf3ca1f1a.tar.xz
Revert my last two commits while I debug what is wrong in a big endian host.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179303 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Object/MachO.h')
-rw-r--r--include/llvm/Object/MachO.h125
1 files changed, 64 insertions, 61 deletions
diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h
index 7bdb638b26..b02e1ac100 100644
--- a/include/llvm/Object/MachO.h
+++ b/include/llvm/Object/MachO.h
@@ -112,33 +112,11 @@ namespace MachOFormat {
MachOInt32 Reserved3;
};
- struct MachOInt24 {
- uint8_t bytes[3];
- operator uint32_t() const {
- return (bytes[2] << 24) | (bytes[1] << 16) | bytes[0];
- }
- };
-
template<endianness TargetEndianness>
struct RelocationEntry {
LLVM_MACHOB_IMPORT_TYPES(TargetEndianness)
- MachOInt32 Address;
- MachOInt24 SymbolNum;
- unsigned PCRel : 1;
- unsigned Length : 2;
- unsigned External : 1;
- unsigned Type : 4;
- };
-
- template<endianness TargetEndianness>
- struct ScatteredRelocationEntry {
- LLVM_MACHOB_IMPORT_TYPES(TargetEndianness)
- unsigned Address : 24;
- unsigned Type : 4;
- unsigned Length : 2;
- unsigned PCRel : 1;
- unsigned Scattered : 1;
- MachOInt32 Value;
+ MachOInt32 Word0;
+ MachOInt32 Word1;
};
template<endianness TargetEndianness>
@@ -228,8 +206,6 @@ public:
SymbolTableEntryBase;
typedef MachOFormat::SymtabLoadCommand<support::little> SymtabLoadCommand;
typedef MachOFormat::RelocationEntry<support::little> RelocationEntry;
- typedef MachOFormat::ScatteredRelocationEntry<support::little>
- ScatteredRelocationEntry;
typedef MachOFormat::SectionBase SectionBase;
typedef MachOFormat::LoadCommand<support::little> LoadCommand;
typedef MachOFormat::Header<support::little> Header;
@@ -267,11 +243,6 @@ public:
const Header *getHeader() const;
unsigned getHeaderSize() const;
StringRef getData(size_t Offset, size_t Size) const;
- const RelocationEntry *getRelocation(DataRefImpl Rel) const;
- bool isScattered(const RelocationEntry *RE) const;
- bool isPCRel(const RelocationEntry *RE) const;
- unsigned getLength(const RelocationEntry *RE) const;
- unsigned getType(const RelocationEntry *RE) const;
static inline bool classof(const Binary *v) {
return v->isMachO();
@@ -508,12 +479,15 @@ MachOObjectFile<MachOT>::getRelocationAddress(DataRefImpl Rel,
const Section *Sect = getSection(Sections[Rel.d.b]);
uint64_t SectAddress = Sect->Address;
const RelocationEntry *RE = getRelocation(Rel);
+ unsigned Arch = getArch();
+ bool isScattered = (Arch != Triple::x86_64) &&
+ (RE->Word0 & macho::RF_Scattered);
uint64_t RelAddr;
- if (isScattered(RE))
- RelAddr = RE->Address & 0xFFFFFF;
+ if (isScattered)
+ RelAddr = RE->Word0 & 0xFFFFFF;
else
- RelAddr = RE->Address;
+ RelAddr = RE->Word0;
Res = SectAddress + RelAddr;
return object_error::success;
@@ -524,10 +498,14 @@ error_code
MachOObjectFile<MachOT>::getRelocationOffset(DataRefImpl Rel,
uint64_t &Res) const {
const RelocationEntry *RE = getRelocation(Rel);
- if (isScattered(RE))
- Res = RE->Address & 0xFFFFFF;
+
+ unsigned Arch = getArch();
+ bool isScattered = (Arch != Triple::x86_64) &&
+ (RE->Word0 & macho::RF_Scattered);
+ if (isScattered)
+ Res = RE->Word0 & 0xFFFFFF;
else
- Res = RE->Address;
+ Res = RE->Word0;
return object_error::success;
}
@@ -536,8 +514,8 @@ error_code
MachOObjectFile<MachOT>::getRelocationSymbol(DataRefImpl Rel,
SymbolRef &Res) const {
const RelocationEntry *RE = getRelocation(Rel);
- uint32_t SymbolIdx = RE->SymbolNum;
- bool isExtern = RE->External;
+ uint32_t SymbolIdx = RE->Word1 & 0xffffff;
+ bool isExtern = (RE->Word1 >> 27) & 1;
DataRefImpl Sym;
moveToNextSymbol(Sym);
@@ -557,7 +535,9 @@ template<class MachOT>
error_code MachOObjectFile<MachOT>::getRelocationType(DataRefImpl Rel,
uint64_t &Res) const {
const RelocationEntry *RE = getRelocation(Rel);
- Res = getType(RE);
+ Res = RE->Word0;
+ Res <<= 32;
+ Res |= RE->Word1;
return object_error::success;
}
@@ -570,8 +550,14 @@ MachOObjectFile<MachOT>::getRelocationTypeName(DataRefImpl Rel,
const RelocationEntry *RE = getRelocation(Rel);
unsigned Arch = getArch();
+ bool isScattered = (Arch != Triple::x86_64) &&
+ (RE->Word0 & macho::RF_Scattered);
- unsigned r_type = getType(RE);
+ unsigned r_type;
+ if (isScattered)
+ r_type = (RE->Word0 >> 24) & 0xF;
+ else
+ r_type = (RE->Word1 >> 28) & 0xF;
switch (Arch) {
case Triple::x86: {
@@ -664,20 +650,30 @@ MachOObjectFile<MachOT>::getRelocationValueString(DataRefImpl Rel,
const RelocationEntry *RE = getRelocation(Rel);
unsigned Arch = getArch();
- bool IsScattered = isScattered(RE);
+ bool isScattered = (Arch != Triple::x86_64) &&
+ (RE->Word0 & macho::RF_Scattered);
std::string fmtbuf;
raw_string_ostream fmt(fmtbuf);
- unsigned Type = getType(RE);
- bool IsPCRel = isPCRel(RE);
+ unsigned Type;
+ if (isScattered)
+ Type = (RE->Word0 >> 24) & 0xF;
+ else
+ Type = (RE->Word1 >> 28) & 0xF;
+
+ bool isPCRel;
+ if (isScattered)
+ isPCRel = ((RE->Word0 >> 30) & 1);
+ else
+ isPCRel = ((RE->Word1 >> 24) & 1);
// Determine any addends that should be displayed with the relocation.
// These require decoding the relocation type, which is triple-specific.
// X86_64 has entirely custom relocation types.
if (Arch == Triple::x86_64) {
- bool isPCRel = RE->PCRel;
+ bool isPCRel = ((RE->Word1 >> 24) & 1);
switch (Type) {
case macho::RIT_X86_64_GOTLoad: // X86_64_RELOC_GOT_LOAD
@@ -695,7 +691,7 @@ MachOObjectFile<MachOT>::getRelocationValueString(DataRefImpl Rel,
// X86_64_SUBTRACTOR must be followed by a relocation of type
// X86_64_RELOC_UNSIGNED.
// NOTE: Scattered relocations don't exist on x86_64.
- unsigned RType = RENext->Type;
+ unsigned RType = (RENext->Word1 >> 28) & 0xF;
if (RType != 0)
report_fatal_error("Expected X86_64_RELOC_UNSIGNED after "
"X86_64_RELOC_SUBTRACTOR.");
@@ -742,12 +738,12 @@ MachOObjectFile<MachOT>::getRelocationValueString(DataRefImpl Rel,
// X86 sect diff's must be followed by a relocation of type
// GENERIC_RELOC_PAIR.
bool isNextScattered = (Arch != Triple::x86_64) &&
- (RENext->Address & macho::RF_Scattered);
+ (RENext->Word0 & macho::RF_Scattered);
unsigned RType;
if (isNextScattered)
- RType = (RENext->Address >> 24) & 0xF;
+ RType = (RENext->Word0 >> 24) & 0xF;
else
- RType = RENext->Type;
+ RType = (RENext->Word1 >> 28) & 0xF;
if (RType != 1)
report_fatal_error("Expected GENERIC_RELOC_PAIR after "
"GENERIC_RELOC_SECTDIFF.");
@@ -771,12 +767,12 @@ MachOObjectFile<MachOT>::getRelocationValueString(DataRefImpl Rel,
// X86 sect diff's must be followed by a relocation of type
// GENERIC_RELOC_PAIR.
bool isNextScattered = (Arch != Triple::x86_64) &&
- (RENext->Address & macho::RF_Scattered);
+ (RENext->Word0 & macho::RF_Scattered);
unsigned RType;
if (isNextScattered)
- RType = (RENext->Address >> 24) & 0xF;
+ RType = (RENext->Word0 >> 24) & 0xF;
else
- RType = RENext->Type;
+ RType = (RENext->Word1 >> 28) & 0xF;
if (RType != 1)
report_fatal_error("Expected GENERIC_RELOC_PAIR after "
"GENERIC_RELOC_LOCAL_SECTDIFF.");
@@ -789,7 +785,7 @@ MachOObjectFile<MachOT>::getRelocationValueString(DataRefImpl Rel,
case macho::RIT_Generic_TLV: {
printRelocationTargetName(RE, fmt);
fmt << "@TLV";
- if (IsPCRel) fmt << "P";
+ if (isPCRel) fmt << "P";
break;
}
default:
@@ -802,10 +798,10 @@ MachOObjectFile<MachOT>::getRelocationValueString(DataRefImpl Rel,
// Half relocations steal a bit from the length field to encode
// whether this is an upper16 or a lower16 relocation.
bool isUpper;
- if (IsScattered)
- isUpper = (RE->Address >> 28) & 1;
+ if (isScattered)
+ isUpper = (RE->Word0 >> 28) & 1;
else
- isUpper = (RE->Length >> 1) & 1;
+ isUpper = (RE->Word1 >> 25) & 1;
if (isUpper)
fmt << ":upper16:(";
@@ -820,12 +816,12 @@ MachOObjectFile<MachOT>::getRelocationValueString(DataRefImpl Rel,
// ARM half relocs must be followed by a relocation of type
// ARM_RELOC_PAIR.
bool isNextScattered = (Arch != Triple::x86_64) &&
- (RENext->Address & macho::RF_Scattered);
+ (RENext->Word0 & macho::RF_Scattered);
unsigned RType;
if (isNextScattered)
- RType = (RENext->Address >> 24) & 0xF;
+ RType = (RENext->Word0 >> 24) & 0xF;
else
- RType = RENext->Type;
+ RType = (RENext->Word1 >> 28) & 0xF;
if (RType != 1)
report_fatal_error("Expected ARM_RELOC_PAIR after "
@@ -864,8 +860,15 @@ error_code
MachOObjectFile<MachOT>::getRelocationHidden(DataRefImpl Rel,
bool &Result) const {
const RelocationEntry *RE = getRelocation(Rel);
+
unsigned Arch = getArch();
- unsigned Type = getType(RE);
+ bool isScattered = (Arch != Triple::x86_64) &&
+ (RE->Word0 & macho::RF_Scattered);
+ unsigned Type;
+ if (isScattered)
+ Type = (RE->Word0 >> 24) & 0xF;
+ else
+ Type = (RE->Word1 >> 28) & 0xF;
Result = false;
@@ -881,7 +884,7 @@ MachOObjectFile<MachOT>::getRelocationHidden(DataRefImpl Rel,
RelPrev.d.a--;
const RelocationEntry *REPrev = getRelocation(RelPrev);
- unsigned PrevType = REPrev->Type;
+ unsigned PrevType = (REPrev->Word1 >> 28) & 0xF;
if (PrevType == macho::RIT_X86_64_Subtractor) Result = true;
}