[llvm-objcopy] Accept --long-option but not -long-option

Summary:

llvm-{objcopy,strip} (and many other LLVM binary utilities) accept
cl::opt style -long-option as well as many short options (e.g. -p -S
-x). People who use them as replacement of GNU binutils often use the
grouped option syntax (POSIX Utility Conventions), e.g. -Sx => -S -x,
-Wd => -W -d, -sj.text => -s -j.text

There is ambiguity if a long option starts with the character used by a
short option. Drop the support for -long-option to resolve the ambiguity.

This divergence from other utilities is accepted (other utilities
continue supporting -long-option).
https://lists.llvm.org/pipermail/llvm-dev/2019-April/131786.html

Reviewers: alexshap, jakehehrlich, jhenderson, rupprecht, espindola

Reviewed By: jakehehrlich, jhenderson, rupprecht

Subscribers: grimar, emaste, arichardson, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D60439

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359265 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Fangrui Song 2019-04-26 02:10:10 +00:00
parent baf32fac2b
commit f0d90ddef5
6 changed files with 56 additions and 60 deletions

View File

@ -1,11 +1,11 @@
# RUN: llvm-objcopy -help | FileCheck --check-prefix=OBJCOPY-USAGE %s
# RUN: llvm-objcopy -h | FileCheck --check-prefix=OBJCOPY-USAGE %s
# RUN: llvm-objcopy --help | FileCheck --check-prefix=OBJCOPY-USAGE %s
# RUN: not llvm-objcopy 2>&1 | FileCheck --check-prefix=OBJCOPY-USAGE %s
# RUN: not llvm-objcopy -abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s
# RUN: not llvm-objcopy --abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s
# RUN: not llvm-objcopy --strip-debug 2>&1 | FileCheck %s --check-prefix=NO-INPUT-FILES
# RUN: llvm-strip -help | FileCheck --check-prefix=STRIP-USAGE %s
# RUN: llvm-strip -h | FileCheck --check-prefix=STRIP-USAGE %s
# RUN: llvm-strip --help | FileCheck --check-prefix=STRIP-USAGE %s
# RUN: not llvm-strip 2>&1 | FileCheck --check-prefix=STRIP-USAGE %s
# RUN: not llvm-strip -abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s

View File

@ -1,4 +1,3 @@
# RUN: llvm-objcopy -version | FileCheck %s
# RUN: llvm-objcopy --version | FileCheck %s
# RUN: llvm-objcopy -V | FileCheck %s

View File

@ -28,27 +28,23 @@
# RUN: cmp %t2 %t6
# RUN: cp %t %t7
# RUN: llvm-strip -strip-all %t7
# RUN: llvm-strip --strip-all %t7
# RUN: cmp %t2 %t7
# RUN: cp %t %t8
# RUN: llvm-strip --strip-all %t8
# RUN: llvm-objcopy -S %t8 %t8
# RUN: cmp %t2 %t8
# RUN: cp %t %t9
# RUN: llvm-objcopy -S %t9 %t9
# RUN: llvm-strip -s %t9
# RUN: cmp %t2 %t9
# RUN: cp %t %t10
# RUN: llvm-strip -s %t10
# RUN: cmp %t2 %t10
# Verify that a non-existent symbol table (after first call to llvm-strip)
# can be handled correctly.
# RUN: cp %t %t11
# RUN: llvm-strip --strip-all --keep-symbol=unavailable_symbol %t11
# RUN: llvm-strip --strip-all --keep-symbol=unavailable_symbol %t11
# RUN: cmp %t2 %t11
# RUN: cp %t %t10
# RUN: llvm-strip --strip-all --keep-symbol=unavailable_symbol %t10
# RUN: llvm-strip --strip-all --keep-symbol=unavailable_symbol %t10
# RUN: cmp %t2 %t10
!ELF
FileHeader:

View File

@ -1,4 +1,3 @@
# RUN: llvm-strip -version | FileCheck %s
# RUN: llvm-strip --version | FileCheck %s
# RUN: llvm-strip -V | FileCheck %s

View File

