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/dynamic.test =================================================================== --- test/tools/llvm-readobj/dynamic.test +++ test/tools/llvm-readobj/dynamic.test @@ -73,6 +73,10 @@ RUN: llvm-readobj -dynamic-table %p/Inputs/dynamic-table-exe.x86 \ RUN: | FileCheck %s -check-prefix ELF-X86-EXE +RUN: llvm-readobj --dynamic %p/Inputs/dynamic-table-exe.x86 \ +RUN: | FileCheck %s -check-prefix ELF-X86-EXE +RUN: llvm-readobj -d %p/Inputs/dynamic-table-exe.x86 \ +RUN: | FileCheck %s -check-prefix ELF-X86-EXE ELF-X86-EXE: Format: ELF32-i386 ELF-X86-EXE: Arch: i386 Index: test/tools/llvm-readobj/file-headers.test =================================================================== --- test/tools/llvm-readobj/file-headers.test +++ test/tools/llvm-readobj/file-headers.test @@ -31,6 +31,12 @@ RUN: llvm-readobj -h %p/Inputs/trivial.obj.wasm \ RUN: | FileCheck %s -check-prefix WASM +# Check flag aliases. +RUN: llvm-readobj --file-header %p/Inputs/trivial.obj.elf-x86-64 \ +RUN: | FileCheck %s -check-prefix ELF64 +RUN: llvm-readobj --file-headers %p/Inputs/trivial.obj.elf-x86-64 \ +RUN: | FileCheck %s -check-prefix ELF64 + COFF-ARM: File: {{(.*[/\\])?}}trivial.obj.coff-arm COFF-ARM-NEXT: Format: COFF-ARM COFF-ARM-NEXT: Arch: thumb Index: test/tools/llvm-readobj/program-headers.test =================================================================== --- test/tools/llvm-readobj/program-headers.test +++ test/tools/llvm-readobj/program-headers.test @@ -21,6 +21,12 @@ RUN: llvm-readobj -program-headers %p/../../Object/Inputs/openbsd-phdrs.elf-x86-64 \ RUN: | FileCheck %s -check-prefix OPENBSD-X86-64 +# Check flag aliases. +RUN: llvm-readobj --segments %p/../../Object/Inputs/program-headers.elf-x86-64 \ +RUN: | FileCheck %s -check-prefix ELF-X86-64 +RUN: llvm-readobj -l %p/../../Object/Inputs/program-headers.elf-x86-64 \ +RUN: | FileCheck %s -check-prefix ELF-X86-64 + ELF-I386: ProgramHeaders [ ELF-I386-NEXT: ProgramHeader { ELF-I386-NEXT: Type: PT_LOAD (0x1) 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/relocations.test =================================================================== --- test/tools/llvm-readobj/relocations.test +++ test/tools/llvm-readobj/relocations.test @@ -19,6 +19,12 @@ RUN: llvm-readobj -r --expand-relocs %p/Inputs/trivial.obj.wasm \ RUN: | FileCheck %s -check-prefix WASM +# Check flag aliases. +RUN: llvm-readobj --relocs %p/Inputs/trivial.obj.elf-i386 \ +RUN: | FileCheck %s -check-prefix ELF +RUN: llvm-readobj --relocations %p/Inputs/trivial.obj.elf-i386 \ +RUN: | FileCheck %s -check-prefix ELF + COFF: Relocations [ COFF-NEXT: Section (1) .text { COFF-NEXT: 0x4 IMAGE_REL_I386_DIR32 .data Index: test/tools/llvm-readobj/sections.test =================================================================== --- test/tools/llvm-readobj/sections.test +++ test/tools/llvm-readobj/sections.test @@ -17,6 +17,14 @@ 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 +RUN: llvm-readobj --section-headers %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,14 @@ cl::desc(""), cl::ZeroOrMore); + // -all, -a + cl::opt All( + "all", + cl::desc("Equivalent to setting: --file-header, --program-headers, " + "--sections, --symbols, --relocs, --dynamic, --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")); @@ -58,17 +66,19 @@ // -file-headers, -h cl::opt FileHeaders("file-headers", cl::desc("Display file headers ")); + cl::alias FileHeadersSingular("file-header", + cl::desc("Alias for --file-headers"), + cl::aliasopt(FileHeaders)); cl::alias FileHeadersShort("h", cl::desc("Alias for --file-headers"), cl::aliasopt(FileHeaders)); - // -sections, -s, -S - // Note: In GNU readelf, -s means --symbols! + // -sections, -section-headers, -S cl::opt Sections("sections", cl::desc("Display all sections.")); - cl::alias SectionsShort("s", - cl::desc("Alias for --sections"), - cl::aliasopt(Sections)); + cl::alias SectionHeadersAlias("section-headers", + cl::desc("Alias for --sections"), + cl::aliasopt(Sections)); cl::alias SectionsShortUpper("S", cl::desc("Alias for --sections"), cl::aliasopt(Sections)); @@ -97,6 +107,8 @@ // -relocations, -r cl::opt Relocations("relocations", cl::desc("Display the relocation entries in the file")); + cl::alias RelocationsMedium("relocs", cl::desc("Alias for --relocations"), + cl::aliasopt(Relocations)); cl::alias RelocationsShort("r", cl::desc("Alias for --relocations"), cl::aliasopt(Relocations)); @@ -133,6 +145,8 @@ // -dynamic-table cl::opt DynamicTable("dynamic-table", cl::desc("Display the ELF .dynamic section table")); + cl::alias DynamicTableAlias("dynamic", cl::desc("Alias for --dynamic-table"), + cl::aliasopt(DynamicTable)); cl::alias DynamicTableShort("d", cl::desc("Alias for --dynamic-table"), cl::aliasopt(DynamicTable)); @@ -143,6 +157,8 @@ // -program-headers cl::opt ProgramHeaders("program-headers", cl::desc("Display ELF program headers")); + cl::alias SegmentsAlias("segments", cl::desc("Alias for --program-headers"), + cl::aliasopt(ProgramHeaders)); cl::alias ProgramHeadersShort("l", cl::desc("Alias for --program-headers"), cl::aliasopt(ProgramHeaders)); @@ -188,11 +204,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 +306,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 +605,22 @@ 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); +} + +/// Registers aliases that should only be allowed by readelf. +static void registerReadelfAliases() { + static cl::alias SymbolsShort("s", cl::desc("Alias for --symbols"), + cl::aliasopt(opts::Symbols)); + SymbolsShort.setHiddenFlag(cl::NotHidden); +} + int main(int argc, const char *argv[]) { InitLLVM X(argc, argv); @@ -599,17 +632,34 @@ 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("-");