aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-readobj/MachODumper.cpp
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2014-07-04 10:57:56 +0000
committerTim Northover <tnorthover@apple.com>2014-07-04 10:57:56 +0000
commit07f99fb769719ce703aa3f334e531f9e1ff852d2 (patch)
tree5032d9c5d19cb8ab8f56ecff0736122cbd8d2cfc /llvm/tools/llvm-readobj/MachODumper.cpp
parenta420df2999fd0362933d381f71ab81e1e6e1fa1e (diff)
downloadllvm-07f99fb769719ce703aa3f334e531f9e1ff852d2.zip
llvm-07f99fb769719ce703aa3f334e531f9e1ff852d2.tar.gz
llvm-07f99fb769719ce703aa3f334e531f9e1ff852d2.tar.bz2
llvm-readobj: fix MachO relocatoin printing a bit.
There were two issues here: 1. At the very least, scattered relocations cannot use the same code to determine the corresponding symbol being referred to. For some reason we pretend there is no symbol, even when one actually exists in the symtab, so to match this behaviour getRelocationSymbol should simply return symbols_end for scattered relocations. 2. Printing "-" when we can't get a symbol (including the scattered case, but not exclusively), isn't that helpful. In both cases there *is* interesting information in that field, so we should print it. As hex will do. Small part of rdar://problem/17553104 llvm-svn: 212332
Diffstat (limited to 'llvm/tools/llvm-readobj/MachODumper.cpp')
-rw-r--r--llvm/tools/llvm-readobj/MachODumper.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/llvm/tools/llvm-readobj/MachODumper.cpp b/llvm/tools/llvm-readobj/MachODumper.cpp
index d168030..a5e5cf8 100644
--- a/llvm/tools/llvm-readobj/MachODumper.cpp
+++ b/llvm/tools/llvm-readobj/MachODumper.cpp
@@ -16,6 +16,7 @@
#include "ObjDumper.h"
#include "StreamWriter.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/Object/MachO.h"
#include "llvm/Support/Casting.h"
@@ -309,18 +310,29 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj,
const RelocationRef &Reloc) {
uint64_t Offset;
SmallString<32> RelocName;
- StringRef SymbolName;
if (error(Reloc.getOffset(Offset)))
return;
if (error(Reloc.getTypeName(RelocName)))
return;
- symbol_iterator Symbol = Reloc.getSymbol();
- if (Symbol != Obj->symbol_end() && error(Symbol->getName(SymbolName)))
- return;
DataRefImpl DR = Reloc.getRawDataRefImpl();
MachO::any_relocation_info RE = Obj->getRelocation(DR);
bool IsScattered = Obj->isRelocationScattered(RE);
+ SmallString<32> SymbolNameOrOffset("0x");
+ if (IsScattered) {
+ // Scattered relocations don't really have an associated symbol
+ // for some reason, even if one exists in the symtab at the correct address.
+ SymbolNameOrOffset += utohexstr(Obj->getScatteredRelocationValue(RE));
+ } else {
+ symbol_iterator Symbol = Reloc.getSymbol();
+ if (Symbol != Obj->symbol_end()) {
+ StringRef SymbolName;
+ if (error(Symbol->getName(SymbolName)))
+ return;
+ SymbolNameOrOffset = SymbolName;
+ } else
+ SymbolNameOrOffset += utohexstr(Obj->getPlainRelocationSymbolNum(RE));
+ }
if (opts::ExpandRelocs) {
DictScope Group(W, "Relocation");
@@ -332,7 +344,7 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj,
else
W.printNumber("Extern", Obj->getPlainRelocationExternal(RE));
W.printNumber("Type", RelocName, Obj->getAnyRelocationType(RE));
- W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
+ W.printString("Symbol", SymbolNameOrOffset);
W.printNumber("Scattered", IsScattered);
} else {
raw_ostream& OS = W.startLine();
@@ -345,7 +357,7 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj,
OS << " " << Obj->getPlainRelocationExternal(RE);
OS << " " << RelocName
<< " " << IsScattered
- << " " << (SymbolName.size() > 0 ? SymbolName : "-")
+ << " " << SymbolNameOrOffset
<< "\n";
}
}