Skip to content

Commit d4dcb55

Browse files
committed
[llvm-readobj] Make -s and -t match llvm-readelf
llvm-readobj is an internal testing tool for binary formats. Its output and command line options do not need to be stable. It isn't supposed to be part of a build process. llvm-readelf was created as a user-facing utility and its interface intends to be compatible with GNU readelf (unless there are good reasons not to). The two tools have mostly compatible options. -s and -t are noticeable exceptions due to history. I think the cost of keeping the inconsistency overweighs the little history-compatible benefit and hinders transition from cl::opt to OptTable, so let's change it. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D105055
1 parent c4a00ed commit d4dcb55

File tree

8 files changed

+21
-39
lines changed

8 files changed

+21
-39
lines changed

llvm/docs/CommandGuide/llvm-readobj.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ file formats.
9595

9696
Display the relocation entries in the file.
9797

98-
.. option:: --sections, --section-headers, -s, -S
98+
.. option:: --sections, --section-headers, -S
9999

100100
Display all sections.
101101

@@ -123,7 +123,7 @@ file formats.
123123
Display the specified section(s) as a list of strings. ``section`` may be a
124124
section index or section name.
125125

126-
.. option:: --symbols, --syms, -t
126+
.. option:: --symbols, --syms, -s
127127

128128
Display the symbol table.
129129

llvm/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ Changes to the LLVM tools
164164
``--x86-asm-syntax`` is a deprecated internal option which will be removed in LLVM 14.0.0.
165165
(`D101695 <https://reviews.llvm.org/D101695>`_)
166166

167+
* The llvm-readobj short aliases ``-s`` (previously ``--sections``) and ``-t``
168+
(previously ``--syms``) have been changed to ``--syms`` and
169+
``--section-details`` respectively, to match llvm-readelf.
170+
(`D105055 <https://reviews.llvm.org/D105055>`_)
171+
167172
Changes to LLDB
168173
---------------------------------
169174

llvm/test/tools/llvm-readobj/ELF/merged.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ DynamicSymbols:
5252
## llvm-readobj does not support merged args, because it also supports some old
5353
## flags (-st, -sd, etc.), and it would be confusing if only some merged args
5454
## were supported.
55-
# RUN: not llvm-readobj -aeWhSrnudlVgIs %t.o 2>&1 | FileCheck %s --check-prefix=UNKNOWN
55+
# RUN: not llvm-readobj -aeWhSsrnudlVgIS %t.o 2>&1 | FileCheck %s --check-prefix=UNKNOWN
5656

5757
# CHECK-NOT: Unknown command line argument
5858
# UNKNOWN: for the --section-headers option: may only occur zero or one times!

llvm/test/tools/llvm-readobj/ELF/sections.test

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,12 @@
1010
# RUN: llvm-readobj --sections %t64 > %t64.llvm.sections
1111
# RUN: llvm-readobj -S %t64 > %t64.llvm.upper.s
1212
# RUN: cmp %t64.llvm.sections %t64.llvm.upper.s
13-
# RUN: llvm-readobj -s %t64 > %t64.llvm.lower.s
14-
# RUN: cmp %t64.llvm.sections %t64.llvm.lower.s
1513
# RUN: llvm-readobj --section-headers %t64 > %t64.llvm.section-headers
1614
# RUN: cmp %t64.llvm.sections %t64.llvm.section-headers
1715

1816
# RUN: llvm-readobj --sections %t32 > %t32.llvm.sections
1917
# RUN: llvm-readobj -S %t32 > %t32.llvm.upper.s
2018
# RUN: cmp %t32.llvm.sections %t32.llvm.upper.s
21-
# RUN: llvm-readobj -s %t32 > %t32.llvm.lower.s
22-
# RUN: cmp %t32.llvm.sections %t32.llvm.lower.s
2319
# RUN: llvm-readobj --section-headers %t32 > %t32.llvm.section-headers
2420
# RUN: cmp %t32.llvm.sections %t32.llvm.section-headers
2521

llvm/test/tools/llvm-readobj/ELF/symbols.test

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,13 @@
7070
# RUN: llvm-readobj --symbols %t64 > %t.symbols
7171
# RUN: llvm-readobj --syms %t64 > %t.syms
7272
# RUN: cmp %t.symbols %t.syms
73-
# RUN: llvm-readobj -t %t64 > %t.t
74-
# RUN: cmp %t.symbols %t.t
75-
# RUN: llvm-readelf -s --elf-output-style=LLVM %t64 > %t.lowers
76-
# RUN: cmp %t.symbols %t.lowers
73+
# RUN: llvm-readobj -s %t64 | diff %t.symbols -
74+
# RUN: llvm-readelf -s --elf-output-style=LLVM %t64 | diff %t.symbols -
7775

