summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-readobj
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-06-18 22:38:20 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-06-18 22:38:20 +0000
commit9ac06a0e6b38f89c2ba86b14da9a91aff83514bf (patch)
tree8f5e2e09b106823a739eb4ab8b5c414765c9c8d8 /llvm/tools/llvm-readobj
parente0b3499db7cf9d26bc774be7d3e1175bac7665e0 (diff)
downloadbcm5719-llvm-9ac06a0e6b38f89c2ba86b14da9a91aff83514bf.tar.gz
bcm5719-llvm-9ac06a0e6b38f89c2ba86b14da9a91aff83514bf.zip
Improve the --expand-relocs handling of MachO.
In a relocation target can take 3 basic forms * A r_value in scattered relocations. * A symbol in external relocations. * A section is non-external relocations. Have the dump reflect that. With this change we go from CHECK-NEXT: Extern: 0 CHECK-NEXT: Type: X86_64_RELOC_SUBTRACTOR (5) CHECK-NEXT: Symbol: 0x2 CHECK-NEXT: Scattered: 0 To just // CHECK-NEXT: Type: X86_64_RELOC_SUBTRACTOR (5) // CHECK-NEXT: Section: __data (2) Since the relocation is with a section, we print the seciton name and don't need to say that it is not scattered or external. Someone motivated can add further special cases for things like ARM64_RELOC_ADDEND and ARM_RELOC_PAIR. llvm-svn: 240073
Diffstat (limited to 'llvm/tools/llvm-readobj')
-rw-r--r--llvm/tools/llvm-readobj/MachODumper.cpp46
1 files changed, 29 insertions, 17 deletions
diff --git a/llvm/tools/llvm-readobj/MachODumper.cpp b/llvm/tools/llvm-readobj/MachODumper.cpp
index 40691a222f0..9017350c403 100644
--- a/llvm/tools/llvm-readobj/MachODumper.cpp
+++ b/llvm/tools/llvm-readobj/MachODumper.cpp
@@ -469,35 +469,47 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj,
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 {
+ bool IsExtern = !IsScattered && Obj->getPlainRelocationExternal(RE);
+
+ StringRef TargetName;
+ if (IsExtern) {
symbol_iterator Symbol = Reloc.getSymbol();
if (Symbol != Obj->symbol_end()) {
- StringRef SymbolName;
- if (error(Symbol->getName(SymbolName)))
+ if (error(Symbol->getName(TargetName)))
return;
- SymbolNameOrOffset = SymbolName;
- } else
- SymbolNameOrOffset += utohexstr(Obj->getPlainRelocationSymbolNum(RE));
+ }
+ } else if (!IsScattered) {
+ section_iterator SecI = Reloc.getSection();
+ if (SecI != Obj->section_end()) {
+ if (error(SecI->getName(TargetName)))
+ return;
+ }
}
+ if (TargetName.empty())
+ TargetName = "-";
if (opts::ExpandRelocs) {
DictScope Group(W, "Relocation");
W.printHex("Offset", Offset);
W.printNumber("PCRel", Obj->getAnyRelocationPCRel(RE));
W.printNumber("Length", Obj->getAnyRelocationLength(RE));
- if (IsScattered)
- W.printString("Extern", StringRef("N/A"));
- else
- W.printNumber("Extern", Obj->getPlainRelocationExternal(RE));
W.printNumber("Type", RelocName, Obj->getAnyRelocationType(RE));
- W.printString("Symbol", SymbolNameOrOffset);
- W.printNumber("Scattered", IsScattered);
+ if (IsScattered) {
+ W.printHex("Value", Obj->getScatteredRelocationValue(RE));
+ } else {
+ const char *Kind = IsExtern ? "Symbol" : "Section";
+ W.printNumber(Kind, TargetName, Obj->getPlainRelocationSymbolNum(RE));
+ }
} else {
+ 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 {
+ SymbolNameOrOffset = TargetName;
+ }
+
raw_ostream& OS = W.startLine();
OS << W.hex(Offset)
<< " " << Obj->getAnyRelocationPCRel(RE)
OpenPOWER on IntegriCloud