aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-readobj
diff options
context:
space:
mode:
authorNico Rieck <nico.rieck@gmail.com>2013-04-12 04:01:52 +0000
committerNico Rieck <nico.rieck@gmail.com>2013-04-12 04:01:52 +0000
commit1c8dfa5e90fa7ba5d351d2e2511dc1495c83f6fd (patch)
tree8f7536c3e589a7b652ae0c70282812309f4d84a1 /tools/llvm-readobj
parenta6cd815994a30888d579e7731a98e668f07a5965 (diff)
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 } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179359 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-readobj')
-rw-r--r--tools/llvm-readobj/COFFDumper.cpp17
-rw-r--r--tools/llvm-readobj/ELFDumper.cpp22
-rw-r--r--tools/llvm-readobj/MachODumper.cpp38
-rw-r--r--tools/llvm-readobj/llvm-readobj.cpp4
-rw-r--r--tools/llvm-readobj/llvm-readobj.h1
5 files changed, 59 insertions, 23 deletions
diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp
index be4e76cc63..d600bc3fd2 100644
--- a/tools/llvm-readobj/COFFDumper.cpp
+++ b/tools/llvm-readobj/COFFDumper.cpp
@@ -680,11 +680,18 @@ void COFFDumper::printRelocation(section_iterator SecI,
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() {
diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp
index 9e111dd905..b0e2734ac9 100644
--- a/tools/llvm-readobj/ELFDumper.cpp
+++ b/tools/llvm-readobj/ELFDumper.cpp
@@ -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>
diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp
index a13593b448..69f1d63b12 100644
--- a/tools/llvm-readobj/MachODumper.cpp
+++ b/tools/llvm-readobj/MachODumper.cpp
@@ -341,18 +341,32 @@ void MachODumper::printRelocation(section_iterator SecI,
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() {
diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp
index 67c9a98f40..9d5cfcbd6a 100644
--- a/tools/llvm-readobj/llvm-readobj.cpp
+++ b/tools/llvm-readobj/llvm-readobj.cpp
@@ -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 {
diff --git a/tools/llvm-readobj/llvm-readobj.h b/tools/llvm-readobj/llvm-readobj.h
index be18268a7f..3f756106c9 100644
--- a/tools/llvm-readobj/llvm-readobj.h
+++ b/tools/llvm-readobj/llvm-readobj.h
@@ -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) \