From 2db79e9d2cacc7a387d3e1e6bf0f6ac0a7d5d292 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 26 Apr 2019 02:10:10 +0000 Subject: [PATCH] [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 llvm-svn: 359265 --- .../tools/llvm-objcopy/ELF/help-message.test | 4 +- .../llvm-objcopy/ELF/objcopy-version.test | 1 - .../tools/llvm-objcopy/ELF/strip-all.test | 18 +++--- .../tools/llvm-objcopy/ELF/strip-version.test | 1 - llvm/tools/llvm-objcopy/ObjcopyOpts.td | 55 ++++++++++--------- llvm/tools/llvm-objcopy/StripOpts.td | 37 +++++++------ 6 files changed, 56 insertions(+), 60 deletions(-) diff --git a/llvm/test/tools/llvm-objcopy/ELF/help-message.test b/llvm/test/tools/llvm-objcopy/ELF/help-message.test index 2dc92f673108..b0e9cf6c0e16 100644 --- a/llvm/test/tools/llvm-objcopy/ELF/help-message.test +++ b/llvm/test/tools/llvm-objcopy/ELF/help-message.test @@ -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 diff --git a/llvm/test/tools/llvm-objcopy/ELF/objcopy-version.test b/llvm/test/tools/llvm-objcopy/ELF/objcopy-version.test index f2f7fa053065..7494ccd2866d 100644 --- a/llvm/test/tools/llvm-objcopy/ELF/objcopy-version.test +++ b/llvm/test/tools/llvm-objcopy/ELF/objcopy-version.test @@ -1,4 +1,3 @@ -# RUN: llvm-objcopy -version | FileCheck %s # RUN: llvm-objcopy --version | FileCheck %s # RUN: llvm-objcopy -V | FileCheck %s diff --git a/llvm/test/tools/llvm-objcopy/ELF/strip-all.test b/llvm/test/tools/llvm-objcopy/ELF/strip-all.test index 32a801d7a6cd..dabb9ef6a91a 100644 --- a/llvm/test/tools/llvm-objcopy/ELF/strip-all.test +++ b/llvm/test/tools/llvm-objcopy/ELF/strip-all.test @@ -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: diff --git a/llvm/test/tools/llvm-objcopy/ELF/strip-version.test b/llvm/test/tools/llvm-objcopy/ELF/strip-version.test index d1d3165106a5..4b2f137ce2aa 100644 --- a/llvm/test/tools/llvm-objcopy/ELF/strip-version.test +++ b/llvm/test/tools/llvm-objcopy/ELF/strip-version.test @@ -1,4 +1,3 @@ -# RUN: llvm-strip -version | FileCheck %s # RUN: llvm-strip --version | FileCheck %s # RUN: llvm-strip -V | FileCheck %s diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td index bf3a1dcfc2f5..326a459ba355 100644 --- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td +++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td @@ -1,16 +1,17 @@ include "llvm/Option/OptParser.td" multiclass Eq { - def NAME : Separate<["--", "-"], name>; - def NAME #_eq : Joined<["--", "-"], name #"=">, + def NAME : Separate<["--"], name>; + def NAME #_eq : Joined<["--"], name #"=">, Alias(NAME)>, HelpText; } -def help : Flag<["-", "--"], "help">; +def help : Flag<["--"], "help">; +def h : Flag<["-"], "h">, Alias; 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; -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, 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; @@ -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; -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, 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 as local">, @@ -189,16 +190,16 @@ defm weaken_symbols MetaVarName<"filename">; def W : JoinedOrSeparate<["-"], "W">, Alias; -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; def discard_all - : Flag<["-", "--"], "discard-all">, + : Flag<["--"], "discard-all">, HelpText<"Remove all local symbols except file and section symbols">; def x : Flag<["-"], "x">, Alias; defm strip_symbol : Eq<"strip-symbol", "Remove 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 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; 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 . Overrides " @@ -264,7 +265,7 @@ defm change_start : Eq<"change-start", "Add 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; defm add_symbol diff --git a/llvm/tools/llvm-objcopy/StripOpts.td b/llvm/tools/llvm-objcopy/StripOpts.td index 3bb41aec259d..99ce3c25a3c0 100644 --- a/llvm/tools/llvm-objcopy/StripOpts.td +++ b/llvm/tools/llvm-objcopy/StripOpts.td @@ -1,22 +1,23 @@ include "llvm/Option/OptParser.td" multiclass Eq { - def NAME : Separate<["--", "-"], name>; - def NAME #_eq : Joined<["--", "-"], name #"=">, + def NAME : Separate<["--"], name>; + def NAME #_eq : Joined<["--"], name #"=">, Alias(NAME)>, HelpText; } -def help : Flag<["-", "--"], "help">; +def help : Flag<["--"], "help">; +def h : Flag<["-"], "h">, Alias; 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, HelpText<"Alias for --disable-deterministic-archives">; -defm output : Eq<"o", "Write output to ">, MetaVarName<"output">; +def output : JoinedOrSeparate<["-"], "o">, HelpText<"Write output to ">; -def preserve_dates : Flag<["-", "--"], "preserve-dates">, +def preserve_dates : Flag<["--"], "preserve-dates">, HelpText<"Preserve access and modification timestamps">; def p : Flag<["-"], "p">, Alias; -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; -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; def g : Flag<["-"], "g">, Alias; def S : Flag<["-"], "S">, Alias; -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
">, @@ -64,30 +65,30 @@ defm keep_section : Eq<"keep-section", "Keep
">, MetaVarName<"section">; defm keep_symbol : Eq<"keep-symbol", "Do not remove 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; 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; def discard_all - : Flag<["-", "--"], "discard-all">, + : Flag<["--"], "discard-all">, HelpText<"Remove all local symbols except file and section symbols">; def x : Flag<["-"], "x">, Alias; 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;