aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
diff options
context:
space:
mode:
authorSeiya Nuta <nuta@seiya.me>2019-07-05 05:28:38 +0000
committerSeiya Nuta <nuta@seiya.me>2019-07-05 05:28:38 +0000
commitecb60b7e5ce7bdfb4edb0963aa657db9d4ccb784 (patch)
treee1b8a6a9769d423fc618b963c6028139d4f8fa76 /llvm/tools/llvm-objcopy/llvm-objcopy.cpp
parent3c47d38f61a7196edd607b323868773aa9eb4fe6 (diff)
downloadllvm-ecb60b7e5ce7bdfb4edb0963aa657db9d4ccb784.zip
llvm-ecb60b7e5ce7bdfb4edb0963aa657db9d4ccb784.tar.gz
llvm-ecb60b7e5ce7bdfb4edb0963aa657db9d4ccb784.tar.bz2
[llvm-objcopy][NFC] Refactor output target parsing v2
Summary: Use an enum instead of string to hold the output file format in Config.InputFormat and Config.OutputFormat. It's essential to support other output file formats other than ELF. This patch originally has been submitted as D63239. However, there was an use-of-uninitialized-value bug and reverted in r364379 (git commit 4ee933c). This patch includes the fix for the bug by setting Config.InputFormat/Config.OutputFormat in parseStripOptions. Reviewers: espindola, alexshap, rupprecht, jhenderson Reviewed By: jhenderson Subscribers: emaste, arichardson, jakehehrlich, MaskRay, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64170 llvm-svn: 365173
Diffstat (limited to 'llvm/tools/llvm-objcopy/llvm-objcopy.cpp')
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index d04b1cf..2b0fef1 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -140,11 +140,18 @@ static Error executeObjcopyOnIHex(const CopyConfig &Config, MemoryBuffer &In,
/// of the output specified by the command line options.
static Error executeObjcopyOnRawBinary(const CopyConfig &Config,
MemoryBuffer &In, Buffer &Out) {
- // TODO: llvm-objcopy should parse CopyConfig.OutputFormat to recognize
- // formats other than ELF / "binary" and invoke
- // elf::executeObjcopyOnRawBinary, macho::executeObjcopyOnRawBinary or
- // coff::executeObjcopyOnRawBinary accordingly.
- return elf::executeObjcopyOnRawBinary(Config, In, Out);
+ switch (Config.OutputFormat) {
+ case FileFormat::ELF:
+ // FIXME: Currently, we call elf::executeObjcopyOnRawBinary even if the
+ // output format is binary/ihex or it's not given. This behavior differs from
+ // GNU objcopy. See https://bugs.llvm.org/show_bug.cgi?id=42171 for details.
+ case FileFormat::Binary:
+ case FileFormat::IHex:
+ case FileFormat::Unspecified:
+ return elf::executeObjcopyOnRawBinary(Config, In, Out);
+ }
+
+ llvm_unreachable("unsupported output format");
}
/// The function executeObjcopyOnBinary does the dispatch based on the format
@@ -238,10 +245,17 @@ static Error executeObjcopy(const CopyConfig &Config) {
}
typedef Error (*ProcessRawFn)(const CopyConfig &, MemoryBuffer &, Buffer &);
- auto ProcessRaw = StringSwitch<ProcessRawFn>(Config.InputFormat)
- .Case("binary", executeObjcopyOnRawBinary)
- .Case("ihex", executeObjcopyOnIHex)
- .Default(nullptr);
+ ProcessRawFn ProcessRaw;
+ switch (Config.InputFormat) {
+ case FileFormat::Binary:
+ ProcessRaw = executeObjcopyOnRawBinary;
+ break;
+ case FileFormat::IHex:
+ ProcessRaw = executeObjcopyOnIHex;
+ break;
+ default:
+ ProcessRaw = nullptr;
+ }
if (ProcessRaw) {
auto BufOrErr = MemoryBuffer::getFileOrSTDIN(Config.InputFilename);