[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
This commit is contained in:
Jordan Rupprecht 2018-09-21 00:47:31 +00:00
parent 7b73473893
commit 5b1329de30
5 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,4 @@
# RUN: llvm-objcopy -version | FileCheck %s
# RUN: llvm-objcopy --version | FileCheck %s
# CHECK: {{ version }}

View File

@ -0,0 +1,4 @@
# RUN: llvm-strip -version | FileCheck %s
# RUN: llvm-strip --version | FileCheck %s
# CHECK: {{ version }}

View File

@ -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 <symbol> as weak">;

View File

@ -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<discard_all>;

View File

@ -892,6 +892,11 @@ static DriverConfig parseObjcopyOptions(ArrayRef<const char *> ArgsArr) {
exit(0);
}
if (InputArgs.hasArg(OBJCOPY_version)) {
cl::PrintVersionMessage();
exit(0);
}
SmallVector<const char *, 2> Positional;
for (auto Arg : InputArgs.filtered(OBJCOPY_UNKNOWN))
@ -1019,6 +1024,11 @@ static DriverConfig parseStripOptions(ArrayRef<const char *> ArgsArr) {
exit(0);
}
if (InputArgs.hasArg(STRIP_version)) {
cl::PrintVersionMessage();
exit(0);
}
SmallVector<const char *, 2> Positional;
for (auto Arg : InputArgs.filtered(STRIP_UNKNOWN))
error("unknown argument '" + Arg->getAsString(InputArgs) + "'");