From 5b1329de30669ab18bf56f829c4b6ea426ec6261 Mon Sep 17 00:00:00 2001 From: Jordan Rupprecht Date: Fri, 21 Sep 2018 00:47:31 +0000 Subject: [PATCH] [llvm-objcopy/llvm-strip]: handle --version Summary: Implement --version for objcopy and strip. I think there are LLVM utilities that automatically handle this, but that doesn't seem to work with custom parsing since this binary handles both objcopy and strip, so it uses custom parsing. This fixes PR38298 Reviewers: jhenderson, alexshap, jakehehrlich Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D52328 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342702 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/tools/llvm-objcopy/objcopy-version.test | 4 ++++ test/tools/llvm-objcopy/strip-version.test | 4 ++++ tools/llvm-objcopy/ObjcopyOpts.td | 3 +++ tools/llvm-objcopy/StripOpts.td | 4 ++++ tools/llvm-objcopy/llvm-objcopy.cpp | 10 ++++++++++ 5 files changed, 25 insertions(+) create mode 100644 test/tools/llvm-objcopy/objcopy-version.test create mode 100644 test/tools/llvm-objcopy/strip-version.test diff --git a/test/tools/llvm-objcopy/objcopy-version.test b/test/tools/llvm-objcopy/objcopy-version.test new file mode 100644 index 00000000000..3b5cd593ddf --- /dev/null +++ b/test/tools/llvm-objcopy/objcopy-version.test @@ -0,0 +1,4 @@ +# RUN: llvm-objcopy -version | FileCheck %s +# RUN: llvm-objcopy --version | FileCheck %s + +# CHECK: {{ version }} diff --git a/test/tools/llvm-objcopy/strip-version.test b/test/tools/llvm-objcopy/strip-version.test new file mode 100644 index 00000000000..bd91dd3de83 --- /dev/null +++ b/test/tools/llvm-objcopy/strip-version.test @@ -0,0 +1,4 @@ +# RUN: llvm-strip -version | FileCheck %s +# RUN: llvm-strip --version | FileCheck %s + +# CHECK: {{ version }} diff --git a/tools/llvm-objcopy/ObjcopyOpts.td b/tools/llvm-objcopy/ObjcopyOpts.td index 9d771451bc6..469f76d24d0 100644 --- a/tools/llvm-objcopy/ObjcopyOpts.td +++ b/tools/llvm-objcopy/ObjcopyOpts.td @@ -107,6 +107,9 @@ defm keep_global_symbols "with '#'. Leading and trailing whitespace is stripped from each " "line. May be repeated to read symbols from many files.">; +def version : Flag<[ "-", "--" ], "version">, + HelpText<"Print the version and exit.">; + defm weaken_symbol : Eq<"weaken-symbol">, MetaVarName<"symbol">, HelpText<"Mark as weak">; diff --git a/tools/llvm-objcopy/StripOpts.td b/tools/llvm-objcopy/StripOpts.td index 5abc23fb577..821dfa3b277 100644 --- a/tools/llvm-objcopy/StripOpts.td +++ b/tools/llvm-objcopy/StripOpts.td @@ -47,6 +47,10 @@ def K : JoinedOrSeparate<["-"], "K">, def discard_all : Flag<["-", "--"], "discard-all">, HelpText<"Remove all local symbols except file and section symbols">; + +def version : Flag<[ "-", "--" ], "version">, + HelpText<"Print the version and exit.">; + def x : Flag<["-"], "x">, Alias; diff --git a/tools/llvm-objcopy/llvm-objcopy.cpp b/tools/llvm-objcopy/llvm-objcopy.cpp index 36ed77a8063..ce2a1f1f259 100644 --- a/tools/llvm-objcopy/llvm-objcopy.cpp +++ b/tools/llvm-objcopy/llvm-objcopy.cpp @@ -892,6 +892,11 @@ static DriverConfig parseObjcopyOptions(ArrayRef ArgsArr) { exit(0); } + if (InputArgs.hasArg(OBJCOPY_version)) { + cl::PrintVersionMessage(); + exit(0); + } + SmallVector Positional; for (auto Arg : InputArgs.filtered(OBJCOPY_UNKNOWN)) @@ -1019,6 +1024,11 @@ static DriverConfig parseStripOptions(ArrayRef ArgsArr) { exit(0); } + if (InputArgs.hasArg(STRIP_version)) { + cl::PrintVersionMessage(); + exit(0); + } + SmallVector Positional; for (auto Arg : InputArgs.filtered(STRIP_UNKNOWN)) error("unknown argument '" + Arg->getAsString(InputArgs) + "'");