From 99e2c41c1aecb77d1b7f3ab74ced9db2a54e5386 Mon Sep 17 00:00:00 2001 From: Jake Ehrlich Date: Tue, 14 Nov 2017 18:41:47 +0000 Subject: [llvm-objcopy] Support the rest of the ELF formats We haven't been supporting anything but ELF64LE since the start. Luckily this was always accounted for and the change is pretty trivial. B35281 requests this change for ELF32LE. This change adds support for ELF32LE, ELF64BE, and ELF32BE with all supported features that already existed for ELF64LE. Differential Revision: https://reviews.llvm.org/D39977 llvm-svn: 318166 --- llvm/tools/llvm-objcopy/llvm-objcopy.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'llvm/tools/llvm-objcopy') diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp index b520a1415c2..f7a94f5f891 100644 --- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp +++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp @@ -142,18 +142,19 @@ void SplitDWOToFile(const ELFObjectFile &ObjFile, StringRef File) { WriteObjectFile(DWOFile, File); } -void CopyBinary(const ELFObjectFile &ObjFile) { - std::unique_ptr> Obj; +template +void CopyBinary(const ELFObjectFile &ObjFile) { + std::unique_ptr> Obj; if (!OutputFormat.empty() && OutputFormat != "binary") error("invalid output format '" + OutputFormat + "'"); if (!OutputFormat.empty() && OutputFormat == "binary") - Obj = llvm::make_unique>(ObjFile); + Obj = llvm::make_unique>(ObjFile); else - Obj = llvm::make_unique>(ObjFile); + Obj = llvm::make_unique>(ObjFile); if (!SplitDWO.empty()) - SplitDWOToFile(ObjFile, SplitDWO.getValue()); + SplitDWOToFile(ObjFile, SplitDWO.getValue()); SectionPred RemovePred = [](const SectionBase &) { return false; }; @@ -225,7 +226,19 @@ int main(int argc, char **argv) { if (!BinaryOrErr) reportError(InputFilename, BinaryOrErr.takeError()); Binary &Binary = *BinaryOrErr.get().getBinary(); - if (ELFObjectFile *o = dyn_cast>(&Binary)) { + if (auto *o = dyn_cast>(&Binary)) { + CopyBinary(*o); + return 0; + } + if (auto *o = dyn_cast>(&Binary)) { + CopyBinary(*o); + return 0; + } + if (auto *o = dyn_cast>(&Binary)) { + CopyBinary(*o); + return 0; + } + if (auto *o = dyn_cast>(&Binary)) { CopyBinary(*o); return 0; } -- cgit v1.2.3