From 07f99fb769719ce703aa3f334e531f9e1ff852d2 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Fri, 4 Jul 2014 10:57:56 +0000 Subject: 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 --- llvm/tools/llvm-readobj/MachODumper.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'llvm/tools') diff --git a/llvm/tools/llvm-readobj/MachODumper.cpp b/llvm/tools/llvm-readobj/MachODumper.cpp index d168030a270..a5e5cf850a3 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"; } } -- cgit v1.2.3