From bed93b0de197c6b64357068ae8e1a883ddbb0e94 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 9 May 2013 13:13:28 +0000 Subject: [PATCH] Introduce convenience typedefs for the 4 ELF object types. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181509 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/ELF.h | 31 ++++++++++++----------- tools/llvm-objdump/ELFDump.cpp | 12 +++------ tools/llvm-readobj/ELFDumper.cpp | 42 ++++++++++++-------------------- 3 files changed, 35 insertions(+), 50 deletions(-) diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index beff6efabbb..22ca201be12 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -839,6 +839,13 @@ public: } }; +// Use an alignment of 2 for the typedefs since that is the worst case for +// ELF files in archives. +typedef ELFObjectFile > ELF32LEObjectFile; +typedef ELFObjectFile > ELF64LEObjectFile; +typedef ELFObjectFile > ELF32BEObjectFile; +typedef ELFObjectFile > ELF64BEObjectFile; + // Iterate through the version definitions, and place each Elf_Verdef // in the VersionMap according to its index. template @@ -2955,23 +2962,19 @@ static inline error_code getELFRelocationAddend(const RelocationRef R, const ObjectFile *Obj = R.getObjectFile(); DataRefImpl DRI = R.getRawDataRefImpl(); // Little-endian 32-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(Obj)) + if (const ELF32LEObjectFile *ELFObj = dyn_cast(Obj)) return ELFObj->getRelocationAddend(DRI, Addend); // Big-endian 32-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(Obj)) + if (const ELF32BEObjectFile *ELFObj = dyn_cast(Obj)) return ELFObj->getRelocationAddend(DRI, Addend); // Little-endian 64-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(Obj)) + if (const ELF64LEObjectFile *ELFObj = dyn_cast(Obj)) return ELFObj->getRelocationAddend(DRI, Addend); // Big-endian 64-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(Obj)) + if (const ELF64BEObjectFile *ELFObj = dyn_cast(Obj)) return ELFObj->getRelocationAddend(DRI, Addend); llvm_unreachable("Object passed to getELFRelocationAddend() is not ELF"); @@ -2984,23 +2987,19 @@ static inline error_code GetELFSymbolVersion(const ObjectFile *Obj, StringRef &Version, bool &IsDefault) { // Little-endian 32-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(Obj)) + if (const ELF32LEObjectFile *ELFObj = dyn_cast(Obj)) return ELFObj->getSymbolVersion(Sym, Version, IsDefault); // Big-endian 32-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(Obj)) + if (const ELF32BEObjectFile *ELFObj = dyn_cast(Obj)) return ELFObj->getSymbolVersion(Sym, Version, IsDefault); // Little-endian 64-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(Obj)) + if (const ELF64LEObjectFile *ELFObj = dyn_cast(Obj)) return ELFObj->getSymbolVersion(Sym, Version, IsDefault); // Big-endian 64-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(Obj)) + if (const ELF64BEObjectFile *ELFObj = dyn_cast(Obj)) return ELFObj->getSymbolVersion(Sym, Version, IsDefault); llvm_unreachable("Object passed to GetELFSymbolVersion() is not ELF"); diff --git a/tools/llvm-objdump/ELFDump.cpp b/tools/llvm-objdump/ELFDump.cpp index bd1523133f5..b9526734c9f 100644 --- a/tools/llvm-objdump/ELFDump.cpp +++ b/tools/llvm-objdump/ELFDump.cpp @@ -79,22 +79,18 @@ void printProgramHeaders( void llvm::printELFFileHeader(const object::ObjectFile *Obj) { // Little-endian 32-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(Obj)) + if (const ELF32LEObjectFile *ELFObj = dyn_cast(Obj)) printProgramHeaders(ELFObj); // Big-endian 32-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(Obj)) + if (const ELF32BEObjectFile *ELFObj = dyn_cast(Obj)) printProgramHeaders(ELFObj); // Little-endian 64-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(Obj)) + if (const ELF64LEObjectFile *ELFObj = dyn_cast(Obj)) printProgramHeaders(ELFObj); // Big-endian 64-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(Obj)) + if (const ELF64BEObjectFile *ELFObj = dyn_cast(Obj)) printProgramHeaders(ELFObj); } diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 66cec615ad5..2427b7d3b14 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -69,42 +69,32 @@ private: namespace llvm { +template +static error_code createELFDumper(const ELFObjectFile *Obj, + StreamWriter &Writer, + OwningPtr &Result) { + Result.reset(new ELFDumper(Obj, Writer)); + return readobj_error::success; +} + error_code createELFDumper(const object::ObjectFile *Obj, StreamWriter& Writer, OwningPtr &Result) { - typedef ELFType Little32ELF; - typedef ELFType Big32ELF; - typedef ELFType Little64ELF; - typedef ELFType Big64ELF; - - typedef ELFObjectFile LittleELF32Obj; - typedef ELFObjectFile BigELF32Obj; - typedef ELFObjectFile LittleELF64Obj; - typedef ELFObjectFile BigELF64Obj; - // Little-endian 32-bit - if (const LittleELF32Obj *ELFObj = dyn_cast(Obj)) { - Result.reset(new ELFDumper(ELFObj, Writer)); - return readobj_error::success; - } + if (const ELF32LEObjectFile *ELFObj = dyn_cast(Obj)) + return createELFDumper(ELFObj, Writer, Result); // Big-endian 32-bit - if (const BigELF32Obj *ELFObj = dyn_cast(Obj)) { - Result.reset(new ELFDumper(ELFObj, Writer)); - return readobj_error::success; - } + if (const ELF32BEObjectFile *ELFObj = dyn_cast(Obj)) + return createELFDumper(ELFObj, Writer, Result); // Little-endian 64-bit - if (const LittleELF64Obj *ELFObj = dyn_cast(Obj)) { - Result.reset(new ELFDumper(ELFObj, Writer)); - return readobj_error::success; - } + if (const ELF64LEObjectFile *ELFObj = dyn_cast(Obj)) + return createELFDumper(ELFObj, Writer, Result); // Big-endian 64-bit - if (const BigELF64Obj *ELFObj = dyn_cast(Obj)) { - Result.reset(new ELFDumper(ELFObj, Writer)); - return readobj_error::success; - } + if (const ELF64BEObjectFile *ELFObj = dyn_cast(Obj)) + return createELFDumper(ELFObj, Writer, Result); return readobj_error::unsupported_obj_file_format; } -- 2.34.1