Skip to content

Commit

Permalink
[llvm-readobj] Make -s and -t match llvm-readelf
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MaskRay committed Jun 29, 2021
1 parent c4a00ed commit d4dcb55
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 39 deletions.
4 changes: 2 additions & 2 deletions llvm/docs/CommandGuide/llvm-readobj.rst
Expand Up @@ -95,7 +95,7 @@ file formats.

Display the relocation entries in the file.

.. option:: --sections, --section-headers, -s, -S
.. option:: --sections, --section-headers, -S

Display all sections.

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

.. option:: --symbols, --syms, -t
.. option:: --symbols, --syms, -s

Display the symbol table.

Expand Down
5 changes: 5 additions & 0 deletions llvm/docs/ReleaseNotes.rst
Expand Up @@ -164,6 +164,11 @@ Changes to the LLVM tools
``--x86-asm-syntax`` is a deprecated internal option which will be removed in LLVM 14.0.0.
(`D101695 <https://reviews.llvm.org/D101695>`_)

* The llvm-readobj short aliases ``-s`` (previously ``--sections``) and ``-t``
(previously ``--syms``) have been changed to ``--syms`` and
``--section-details`` respectively, to match llvm-readelf.
(`D105055 <https://reviews.llvm.org/D105055>`_)

Changes to LLDB
---------------------------------

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-readobj/ELF/merged.test
Expand Up @@ -52,7 +52,7 @@ DynamicSymbols:
## 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 %t.o 2>&1 | FileCheck %s --check-prefix=UNKNOWN
# RUN: not llvm-readobj -aeWhSsrnudlVgIS %t.o 2>&1 | FileCheck %s --check-prefix=UNKNOWN

# CHECK-NOT: Unknown command line argument
# UNKNOWN: for the --section-headers option: may only occur zero or one times!
4 changes: 0 additions & 4 deletions llvm/test/tools/llvm-readobj/ELF/sections.test
Expand Up @@ -10,16 +10,12 @@
# RUN: llvm-readobj --sections %t64 > %t64.llvm.sections
# RUN: llvm-readobj -S %t64 > %t64.llvm.upper.s
# RUN: cmp %t64.llvm.sections %t64.llvm.upper.s
# RUN: llvm-readobj -s %t64 > %t64.llvm.lower.s
# RUN: cmp %t64.llvm.sections %t64.llvm.lower.s
# RUN: llvm-readobj --section-headers %t64 > %t64.llvm.section-headers
# RUN: cmp %t64.llvm.sections %t64.llvm.section-headers

# RUN: llvm-readobj --sections %t32 > %t32.llvm.sections
# RUN: llvm-readobj -S %t32 > %t32.llvm.upper.s
# RUN: cmp %t32.llvm.sections %t32.llvm.upper.s
# RUN: llvm-readobj -s %t32 > %t32.llvm.lower.s
# RUN: cmp %t32.llvm.sections %t32.llvm.lower.s
# RUN: llvm-readobj --section-headers %t32 > %t32.llvm.section-headers
# RUN: cmp %t32.llvm.sections %t32.llvm.section-headers

Expand Down
10 changes: 3 additions & 7 deletions llvm/test/tools/llvm-readobj/ELF/symbols.test
Expand Up @@ -70,17 +70,13 @@
# RUN: llvm-readobj --symbols %t64 > %t.symbols
# RUN: llvm-readobj --syms %t64 > %t.syms
# RUN: cmp %t.symbols %t.syms
# RUN: llvm-readobj -t %t64 > %t.t
# RUN: cmp %t.symbols %t.t
# RUN: llvm-readelf -s --elf-output-style=LLVM %t64 > %t.lowers
# RUN: cmp %t.symbols %t.lowers
# RUN: llvm-readobj -s %t64 | diff %t.symbols -
# RUN: llvm-readelf -s --elf-output-style=LLVM %t64 | diff %t.symbols -

# RUN: llvm-readelf --symbols %t64 > %t.symbols.gnu
# RUN: llvm-readelf --syms %t64 > %t.syms.gnu
# RUN: cmp %t.symbols.gnu %t.syms.gnu

## -s is an llvm-readobj option to dump sections.
# RUN: llvm-readobj -s --elf-output-style=GNU %t64 | FileCheck %s --implicit-check-not="Symbol table"
# RUN: llvm-readelf -s %t64 | diff %t.symbols.gnu -

## Case 3: Test that both regular and dynamic symbols are dumped when `--symbols` and `--dyn-symbols`
## are specified together. Note that the order is different for different styles.
Expand Down
6 changes: 2 additions & 4 deletions llvm/test/tools/llvm-readobj/basic.test
Expand Up @@ -54,8 +54,6 @@ HELP: OVERVIEW: LLVM Object Reader
OBJ: llvm-readobj{{.*}} [options] <input object files>
ELF: llvm-readelf{{.*}} [options] <input object files>
HELP: OPTIONS:
OBJ: -s - Alias for --section-headers
OBJ: -t - Alias for --symbols
ELF: -s - Alias for --symbols
ELF: -t - Alias for --section-details
HELP -s - Alias for --symbols
HELP -t - Alias for --section-details
HELP: @FILE
2 changes: 1 addition & 1 deletion llvm/test/tools/yaml2obj/ELF/duplicate-symbol-names.yaml
Expand Up @@ -2,7 +2,7 @@
## containing symbols with duplicate names (but different name suffixes).

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

# CASE1: Name: localfoo (1)
# CASE1: Name: localfoo (1)
Expand Down
27 changes: 7 additions & 20 deletions llvm/tools/llvm-readobj/llvm-readobj.cpp
Expand Up @@ -142,6 +142,10 @@ namespace opts {
// Also -t in llvm-readelf mode.
cl::opt<bool> SectionDetails("section-details",
cl::desc("Display the section details"));
static cl::alias SectionDetailsShort("t",
cl::desc("Alias for --section-details"),
cl::aliasopt(SectionDetails),
cl::NotHidden);

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

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

/// 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 --section-headers"),
cl::aliasopt(opts::SectionHeaders),
cl::NotHidden);

// llvm-readelf reserves it for --section-details.
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 single-letter args to be grouped together.
static cl::alias SectionRelocationsShort(
Expand All @@ -721,16 +718,6 @@ static void registerReadobjAliases() {

/// 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::Grouping);

// -t is here because for readobj it is an alias for --symbols.
static cl::alias SectionDetailsShort(
"t", cl::desc("Alias for --section-details"),
cl::aliasopt(opts::SectionDetails), cl::NotHidden);

// Allow all single letter flags to be grouped together.
for (auto &OptEntry : cl::getRegisteredOptions()) {
StringRef ArgName = OptEntry.getKey();
Expand Down

0 comments on commit d4dcb55

Please sign in to comment.