[llvm] r179359 - Add -expand-relocs to llvm-readobj
Nico Rieck
nico.rieck at gmail.com
Thu Apr 11 21:01:53 PDT 2013
Author: nrieck
Date: Thu Apr 11 23:01:52 2013
New Revision: 179359
URL: http://llvm.org/viewvc/llvm-project?rev=179359&view=rev
Log:
Add -expand-relocs to llvm-readobj
This option expands shown relocations from single line to a dictionary
format:
Relocation {
Offset: 0x4
Type: R_386_32 (1)
Symbol: sym
Info: 0x0
}
Modified:
llvm/trunk/docs/CommandGuide/llvm-readobj.rst
llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
llvm/trunk/tools/llvm-readobj/MachODumper.cpp
llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
llvm/trunk/tools/llvm-readobj/llvm-readobj.h
Modified: llvm/trunk/docs/CommandGuide/llvm-readobj.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-readobj.rst?rev=179359&r1=179358&r2=179359&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/llvm-readobj.rst (original)
+++ llvm/trunk/docs/CommandGuide/llvm-readobj.rst Thu Apr 11 23:01:52 2013
@@ -63,6 +63,11 @@ input. Otherwise, it will read from the
Display unwind information.
+.. option:: -expand-relocs
+
+ When used with ``-relocations``, display each relocation in an expanded
+ multi-line format.
+
.. option:: -dynamic-table
Display the ELF .dynamic section table (only for ELF object files).
Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=179359&r1=179358&r2=179359&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Thu Apr 11 23:01:52 2013
@@ -680,11 +680,18 @@ void COFFDumper::printRelocation(section
if (error(Symbol.getName(SymbolName))) return;
if (error(SecI->getContents(Contents))) return;
- raw_ostream& OS = W.startLine();
- OS << W.hex(Offset)
- << " " << RelocName
- << " " << (SymbolName.size() > 0 ? SymbolName : "-")
- << "\n";
+ if (opts::ExpandRelocs) {
+ DictScope Group(W, "Relocation");
+ W.printHex("Offset", Offset);
+ W.printNumber("Type", RelocName, RelocType);
+ W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
+ } else {
+ raw_ostream& OS = W.startLine();
+ OS << W.hex(Offset)
+ << " " << RelocName
+ << " " << (SymbolName.size() > 0 ? SymbolName : "-")
+ << "\n";
+ }
}
void COFFDumper::printSymbols() {
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=179359&r1=179358&r2=179359&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Thu Apr 11 23:01:52 2013
@@ -549,22 +549,32 @@ template<class ELFT>
void ELFDumper<ELFT>::printRelocation(section_iterator Sec,
relocation_iterator RelI) {
uint64_t Offset;
+ uint64_t RelocType;
SmallString<32> RelocName;
int64_t Info;
StringRef SymbolName;
SymbolRef Symbol;
if (error(RelI->getOffset(Offset))) return;
+ if (error(RelI->getType(RelocType))) return;
if (error(RelI->getTypeName(RelocName))) return;
if (error(RelI->getAdditionalInfo(Info))) return;
if (error(RelI->getSymbol(Symbol))) return;
if (error(Symbol.getName(SymbolName))) return;
- raw_ostream& OS = W.startLine();
- OS << W.hex(Offset)
- << " " << RelocName
- << " " << (SymbolName.size() > 0 ? SymbolName : "-")
- << " " << W.hex(Info)
- << "\n";
+ if (opts::ExpandRelocs) {
+ DictScope Group(W, "Relocation");
+ W.printHex("Offset", Offset);
+ W.printNumber("Type", RelocName, RelocType);
+ W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
+ W.printHex("Info", Info);
+ } else {
+ raw_ostream& OS = W.startLine();
+ OS << W.hex(Offset)
+ << " " << RelocName
+ << " " << (SymbolName.size() > 0 ? SymbolName : "-")
+ << " " << W.hex(Info)
+ << "\n";
+ }
}
template<class ELFT>
Modified: llvm/trunk/tools/llvm-readobj/MachODumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/MachODumper.cpp?rev=179359&r1=179358&r2=179359&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/MachODumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/MachODumper.cpp Thu Apr 11 23:01:52 2013
@@ -341,18 +341,32 @@ void MachODumper::printRelocation(sectio
const MachOObjectFileBase::RelocationEntry *RE = Obj->getRelocation(DR);
bool IsScattered = Obj->isScattered(RE);
- raw_ostream& OS = W.startLine();
- OS << W.hex(Offset)
- << " " << Obj->isPCRel(RE)
- << " " << Obj->getLength(RE);
- if (IsScattered)
- OS << " n/a";
- else
- OS << " " << RE->getExternal();
- OS << " " << RelocName
- << " " << IsScattered
- << " " << (SymbolName.size() > 0 ? SymbolName : "-")
- << "\n";
+ if (opts::ExpandRelocs) {
+ DictScope Group(W, "Relocation");
+ W.printHex("Offset", Offset);
+ W.printNumber("PCRel", Obj->isPCRel(RE));
+ W.printNumber("Length", Obj->getLength(RE));
+ if (IsScattered)
+ W.printString("Extern", StringRef("N/A"));
+ else
+ W.printNumber("Extern", RE->getExternal());
+ W.printNumber("Type", RelocName, RE->getType());
+ W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
+ W.printNumber("Scattered", IsScattered);
+ } else {
+ raw_ostream& OS = W.startLine();
+ OS << W.hex(Offset)
+ << " " << Obj->isPCRel(RE)
+ << " " << Obj->getLength(RE);
+ if (IsScattered)
+ OS << " n/a";
+ else
+ OS << " " << RE->getExternal();
+ OS << " " << RelocName
+ << " " << IsScattered
+ << " " << (SymbolName.size() > 0 ? SymbolName : "-")
+ << "\n";
+ }
}
void MachODumper::printSymbols() {
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=179359&r1=179358&r2=179359&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Thu Apr 11 23:01:52 2013
@@ -120,6 +120,10 @@ namespace opts {
// -needed-libs
cl::opt<bool> NeededLibraries("needed-libs",
cl::desc("Display the needed libraries"));
+
+ // -expand-relocs
+ cl::opt<bool> ExpandRelocs("expand-relocs",
+ cl::desc("Expand each shown relocation to multiple lines"));
} // namespace opts
namespace llvm {
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.h?rev=179359&r1=179358&r2=179359&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.h (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.h Thu Apr 11 23:01:52 2013
@@ -37,6 +37,7 @@ namespace opts {
extern llvm::cl::opt<bool> Symbols;
extern llvm::cl::opt<bool> DynamicSymbols;
extern llvm::cl::opt<bool> UnwindInfo;
+ extern llvm::cl::opt<bool> ExpandRelocs;
} // namespace opts
#define LLVM_READOBJ_ENUM_ENT(ns, enum) \
More information about the llvm-commits
mailing list