@ -1,16 +1,17 @@
include "llvm/Option/OptParser.td"
multiclass Eq<string name, string help> {
def NAME : Separate<["--", "-"], name>;
def NAME #_eq : Joined<["--", "-"], name #"=">,
def NAME : Separate<["--"], name>;
def NAME #_eq : Joined<["--"], name #"=">,
Alias<!cast<Separate>(NAME)>,
HelpText<help>;
}
def help : Flag<["-", "--"], "help">;
def help : Flag<["--"], "help">;
def h : Flag<["-"], "h">, Alias<help>;
def allow_broken_links
: Flag<["-", "--"], "allow-broken-links">,
: Flag<["--"], "allow-broken-links">,
HelpText<"Allow llvm-objcopy to remove sections even if it would leave "
"invalid section references. The appropriate sh_link fields"
"will be set to zero.">;
@ -32,13 +33,13 @@ defm output_target : Eq<"output-target", "Format of the output file">,
Values<"binary">;
def O : JoinedOrSeparate<["-"], "O">, Alias<output_target>;
def compress_debug_sections : Flag<["--", "-"], "compress-debug-sections">;
def compress_debug_sections : Flag<["--"], "compress-debug-sections">;
def compress_debug_sections_eq
: Joined<["--", "-"], "compress-debug-sections=">,
: Joined<["--"], "compress-debug-sections=">,
MetaVarName<"[ zlib | zlib-gnu ]">,
HelpText<"Compress DWARF debug sections using specified style. Supported "
"styles: 'zlib-gnu' and 'zlib'">;
def decompress_debug_sections : Flag<["-", "--"], "decompress-debug-sections">,
def decompress_debug_sections : Flag<["--"], "decompress-debug-sections">,
HelpText<"Decompress DWARF debug sections.">;
defm split_dwo
: Eq<"split-dwo", "Equivalent to extract-dwo on the input file to "
@ -46,7 +47,7 @@ defm split_dwo
MetaVarName<"dwo-file">;
def enable_deterministic_archives
: Flag<["-", "--"], "enable-deterministic-archives">,
: Flag<["--"], "enable-deterministic-archives">,
HelpText<"Enable deterministic mode when copying archives (use zero for "
"UIDs, GIDs, and timestamps).">;
def D : Flag<["-"], "D">,
@ -54,14 +55,14 @@ def D : Flag<["-"], "D">,
HelpText<"Alias for --enable-deterministic-archives">;
def disable_deterministic_archives
: Flag<["-", "--"], "disable-deterministic-archives">,
: Flag<["--"], "disable-deterministic-archives">,
HelpText<"Disable deterministic mode when copying archives (use real "
"values for UIDs, GIDs, and timestamps).">;
def U : Flag<["-"], "U">,
Alias<disable_deterministic_archives>,
HelpText<"Alias for --disable-deterministic-archives">;
def preserve_dates : Flag<["-", "--"], "preserve-dates">,
def preserve_dates : Flag<["--"], "preserve-dates">,
HelpText<"Preserve access and modification timestamps">;
def p : Flag<["-"], "p">, Alias<preserve_dates>;
@ -109,25 +110,25 @@ defm set_section_flags
"rom, share, contents, merge, strings.">,
MetaVarName<"section=flag1[,flag2,...]">;
def strip_all : Flag<["-", "--"], "strip-all">,
def strip_all : Flag<["--"], "strip-all">,
HelpText<"Remove non-allocated sections outside segments. "
".gnu.warning* sections are not removed">;
def S : Flag<["-"], "S">, Alias<strip_all>;
def strip_all_gnu : Flag<["-", "--"], "strip-all-gnu">,
def strip_all_gnu : Flag<["--"], "strip-all-gnu">,
HelpText<"Compatible with GNU objcopy's --strip-all">;
def strip_debug : Flag<["-", "--"], "strip-debug">,
def strip_debug : Flag<["--"], "strip-debug">,
HelpText<"Remove all debug information">;
def g : Flag<["-"], "g">, Alias<strip_debug>,
HelpText<"Alias for --strip-debug">;
def strip_dwo : Flag<["-", "--"], "strip-dwo">,
def strip_dwo : Flag<["--"], "strip-dwo">,
HelpText<"Remove all DWARF .dwo sections from file">;
def strip_sections
: Flag<["-", "--"], "strip-sections">,
: Flag<["--"], "strip-sections">,
HelpText<"Remove all section headers and all sections not in segments">;
def strip_non_alloc
: Flag<["-", "--"], "strip-non-alloc">,
: Flag<["--"], "strip-non-alloc">,
HelpText<"Remove all non-allocated sections outside segments">;
def strip_unneeded : Flag<["-", "--"], "strip-unneeded">,
def strip_unneeded : Flag<["--"], "strip-unneeded">,
HelpText<"Remove all symbols not needed by relocations">;
defm strip_unneeded_symbol
: Eq<"strip-unneeded-symbol",
@ -140,12 +141,12 @@ defm strip_unneeded_symbols
MetaVarName<"filename">;
def extract_dwo
: Flag<["-", "--"], "extract-dwo">,
: Flag<["--"], "extract-dwo">,
HelpText<
"Remove all sections that are not DWARF .dwo sections from file">;
def localize_hidden
: Flag<["-", "--"], "localize-hidden">,
: Flag<["--"], "localize-hidden">,
HelpText<
"Mark all symbols that have hidden or internal visibility as local">;
defm localize_symbol : Eq<"localize-symbol", "Mark <symbol> as local">,
@ -189,16 +190,16 @@ defm weaken_symbols
MetaVarName<"filename">;
def W : JoinedOrSeparate<["-"], "W">, Alias<weaken_symbol>;
def weaken : Flag<["-", "--"], "weaken">,
def weaken : Flag<["--"], "weaken">,
HelpText<"Mark all global symbols as weak">;
def discard_locals : Flag<["-", "--"], "discard-locals">,
def discard_locals : Flag<["--"], "discard-locals">,
HelpText<"Remove compiler-generated local symbols, (e.g. "
"symbols starting with .L)">;
def X : Flag<["-"], "X">, Alias<discard_locals>;
def discard_all
: Flag<["-", "--"], "discard-all">,
: Flag<["--"], "discard-all">,
HelpText<"Remove all local symbols except file and section symbols">;
def x : Flag<["-"], "x">, Alias<discard_all>;
defm strip_symbol : Eq<"strip-symbol", "Remove symbol <symbol>">,
@ -223,11 +224,11 @@ defm keep_symbols
MetaVarName<"filename">;
def only_keep_debug
: Flag<["-", "--"], "only-keep-debug">,
: Flag<["--"], "only-keep-debug">,
HelpText<"Clear sections that would not be stripped by --strip-debug. "
"Currently only implemented for COFF.">;
def keep_file_symbols : Flag<["-", "--"], "keep-file-symbols">,
def keep_file_symbols : Flag<["--"], "keep-file-symbols">,
HelpText<"Do not remove file symbols">;
defm dump_section
: Eq<"dump-section",
@ -237,7 +238,7 @@ defm prefix_symbols
: Eq<"prefix-symbols", "Add <prefix> to the start of every symbol name">,
MetaVarName<"prefix">;
def version : Flag<["-", "--"], "version">,
def version : Flag<["--"], "version">,
HelpText<"Print the version and exit.">;
def V : Flag<["-"], "V">, Alias<version>;
defm build_id_link_dir
@ -254,7 +255,7 @@ defm build_id_link_output
MetaVarName<"suffix">;
def regex
: Flag<["-", "--"], "regex">,
: Flag<["--"], "regex">,
HelpText<"Permit regular expressions in name comparison">;
defm set_start : Eq<"set-start", "Set the start address to <addr>. Overrides "
@ -264,7 +265,7 @@ defm change_start : Eq<"change-start", "Add <incr> to the start address. Can be
"specified multiple times, all values will be applied "
"cumulatively.">,
MetaVarName<"incr">;
def adjust_start : JoinedOrSeparate<["-", "--"], "adjust-start">,
def adjust_start : JoinedOrSeparate<["--"], "adjust-start">,
Alias<change_start>;
defm add_symbol

