Index: test/MC/ARM/elf-execute-only-section.ll =================================================================== --- test/MC/ARM/elf-execute-only-section.ll +++ 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: test/tools/llvm-readobj/all.test =================================================================== --- /dev/null +++ test/tools/llvm-readobj/all.test @@ -0,0 +1,14 @@ +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 [ Index: test/tools/llvm-readobj/readelf-s-alias.test =================================================================== --- /dev/null +++ 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: test/tools/llvm-readobj/sections.test =================================================================== --- test/tools/llvm-readobj/sections.test +++ test/tools/llvm-readobj/sections.test @@ -17,6 +17,12 @@ RUN: llvm-readobj -s %p/Inputs/trivial.obj.wasm \ RUN: | FileCheck %s -check-prefix WASM +# Check flag aliases. +RUN: llvm-readobj -S %p/Inputs/trivial.obj.elf-i386 \ +RUN: | FileCheck %s -check-prefix ELF +RUN: llvm-readobj --sections %p/Inputs/trivial.obj.elf-i386 \ +RUN: | FileCheck %s -check-prefix ELF + COFF: Sections [ COFF-NEXT: Section { COFF-NEXT: Number: 1 Index: tools/llvm-readobj/llvm-readobj.cpp =================================================================== --- tools/llvm-readobj/llvm-readobj.cpp +++ tools/llvm-readobj/llvm-readobj.cpp @@ -48,6 +48,15 @@ cl::desc(""), cl::ZeroOrMore); + // -all, -a + cl::opt + All("all", + cl::desc( + "Equivalent to setting: --file-headers, --program-headers, " + "--sections, --symbols, --relocations, --dynamic-table, --notes, " + "--version-info --unwind, --section-groups and --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")); @@ -62,13 +71,9 @@ cl::desc("Alias for --file-headers"), cl::aliasopt(FileHeaders)); - // -sections, -s, -S - // Note: In GNU readelf, -s means --symbols! + // -sections, -S 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)); @@ -109,12 +114,9 @@ cl::opt DynRelocs("dyn-relocations", cl::desc("Display the dynamic relocation entries in the file")); - // -symbols, -t + // -symbols cl::opt Symbols("symbols", cl::desc("Display the symbol table")); - cl::alias SymbolsShort("t", - cl::desc("Alias for --symbols"), - cl::aliasopt(Symbols)); // -dyn-symbols, -dt cl::opt DynamicSymbols("dyn-symbols", @@ -188,11 +190,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 @@ -292,6 +292,9 @@ 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)); cl::opt HashHistogram( @@ -588,6 +591,46 @@ 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 something else in readelf. + static cl::alias SectionsShort("s", cl::desc("Alias for --sections"), + cl::aliasopt(opts::Sections)); + SectionsShort.setHiddenFlag(cl::NotHidden); + + // Only register -t in llvm-readobj, and readelf reserves it for + // --section-details (not implemented yet) + static cl::alias SymbolsShort("t", cl::desc("Alias for --symbols"), + cl::aliasopt(opts::Symbols)); + SymbolsShort.setHiddenFlag(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)); + SymbolsShort.setHiddenFlag(cl::NotHidden); + + // Names that are less clear and only exposed for compatibility. + static cl::alias SectionHeadersAlias("section-headers", + cl::desc("Alias for --sections"), + cl::aliasopt(opts::Sections)); + static cl::alias FileHeadersSingular("file-header", + cl::desc("Alias for --file-headers"), + cl::aliasopt(opts::FileHeaders)); + static cl::alias RelocationsMedium("relocs", + cl::desc("Alias for --relocations"), + cl::aliasopt(opts::Relocations)); + static cl::alias DynamicTableAlias("dynamic", + cl::desc("Alias for --dynamic-table"), + cl::aliasopt(opts::DynamicTable)); + static cl::alias SegmentsAlias("segments", + cl::desc("Alias for --program-headers"), + cl::aliasopt(opts::ProgramHeaders)); +} + int main(int argc, const char *argv[]) { InitLLVM X(argc, argv); @@ -599,17 +642,33 @@ 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]).find("readelf") != StringRef::npos) { 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::Sections = 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("-");