[llvm-readelf] Make llvm-readelf more compatible with GNU readelf.

Summary:
This change adds a bunch of options that GNU readelf supports. There is one breaking change when invoked as `llvm-readobj`, and three breaking changes when invoked as `llvm-readelf`:
 - Add --all (implies --file-header, --program-headers, etc.)
 - [Breaking] -a is --all instead of --arm-attributes
 - Add --file-header as an alias for --file-headers
 - Replace --sections with --sections-headers, keeping --sections as an alias for it
 - Add --relocs as an alias for --relocations
 - Add --dynamic as an alias for --dynamic-table
 - Add --segments as an alias for --program-headers
 - Add --section-groups as an alias for --elf-section-groups
 - Add --dyn-syms as an alias for --dyn-symbols
 - Add --syms as an alias for --symbols
 - Add --histogram as an alias for --elf-hash-histogram
 - [Breaking] When invoked as `llvm-readelf`, -s is --symbols instead of --sections
 - [Breaking] When invoked as `llvm-readelf`, -t is no longer an alias for --symbols

Reviewers: MaskRay, phosek, mcgrathr, jhenderson

Reviewed By: MaskRay, jhenderson

Subscribers: sbc100, aheejin, edd, jhenderson, silvas, echristo, compnerd, kristina, javed.absar, kristof.beyls, llvm-commits, Bigcheese

Differential Revision: https://reviews.llvm.org/D54124

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346685 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jordan Rupprecht 2018-11-12 18:02:38 +00:00
parent cd74b07175
commit 6856bcc93c
12 changed files with 219 additions and 93 deletions

View File

@ -1,9 +1,9 @@
; RUN: llc < %s -mtriple=thumbv8m.base-eabi -mattr=+execute-only -filetype=obj %s -o - | \
; RUN: llvm-readelf -s | FileCheck %s
; RUN: llvm-readelf -S | FileCheck %s
; RUN: llc < %s -mtriple=thumbv8m.main-eabi -mattr=+execute-only -filetype=obj %s -o - | \
; RUN: llvm-readelf -s | FileCheck %s
; RUN: llvm-readelf -S | FileCheck %s
; RUN: llc < %s -mtriple=thumbv7m-eabi -mattr=+execute-only -filetype=obj %s -o - | \
; RUN: llvm-readelf -s | FileCheck %s
; RUN: llvm-readelf -S | FileCheck %s
; CHECK-NOT: {{.text[ ]+PROGBITS[ ]+[0-9]+ [0-9]+ [0-9]+ [0-9]+ AX[^p]}}
; CHECK: {{.text[ ]+PROGBITS[ ]+[0-9]+ [0-9]+ [0-9]+ [0-9]+ AXp}}

View File

