Index: test/tools/llvm-readobj/merged.test =================================================================== --- /dev/null +++ test/tools/llvm-readobj/merged.test @@ -0,0 +1,19 @@ +# Check merged args produce identical output to when not merged. +RUN: llvm-readelf -aeWhSrnudlVgIs %p/Inputs/trivial.obj.elf-i386 > %t.merged +RUN: llvm-readelf -a -e -W -h -S -r -n -u -d -l -V -g -I -s %p/Inputs/trivial.obj.elf-i386 > %t.not-merged +RUN: cmp %t.merged %t.not-merged +RUN: cat %t.merged | FileCheck %s + +# llvm-readobj does not support merged args, because it also supports some old +# flags (-st, -sd, etc.), and it would be confusing if only some merged args +# were supported. +RUN: not llvm-readobj -aeWhSrnudlVgIs %p/Inputs/trivial.obj.elf-i386 |& FileCheck %s --check-prefix=UNKNOWN + +# Check the two-letter aliases that we *do* support in llvm-readobj. +RUN: llvm-readobj -sr %p/Inputs/trivial.obj.elf-i386 | FileCheck %s +RUN: llvm-readobj -sd %p/Inputs/trivial.obj.elf-i386 | FileCheck %s +RUN: llvm-readobj -st %p/Inputs/trivial.obj.elf-i386 | FileCheck %s +RUN: llvm-readobj -dt %p/Inputs/trivial.obj.elf-i386 | FileCheck %s + +CHECK-NOT: Unknown command line argument +UNKNOWN: Unknown command line argument Index: tools/llvm-readobj/llvm-readobj.cpp =================================================================== --- tools/llvm-readobj/llvm-readobj.cpp +++ tools/llvm-readobj/llvm-readobj.cpp @@ -92,26 +92,20 @@ cl::desc("Alias for --section-headers"), cl::aliasopt(SectionHeaders), cl::NotHidden); - // -section-relocations, -sr + // -section-relocations + // Also -sr in llvm-readobj mode. cl::opt SectionRelocations("section-relocations", cl::desc("Display relocations for each section shown.")); - cl::alias SectionRelocationsShort("sr", - cl::desc("Alias for --section-relocations"), - cl::aliasopt(SectionRelocations)); - // -section-symbols, -st + // -section-symbols + // Also -st in llvm-readobj mode. cl::opt SectionSymbols("section-symbols", cl::desc("Display symbols for each section shown.")); - cl::alias SectionSymbolsShort("st", - cl::desc("Alias for --section-symbols"), - cl::aliasopt(SectionSymbols)); - // -section-data, -sd + // -section-data + // Also -sd in llvm-readobj mode. cl::opt SectionData("section-data", cl::desc("Display section data for each section shown.")); - cl::alias SectionDataShort("sd", - cl::desc("Alias for --section-data"), - cl::aliasopt(SectionData)); // -relocations, -relocs, -r cl::opt Relocations("relocations", @@ -136,12 +130,10 @@ cl::alias SymbolsGNU("syms", cl::desc("Alias for --symbols"), cl::aliasopt(Symbols)); - // -dyn-symbols, -dyn-syms, -dt + // -dyn-symbols, -dyn-syms + // Also -dt in llvm-readobj mode. 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)); @@ -636,13 +628,43 @@ // --section-details (not implemented yet). static cl::alias SymbolsShort("t", cl::desc("Alias for --symbols"), cl::aliasopt(opts::Symbols), cl::NotHidden); + + // The following two-letter aliases are only provided for readobj, as readelf + // allows these args to be grouped together. + static cl::alias SectionRelocationsShort( + "sr", cl::desc("Alias for --section-relocations"), + cl::aliasopt(opts::SectionRelocations)); + static cl::alias SectionDataShort("sd", cl::desc("Alias for --section-data"), + cl::aliasopt(opts::SectionData)); + static cl::alias SectionSymbolsShort("st", + cl::desc("Alias for --section-symbols"), + cl::aliasopt(opts::SectionSymbols)); + static cl::alias DynamicSymbolsShort("dt", + cl::desc("Alias for --dyn-symbols"), + cl::aliasopt(opts::DynamicSymbols)); } /// 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); + cl::aliasopt(opts::Symbols), cl::NotHidden, + cl::Grouping); + + // Allow all single letter flags to be grouped together. + opts::AllShort.setFormattingFlag(cl::Grouping); + opts::HeadersShort.setFormattingFlag(cl::Grouping); + opts::WideOutputShort.setFormattingFlag(cl::Grouping); + opts::FileHeadersShort.setFormattingFlag(cl::Grouping); + opts::SectionsShortUpper.setFormattingFlag(cl::Grouping); + opts::RelocationsShort.setFormattingFlag(cl::Grouping); + opts::NotesShort.setFormattingFlag(cl::Grouping); + opts::UnwindInfoShort.setFormattingFlag(cl::Grouping); + opts::DynamicTableShort.setFormattingFlag(cl::Grouping); + opts::ProgramHeadersShort.setFormattingFlag(cl::Grouping); + opts::VersionInfoShort.setFormattingFlag(cl::Grouping); + opts::SectionGroupsShort.setFormattingFlag(cl::Grouping); + opts::HashHistogramShort.setFormattingFlag(cl::Grouping); } int main(int argc, const char *argv[]) {