summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
diff options
context:
space:
mode:
authorJake Ehrlich <jakehehrlich@google.com>2017-11-14 18:41:47 +0000
committerJake Ehrlich <jakehehrlich@google.com>2017-11-14 18:41:47 +0000
commit99e2c41c1aecb77d1b7f3ab74ced9db2a54e5386 (patch)
tree1c603fad438138f89f46054e4ffb024c08ffe133 /llvm/tools/llvm-objcopy/llvm-objcopy.cpp
parentb8a11bbcf139087b7487dee78af275bd87c5d39d (diff)
downloadbcm5719-llvm-99e2c41c1aecb77d1b7f3ab74ced9db2a54e5386.tar.gz
bcm5719-llvm-99e2c41c1aecb77d1b7f3ab74ced9db2a54e5386.zip
[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
Diffstat (limited to 'llvm/tools/llvm-objcopy/llvm-objcopy.cpp')
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp25
1 files changed, 19 insertions, 6 deletions
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<ELFT> &ObjFile, StringRef File) {
WriteObjectFile(DWOFile, File);
}
-void CopyBinary(const ELFObjectFile<ELF64LE> &ObjFile) {
- std::unique_ptr<Object<ELF64LE>> Obj;
+template <class ELFT>
+void CopyBinary(const ELFObjectFile<ELFT> &ObjFile) {
+ std::unique_ptr<Object<ELFT>> Obj;
if (!OutputFormat.empty() && OutputFormat != "binary")
error("invalid output format '" + OutputFormat + "'");
if (!OutputFormat.empty() && OutputFormat == "binary")
- Obj = llvm::make_unique<BinaryObject<ELF64LE>>(ObjFile);
+ Obj = llvm::make_unique<BinaryObject<ELFT>>(ObjFile);
else
- Obj = llvm::make_unique<ELFObject<ELF64LE>>(ObjFile);
+ Obj = llvm::make_unique<ELFObject<ELFT>>(ObjFile);
if (!SplitDWO.empty())
- SplitDWOToFile<ELF64LE>(ObjFile, SplitDWO.getValue());
+ SplitDWOToFile<ELFT>(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<ELF64LE> *o = dyn_cast<ELFObjectFile<ELF64LE>>(&Binary)) {
+ if (auto *o = dyn_cast<ELFObjectFile<ELF64LE>>(&Binary)) {
+ CopyBinary(*o);
+ return 0;
+ }
+ if (auto *o = dyn_cast<ELFObjectFile<ELF32LE>>(&Binary)) {
+ CopyBinary(*o);
+ return 0;
+ }
+ if (auto *o = dyn_cast<ELFObjectFile<ELF64BE>>(&Binary)) {
+ CopyBinary(*o);
+ return 0;
+ }
+ if (auto *o = dyn_cast<ELFObjectFile<ELF32BE>>(&Binary)) {
CopyBinary(*o);
return 0;
}
OpenPOWER on IntegriCloud