llvm.org GIT mirror llvm / 1c8dfa5
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 Nico Rieck 7 years ago
6 changed file(s) with 64 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
6262
6363 Display unwind information.
6464
65 .. option:: -expand-relocs
66
67 When used with ``-relocations``, display each relocation in an expanded
68 multi-line format.
69
6570 .. option:: -dynamic-table
6671
6772 Display the ELF .dynamic section table (only for ELF object files).
679679 if (error(Symbol.getName(SymbolName))) return;
680680 if (error(SecI->getContents(Contents))) return;
681681
682 raw_ostream& OS = W.startLine();
683 OS << W.hex(Offset)
684 << " " << RelocName
685 << " " << (SymbolName.size() > 0 ? SymbolName : "-")
686 << "\n";
682 if (opts::ExpandRelocs) {
683 DictScope Group(W, "Relocation");
684 W.printHex("Offset", Offset);
685 W.printNumber("Type", RelocName, RelocType);
686 W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
687 } else {
688 raw_ostream& OS = W.startLine();
689 OS << W.hex(Offset)
690 << " " << RelocName
691 << " " << (SymbolName.size() > 0 ? SymbolName : "-")
692 << "\n";
693 }
687694 }
688695
689696 void COFFDumper::printSymbols() {
548548 void ELFDumper::printRelocation(section_iterator Sec,
549549 relocation_iterator RelI) {
550550 uint64_t Offset;
551 uint64_t RelocType;
551552 SmallString<32> RelocName;
552553 int64_t Info;
553554 StringRef SymbolName;
554555 SymbolRef Symbol;
555556 if (error(RelI->getOffset(Offset))) return;
557 if (error(RelI->getType(RelocType))) return;
556558 if (error(RelI->getTypeName(RelocName))) return;
557559 if (error(RelI->getAdditionalInfo(Info))) return;
558560 if (error(RelI->getSymbol(Symbol))) return;
559561 if (error(Symbol.getName(SymbolName))) return;
560562
561 raw_ostream& OS = W.startLine();
562 OS << W.hex(Offset)
563 << " " << RelocName
564 << " " << (SymbolName.size() > 0 ? SymbolName : "-")
565 << " " << W.hex(Info)
566 << "\n";
563 if (opts::ExpandRelocs) {
564 DictScope Group(W, "Relocation");
565 W.printHex("Offset", Offset);
566 W.printNumber("Type", RelocName, RelocType);
567 W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
568 W.printHex("Info", Info);
569 } else {
570 raw_ostream& OS = W.startLine();
571 OS << W.hex(Offset)
572 << " " << RelocName
573 << " " << (SymbolName.size() > 0 ? SymbolName : "-")
574 << " " << W.hex(Info)
575 << "\n";
576 }
567577 }
568578
569579 template
340340 const MachOObjectFileBase::RelocationEntry *RE = Obj->getRelocation(DR);
341341 bool IsScattered = Obj->isScattered(RE);
342342
343 raw_ostream& OS = W.startLine();
344 OS << W.hex(Offset)
345 << " " << Obj->isPCRel(RE)
346 << " " << Obj->getLength(RE);
347 if (IsScattered)
348 OS << " n/a";
349 else
350 OS << " " << RE->getExternal();
351 OS << " " << RelocName
352 << " " << IsScattered
353 << " " << (SymbolName.size() > 0 ? SymbolName : "-")
354 << "\n";
343 if (opts::ExpandRelocs) {
344 DictScope Group(W, "Relocation");
345 W.printHex("Offset", Offset);
346 W.printNumber("PCRel", Obj->isPCRel(RE));
347 W.printNumber("Length", Obj->getLength(RE));
348 if (IsScattered)
349 W.printString("Extern", StringRef("N/A"));
350 else
351 W.printNumber("Extern", RE->getExternal());
352 W.printNumber("Type", RelocName, RE->getType());
353 W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
354 W.printNumber("Scattered", IsScattered);
355 } else {
356 raw_ostream& OS = W.startLine();
357 OS << W.hex(Offset)
358 << " " << Obj->isPCRel(RE)
359 << " " << Obj->getLength(RE);
360 if (IsScattered)
361 OS << " n/a";
362 else
363 OS << " " << RE->getExternal();
364 OS << " " << RelocName
365 << " " << IsScattered
366 << " " << (SymbolName.size() > 0 ? SymbolName : "-")
367 << "\n";
368 }
355369 }
356370
357371 void MachODumper::printSymbols() {
119119 // -needed-libs
120120 cl::opt NeededLibraries("needed-libs",
121121 cl::desc("Display the needed libraries"));
122
123 // -expand-relocs
124 cl::opt ExpandRelocs("expand-relocs",
125 cl::desc("Expand each shown relocation to multiple lines"));
122126 } // namespace opts
123127
124128 namespace llvm {
3636 extern llvm::cl::opt Symbols;
3737 extern llvm::cl::opt DynamicSymbols;
3838 extern llvm::cl::opt UnwindInfo;
39 extern llvm::cl::opt ExpandRelocs;
3940 } // namespace opts
4041
4142 #define LLVM_READOBJ_ENUM_ENT(ns, enum) \