@ -0,0 +1,15 @@
RUN: llvm-readobj -a %p/Inputs/trivial.obj.elf-i386 \
RUN: | FileCheck %s -check-prefix ALL
RUN: llvm-readobj --all %p/Inputs/trivial.obj.elf-i386 \
RUN: | FileCheck %s -check-prefix ALL
ALL: Format: ELF32-i386
ALL: Arch: i386
ALL: AddressSize: 32bit
ALL: LoadName:
ALL: ElfHeader {
ALL: Sections [
ALL: Relocations [
ALL: Symbols [
ALL: ProgramHeaders [
ALL: Notes [

View File

@ -0,0 +1,49 @@
# In llvm-readobj, -s is an alias for --sections.
RUN: llvm-readobj -s %p/Inputs/trivial.obj.elf-i386 \
RUN: | FileCheck %s -check-prefix SEC
RUN: llvm-readobj --sections %p/Inputs/trivial.obj.elf-i386 \
RUN: | FileCheck %s -check-prefix SEC
# In llvm-readelf, -s is an alias for --symbols.
RUN: llvm-readelf -s %p/Inputs/trivial.obj.elf-i386 \
RUN: | FileCheck %s -check-prefix SYM
RUN: llvm-readelf --symbols %p/Inputs/trivial.obj.elf-i386 \
RUN: | FileCheck %s -check-prefix SYM
SEC: Sections [
SEC-NEXT: Section {
SEC-NEXT: Index: 0
SEC-NEXT: Name: (0)
SEC-NEXT: Type: SHT_NULL (0x0)
SEC-NEXT: Flags [ (0x0)
SEC-NEXT: ]
SEC-NEXT: Address: 0x0
SEC-NEXT: Offset: 0x0
SEC-NEXT: Size: 0
SEC-NEXT: Link: 0
SEC-NEXT: Info: 0
SEC-NEXT: AddressAlignment: 0
SEC-NEXT: EntrySize: 0
SEC-NEXT: }
SEC-NEXT: Section {
SEC-NEXT: Index: 1
SEC-NEXT: Name: .text (5)
SEC-NEXT: Type: SHT_PROGBITS (0x1)
SEC-NEXT: Flags [ (0x6)
SEC-NEXT: SHF_ALLOC (0x2)
SEC-NEXT: SHF_EXECINSTR (0x4)
SEC-NEXT: ]
SEC-NEXT: Address: 0x0
SEC-NEXT: Offset: 0x40
SEC-NEXT: Size: 42
SEC-NEXT: Link: 0
SEC-NEXT: Info: 0
SEC-NEXT: AddressAlignment: 16
SEC-NEXT: EntrySize: 0
SEC-NEXT: }
SYM: Symbol table '.symtab' contains {{.*}} entries:
SYM-NEXT: Num: Value Size Type Bind Vis Ndx Name
SYM-NEXT: 0: {{.*}} NOTYPE {{.*}} UND
SYM-NEXT: 1: {{.*}} FILE {{.*}} trivial.ll
SYM-NEXT: 2: {{.*}} OBJECT {{.*}} .L.str

View File

@ -1,22 +1,29 @@
RUN: llvm-readobj -s %p/Inputs/trivial.obj.coff-i386 \
RUN: llvm-readobj --sections %p/Inputs/trivial.obj.coff-i386 \
RUN: | FileCheck %s -check-prefix COFF
RUN: llvm-readobj -s %p/Inputs/trivial.obj.elf-i386 \
RUN: llvm-readobj --sections %p/Inputs/trivial.obj.elf-i386 \
RUN: | FileCheck %s -check-prefix ELF
RUN: llvm-readobj -s %p/Inputs/trivial.obj.elf-mipsel \
RUN: llvm-readobj --sections %p/Inputs/trivial.obj.elf-mipsel \
RUN: | FileCheck %s -check-prefix ELF-MIPSEL
RUN: llvm-readobj -s %p/Inputs/trivial.obj.macho-i386 \
RUN: llvm-readobj --sections %p/Inputs/trivial.obj.macho-i386 \
RUN: | FileCheck %s -check-prefix MACHO-I386
RUN: llvm-readobj -s %p/Inputs/trivial.obj.macho-x86-64 \
RUN: llvm-readobj --sections %p/Inputs/trivial.obj.macho-x86-64 \
RUN: | FileCheck %s -check-prefix MACHO-X86-64
RUN: llvm-readobj -s %p/Inputs/trivial.obj.macho-ppc \
RUN: llvm-readobj --sections %p/Inputs/trivial.obj.macho-ppc \
RUN: | FileCheck %s -check-prefix MACHO-PPC
RUN: llvm-readobj -s %p/Inputs/trivial.obj.macho-ppc64 \
RUN: llvm-readobj --sections %p/Inputs/trivial.obj.macho-ppc64 \
RUN: | FileCheck %s -check-prefix MACHO-PPC64
RUN: llvm-readobj -s %p/Inputs/trivial.obj.macho-arm \
RUN: llvm-readobj --sections %p/Inputs/trivial.obj.macho-arm \
RUN: | FileCheck %s -check-prefix MACHO-ARM
RUN: llvm-readobj -s %p/Inputs/trivial.obj.wasm \
RUN: llvm-readobj --sections %p/Inputs/trivial.obj.wasm \
RUN: | FileCheck %s -check-prefix WASM
# Check flag aliases produce identical output.
RUN: llvm-readobj --sections %p/Inputs/trivial.obj.elf-i386 > %t.sections
RUN: llvm-readobj -S %p/Inputs/trivial.obj.elf-i386 > %t.uppers
RUN: cmp %t.sections %t.uppers
RUN: llvm-readobj -s %p/Inputs/trivial.obj.elf-i386 > %t.lowers
RUN: cmp %t.sections %t.lowers
COFF: Sections [
COFF-NEXT: Section {
COFF-NEXT: Number: 1

View File

@ -1,10 +1,19 @@
RUN: llvm-readobj -t %p/Inputs/trivial.obj.coff-i386 \
RUN: llvm-readobj --symbols %p/Inputs/trivial.obj.coff-i386 \
RUN: | FileCheck %s -check-prefix COFF
RUN: llvm-readobj -t %p/Inputs/trivial.obj.elf-i386 \
RUN: llvm-readobj --symbols %p/Inputs/trivial.obj.elf-i386 \
RUN: | FileCheck %s -check-prefix ELF
RUN: llvm-readobj -t %p/Inputs/trivial.obj.wasm \
RUN: llvm-readobj --symbols %p/Inputs/trivial.obj.wasm \
RUN: | FileCheck %s -check-prefix WASM
# Check flag aliases produce identical output.
RUN: llvm-readobj --symbols %p/Inputs/trivial.obj.elf-i386 > %t.symbols
RUN: llvm-readobj --syms %p/Inputs/trivial.obj.elf-i386 > %t.syms
RUN: cmp %t.symbols %t.syms
RUN: llvm-readobj -t %p/Inputs/trivial.obj.elf-i386 > %t.t
RUN: cmp %t.symbols %t.t
RUN: llvm-readelf -s -elf-output-style LLVM %p/Inputs/trivial.obj.elf-i386 > %t.lowers
RUN: cmp %t.symbols %t.lowers
COFF: Symbols [
COFF-NEXT: Symbol {
COFF-NEXT: Name: @comp.id

View File

@ -79,7 +79,7 @@ public:
: ObjDumper(Writer), Obj(Obj), Writer(Writer), Types(100) {}
void printFileHeaders() override;
void printSections() override;
void printSectionHeaders() override;
void printRelocations() override;
void printSymbols() override;
void printDynamicSymbols() override;
@ -959,7 +959,7 @@ void COFFDumper::printCodeViewSymbolSection(StringRef SectionName,
StringMap<StringRef> FunctionLineTables;
ListScope D(W, "CodeViewDebugInfo");
// Print the section to allow correlation with printSections.
// Print the section to allow correlation with printSectionHeaders.
W.printNumber("Section", SectionName, Obj->getSectionID(Section));
uint32_t Magic;
@ -1279,7 +1279,7 @@ void COFFDumper::printCodeViewTypeSection(StringRef SectionName,
W.flush();
}
void COFFDumper::printSections() {
void COFFDumper::printSectionHeaders() {
ListScope SectionsD(W, "Sections");
int SectionNumber = 0;
for (const SectionRef &Sec : Obj->sections()) {

View File

@ -143,7 +143,7 @@ public:
ELFDumper(const ELFFile<ELFT> *Obj, ScopedPrinter &Writer);
void printFileHeaders() override;
void printSections() override;
void printSectionHeaders() override;
void printRelocations() override;
void printDynamicRelocations() override;
void printSymbols() override;
@ -324,7 +324,7 @@ public:
virtual void printFileHeaders(const ELFFile<ELFT> *Obj) = 0;
virtual void printGroupSections(const ELFFile<ELFT> *Obj) = 0;
virtual void printRelocations(const ELFFile<ELFT> *Obj) = 0;
virtual void printSections(const ELFFile<ELFT> *Obj) = 0;
virtual void printSectionHeaders(const ELFFile<ELFT> *Obj) = 0;
virtual void printSymbols(const ELFFile<ELFT> *Obj) = 0;
virtual void printDynamicSymbols(const ELFFile<ELFT> *Obj) = 0;
virtual void printDynamicRelocations(const ELFFile<ELFT> *Obj) = 0;
@ -359,7 +359,7 @@ public:
void printFileHeaders(const ELFO *Obj) override;
void printGroupSections(const ELFFile<ELFT> *Obj) override;
void printRelocations(const ELFO *Obj) override;
void printSections(const ELFO *Obj) override;
void printSectionHeaders(const ELFO *Obj) override;
void printSymbols(const ELFO *Obj) override;
void printDynamicSymbols(const ELFO *Obj) override;
void printDynamicRelocations(const ELFO *Obj) override;
@ -452,7 +452,7 @@ public:
void printGroupSections(const ELFFile<ELFT> *Obj) override;
void printRelocations(const ELFO *Obj) override;
void printRelocations(const Elf_Shdr *Sec, const ELFO *Obj);
void printSections(const ELFO *Obj) override;
void printSectionHeaders(const ELFO *Obj) override;
void printSymbols(const ELFO *Obj) override;
void printDynamicSymbols(const ELFO *Obj) override;
void printDynamicRelocations(const ELFO *Obj) override;
@ -1592,9 +1592,8 @@ void ELFDumper<ELFT>::printFileHeaders() {
ELFDumperStyle->printFileHeaders(Obj);
}
template<class ELFT>
void ELFDumper<ELFT>::printSections() {
ELFDumperStyle->printSections(Obj);
template <class ELFT> void ELFDumper<ELFT>::printSectionHeaders() {
ELFDumperStyle->printSectionHeaders(Obj);
}
template<class ELFT>
@ -2920,7 +2919,8 @@ std::string getSectionTypeString(unsigned Arch, unsigned Type) {
return "";
}
template <class ELFT> void GNUStyle<ELFT>::printSections(const ELFO *Obj) {
template <class ELFT>
void GNUStyle<ELFT>::printSectionHeaders(const ELFO *Obj) {
size_t SectionIndex = 0;
std::string Number, Type, Size, Address, Offset, Flags, Link, Info, EntrySize,
Alignment;
@ -4213,7 +4213,8 @@ void LLVMStyle<ELFT>::printRelocation(const ELFO *Obj, Elf_Rela Rel,
}
}
template <class ELFT> void LLVMStyle<ELFT>::printSections(const ELFO *Obj) {
template <class ELFT>
void LLVMStyle<ELFT>::printSectionHeaders(const ELFO *Obj) {
ListScope SectionsD(W, "Sections");
int SectionIndex = -1;

View File

@ -32,7 +32,7 @@ public:
: ObjDumper(Writer), Obj(Obj) {}
void printFileHeaders() override;
void printSections() override;
void printSectionHeaders() override;
void printRelocations() override;
void printSymbols() override;
void printDynamicSymbols() override;
@ -59,7 +59,7 @@ private:
void printRelocation(const MachOObjectFile *Obj, const RelocationRef &Reloc);
void printSections(const MachOObjectFile *Obj);
void printSectionHeaders(const MachOObjectFile *Obj);
const MachOObjectFile *Obj;
};
@ -428,11 +428,9 @@ void MachODumper::printFileHeaders(const MachHeader &Header) {
W.printFlags("Flags", Header.flags, makeArrayRef(MachOHeaderFlags));
}
void MachODumper::printSections() {
return printSections(Obj);
}
void MachODumper::printSectionHeaders() { return printSectionHeaders(Obj); }
void MachODumper::printSections(const MachOObjectFile *Obj) {
void MachODumper::printSectionHeaders(const MachOObjectFile *Obj) {
ListScope Group(W, "Sections");
int SectionIndex = -1;

View File

@ -33,7 +33,7 @@ public:
virtual ~ObjDumper();
virtual void printFileHeaders() = 0;
virtual void printSections() = 0;
virtual void printSectionHeaders() = 0;
virtual void printRelocations() = 0;
virtual void printSymbols() = 0;
virtual void printDynamicSymbols() = 0;

View File

@ -48,7 +48,7 @@ public:
: ObjDumper(Writer), Obj(Obj) {}
void printFileHeaders() override;
void printSections() override;
void printSectionHeaders() override;
void printRelocations() override;
void printSymbols() override;
void printDynamicSymbols() override { llvm_unreachable("unimplemented"); }
@ -148,7 +148,7 @@ void WasmDumper::printSymbols() {
printSymbol(Symbol);
}
void WasmDumper::printSections() {
void WasmDumper::printSectionHeaders() {
ListScope Group(W, "Sections");
for (const SectionRef &Section : Obj->sections()) {
const WasmSection &WasmSec = Obj->getWasmSection(Section);

View File

@ -48,30 +48,41 @@ namespace opts {
cl::desc("<input object files>"),
cl::ZeroOrMore);
// -all, -a
cl::opt<bool>
All("all",
cl::desc("Equivalent to setting: --file-headers, --program-headers, "
"--section-headers, --symbols, --relocations, "
"--dynamic-table, --notes, --version-info, --unwind, "
"--section-groups and --elf-hash-histogram."));
cl::alias AllShort("a", cl::desc("Alias for --all"), cl::aliasopt(All));
// -wide, -W
cl::opt<bool> WideOutput("wide",
cl::desc("Ignored for compatibility with GNU readelf"));
cl::opt<bool>
WideOutput("wide", cl::desc("Ignored for compatibility with GNU readelf"),
cl::Hidden);
cl::alias WideOutputShort("W",
cl::desc("Alias for --wide"),
cl::aliasopt(WideOutput));
// -file-headers, -h
// -file-headers, -file-header, -h
cl::opt<bool> FileHeaders("file-headers",
cl::desc("Display file headers "));
cl::alias FileHeadersShort("h",
cl::desc("Alias for --file-headers"),
cl::aliasopt(FileHeaders));
cl::alias FileHeadersShort("h", cl::desc("Alias for --file-headers"),
cl::aliasopt(FileHeaders), cl::NotHidden);
cl::alias FileHeadersSingular("file-header",
cl::desc("Alias for --file-headers"),
cl::aliasopt(FileHeaders));
// -sections, -s, -S
// Note: In GNU readelf, -s means --symbols!
cl::opt<bool> Sections("sections",
cl::desc("Display all sections."));
cl::alias SectionsShort("s",
cl::desc("Alias for --sections"),
cl::aliasopt(Sections));
cl::alias SectionsShortUpper("S",
cl::desc("Alias for --sections"),
cl::aliasopt(Sections));
// -section-headers, -sections, -S
// Also -s in llvm-readobj mode.
cl::opt<bool> SectionHeaders("section-headers",
cl::desc("Display all section headers."));
cl::alias SectionsShortUpper("S", cl::desc("Alias for --section-headers"),
cl::aliasopt(SectionHeaders), cl::NotHidden);
cl::alias SectionHeadersAlias("sections",
cl::desc("Alias for --section-headers"),
cl::aliasopt(SectionHeaders), cl::NotHidden);
// -section-relocations, -sr
cl::opt<bool> SectionRelocations("section-relocations",
@ -94,12 +105,13 @@ namespace opts {
cl::desc("Alias for --section-data"),
cl::aliasopt(SectionData));
// -relocations, -r
// -relocations, -relocs, -r
cl::opt<bool> Relocations("relocations",
cl::desc("Display the relocation entries in the file"));
cl::alias RelocationsShort("r",
cl::desc("Alias for --relocations"),
cl::aliasopt(Relocations));
cl::alias RelocationsShort("r", cl::desc("Alias for --relocations"),
cl::aliasopt(Relocations), cl::NotHidden);
cl::alias RelocationsGNU("relocs", cl::desc("Alias for --relocations"),
cl::aliasopt(Relocations));
// -notes, -n
cl::opt<bool> Notes("notes", cl::desc("Display the ELF notes in the file"));
@ -109,19 +121,21 @@ namespace opts {
cl::opt<bool> DynRelocs("dyn-relocations",
cl::desc("Display the dynamic relocation entries in the file"));
// -symbols, -t
// -symbols
// Also -s in llvm-readelf mode, or -t in llvm-readobj mode.
cl::opt<bool> Symbols("symbols",
cl::desc("Display the symbol table"));
cl::alias SymbolsShort("t",
cl::desc("Alias for --symbols"),
cl::aliasopt(Symbols));
cl::alias SymbolsGNU("syms", cl::desc("Alias for --symbols"),
cl::aliasopt(Symbols));
// -dyn-symbols, -dt
// -dyn-symbols, -dyn-syms, -dt
cl::opt<bool> DynamicSymbols("dyn-symbols",
cl::desc("Display the dynamic symbol table"));
cl::alias DynamicSymbolsShort("dt",
cl::desc("Alias for --dyn-symbols"),
cl::aliasopt(DynamicSymbols));
cl::alias DynSymsGNU("dyn-syms", cl::desc("Alias for --dyn-symbols"),
cl::aliasopt(DynamicSymbols));
// -unwind, -u
cl::opt<bool> UnwindInfo("unwind",
@ -130,29 +144,33 @@ namespace opts {
cl::desc("Alias for --unwind"),
cl::aliasopt(UnwindInfo));
// -dynamic-table
// -dynamic-table, -dynamic, -d
cl::opt<bool> DynamicTable("dynamic-table",
cl::desc("Display the ELF .dynamic section table"));
cl::alias DynamicTableShort("d", cl::desc("Alias for --dynamic-table"),
cl::aliasopt(DynamicTable), cl::NotHidden);
cl::alias DynamicTableAlias("dynamic", cl::desc("Alias for --dynamic-table"),
cl::aliasopt(DynamicTable));
// -needed-libs
cl::opt<bool> NeededLibraries("needed-libs",
cl::desc("Display the needed libraries"));
// -program-headers
// -program-headers, -segments, -l
cl::opt<bool> ProgramHeaders("program-headers",
cl::desc("Display ELF program headers"));
cl::alias ProgramHeadersShort("l", cl::desc("Alias for --program-headers"),
cl::aliasopt(ProgramHeaders));
cl::aliasopt(ProgramHeaders), cl::NotHidden);
cl::alias SegmentsAlias("segments", cl::desc("Alias for --program-headers"),
cl::aliasopt(ProgramHeaders));
// -string-dump
// -string-dump, -p
cl::list<std::string> StringDump("string-dump", cl::desc("<number|name>"),
cl::ZeroOrMore);
cl::alias StringDumpShort("p", cl::desc("Alias for --string-dump"),
cl::aliasopt(StringDump));
// -hex-dump
// -hex-dump, -x
cl::list<std::string> HexDump("hex-dump", cl::desc("<number|name>"),
cl::ZeroOrMore);
cl::alias HexDumpShort("x", cl::desc("Alias for --hex-dump"),
@ -188,11 +206,9 @@ namespace opts {
"codeview-subsection-bytes",
cl::desc("Dump raw contents of codeview debug sections and records"));
// -arm-attributes, -a
// -arm-attributes
cl::opt<bool> ARMAttributes("arm-attributes",
cl::desc("Display the ARM attributes section"));
cl::alias ARMAttributesShort("a", cl::desc("Alias for --arm-attributes"),
cl::aliasopt(ARMAttributes));
// -mips-plt-got
cl::opt<bool>
@ -283,28 +299,40 @@ namespace opts {
PrintStackMap("stackmap",
cl::desc("Display contents of stackmap section"));
// -version-info
// -version-info, -V
cl::opt<bool>
VersionInfo("version-info",
cl::desc("Display ELF version sections (if present)"));
cl::alias VersionInfoShort("V", cl::desc("Alias for -version-info"),
cl::aliasopt(VersionInfo));
// -elf-section-groups, -section-groups, -g
cl::opt<bool> SectionGroups("elf-section-groups",
cl::desc("Display ELF section group contents"));
cl::alias SectionGroupsAlias("section-groups",
cl::desc("Alias for -elf-sections-groups"),
cl::aliasopt(SectionGroups));
cl::alias SectionGroupsShort("g", cl::desc("Alias for -elf-sections-groups"),
cl::aliasopt(SectionGroups));
// -elf-hash-histogram, -histogram, -I
cl::opt<bool> HashHistogram(
"elf-hash-histogram",
cl::desc("Display bucket list histogram for hash sections"));
cl::alias HashHistogramShort("I", cl::desc("Alias for -elf-hash-histogram"),
cl::aliasopt(HashHistogram));
cl::alias HistogramAlias("histogram",
cl::desc("Alias for --elf-hash-histogram"),
cl::aliasopt(HashHistogram));
// -elf-cg-profile
cl::opt<bool> CGProfile("elf-cg-profile", cl::desc("Display callgraph profile section"));
// -addrsig
cl::opt<bool> Addrsig("addrsig",
cl::desc("Display address-significance table"));
// -elf-output-style
cl::opt<OutputStyleTy>
Output("elf-output-style", cl::desc("Specify ELF dump style"),
cl::values(clEnumVal(LLVM, "LLVM default style"),
@ -418,8 +446,8 @@ static void dumpObject(const ObjectFile *Obj, ScopedPrinter &Writer) {
if (opts::FileHeaders)
Dumper->printFileHeaders();
if (opts::Sections)
Dumper->printSections();
if (opts::SectionHeaders)
Dumper->printSectionHeaders();
if (opts::Relocations)
Dumper->printRelocations();
if (opts::DynRelocs)
@ -588,28 +616,56 @@ static void dumpInput(StringRef File) {
reportError(File, readobj_error::unrecognized_file_format);
}
/// Registers aliases that should only be allowed by readobj.
static void registerReadobjAliases() {
// -s has meant --sections for a very long time in llvm-readobj despite
// meaning --symbols in readelf.
static cl::alias SectionsShort("s", cl::desc("Alias for --section-headers"),
cl::aliasopt(opts::SectionHeaders),
cl::NotHidden);
// Only register -t in llvm-readobj, as readelf reserves it for
// --section-details (not implemented yet).
static cl::alias SymbolsShort("t", cl::desc("Alias for --symbols"),
cl::aliasopt(opts::Symbols), cl::NotHidden);
}
/// Registers aliases that should only be allowed by readelf.
static void registerReadelfAliases() {
// -s is here because for readobj it means --sections.
static cl::alias SymbolsShort("s", cl::desc("Alias for --symbols"),
cl::aliasopt(opts::Symbols), cl::NotHidden);
}
int main(int argc, const char *argv[]) {
InitLLVM X(argc, argv);
// Register the target printer for --version.
cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
// Make some commonly used short options visibile in -help.
opts::DynamicTableShort.setHiddenFlag(cl::NotHidden);
opts::FileHeadersShort.setHiddenFlag(cl::NotHidden);
opts::ProgramHeadersShort.setHiddenFlag(cl::NotHidden);
opts::RelocationsShort.setHiddenFlag(cl::NotHidden);
opts::SectionsShort.setHiddenFlag(cl::NotHidden);
opts::SectionsShortUpper.setHiddenFlag(cl::NotHidden);
opts::SymbolsShort.setHiddenFlag(cl::NotHidden);
opts::WideOutput.setHiddenFlag(cl::Hidden);
if (sys::path::stem(argv[0]).find("readelf") != StringRef::npos)
if (sys::path::stem(argv[0]).contains("readelf")) {
opts::Output = opts::GNU;
registerReadelfAliases();
} else {
registerReadobjAliases();
}
cl::ParseCommandLineOptions(argc, argv, "LLVM Object Reader\n");
if (opts::All) {
opts::FileHeaders = true;
opts::ProgramHeaders = true;
opts::SectionHeaders = true;
opts::Symbols = true;
opts::Relocations = true;
opts::DynamicTable = true;
opts::Notes = true;
opts::VersionInfo = true;
opts::UnwindInfo = true;
opts::SectionGroups = true;
opts::HashHistogram = true;
}
// Default to stdin if no filename is specified.
if (opts::InputFilenames.size() == 0)
opts::InputFilenames.push_back("-");

View File

@ -49,22 +49,13 @@ namespace llvm {
} // namespace llvm
namespace opts {
extern llvm::cl::list<std::string> InputFilenames;
extern llvm::cl::opt<bool> FileHeaders;
extern llvm::cl::opt<bool> Sections;
extern llvm::cl::opt<bool> SectionRelocations;
extern llvm::cl::opt<bool> SectionSymbols;
extern llvm::cl::opt<bool> SectionData;
extern llvm::cl::opt<bool> Relocations;
extern llvm::cl::opt<bool> Symbols;
extern llvm::cl::opt<bool> DynamicSymbols;
extern llvm::cl::opt<bool> UnwindInfo;
extern llvm::cl::opt<bool> ExpandRelocs;
extern llvm::cl::opt<bool> RawRelr;
extern llvm::cl::opt<bool> CodeView;
extern llvm::cl::opt<bool> CodeViewSubsectionBytes;
extern llvm::cl::opt<bool> ARMAttributes;
extern llvm::cl::opt<bool> MipsPLTGOT;
enum OutputStyleTy { LLVM, GNU };
extern llvm::cl::opt<OutputStyleTy> Output;
} // namespace opts