View File

@ -1,22 +1,23 @@
include "llvm/Option/OptParser.td"
multiclass Eq<string name, string help> {
def NAME : Separate<["--", "-"], name>;
def NAME #_eq : Joined<["--", "-"], name #"=">,
def NAME : Separate<["--"], name>;
def NAME #_eq : Joined<["--"], name #"=">,
Alias<!cast<Separate>(NAME)>,
HelpText<help>;
}
def help : Flag<["-", "--"], "help">;
def help : Flag<["--"], "help">;
def h : Flag<["-"], "h">, Alias<help>;
def allow_broken_links
: Flag<["-", "--"], "allow-broken-links">,
: Flag<["--"], "allow-broken-links">,
HelpText<"Allow llvm-strip to remove sections even if it would leave "
"invalid section references. The appropriate sh_link fields"
"will be set to zero.">;
def enable_deterministic_archives
: Flag<["-", "--"], "enable-deterministic-archives">,
: Flag<["--"], "enable-deterministic-archives">,
HelpText<"Enable deterministic mode when stripping archives (use zero "
"for UIDs, GIDs, and timestamps).">;
def D : Flag<["-"], "D">,
@ -24,32 +25,32 @@ def D : Flag<["-"], "D">,
HelpText<"Alias for --enable-deterministic-archives">;
def disable_deterministic_archives
: Flag<["-", "--"], "disable-deterministic-archives">,
: Flag<["--"], "disable-deterministic-archives">,
HelpText<"Disable deterministic mode when stripping archives (use real "
"values for UIDs, GIDs, and timestamps).">;
def U : Flag<["-"], "U">,
Alias<disable_deterministic_archives>,
HelpText<"Alias for --disable-deterministic-archives">;
defm output : Eq<"o", "Write output to <file>">, MetaVarName<"output">;
def output : JoinedOrSeparate<["-"], "o">, HelpText<"Write output to <file>">;
def preserve_dates : Flag<["-", "--"], "preserve-dates">,
def preserve_dates : Flag<["--"], "preserve-dates">,
HelpText<"Preserve access and modification timestamps">;
def p : Flag<["-"], "p">, Alias<preserve_dates>;
def strip_all : Flag<["-", "--"], "strip-all">,
def strip_all : Flag<["--"], "strip-all">,
HelpText<"Remove non-allocated sections outside segments. "
".gnu.warning* sections are not removed">;
def s : Flag<["-"], "s">, Alias<strip_all>;
def strip_all_gnu : Flag<["-", "--"], "strip-all-gnu">,
def strip_all_gnu : Flag<["--"], "strip-all-gnu">,
HelpText<"Compatible with GNU strip's --strip-all">;
def strip_debug : Flag<["-", "--"], "strip-debug">,
def strip_debug : Flag<["--"], "strip-debug">,
HelpText<"Remove debugging symbols only">;
def d : Flag<["-"], "d">, Alias<strip_debug>;
def g : Flag<["-"], "g">, Alias<strip_debug>;
def S : Flag<["-"], "S">, Alias<strip_debug>;
def strip_unneeded : Flag<["-", "--"], "strip-unneeded">,
def strip_unneeded : Flag<["--"], "strip-unneeded">,
HelpText<"Remove all symbols not needed by relocations">;
defm remove_section : Eq<"remove-section", "Remove <section>">,
@ -64,30 +65,30 @@ defm keep_section : Eq<"keep-section", "Keep <section>">,
MetaVarName<"section">;
defm keep_symbol : Eq<"keep-symbol", "Do not remove symbol <symbol>">,
MetaVarName<"symbol">;
def keep_file_symbols : Flag<["-", "--"], "keep-file-symbols">,
def keep_file_symbols : Flag<["--"], "keep-file-symbols">,
HelpText<"Do not remove file symbols">;
def K : JoinedOrSeparate<["-"], "K">, Alias<keep_symbol>;
def only_keep_debug
: Flag<["-", "--"], "only-keep-debug">,
: Flag<["--"], "only-keep-debug">,
HelpText<"Clear sections that would not be stripped by --strip-debug. "
"Currently only implemented for COFF.">;
def discard_locals : Flag<["-", "--"], "discard-locals">,
def discard_locals : Flag<["--"], "discard-locals">,
HelpText<"Remove compiler-generated local symbols, (e.g. "
"symbols starting with .L)">;
def X : Flag<["-"], "X">, Alias<discard_locals>;
def discard_all
: Flag<["-", "--"], "discard-all">,
: Flag<["--"], "discard-all">,
HelpText<"Remove all local symbols except file and section symbols">;
def x : Flag<["-"], "x">, Alias<discard_all>;
def regex
: Flag<["-", "--"], "regex">,
: Flag<["--"], "regex">,
HelpText<"Permit regular expressions in name comparison">;
def version : Flag<["-", "--"], "version">,
def version : Flag<["--"], "version">,
HelpText<"Print the version and exit.">;
def V : Flag<["-"], "V">, Alias<version>;