Index: llvm/trunk/test/MC/ARM/elf-execute-only-section.ll =================================================================== --- llvm/trunk/test/MC/ARM/elf-execute-only-section.ll +++ llvm/trunk/test/MC/ARM/elf-execute-only-section.ll @@ -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}} Index: llvm/trunk/test/tools/llvm-readobj/all.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/all.test +++ llvm/trunk/test/tools/llvm-readobj/all.test @@ -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 [ Index: llvm/trunk/test/tools/llvm-readobj/readelf-s-alias.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/readelf-s-alias.test +++ llvm/trunk/test/tools/llvm-readobj/readelf-s-alias.test @@ -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 Index: llvm/trunk/test/tools/llvm-readobj/sections.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/sections.test +++ llvm/trunk/test/tools/llvm-readobj/sections.test @@ -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 Index: llvm/trunk/test/tools/llvm-readobj/symbols.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/symbols.test +++ llvm/trunk/test/tools/llvm-readobj/symbols.test @@ -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 Index: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp +++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp @@ -79,7 +79,7 @@ : 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 @@ StringMap 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 @@ W.flush(); } -void COFFDumper::printSections() { +void COFFDumper::printSectionHeaders() { ListScope SectionsD(W, "Sections"); int SectionNumber = 0; for (const SectionRef &Sec : Obj->sections()) { Index: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp +++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp @@ -143,7 +143,7 @@ ELFDumper(const ELFFile *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 @@ virtual void printFileHeaders(const ELFFile *Obj) = 0; virtual void printGroupSections(const ELFFile *Obj) = 0; virtual void printRelocations(const ELFFile *Obj) = 0; - virtual void printSections(const ELFFile *Obj) = 0; + virtual void printSectionHeaders(const ELFFile *Obj) = 0; virtual void printSymbols(const ELFFile *Obj) = 0; virtual void printDynamicSymbols(const ELFFile *Obj) = 0; virtual void printDynamicRelocations(const ELFFile *Obj) = 0; @@ -359,7 +359,7 @@ void printFileHeaders(const ELFO *Obj) override; void printGroupSections(const ELFFile *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 @@ void printGroupSections(const ELFFile *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 @@ ELFDumperStyle->printFileHeaders(Obj); } -template -void ELFDumper::printSections() { - ELFDumperStyle->printSections(Obj); +template void ELFDumper::printSectionHeaders() { + ELFDumperStyle->printSectionHeaders(Obj); } template @@ -2920,7 +2919,8 @@ return ""; } -template void GNUStyle::printSections(const ELFO *Obj) { +template +void GNUStyle::printSectionHeaders(const ELFO *Obj) { size_t SectionIndex = 0; std::string Number, Type, Size, Address, Offset, Flags, Link, Info, EntrySize, Alignment; @@ -4213,7 +4213,8 @@ } } -template void LLVMStyle::printSections(const ELFO *Obj) { +template +void LLVMStyle::printSectionHeaders(const ELFO *Obj) { ListScope SectionsD(W, "Sections"); int SectionIndex = -1; Index: llvm/trunk/tools/llvm-readobj/MachODumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/MachODumper.cpp +++ llvm/trunk/tools/llvm-readobj/MachODumper.cpp @@ -32,7 +32,7 @@ : 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 @@ 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 @@ 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; Index: llvm/trunk/tools/llvm-readobj/ObjDumper.h =================================================================== --- llvm/trunk/tools/llvm-readobj/ObjDumper.h +++ llvm/trunk/tools/llvm-readobj/ObjDumper.h @@ -33,7 +33,7 @@ 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; Index: llvm/trunk/tools/llvm-readobj/WasmDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/WasmDumper.cpp +++ llvm/trunk/tools/llvm-readobj/WasmDumper.cpp @@ -48,7 +48,7 @@ : 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 @@ printSymbol(Symbol); } -void WasmDumper::printSections() { +void WasmDumper::printSectionHeaders() { ListScope Group(W, "Sections"); for (const SectionRef &Section : Obj->sections()) { const WasmSection &WasmSec = Obj->getWasmSection(Section); Index: llvm/trunk/tools/llvm-readobj/llvm-readobj.h =================================================================== --- llvm/trunk/tools/llvm-readobj/llvm-readobj.h +++ llvm/trunk/tools/llvm-readobj/llvm-readobj.h @@ -49,22 +49,13 @@ } // namespace llvm namespace opts { - extern llvm::cl::list InputFilenames; - extern llvm::cl::opt FileHeaders; - extern llvm::cl::opt Sections; extern llvm::cl::opt SectionRelocations; extern llvm::cl::opt SectionSymbols; extern llvm::cl::opt SectionData; - extern llvm::cl::opt Relocations; - extern llvm::cl::opt Symbols; extern llvm::cl::opt DynamicSymbols; - extern llvm::cl::opt UnwindInfo; extern llvm::cl::opt ExpandRelocs; extern llvm::cl::opt RawRelr; - extern llvm::cl::opt CodeView; extern llvm::cl::opt CodeViewSubsectionBytes; - extern llvm::cl::opt ARMAttributes; - extern llvm::cl::opt MipsPLTGOT; enum OutputStyleTy { LLVM, GNU }; extern llvm::cl::opt Output; } // namespace opts Index: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp +++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp @@ -48,30 +48,41 @@ cl::desc(""), cl::ZeroOrMore); + // -all, -a + cl::opt + 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 WideOutput("wide", - cl::desc("Ignored for compatibility with GNU readelf")); + cl::opt + 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 FileHeaders("file-headers", cl::desc("Display file headers ")); - cl::alias FileHeadersShort("h", - cl::desc("Alias for --file-headers"), - cl::aliasopt(FileHeaders)); - - // -sections, -s, -S - // Note: In GNU readelf, -s means --symbols! - cl::opt 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)); + 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)); + + // -section-headers, -sections, -S + // Also -s in llvm-readobj mode. + cl::opt 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 SectionRelocations("section-relocations", @@ -94,12 +105,13 @@ cl::desc("Alias for --section-data"), cl::aliasopt(SectionData)); - // -relocations, -r + // -relocations, -relocs, -r cl::opt 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 Notes("notes", cl::desc("Display the ELF notes in the file")); @@ -109,19 +121,21 @@ cl::opt 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 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 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 UnwindInfo("unwind", @@ -130,29 +144,33 @@ cl::desc("Alias for --unwind"), cl::aliasopt(UnwindInfo)); - // -dynamic-table + // -dynamic-table, -dynamic, -d cl::opt 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 NeededLibraries("needed-libs", cl::desc("Display the needed libraries")); - // -program-headers + // -program-headers, -segments, -l cl::opt 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 StringDump("string-dump", cl::desc(""), cl::ZeroOrMore); cl::alias StringDumpShort("p", cl::desc("Alias for --string-dump"), cl::aliasopt(StringDump)); - // -hex-dump + // -hex-dump, -x cl::list HexDump("hex-dump", cl::desc(""), cl::ZeroOrMore); cl::alias HexDumpShort("x", cl::desc("Alias for --hex-dump"), @@ -188,11 +206,9 @@ "codeview-subsection-bytes", cl::desc("Dump raw contents of codeview debug sections and records")); - // -arm-attributes, -a + // -arm-attributes cl::opt 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 @@ -283,28 +299,40 @@ PrintStackMap("stackmap", cl::desc("Display contents of stackmap section")); - // -version-info + // -version-info, -V cl::opt 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 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 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 CGProfile("elf-cg-profile", cl::desc("Display callgraph profile section")); + // -addrsig cl::opt Addrsig("addrsig", cl::desc("Display address-significance table")); + // -elf-output-style cl::opt Output("elf-output-style", cl::desc("Specify ELF dump style"), cl::values(clEnumVal(LLVM, "LLVM default style"), @@ -418,8 +446,8 @@ 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 @@ 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("-");