summaryrefslogtreecommitdiffstats
path: root/lib/Object/MachOObjectFile.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-04-12 00:17:33 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-04-12 00:17:33 +0000
commite292347503cd7598429c08f9984ab3e0a44ab8a3 (patch)
tree95a231a9f2d14de9a5043f87149698c3786a631c /lib/Object/MachOObjectFile.cpp
parent33c55bdfed027313b05217d7049aa0e810da5caa (diff)
downloadexternal_llvm-e292347503cd7598429c08f9984ab3e0a44ab8a3.zip
external_llvm-e292347503cd7598429c08f9984ab3e0a44ab8a3.tar.gz
external_llvm-e292347503cd7598429c08f9984ab3e0a44ab8a3.tar.bz2
Add 179294 back, but don't use bit fields so that it works on big endian hosts.
Original message: Print more information about relocations. With this patch llvm-readobj now prints if a relocation is pcrel, its length, if it is extern and if it is scattered. It also refactors the code a bit to use bit fields instead of shifts and masks all over the place. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179345 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Object/MachOObjectFile.cpp')
-rw-r--r--lib/Object/MachOObjectFile.cpp52
1 files changed, 44 insertions, 8 deletions
diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp
index c846206..627e748 100644
--- a/lib/Object/MachOObjectFile.cpp
+++ b/lib/Object/MachOObjectFile.cpp
@@ -80,6 +80,46 @@ StringRef MachOObjectFileBase::getData(size_t Offset, size_t Size) const {
return ObjectFile::getData().substr(Offset, Size);
}
+const MachOObjectFileBase::RelocationEntry *
+MachOObjectFileBase::getRelocation(DataRefImpl Rel) const {
+ if (const MachOObjectFile32Le *O = dyn_cast<MachOObjectFile32Le>(this))
+ return O->getRelocation(Rel);
+ const MachOObjectFile64Le *O = dyn_cast<MachOObjectFile64Le>(this);
+ return O->getRelocation(Rel);
+}
+
+bool MachOObjectFileBase::isScattered(const RelocationEntry *RE) const {
+ unsigned Arch = getArch();
+ return (Arch != Triple::x86_64) && (RE->Address & macho::RF_Scattered);
+}
+
+bool MachOObjectFileBase::isPCRel(const RelocationEntry *RE) const {
+ if (isScattered(RE)) {
+ const ScatteredRelocationEntry *SRE =
+ reinterpret_cast<const ScatteredRelocationEntry *>(RE);
+ return SRE->getPCRel();
+ }
+ return RE->getPCRel();
+}
+
+unsigned MachOObjectFileBase::getLength(const RelocationEntry *RE) const {
+ if (isScattered(RE)) {
+ const ScatteredRelocationEntry *SRE =
+ reinterpret_cast<const ScatteredRelocationEntry *>(RE);
+ return SRE->getLength();
+ }
+ return RE->getLength();
+}
+
+unsigned MachOObjectFileBase::getType(const RelocationEntry *RE) const {
+ if (isScattered(RE)) {
+ const ScatteredRelocationEntry *SRE =
+ reinterpret_cast<const ScatteredRelocationEntry *>(RE);
+ return SRE->getType();
+ }
+ return RE->getType();
+}
+
ObjectFile *ObjectFile::createMachOObjectFile(MemoryBuffer *Buffer) {
StringRef Magic = Buffer->getBuffer().slice(0, 4);
error_code ec;
@@ -435,16 +475,12 @@ void advanceTo(T &it, size_t Val) {
void
MachOObjectFileBase::printRelocationTargetName(const RelocationEntry *RE,
raw_string_ostream &fmt) const {
- unsigned Arch = getArch();
- bool isScattered = (Arch != Triple::x86_64) &&
- (RE->Word0 & macho::RF_Scattered);
-
// Target of a scattered relocation is an address. In the interest of
// generating pretty output, scan through the symbol table looking for a
// symbol that aligns with that address. If we find one, print it.
// Otherwise, we just print the hex address of the target.
- if (isScattered) {
- uint32_t Val = RE->Word1;
+ if (isScattered(RE)) {
+ uint32_t Val = RE->SymbolNum;
error_code ec;
for (symbol_iterator SI = begin_symbols(), SE = end_symbols(); SI != SE;
@@ -486,8 +522,8 @@ MachOObjectFileBase::printRelocationTargetName(const RelocationEntry *RE,
}
StringRef S;
- bool isExtern = (RE->Word1 >> 27) & 1;
- uint32_t Val = RE->Word1 & 0xFFFFFF;
+ bool isExtern = RE->getExternal();
+ uint32_t Val = RE->Address;
if (isExtern) {
symbol_iterator SI = begin_symbols();