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
@@ -1,22 +1,28 @@
-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.
+RUN: llvm-readobj -S %p/Inputs/trivial.obj.elf-i386 \
+RUN: | FileCheck %s -check-prefix ELF
+RUN: llvm-readobj -s %p/Inputs/trivial.obj.elf-i386 \
+RUN: | FileCheck %s -check-prefix ELF
+
COFF: Sections [
COFF-NEXT: Section {
COFF-NEXT: Number: 1
Index: test/tools/llvm-readobj/symbols.test
===================================================================
--- test/tools/llvm-readobj/symbols.test
+++ test/tools/llvm-readobj/symbols.test
@@ -1,10 +1,16 @@
-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.
+RUN: llvm-readobj --syms %p/Inputs/trivial.obj.elf-i386 \
+RUN: | FileCheck %s -check-prefix ELF
+RUN: llvm-readobj -t %p/Inputs/trivial.obj.elf-i386 \
+RUN: | FileCheck %s -check-prefix ELF
+
COFF: Symbols [
COFF-NEXT: Symbol {
COFF-NEXT: Name: @comp.id
Index: tools/llvm-readobj/llvm-readobj.cpp
===================================================================
--- tools/llvm-readobj/llvm-readobj.cpp
+++ tools/llvm-readobj/llvm-readobj.cpp
@@ -48,9 +48,19 @@
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"));
+ 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));
@@ -58,20 +68,20 @@
// -file-headers, -h
cl::opt 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!
+ // -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));
+ cl::alias SectionsShortUpper("S", cl::desc("Alias for --sections"),
+ cl::aliasopt(Sections), cl::NotHidden);
+ cl::alias SectionHeadersAlias("section-headers",
+ cl::desc("Alias for --sections"),
+ cl::aliasopt(Sections));
// -section-relocations, -sr
cl::opt SectionRelocations("section-relocations",
@@ -97,9 +107,10 @@
// -relocations, -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 RelocationsMedium("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,12 +120,11 @@
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));
+ cl::alias SymbolsMedium("syms", cl::desc("Alias for --symbols"),
+ cl::aliasopt(Symbols));
// -dyn-symbols, -dt
cl::opt DynamicSymbols("dyn-symbols",
@@ -122,6 +132,8 @@
cl::alias DynamicSymbolsShort("dt",
cl::desc("Alias for --dyn-symbols"),
cl::aliasopt(DynamicSymbols));
+ cl::alias DynSymsMedium("dyn-syms", cl::desc("Alias for --dyn-symbols"),
+ cl::aliasopt(DynamicSymbols));
// -unwind, -u
cl::opt UnwindInfo("unwind",
@@ -134,6 +146,8 @@
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
@@ -144,7 +158,9 @@
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
cl::list StringDump("string-dump", cl::desc(""),
@@ -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(
@@ -299,6 +316,9 @@
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));
cl::opt CGProfile("elf-cg-profile", cl::desc("Display callgraph profile section"));
@@ -588,28 +608,55 @@
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 --sections"),
+ cl::aliasopt(opts::Sections), 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), 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::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("-");