7876
# RUN: llvm-readelf --symbols %t64 > %t.symbols.gnu
7977
# RUN: llvm-readelf --syms %t64 > %t.syms.gnu
8078
# RUN: cmp %t.symbols.gnu %t.syms.gnu
81-
82-
## -s is an llvm-readobj option to dump sections.
83-
# RUN: llvm-readobj -s --elf-output-style=GNU %t64 | FileCheck %s --implicit-check-not="Symbol table"
79+
# RUN: llvm-readelf -s %t64 | diff %t.symbols.gnu -
8480

8581
## Case 3: Test that both regular and dynamic symbols are dumped when `--symbols` and `--dyn-symbols`
8682
## are specified together. Note that the order is different for different styles.

llvm/test/tools/llvm-readobj/basic.test

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ HELP: OVERVIEW: LLVM Object Reader
5454
OBJ: llvm-readobj{{.*}} [options] <input object files>
5555
ELF: llvm-readelf{{.*}} [options] <input object files>
5656
HELP: OPTIONS:
57-
OBJ: -s - Alias for --section-headers
58-
OBJ: -t - Alias for --symbols
59-
ELF: -s - Alias for --symbols
60-
ELF: -t - Alias for --section-details
57+
HELP -s - Alias for --symbols
58+
HELP -t - Alias for --section-details
6159
HELP: @FILE

llvm/test/tools/yaml2obj/ELF/duplicate-symbol-names.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## containing symbols with duplicate names (but different name suffixes).
33

44
# RUN: yaml2obj --docnum=1 %s -o %t1
5-
# RUN: llvm-readobj -t %t1 | FileCheck %s --check-prefix=CASE1
5+
# RUN: llvm-readobj --syms %t1 | FileCheck %s --check-prefix=CASE1
66

77
# CASE1: Name: localfoo (1)
88
# CASE1: Name: localfoo (1)

llvm/tools/llvm-readobj/llvm-readobj.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ namespace opts {
142142
// Also -t in llvm-readelf mode.
143143
cl::opt<bool> SectionDetails("section-details",
144144
cl::desc("Display the section details"));
145+
static cl::alias SectionDetailsShort("t",
146+
cl::desc("Alias for --section-details"),
147+
cl::aliasopt(SectionDetails),
148+
cl::NotHidden);
145149

146150
// --symbols
147151
// Also -s in llvm-readelf mode, or -t in llvm-readobj mode.
@@ -151,6 +155,9 @@ namespace opts {
151155
"symbol table when using GNU output style for ELF"));
152156
cl::alias SymbolsGNU("syms", cl::desc("Alias for --symbols"),
153157
cl::aliasopt(Symbols));
158+
static cl::alias SymbolsShort("s", cl::desc("Alias for --symbols"),
159+
cl::aliasopt(Symbols), cl::NotHidden,
160+
cl::Grouping);
154161

155162
// --dyn-symbols, --dyn-syms
156163
// Also --dt in llvm-readobj mode.
@@ -694,16 +701,6 @@ static void dumpInput(StringRef File, ScopedPrinter &Writer) {
694701

695702
/// Registers aliases that should only be allowed by readobj.
696703
static void registerReadobjAliases() {
697-
// -s has meant --sections for a very long time in llvm-readobj despite
698-
// meaning --symbols in readelf.
699-
static cl::alias SectionsShort("s", cl::desc("Alias for --section-headers"),
700-
cl::aliasopt(opts::SectionHeaders),
701-
cl::NotHidden);
702-
703-
// llvm-readelf reserves it for --section-details.
704-
static cl::alias SymbolsShort("t", cl::desc("Alias for --symbols"),
705-
cl::aliasopt(opts::Symbols), cl::NotHidden);
706-
707704
// The following two-letter aliases are only provided for readobj, as readelf
708705
// allows single-letter args to be grouped together.
709706
static cl::alias SectionRelocationsShort(
@@ -721,16 +718,6 @@ static void registerReadobjAliases() {
721718

722719
/// Registers aliases that should only be allowed by readelf.
723720
static void registerReadelfAliases() {
724-
// -s is here because for readobj it means --sections.
725-
static cl::alias SymbolsShort("s", cl::desc("Alias for --symbols"),
726-
cl::aliasopt(opts::Symbols), cl::NotHidden,
727-
cl::Grouping);
728-
729-
// -t is here because for readobj it is an alias for --symbols.
730-
static cl::alias SectionDetailsShort(
731-
"t", cl::desc("Alias for --section-details"),
732-
cl::aliasopt(opts::SectionDetails), cl::NotHidden);
733-
734721
// Allow all single letter flags to be grouped together.
735722
for (auto &OptEntry : cl::getRegisteredOptions()) {
736723
StringRef ArgName = OptEntry.getKey();

0 commit comments

Comments
 (0)