diff options
| author | Jordan Rupprecht <rupprecht@google.com> | 2018-10-12 00:36:01 +0000 |
|---|---|---|
| committer | Jordan Rupprecht <rupprecht@google.com> | 2018-10-12 00:36:01 +0000 |
| commit | bb4588e9c187b33667cd8b8ccfd4219b3e1c8cae (patch) | |
| tree | fa54aae9e097b04f67b38c32217a2ab6f126435a /llvm | |
| parent | 56b6660d2ed92f3d879eac6e49e70e9279aca9da (diff) | |
| download | bcm5719-llvm-bb4588e9c187b33667cd8b8ccfd4219b3e1c8cae.tar.gz bcm5719-llvm-bb4588e9c187b33667cd8b8ccfd4219b3e1c8cae.zip | |
[llvm-objcopy] Add -F|--target compatibility
Summary:
This change adds support for the GNU --target flag, which sets both --input-target and --output-target.
GNU objcopy doesn't do any checking for whether both --target and --{input,output}-target are used, and so it allows both, e.g. "--target A --output-target B" is equivalent to "--input-target A --output-target B" since the later command line flag would override earlier ones. This may be error prone, so I chose to implement it as an error if both are used. I'm not sure if anyone is actually using both.
Reviewers: jakehehrlich, jhenderson, alexshap
Reviewed By: jakehehrlich, alexshap
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D53029
llvm-svn: 344321
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/test/tools/llvm-objcopy/input-output-target.test | 22 | ||||
| -rw-r--r-- | llvm/tools/llvm-objcopy/CopyConfig.cpp | 14 | ||||
| -rw-r--r-- | llvm/tools/llvm-objcopy/ObjcopyOpts.td | 4 |
3 files changed, 38 insertions, 2 deletions
diff --git a/llvm/test/tools/llvm-objcopy/input-output-target.test b/llvm/test/tools/llvm-objcopy/input-output-target.test new file mode 100644 index 00000000000..e81770a239a --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/input-output-target.test @@ -0,0 +1,22 @@ +# RUN: echo abcd > %t.txt + +# Preserve input to verify it is not modified +# RUN: cp %t.txt %t-copy.txt + +# -F <target> is equivalent to -I <target> -O <target> +# RUN: llvm-objcopy -F binary -B i386:x86-64 %t.txt %t.2.txt +# RUN: cmp %t-copy.txt %t.2.txt + +# --target <target> is equivalent to --input-target <target> --output-target <target> +# RUN: llvm-objcopy --target binary -B i386:x86-64 %t.txt %t.3.txt +# RUN: cmp %t-copy.txt %t.3.txt + +# TODO: check --target and --input-target/--output-target are incompatible +# RUN: not llvm-objcopy --target binary --input-target binary -B i386:x86-64 \ +# RUN: %t.txt %t.4.txt 2>&1 \ +# RUN: | FileCheck %s --check-prefix=BAD-FLAG +# RUN: not llvm-objcopy --target binary --output-target binary -B i386:x86-64 \ +# RUN: %t.txt %t.4.txt 2>&1 \ +# RUN: | FileCheck %s --check-prefix=BAD-FLAG + +# BAD-FLAG: --target cannot be used with --input-target or --output-target. diff --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp index d814df10525..2c3551ba026 100644 --- a/llvm/tools/llvm-objcopy/CopyConfig.cpp +++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp @@ -247,8 +247,18 @@ DriverConfig parseObjcopyOptions(ArrayRef<const char *> ArgsArr) { CopyConfig Config; Config.InputFilename = Positional[0]; Config.OutputFilename = Positional[Positional.size() == 1 ? 0 : 1]; - Config.InputFormat = InputArgs.getLastArgValue(OBJCOPY_input_target); - Config.OutputFormat = InputArgs.getLastArgValue(OBJCOPY_output_target); + if (InputArgs.hasArg(OBJCOPY_target) && + (InputArgs.hasArg(OBJCOPY_input_target) || + InputArgs.hasArg(OBJCOPY_output_target))) + error("--target cannot be used with --input-target or --output-target"); + + if (InputArgs.hasArg(OBJCOPY_target)) { + Config.InputFormat = InputArgs.getLastArgValue(OBJCOPY_target); + Config.OutputFormat = InputArgs.getLastArgValue(OBJCOPY_target); + } else { + Config.InputFormat = InputArgs.getLastArgValue(OBJCOPY_input_target); + Config.OutputFormat = InputArgs.getLastArgValue(OBJCOPY_output_target); + } if (Config.InputFormat == "binary") { auto BinaryArch = InputArgs.getLastArgValue(OBJCOPY_binary_architecture); if (BinaryArch.empty()) diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td index 18b270b7758..f6c8a959e8b 100644 --- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td +++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td @@ -10,6 +10,10 @@ defm binary_architecture : Eq<"binary-architecture">, HelpText<"Used when transforming an architecture-less format (such as binary) to another format">; def B : JoinedOrSeparate<["-"], "B">, Alias<binary_architecture>; +defm target : Eq<"target">, + HelpText<"Format of the input and output file">, + Values<"binary">; +def F : JoinedOrSeparate<[ "-" ], "F">, Alias<target>; defm input_target : Eq<"input-target">, HelpText<"Format of the input file">, Values<"binary">; |

