diff options
| author | Fangrui Song <maskray@google.com> | 2019-09-14 01:36:16 +0000 |
|---|---|---|
| committer | Fangrui Song <maskray@google.com> | 2019-09-14 01:36:16 +0000 |
| commit | ba53030dd0938902dd858f7eac45732295e74120 (patch) | |
| tree | 77f51df48d84d05bfae455e8cb0757d0214a279c /llvm/tools/llvm-objcopy | |
| parent | 8a468031cd0b088d0f0b01df72d981885a6d4e89 (diff) | |
| download | bcm5719-llvm-ba53030dd0938902dd858f7eac45732295e74120.tar.gz bcm5719-llvm-ba53030dd0938902dd858f7eac45732295e74120.zip | |
[llvm-objcopy] Default --output-target to --input-target when unspecified
Fixes PR42171.
In GNU objcopy, if -O (--output-target) is not specified, the value is
copied from -I (--input-target).
```
objcopy -I binary -B i386:x86-64 a.txt b # b is copied from a.txt
llvm-objcopy -I binary -B i386:x86-64 a.txt b # b is an x86-64 object file
```
This patch changes our behavior to match GNU. With this change, we can
delete code related to -B handling (D67215).
Reviewed By: jakehehrlich
Differential Revision: https://reviews.llvm.org/D67144
llvm-svn: 371913
Diffstat (limited to 'llvm/tools/llvm-objcopy')
| -rw-r--r-- | llvm/tools/llvm-objcopy/CopyConfig.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp index d235f23e13d..73e9221a476 100644 --- a/llvm/tools/llvm-objcopy/CopyConfig.cpp +++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp @@ -491,14 +491,12 @@ Expected<DriverConfig> parseObjcopyOptions(ArrayRef<const char *> ArgsArr) { .Default(FileFormat::Unspecified); if (Config.InputFormat == FileFormat::Binary) { auto BinaryArch = InputArgs.getLastArgValue(OBJCOPY_binary_architecture); - if (BinaryArch.empty()) - return createStringError( - errc::invalid_argument, - "specified binary input without specifiying an architecture"); - Expected<const MachineInfo &> MI = getMachineInfo(BinaryArch); - if (!MI) - return MI.takeError(); - Config.BinaryArch = *MI; + if (!BinaryArch.empty()) { + Expected<const MachineInfo &> MI = getMachineInfo(BinaryArch); + if (!MI) + return MI.takeError(); + Config.BinaryArch = *MI; + } } if (opt::Arg *A = InputArgs.getLastArg(OBJCOPY_new_symbol_visibility)) { @@ -520,12 +518,17 @@ Expected<DriverConfig> parseObjcopyOptions(ArrayRef<const char *> ArgsArr) { .Case("binary", FileFormat::Binary) .Case("ihex", FileFormat::IHex) .Default(FileFormat::Unspecified); - if (Config.OutputFormat == FileFormat::Unspecified && !OutputFormat.empty()) { - Expected<TargetInfo> Target = getOutputTargetInfoByTargetName(OutputFormat); - if (!Target) - return Target.takeError(); - Config.OutputFormat = Target->Format; - Config.OutputArch = Target->Machine; + if (Config.OutputFormat == FileFormat::Unspecified) { + if (OutputFormat.empty()) { + Config.OutputFormat = Config.InputFormat; + } else { + Expected<TargetInfo> Target = + getOutputTargetInfoByTargetName(OutputFormat); + if (!Target) + return Target.takeError(); + Config.OutputFormat = Target->Format; + Config.OutputArch = Target->Machine; + } } if (auto Arg = InputArgs.getLastArg(OBJCOPY_compress_debug_sections, |

