[Object] Split the ELF interface into 3 parts.

* ELFTypes.h contains template magic for defining types based on endianess, size, and alignment.
* ELFFile.h defines the ELFFile class which provides low level ELF specific access.
* ELFObjectFile.h contains ELFObjectFile which uses ELFFile to implement the ObjectFile interface.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188022 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael J. Spencer 2013-08-08 22:27:13 +00:00
parent 491d04969d
commit 081a1941b5
17 changed files with 2845 additions and 2761 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,463 @@
//===- ELFTypes.h - Endian specific types for ELF ---------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_OBJECT_ELF_TYPES_H
#define LLVM_OBJECT_ELF_TYPES_H
#include "llvm/Support/AlignOf.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/Endian.h"
namespace llvm {
namespace object {
using support::endianness;
template <endianness target_endianness, std::size_t max_alignment,
bool is64Bits>
struct ELFType {
static const endianness TargetEndianness = target_endianness;
static const std::size_t MaxAlignment = max_alignment;
static const bool Is64Bits = is64Bits;
};
template <typename T, int max_align> struct MaximumAlignment {
enum { value = AlignOf<T>::Alignment > max_align ? max_align
: AlignOf<T>::Alignment
};
};
// Templates to choose Elf_Addr and Elf_Off depending on is64Bits.
template <endianness target_endianness, std::size_t max_alignment>
struct ELFDataTypeTypedefHelperCommon {
typedef support::detail::packed_endian_specific_integral<
uint16_t, target_endianness,
MaximumAlignment<uint16_t, max_alignment>::value> Elf_Half;
typedef support::detail::packed_endian_specific_integral<
uint32_t, target_endianness,
MaximumAlignment<uint32_t, max_alignment>::value> Elf_Word;
typedef support::detail::packed_endian_specific_integral<
int32_t, target_endianness,
MaximumAlignment<int32_t, max_alignment>::value> Elf_Sword;
typedef support::detail::packed_endian_specific_integral<
uint64_t, target_endianness,
MaximumAlignment<uint64_t, max_alignment>::value> Elf_Xword;
typedef support::detail::packed_endian_specific_integral<
int64_t, target_endianness,
MaximumAlignment<int64_t, max_alignment>::value> Elf_Sxword;
};
template <class ELFT> struct ELFDataTypeTypedefHelper;
/// ELF 32bit types.
template <endianness TargetEndianness, std::size_t MaxAlign>
struct ELFDataTypeTypedefHelper<ELFType<TargetEndianness, MaxAlign, false> >
: ELFDataTypeTypedefHelperCommon<TargetEndianness, MaxAlign> {
typedef uint32_t value_type;
typedef support::detail::packed_endian_specific_integral<
value_type, TargetEndianness,
MaximumAlignment<value_type, MaxAlign>::value> Elf_Addr;
typedef support::detail::packed_endian_specific_integral<
value_type, TargetEndianness,
MaximumAlignment<value_type, MaxAlign>::value> Elf_Off;
};
/// ELF 64bit types.
template <endianness TargetEndianness, std::size_t MaxAlign>
struct ELFDataTypeTypedefHelper<ELFType<TargetEndianness, MaxAlign, true> >
: ELFDataTypeTypedefHelperCommon<TargetEndianness, MaxAlign> {
typedef uint64_t value_type;
typedef support::detail::packed_endian_specific_integral<
value_type, TargetEndianness,
MaximumAlignment<value_type, MaxAlign>::value> Elf_Addr;
typedef support::detail::packed_endian_specific_integral<
value_type, TargetEndianness,
MaximumAlignment<value_type, MaxAlign>::value> Elf_Off;
};
// I really don't like doing this, but the alternative is copypasta.
#define LLVM_ELF_IMPORT_TYPES(E, M, W) \
typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Addr \
Elf_Addr; \
typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Off \
Elf_Off; \
typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Half \
Elf_Half; \
typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Word \
Elf_Word; \
typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Sword \
Elf_Sword; \
typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Xword \
Elf_Xword; \
typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Sxword \
Elf_Sxword;
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) \
LLVM_ELF_IMPORT_TYPES(ELFT::TargetEndianness, ELFT::MaxAlignment, \
ELFT::Is64Bits)
// Section header.
template <class ELFT> struct Elf_Shdr_Base;
template <endianness TargetEndianness, std::size_t MaxAlign>
struct Elf_Shdr_Base<ELFType<TargetEndianness, MaxAlign, false> > {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
Elf_Word sh_name; // Section name (index into string table)
Elf_Word sh_type; // Section type (SHT_*)
Elf_Word sh_flags; // Section flags (SHF_*)
Elf_Addr sh_addr; // Address where section is to be loaded
Elf_Off sh_offset; // File offset of section data, in bytes
Elf_Word sh_size; // Size of section, in bytes
Elf_Word sh_link; // Section type-specific header table index link
Elf_Word sh_info; // Section type-specific extra information
Elf_Word sh_addralign; // Section address alignment
Elf_Word sh_entsize; // Size of records contained within the section
};
template <endianness TargetEndianness, std::size_t MaxAlign>
struct Elf_Shdr_Base<ELFType<TargetEndianness, MaxAlign, true> > {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
Elf_Word sh_name; // Section name (index into string table)
Elf_Word sh_type; // Section type (SHT_*)
Elf_Xword sh_flags; // Section flags (SHF_*)
Elf_Addr sh_addr; // Address where section is to be loaded
Elf_Off sh_offset; // File offset of section data, in bytes
Elf_Xword sh_size; // Size of section, in bytes
Elf_Word sh_link; // Section type-specific header table index link
Elf_Word sh_info; // Section type-specific extra information
Elf_Xword sh_addralign; // Section address alignment
Elf_Xword sh_entsize; // Size of records contained within the section
};
template <class ELFT>
struct Elf_Shdr_Impl : Elf_Shdr_Base<ELFT> {
using Elf_Shdr_Base<ELFT>::sh_entsize;
using Elf_Shdr_Base<ELFT>::sh_size;
/// @brief Get the number of entities this section contains if it has any.
unsigned getEntityCount() const {
if (sh_entsize == 0)
return 0;
return sh_size / sh_entsize;
}
};
template <class ELFT> struct Elf_Sym_Base;
template <endianness TargetEndianness, std::size_t MaxAlign>
struct Elf_Sym_Base<ELFType<TargetEndianness, MaxAlign, false> > {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
Elf_Word st_name; // Symbol name (index into string table)
Elf_Addr st_value; // Value or address associated with the symbol
Elf_Word st_size; // Size of the symbol
unsigned char st_info; // Symbol's type and binding attributes
unsigned char st_other; // Must be zero; reserved
Elf_Half st_shndx; // Which section (header table index) it's defined in
};
template <endianness TargetEndianness, std::size_t MaxAlign>
struct Elf_Sym_Base<ELFType<TargetEndianness, MaxAlign, true> > {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
Elf_Word st_name; // Symbol name (index into string table)
unsigned char st_info; // Symbol's type and binding attributes
unsigned char st_other; // Must be zero; reserved
Elf_Half st_shndx; // Which section (header table index) it's defined in
Elf_Addr st_value; // Value or address associated with the symbol
Elf_Xword st_size; // Size of the symbol
};
template <class ELFT>
struct Elf_Sym_Impl : Elf_Sym_Base<ELFT> {
using Elf_Sym_Base<ELFT>::st_info;
// These accessors and mutators correspond to the ELF32_ST_BIND,
// ELF32_ST_TYPE, and ELF32_ST_INFO macros defined in the ELF specification:
unsigned char getBinding() const { return st_info >> 4; }
unsigned char getType() const { return st_info & 0x0f; }
void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
void setBindingAndType(unsigned char b, unsigned char t) {
st_info = (b << 4) + (t & 0x0f);
}
};
/// Elf_Versym: This is the structure of entries in the SHT_GNU_versym section
/// (.gnu.version). This structure is identical for ELF32 and ELF64.
template <class ELFT>
struct Elf_Versym_Impl {
LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
Elf_Half vs_index; // Version index with flags (e.g. VERSYM_HIDDEN)
};
template <class ELFT> struct Elf_Verdaux_Impl;
/// Elf_Verdef: This is the structure of entries in the SHT_GNU_verdef section
/// (.gnu.version_d). This structure is identical for ELF32 and ELF64.
template <class ELFT>
struct Elf_Verdef_Impl {
LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
typedef Elf_Verdaux_Impl<ELFT> Elf_Verdaux;
Elf_Half vd_version; // Version of this structure (e.g. VER_DEF_CURRENT)
Elf_Half vd_flags; // Bitwise flags (VER_DEF_*)
Elf_Half vd_ndx; // Version index, used in .gnu.version entries
Elf_Half vd_cnt; // Number of Verdaux entries
Elf_Word vd_hash; // Hash of name
Elf_Word vd_aux; // Offset to the first Verdaux entry (in bytes)
Elf_Word vd_next; // Offset to the next Verdef entry (in bytes)
/// Get the first Verdaux entry for this Verdef.
const Elf_Verdaux *getAux() const {
return reinterpret_cast<const Elf_Verdaux *>((const char *)this + vd_aux);
}
};
/// Elf_Verdaux: This is the structure of auxiliary data in the SHT_GNU_verdef
/// section (.gnu.version_d). This structure is identical for ELF32 and ELF64.
template <class ELFT>
struct Elf_Verdaux_Impl {
LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
Elf_Word vda_name; // Version name (offset in string table)
Elf_Word vda_next; // Offset to next Verdaux entry (in bytes)
};
/// Elf_Verneed: This is the structure of entries in the SHT_GNU_verneed
/// section (.gnu.version_r). This structure is identical for ELF32 and ELF64.
template <class ELFT>
struct Elf_Verneed_Impl {
LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
Elf_Half vn_version; // Version of this structure (e.g. VER_NEED_CURRENT)
Elf_Half vn_cnt; // Number of associated Vernaux entries
Elf_Word vn_file; // Library name (string table offset)
Elf_Word vn_aux; // Offset to first Vernaux entry (in bytes)
Elf_Word vn_next; // Offset to next Verneed entry (in bytes)
};
/// Elf_Vernaux: This is the structure of auxiliary data in SHT_GNU_verneed
/// section (.gnu.version_r). This structure is identical for ELF32 and ELF64.
template <class ELFT>
struct Elf_Vernaux_Impl {
LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
Elf_Word vna_hash; // Hash of dependency name
Elf_Half vna_flags; // Bitwise Flags (VER_FLAG_*)
Elf_Half vna_other; // Version index, used in .gnu.version entries
Elf_Word vna_name; // Dependency name
Elf_Word vna_next; // Offset to next Vernaux entry (in bytes)
};
/// Elf_Dyn_Base: This structure matches the form of entries in the dynamic
/// table section (.dynamic) look like.
template <class ELFT> struct Elf_Dyn_Base;
template <endianness TargetEndianness, std::size_t MaxAlign>
struct Elf_Dyn_Base<ELFType<TargetEndianness, MaxAlign, false> > {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
Elf_Sword d_tag;
union {
Elf_Word d_val;
Elf_Addr d_ptr;
} d_un;
};
template <endianness TargetEndianness, std::size_t MaxAlign>
struct Elf_Dyn_Base<ELFType<TargetEndianness, MaxAlign, true> > {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
Elf_Sxword d_tag;
union {
Elf_Xword d_val;
Elf_Addr d_ptr;
} d_un;
};
/// Elf_Dyn_Impl: This inherits from Elf_Dyn_Base, adding getters and setters.
template <class ELFT>
struct Elf_Dyn_Impl : Elf_Dyn_Base<ELFT> {
using Elf_Dyn_Base<ELFT>::d_tag;
using Elf_Dyn_Base<ELFT>::d_un;
int64_t getTag() const { return d_tag; }
uint64_t getVal() const { return d_un.d_val; }
uint64_t getPtr() const { return d_un.ptr; }
};
// Elf_Rel: Elf Relocation
template <class ELFT, bool isRela> struct Elf_Rel_Base;
template <endianness TargetEndianness, std::size_t MaxAlign>
struct Elf_Rel_Base<ELFType<TargetEndianness, MaxAlign, false>, false> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
Elf_Word r_info; // Symbol table index and type of relocation to apply
uint32_t getRInfo(bool isMips64EL) const {
assert(!isMips64EL);
return r_info;
}
void setRInfo(uint32_t R) { r_info = R; }
};
template <endianness TargetEndianness, std::size_t MaxAlign>
struct Elf_Rel_Base<ELFType<TargetEndianness, MaxAlign, true>, false> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
Elf_Xword r_info; // Symbol table index and type of relocation to apply
uint64_t getRInfo(bool isMips64EL) const {
uint64_t t = r_info;
if (!isMips64EL)
return t;
// Mips64 little endian has a "special" encoding of r_info. Instead of one
// 64 bit little endian number, it is a little endian 32 bit number followed
// by a 32 bit big endian number.
return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
}
void setRInfo(uint64_t R) {
// FIXME: Add mips64el support.
r_info = R;
}
};
template <endianness TargetEndianness, std::size_t MaxAlign>
struct Elf_Rel_Base<ELFType<TargetEndianness, MaxAlign, false>, true> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
Elf_Word r_info; // Symbol table index and type of relocation to apply
Elf_Sword r_addend; // Compute value for relocatable field by adding this
uint32_t getRInfo(bool isMips64EL) const {
assert(!isMips64EL);
return r_info;
}
void setRInfo(uint32_t R) { r_info = R; }
};
template <endianness TargetEndianness, std::size_t MaxAlign>
struct Elf_Rel_Base<ELFType<TargetEndianness, MaxAlign, true>, true> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
Elf_Xword r_info; // Symbol table index and type of relocation to apply
Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
uint64_t getRInfo(bool isMips64EL) const {
// Mips64 little endian has a "special" encoding of r_info. Instead of one
// 64 bit little endian number, it is a little endian 32 bit number followed
// by a 32 bit big endian number.
uint64_t t = r_info;
if (!isMips64EL)
return t;
return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
}
void setRInfo(uint64_t R) {
// FIXME: Add mips64el support.
r_info = R;
}
};
template <class ELFT, bool isRela> struct Elf_Rel_Impl;
template <endianness TargetEndianness, std::size_t MaxAlign, bool isRela>
struct Elf_Rel_Impl<ELFType<TargetEndianness, MaxAlign, true>,
isRela> : Elf_Rel_Base<
ELFType<TargetEndianness, MaxAlign, true>, isRela> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
// These accessors and mutators correspond to the ELF64_R_SYM, ELF64_R_TYPE,
// and ELF64_R_INFO macros defined in the ELF specification:
uint32_t getSymbol(bool isMips64EL) const {
return (uint32_t)(this->getRInfo(isMips64EL) >> 32);
}
uint32_t getType(bool isMips64EL) const {
return (uint32_t)(this->getRInfo(isMips64EL) & 0xffffffffL);
}
void setSymbol(uint32_t s) { setSymbolAndType(s, getType()); }
void setType(uint32_t t) { setSymbolAndType(getSymbol(), t); }
void setSymbolAndType(uint32_t s, uint32_t t) {
this->setRInfo(((uint64_t)s << 32) + (t & 0xffffffffL));
}
};
template <endianness TargetEndianness, std::size_t MaxAlign, bool isRela>
struct Elf_Rel_Impl<ELFType<TargetEndianness, MaxAlign, false>,
isRela> : Elf_Rel_Base<
ELFType<TargetEndianness, MaxAlign, false>, isRela> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
// These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
// and ELF32_R_INFO macros defined in the ELF specification:
uint32_t getSymbol(bool isMips64EL) const {
return this->getRInfo(isMips64EL) >> 8;
}
unsigned char getType(bool isMips64EL) const {
return (unsigned char)(this->getRInfo(isMips64EL) & 0x0ff);
}
void setSymbol(uint32_t s) { setSymbolAndType(s, getType()); }
void setType(unsigned char t) { setSymbolAndType(getSymbol(), t); }
void setSymbolAndType(uint32_t s, unsigned char t) {
this->setRInfo((s << 8) + t);
}
};
template <class ELFT>
struct Elf_Ehdr_Impl {
LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
unsigned char e_ident[ELF::EI_NIDENT]; // ELF Identification bytes
Elf_Half e_type; // Type of file (see ET_*)
Elf_Half e_machine; // Required architecture for this file (see EM_*)
Elf_Word e_version; // Must be equal to 1
Elf_Addr e_entry; // Address to jump to in order to start program
Elf_Off e_phoff; // Program header table's file offset, in bytes
Elf_Off e_shoff; // Section header table's file offset, in bytes
Elf_Word e_flags; // Processor-specific flags
Elf_Half e_ehsize; // Size of ELF header, in bytes
Elf_Half e_phentsize; // Size of an entry in the program header table
Elf_Half e_phnum; // Number of entries in the program header table
Elf_Half e_shentsize; // Size of an entry in the section header table
Elf_Half e_shnum; // Number of entries in the section header table
Elf_Half e_shstrndx; // Section header table index of section name
// string table
bool checkMagic() const {
return (memcmp(e_ident, ELF::ElfMagic, strlen(ELF::ElfMagic))) == 0;
}
unsigned char getFileClass() const { return e_ident[ELF::EI_CLASS]; }
unsigned char getDataEncoding() const { return e_ident[ELF::EI_DATA]; }
};
template <class ELFT> struct Elf_Phdr_Impl;
template <endianness TargetEndianness, std::size_t MaxAlign>
struct Elf_Phdr_Impl<ELFType<TargetEndianness, MaxAlign, false> > {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
Elf_Word p_type; // Type of segment
Elf_Off p_offset; // FileOffset where segment is located, in bytes
Elf_Addr p_vaddr; // Virtual Address of beginning of segment
Elf_Addr p_paddr; // Physical address of beginning of segment (OS-specific)
Elf_Word p_filesz; // Num. of bytes in file image of segment (may be zero)
Elf_Word p_memsz; // Num. of bytes in mem image of segment (may be zero)
Elf_Word p_flags; // Segment flags
Elf_Word p_align; // Segment alignment constraint
};
template <endianness TargetEndianness, std::size_t MaxAlign>
struct Elf_Phdr_Impl<ELFType<TargetEndianness, MaxAlign, true> > {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
Elf_Word p_type; // Type of segment
Elf_Word p_flags; // Segment flags
Elf_Off p_offset; // FileOffset where segment is located, in bytes
Elf_Addr p_vaddr; // Virtual Address of beginning of segment
Elf_Addr p_paddr; // Physical address of beginning of segment (OS-specific)
Elf_Xword p_filesz; // Num. of bytes in file image of segment (may be zero)
Elf_Xword p_memsz; // Num. of bytes in mem image of segment (may be zero)
Elf_Xword p_align; // Segment alignment constraint
};
} // end namespace object.
} // end namespace llvm.
#endif

View File

@ -18,7 +18,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/raw_ostream.h"

View File

@ -22,7 +22,7 @@
#include "llvm/ADT/Triple.h"
#include "llvm/ExecutionEngine/ObjectBuffer.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/ELF.h"
using namespace llvm;
@ -304,7 +304,7 @@ void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section,
}
case ELF::R_AARCH64_PREL32: {
uint64_t Result = Value + Addend - FinalAddress;
assert(static_cast<int64_t>(Result) >= INT32_MIN &&
assert(static_cast<int64_t>(Result) >= INT32_MIN &&
static_cast<int64_t>(Result) <= UINT32_MAX);
*TargetPtr = static_cast<uint32_t>(Result & 0xffffffffU);
break;
@ -316,7 +316,7 @@ void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section,
uint64_t BranchImm = Value + Addend - FinalAddress;
// "Check that -2^27 <= result < 2^27".
assert(-(1LL << 27) <= static_cast<int64_t>(BranchImm) &&
assert(-(1LL << 27) <= static_cast<int64_t>(BranchImm) &&
static_cast<int64_t>(BranchImm) < (1LL << 27));
// AArch64 code is emitted with .rela relocations. The data already in any
@ -341,7 +341,6 @@ void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section,
case ELF::R_AARCH64_MOVW_UABS_G2_NC: {
uint64_t Result = Value + Addend;
// AArch64 code is emitted with .rela relocations. The data already in any
// bits affected by the relocation on entry is garbage.
*TargetPtr &= 0xffe0001fU;

View File

@ -15,7 +15,7 @@
#include "llvm/MC/MCRelocationInfo.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Object/MachO.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
@ -96,7 +96,7 @@ MCObjectSymbolizer::MCObjectSymbolizer(MCContext &Ctx,
const ELF64LEObjectFile *ELFObj = dyn_cast<ELF64LEObjectFile>(Obj);
if (ELFObj == 0)
break;
if (ELFObj->getElfHeader()->e_type == ELF::ET_REL) {
if (ELFObj->getELFFile()->getHeader()->e_type == ELF::ET_REL) {
RI->getOffset(Offset);
Offset += StartAddr;
} else {

View File

@ -3,6 +3,7 @@ add_llvm_library(LLVMObject
Binary.cpp
COFFObjectFile.cpp
COFFYAML.cpp
ELF.cpp
ELFObjectFile.cpp
ELFYAML.cpp
Error.cpp

623
lib/Object/ELF.cpp Normal file
View File

@ -0,0 +1,623 @@
//===- ELF.cpp - ELF object file implementation -----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/Object/ELF.h"
namespace llvm {
namespace object {
#define LLVM_ELF_SWITCH_RELOC_TYPE_NAME(enum) \
case ELF::enum: \
return #enum; \
StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type) {
switch (Machine) {
case ELF::EM_X86_64:
switch (Type) {
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_NONE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_PC32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOT32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_PLT32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_COPY);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GLOB_DAT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_JUMP_SLOT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_RELATIVE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTPCREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_32S);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_PC16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_8);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_PC8);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_DTPMOD64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_DTPOFF64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_TPOFF64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_TLSGD);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_TLSLD);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_DTPOFF32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTTPOFF);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_TPOFF32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_PC64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTOFF64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTPC32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOT64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTPCREL64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTPC64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTPLT64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_PLTOFF64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_SIZE32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_SIZE64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTPC32_TLSDESC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_TLSDESC_CALL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_TLSDESC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_IRELATIVE);
default:
break;
}
break;
case ELF::EM_386:
switch (Type) {
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_NONE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_PC32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_GOT32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_PLT32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_COPY);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_GLOB_DAT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_JUMP_SLOT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_RELATIVE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_GOTOFF);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_GOTPC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_32PLT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_TPOFF);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_IE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GOTIE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GD);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LDM);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_PC16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_8);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_PC8);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GD_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GD_PUSH);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GD_CALL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GD_POP);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LDM_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LDM_PUSH);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LDM_CALL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LDM_POP);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LDO_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_IE_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LE_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_DTPMOD32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_DTPOFF32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_TPOFF32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GOTDESC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_DESC_CALL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_DESC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_IRELATIVE);
default:
break;
}
break;
case ELF::EM_MIPS:
switch (Type) {
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_NONE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_REL32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_26);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GPREL16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_LITERAL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GOT16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_PC16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_CALL16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GPREL32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_SHIFT5);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_SHIFT6);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GOT_DISP);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GOT_PAGE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GOT_OFST);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GOT_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GOT_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_SUB);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_INSERT_A);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_INSERT_B);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_DELETE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_HIGHER);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_HIGHEST);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_CALL_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_CALL_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_SCN_DISP);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_REL16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_ADD_IMMEDIATE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_PJUMP);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_RELGOT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_JALR);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_DTPMOD32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_DTPREL32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_DTPMOD64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_DTPREL64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_GD);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_LDM);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_DTPREL_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_DTPREL_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_GOTTPREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_TPREL32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_TPREL64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_TPREL_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_TPREL_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GLOB_DAT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_COPY);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_JUMP_SLOT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_NUM);
default:
break;
}
break;
case ELF::EM_AARCH64:
switch (Type) {
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_NONE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ABS64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ABS32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ABS16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_PREL64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_PREL32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_PREL16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G0_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G1_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G2_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G3);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_SABS_G0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_SABS_G1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_SABS_G2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LD_PREL_LO19);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ADR_PREL_LO21);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ADR_PREL_PG_HI21);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ADD_ABS_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LDST8_ABS_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TSTBR14);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_CONDBR19);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_JUMP26);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_CALL26);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LDST16_ABS_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LDST32_ABS_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LDST64_ABS_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LDST128_ABS_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ADR_GOT_PAGE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LD64_GOT_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_MOVW_DTPREL_G2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_MOVW_DTPREL_G1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_MOVW_DTPREL_G0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_ADD_DTPREL_HI12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_ADD_DTPREL_LO12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST8_DTPREL_LO12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST16_DTPREL_LO12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST32_DTPREL_LO12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST64_DTPREL_LO12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSIE_MOVW_GOTTPREL_G1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_MOVW_TPREL_G2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_MOVW_TPREL_G1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_MOVW_TPREL_G1_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_MOVW_TPREL_G0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_MOVW_TPREL_G0_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_ADD_TPREL_HI12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_ADD_TPREL_LO12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_ADD_TPREL_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST8_TPREL_LO12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST16_TPREL_LO12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST32_TPREL_LO12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST64_TPREL_LO12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSDESC_ADR_PAGE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSDESC_LD64_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSDESC_ADD_LO12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSDESC_CALL);
default:
break;
}
break;
case ELF::EM_ARM:
switch (Type) {
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_NONE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PC24);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ABS32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_REL32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_PC_G0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ABS16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ABS12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_ABS5);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ABS8);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_SBREL32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_CALL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_PC8);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_BREL_ADJ);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_DESC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_SWI8);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_XPC25);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_XPC22);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_DTPMOD32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_DTPOFF32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_TPOFF32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_COPY);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GLOB_DAT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_JUMP_SLOT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_RELATIVE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOTOFF32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_BASE_PREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOT_BREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PLT32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_CALL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_JUMP24);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_JUMP24);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_BASE_ABS);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PCREL_7_0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PCREL_15_8);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PCREL_23_15);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_SBREL_11_0_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SBREL_19_12_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SBREL_27_20_CK);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TARGET1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_SBREL31);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_V4BX);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TARGET2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PREL31);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVW_ABS_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVT_ABS);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVW_PREL_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVT_PREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVW_ABS_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVT_ABS);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVW_PREL_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVT_PREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_JUMP19);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_JUMP6);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_ALU_PREL_11_0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_PC12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ABS32_NOI);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_REL32_NOI);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PC_G0_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PC_G0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PC_G1_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PC_G1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PC_G2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_PC_G1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_PC_G2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDRS_PC_G0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDRS_PC_G1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDRS_PC_G2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDC_PC_G0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDC_PC_G1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDC_PC_G2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SB_G0_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SB_G0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SB_G1_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SB_G1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SB_G2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_SB_G0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_SB_G1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_SB_G2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDRS_SB_G0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDRS_SB_G1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDRS_SB_G2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDC_SB_G0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDC_SB_G1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDC_SB_G2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVW_BREL_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVT_BREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVW_BREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVW_BREL_NC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVT_BREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVW_BREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_GOTDESC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_CALL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_DESCSEQ);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_TLS_CALL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PLT32_ABS);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOT_ABS);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOT_PREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOT_BREL12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOTOFF12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOTRELAX);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GNU_VTENTRY);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GNU_VTINHERIT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_JUMP11);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_JUMP8);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_GD32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_LDM32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_LDO32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_IE32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_LE32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_LDO12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_LE12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_IE12GP);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_3);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_4);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_5);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_6);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_7);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_8);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_9);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_10);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_11);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_13);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_14);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_15);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ME_TOO);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_TLS_DESCSEQ16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_TLS_DESCSEQ32);
default:
break;
}
break;
case ELF::EM_HEXAGON:
switch (Type) {
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_NONE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B22_PCREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B15_PCREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B7_PCREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_8);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GPREL16_0);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GPREL16_1);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GPREL16_2);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GPREL16_3);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_HL16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B13_PCREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B9_PCREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B32_PCREL_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_32_6_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B22_PCREL_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B15_PCREL_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B13_PCREL_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B9_PCREL_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B7_PCREL_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_16_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_12_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_11_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_10_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_9_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_8_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_7_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_6_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_32_PCREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_COPY);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GLOB_DAT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_JMP_SLOT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_RELATIVE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_PLT_B22_PCREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOTREL_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOTREL_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOTREL_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPMOD_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_PLT_B22_PCREL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_6_PCREL_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOTREL_32_6_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOTREL_16_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOTREL_11_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_32_6_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_16_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_11_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_32_6_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_16_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_11_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_32_6_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_16_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_11_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_32_6_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_16_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_32_6_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_16_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_11_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_32_6_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_16_X);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_11_X);
default:
break;
}
break;
case ELF::EM_PPC:
switch (Type) {
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_NONE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR24);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR16_LO);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR16_HI);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR16_HA);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR14);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR14_BRTAKEN);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR14_BRNTAKEN);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL24);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL14);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL14_BRTAKEN);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL14_BRNTAKEN);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_TPREL16_LO);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_TPREL16_HA);
default:
break;
}
break;
case ELF::EM_PPC64:
switch (Type) {
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_NONE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR24);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_LO);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_HI);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_HA);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR14);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR14_BRTAKEN);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR14_BRNTAKEN);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL24);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL14);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL14_BRTAKEN);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL14_BRNTAKEN);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_HIGHER);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_HIGHEST);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TOC16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TOC16_LO);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TOC16_HA);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TOC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_DS);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_LO_DS);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TOC16_DS);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TOC16_LO_DS);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TLS);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TPREL16_LO);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TPREL16_HA);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPREL16_LO);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPREL16_HA);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TLSGD16_LO);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TLSGD16_HA);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TLSLD16_LO);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TLSLD16_HA);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TPREL16_LO_DS);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TPREL16_HA);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TLSGD);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TLSLD);
default:
break;
}
break;
case ELF::EM_S390:
switch (Type) {
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_NONE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_8);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PC32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOT12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOT32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLT32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_COPY);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GLOB_DAT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_JMP_SLOT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_RELATIVE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTOFF);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPC);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOT16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PC16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PC16DBL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLT16DBL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PC32DBL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLT32DBL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPCDBL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PC64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOT64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLT64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTENT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTOFF16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTOFF64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPLT12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPLT16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPLT32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPLT64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPLTENT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLTOFF16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLTOFF32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLTOFF64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LOAD);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GDCALL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LDCALL);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GD32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GD64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GOTIE12);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GOTIE32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GOTIE64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LDM32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LDM64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_IE32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_IE64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_IEENT);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LE32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LE64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LDO32);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LDO64);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_DTPMOD);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_DTPOFF);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_TPOFF);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_20);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOT20);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPLT20);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GOTIE20);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_IRELATIVE);
default:
break;
}
break;
default:
break;
}
return "Unknown";
}
#undef LLVM_ELF_SWITCH_RELOC_TYPE_NAME
} // end namespace object
} // end namespace llvm

View File

@ -11,11 +11,10 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/Object/ELF.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Support/MathExtras.h"
namespace llvm {
using namespace object;
// Creates an in-memory object-file by default: createELFObjectFile(Buffer)

View File

@ -13,7 +13,7 @@
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCRelocationInfo.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Support/ELF.h"
using namespace llvm;

Binary file not shown.

Binary file not shown.

24
test/Object/corrupt.test Normal file
View File

@ -0,0 +1,24 @@
// Section name offset overflows section name string table.
RUN: not llvm-readobj %p/Inputs/corrupt.elf-x86-64 -sections \
RUN: 2>&1 | FileCheck --check-prefix=SECNAME %s
// Section data offset past end of file.
RUN: not llvm-readobj %p/Inputs/corrupt.elf-x86-64 -sections -section-data \
RUN: 2>&1 | FileCheck --check-prefix=SECDATA %s
// Symbol name offset overflows string table.
RUN: not llvm-readobj %p/Inputs/corrupt.elf-x86-64 -symbols \
RUN: 2>&1 | FileCheck --check-prefix=SYMNAME %s
// Version index in .gnu.version overflows the version map.
RUN: not llvm-readobj %p/Inputs/corrupt-version.elf-x86_64 -dt \
RUN: 2>&1 | FileCheck --check-prefix=VER %s
SECNAME: Error reading file: Invalid data was encountered while parsing the file.
SECDATA: Error reading file: Invalid data was encountered while parsing the file.
SECDATA: Error reading file: Invalid data was encountered while parsing the file.
SYMNAME: Error reading file: Invalid data was encountered while parsing the file.
VER: Error reading file: Invalid data was encountered while parsing the file.

View File

@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//
#include "llvm-objdump.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
@ -21,10 +21,8 @@
using namespace llvm;
using namespace llvm::object;
template<class ELFT>
void printProgramHeaders(
const ELFObjectFile<ELFT> *o) {
typedef ELFObjectFile<ELFT> ELFO;
template <class ELFT> void printProgramHeaders(const ELFFile<ELFT> *o) {
typedef ELFFile<ELFT> ELFO;
outs() << "Program Header:\n";
for (typename ELFO::Elf_Phdr_Iter pi = o->begin_program_headers(),
pe = o->end_program_headers();
@ -80,17 +78,17 @@ void printProgramHeaders(
void llvm::printELFFileHeader(const object::ObjectFile *Obj) {
// Little-endian 32-bit
if (const ELF32LEObjectFile *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
printProgramHeaders(ELFObj);
printProgramHeaders(ELFObj->getELFFile());
// Big-endian 32-bit
if (const ELF32BEObjectFile *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj))
printProgramHeaders(ELFObj);
printProgramHeaders(ELFObj->getELFFile());
// Little-endian 64-bit
if (const ELF64LEObjectFile *ELFObj = dyn_cast<ELF64LEObjectFile>(Obj))
printProgramHeaders(ELFObj);
printProgramHeaders(ELFObj->getELFFile());
// Big-endian 64-bit
if (const ELF64BEObjectFile *ELFObj = dyn_cast<ELF64BEObjectFile>(Obj))
printProgramHeaders(ELFObj);
printProgramHeaders(ELFObj->getELFFile());
}

View File

@ -18,7 +18,7 @@
#include "StreamWriter.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/MathExtras.h"
@ -28,7 +28,6 @@ using namespace llvm;
using namespace llvm::object;
using namespace ELF;
#define LLVM_READOBJ_ENUM_CASE(ns, enum) \
case ns::enum: return #enum;
@ -37,9 +36,8 @@ namespace {
template<typename ELFT>
class ELFDumper : public ObjDumper {
public:
ELFDumper(const ELFObjectFile<ELFT> *Obj, StreamWriter& Writer)
: ObjDumper(Writer)
, Obj(Obj) { }
ELFDumper(const ELFFile<ELFT> *Obj, StreamWriter &Writer)
: ObjDumper(Writer), Obj(Obj) {}
virtual void printFileHeaders() LLVM_OVERRIDE;
virtual void printSections() LLVM_OVERRIDE;
@ -53,24 +51,32 @@ public:
virtual void printProgramHeaders() LLVM_OVERRIDE;
private:
typedef ELFObjectFile<ELFT> ELFO;
typedef ELFFile<ELFT> ELFO;
typedef typename ELFO::Elf_Shdr Elf_Shdr;
typedef typename ELFO::Elf_Sym Elf_Sym;
void printSymbol(symbol_iterator SymI, bool IsDynamic = false);
void printSymbol(typename ELFO::Elf_Sym_Iter Symbol);
void printRelocation(section_iterator SecI, relocation_iterator RelI);
void printRelocations(const Elf_Shdr *Sec);
void printRelocation(const Elf_Shdr *Sec, typename ELFO::Elf_Rela Rel);
const ELFO *Obj;
};
} // namespace
template <class T> T errorOrDefault(ErrorOr<T> Val, T Default = T()) {
if (!Val) {
error(Val);
return Default;
}
return *Val;
}
} // namespace
namespace llvm {
template <class ELFT>
static error_code createELFDumper(const ELFObjectFile<ELFT> *Obj,
static error_code createELFDumper(const ELFFile<ELFT> *Obj,
StreamWriter &Writer,
OwningPtr<ObjDumper> &Result) {
Result.reset(new ELFDumper<ELFT>(Obj, Writer));
@ -82,26 +88,25 @@ error_code createELFDumper(const object::ObjectFile *Obj,
OwningPtr<ObjDumper> &Result) {
// Little-endian 32-bit
if (const ELF32LEObjectFile *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
return createELFDumper(ELFObj, Writer, Result);
return createELFDumper(ELFObj->getELFFile(), Writer, Result);
// Big-endian 32-bit
if (const ELF32BEObjectFile *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj))
return createELFDumper(ELFObj, Writer, Result);
return createELFDumper(ELFObj->getELFFile(), Writer, Result);
// Little-endian 64-bit
if (const ELF64LEObjectFile *ELFObj = dyn_cast<ELF64LEObjectFile>(Obj))
return createELFDumper(ELFObj, Writer, Result);
return createELFDumper(ELFObj->getELFFile(), Writer, Result);
// Big-endian 64-bit
if (const ELF64BEObjectFile *ELFObj = dyn_cast<ELF64BEObjectFile>(Obj))
return createELFDumper(ELFObj, Writer, Result);
return createELFDumper(ELFObj->getELFFile(), Writer, Result);
return readobj_error::unsupported_obj_file_format;
}
} // namespace llvm
static const EnumEntry<unsigned> ElfClass[] = {
{ "None", ELF::ELFCLASSNONE },
{ "32-bit", ELF::ELFCLASS32 },
@ -322,7 +327,7 @@ static const EnumEntry<unsigned> ElfSymbolTypes[] = {
static const char *getElfSectionType(unsigned Arch, unsigned Type) {
switch (Arch) {
case Triple::arm:
case ELF::EM_ARM:
switch (Type) {
LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_EXIDX);
LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_PREEMPTMAP);
@ -330,16 +335,12 @@ static const char *getElfSectionType(unsigned Arch, unsigned Type) {
LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_DEBUGOVERLAY);
LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_OVERLAYSECTION);
}
case Triple::hexagon:
switch (Type) {
LLVM_READOBJ_ENUM_CASE(ELF, SHT_HEX_ORDERED);
}
case Triple::x86_64:
switch (Type) {
LLVM_READOBJ_ENUM_CASE(ELF, SHT_X86_64_UNWIND);
}
case Triple::mips:
case Triple::mipsel:
case ELF::EM_HEXAGON:
switch (Type) { LLVM_READOBJ_ENUM_CASE(ELF, SHT_HEX_ORDERED); }
case ELF::EM_X86_64:
switch (Type) { LLVM_READOBJ_ENUM_CASE(ELF, SHT_X86_64_UNWIND); }
case ELF::EM_MIPS:
case ELF::EM_MIPS_RS3_LE:
switch (Type) {
LLVM_READOBJ_ENUM_CASE(ELF, SHT_MIPS_REGINFO);
LLVM_READOBJ_ENUM_CASE(ELF, SHT_MIPS_OPTIONS);
@ -416,12 +417,11 @@ static const EnumEntry<unsigned> ElfSegmentFlags[] = {
LLVM_READOBJ_ENUM_ENT(ELF, PF_R)
};
template<class ELFT>
void ELFDumper<ELFT>::printFileHeaders() {
error_code EC;
const typename ELFO::Elf_Ehdr *Header = Obj->getElfHeader();
const typename ELFO::Elf_Ehdr *Header = Obj->getHeader();
{
DictScope D(W, "ElfHeader");
@ -461,24 +461,20 @@ void ELFDumper<ELFT>::printSections() {
ListScope SectionsD(W, "Sections");
int SectionIndex = -1;
error_code EC;
for (section_iterator SecI = Obj->begin_sections(),
SecE = Obj->end_sections();
SecI != SecE; SecI.increment(EC)) {
if (error(EC)) break;
for (typename ELFO::Elf_Shdr_Iter SecI = Obj->begin_sections(),
SecE = Obj->end_sections();
SecI != SecE; ++SecI) {
++SectionIndex;
const Elf_Shdr *Section = Obj->getElfSection(SecI);
StringRef Name;
if (error(SecI->getName(Name)))
Name = "";
const Elf_Shdr *Section = &*SecI;
StringRef Name = errorOrDefault(Obj->getSectionName(Section));
DictScope SectionD(W, "Section");
W.printNumber("Index", SectionIndex);
W.printNumber("Name", Name, Section->sh_name);
W.printHex ("Type", getElfSectionType(Obj->getArch(), Section->sh_type),
Section->sh_type);
W.printHex("Type",
getElfSectionType(Obj->getHeader()->e_machine, Section->sh_type),
Section->sh_type);
W.printFlags ("Flags", Section->sh_flags, makeArrayRef(ElfSectionFlags));
W.printHex ("Address", Section->sh_addr);
W.printHex ("Offset", Section->sh_offset);
@ -490,35 +486,23 @@ void ELFDumper<ELFT>::printSections() {
if (opts::SectionRelocations) {
ListScope D(W, "Relocations");
for (relocation_iterator RelI = SecI->begin_relocations(),
RelE = SecI->end_relocations();
RelI != RelE; RelI.increment(EC)) {
if (error(EC)) break;
printRelocation(SecI, RelI);
}
printRelocations(Section);
}
if (opts::SectionSymbols) {
ListScope D(W, "Symbols");
for (symbol_iterator SymI = Obj->begin_symbols(),
SymE = Obj->end_symbols();
SymI != SymE; SymI.increment(EC)) {
if (error(EC)) break;
bool Contained = false;
if (SecI->containsSymbol(*SymI, Contained) || !Contained)
continue;
printSymbol(SymI);
for (typename ELFO::Elf_Sym_Iter SymI = Obj->begin_symbols(),
SymE = Obj->end_symbols();
SymI != SymE; ++SymI) {
if (Obj->getSection(&*SymI) == Section)
printSymbol(SymI);
}
}
if (opts::SectionData) {
StringRef Data;
if (error(SecI->getContents(Data))) break;
W.printBinaryBlock("SectionData", Data);
ArrayRef<uint8_t> Data = errorOrDefault(Obj->getSectionContents(Section));
W.printBinaryBlock("SectionData",
StringRef((const char *)Data.data(), Data.size()));
}
}
}
@ -529,70 +513,73 @@ void ELFDumper<ELFT>::printRelocations() {
error_code EC;
int SectionNumber = -1;
for (section_iterator SecI = Obj->begin_sections(),
SecE = Obj->end_sections();
SecI != SecE; SecI.increment(EC)) {
if (error(EC)) break;
for (typename ELFO::Elf_Shdr_Iter SecI = Obj->begin_sections(),
SecE = Obj->end_sections();
SecI != SecE; ++SecI) {
++SectionNumber;
StringRef Name;
if (error(SecI->getName(Name)))
if (SecI->sh_type != ELF::SHT_REL && SecI->sh_type != ELF::SHT_RELA)
continue;
bool PrintedGroup = false;
for (relocation_iterator RelI = SecI->begin_relocations(),
RelE = SecI->end_relocations();
RelI != RelE; RelI.increment(EC)) {
if (error(EC)) break;
StringRef Name = errorOrDefault(Obj->getSectionName(&*SecI));
if (!PrintedGroup) {
W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n";
W.indent();
PrintedGroup = true;
}
W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n";
W.indent();
printRelocation(SecI, RelI);
}
printRelocations(&*SecI);
if (PrintedGroup) {
W.unindent();
W.startLine() << "}\n";
}
W.unindent();
W.startLine() << "}\n";
}
}
template<class ELFT>
void ELFDumper<ELFT>::printRelocation(section_iterator Sec,
relocation_iterator RelI) {
uint64_t Offset;
uint64_t RelocType;
SmallString<32> RelocName;
int64_t Addend;
StringRef SymbolName;
if (Obj->getElfHeader()->e_type == ELF::ET_REL){
if (error(RelI->getOffset(Offset))) return;
} else {
if (error(RelI->getAddress(Offset))) return;
template <class ELFT>
void ELFDumper<ELFT>::printRelocations(const Elf_Shdr *Sec) {
switch (Sec->sh_type) {
case ELF::SHT_REL:
for (typename ELFO::Elf_Rel_Iter RI = Obj->begin_rel(Sec),
RE = Obj->end_rel(Sec);
RI != RE; ++RI) {
typename ELFO::Elf_Rela Rela;
Rela.r_offset = RI->r_offset;
Rela.r_info = RI->r_info;
Rela.r_addend = 0;
printRelocation(Sec, Rela);
}
break;
case ELF::SHT_RELA:
for (typename ELFO::Elf_Rela_Iter RI = Obj->begin_rela(Sec),
RE = Obj->end_rela(Sec);
RI != RE; ++RI) {
printRelocation(Sec, *RI);
}
break;
}
if (error(RelI->getType(RelocType))) return;
if (error(RelI->getTypeName(RelocName))) return;
if (error(getELFRelocationAddend(*RelI, Addend))) return;
symbol_iterator Symbol = RelI->getSymbol();
if (Symbol != Obj->end_symbols() && error(Symbol->getName(SymbolName)))
return;
}
template <class ELFT>
void ELFDumper<ELFT>::printRelocation(const Elf_Shdr *Sec,
typename ELFO::Elf_Rela Rel) {
SmallString<32> RelocName;
Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName);
StringRef SymbolName;
std::pair<const Elf_Shdr *, const Elf_Sym *> Sym =
Obj->getRelocationSymbol(Sec, &Rel);
if (Sym.first)
SymbolName = errorOrDefault(Obj->getSymbolName(Sym.first, Sym.second));
if (opts::ExpandRelocs) {
DictScope Group(W, "Relocation");
W.printHex("Offset", Offset);
W.printNumber("Type", RelocName, RelocType);
W.printHex("Offset", Rel.r_offset);
W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL()));
W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
W.printHex("Addend", Addend);
W.printHex("Addend", Rel.r_addend);
} else {
raw_ostream& OS = W.startLine();
OS << W.hex(Offset)
OS << W.hex(Rel.r_offset)
<< " " << RelocName
<< " " << (SymbolName.size() > 0 ? SymbolName : "-")
<< " " << W.hex(Addend)
<< " " << W.hex(Rel.r_addend)
<< "\n";
}
}
@ -600,12 +587,9 @@ void ELFDumper<ELFT>::printRelocation(section_iterator Sec,
template<class ELFT>
void ELFDumper<ELFT>::printSymbols() {
ListScope Group(W, "Symbols");
error_code EC;
for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols();
SymI != SymE; SymI.increment(EC)) {
if (error(EC)) break;
for (typename ELFO::Elf_Sym_Iter SymI = Obj->begin_symbols(),
SymE = Obj->end_symbols();
SymI != SymE; ++SymI) {
printSymbol(SymI);
}
}
@ -614,41 +598,27 @@ template<class ELFT>
void ELFDumper<ELFT>::printDynamicSymbols() {
ListScope Group(W, "DynamicSymbols");
error_code EC;
for (symbol_iterator SymI = Obj->begin_dynamic_symbols(),
SymE = Obj->end_dynamic_symbols();
SymI != SymE; SymI.increment(EC)) {
if (error(EC)) break;
printSymbol(SymI, true);
for (typename ELFO::Elf_Sym_Iter SymI = Obj->begin_dynamic_symbols(),
SymE = Obj->end_dynamic_symbols();
SymI != SymE; ++SymI) {
printSymbol(SymI);
}
}
template<class ELFT>
void ELFDumper<ELFT>::printSymbol(symbol_iterator SymI, bool IsDynamic) {
error_code EC;
const Elf_Sym *Symbol = Obj->getElfSymbol(SymI);
const Elf_Shdr *Section = Obj->getSection(Symbol);
StringRef SymbolName;
if (SymI->getName(SymbolName))
SymbolName = "";
StringRef SectionName = "";
if (Section)
Obj->getSectionName(Section, SectionName);
template <class ELFT>
void ELFDumper<ELFT>::printSymbol(typename ELFO::Elf_Sym_Iter Symbol) {
StringRef SymbolName = errorOrDefault(Obj->getSymbolName(Symbol));
const Elf_Shdr *Sec = Obj->getSection(&*Symbol);
StringRef SectionName = Sec ? errorOrDefault(Obj->getSectionName(Sec)) : "";
std::string FullSymbolName(SymbolName);
if (IsDynamic) {
StringRef Version;
if (Symbol.isDynamic()) {
bool IsDefault;
if (error(Obj->getSymbolVersion(*SymI, Version, IsDefault)))
return;
if (!Version.empty()) {
ErrorOr<StringRef> Version = Obj->getSymbolVersion(0, &*Symbol, IsDefault);
if (Version) {
FullSymbolName += (IsDefault ? "@@" : "@");
FullSymbolName += Version;
}
FullSymbolName += *Version;
} else
error(Version);
}
DictScope D(W, "Symbol");
@ -706,9 +676,9 @@ static const char *getTypeString(uint64_t Type) {
#undef LLVM_READOBJ_TYPE_CASE
template<class ELFT>
static void printValue(const ELFObjectFile<ELFT> *O, uint64_t Type,
uint64_t Value, bool Is64, raw_ostream &OS) {
template <class ELFT>
static void printValue(const ELFFile<ELFT> *O, uint64_t Type, uint64_t Value,
bool Is64, raw_ostream &OS) {
switch (Type) {
case DT_PLTREL:
if (Value == DT_REL) {
@ -748,12 +718,10 @@ static void printValue(const ELFObjectFile<ELFT> *O, uint64_t Type,
OS << Value << " (bytes)";
break;
case DT_NEEDED:
OS << "SharedLibrary ("
<< O->getString(O->getDynamicStringTableSectionHeader(), Value) << ")";
OS << "SharedLibrary (" << O->getDynamicString(Value) << ")";
break;
case DT_SONAME:
OS << "LibrarySoname ("
<< O->getString(O->getDynamicStringTableSectionHeader(), Value) << ")";
OS << "LibrarySoname (" << O->getDynamicString(Value) << ")";
break;
}
}
@ -765,9 +733,8 @@ void ELFDumper<ELFT>::printUnwindInfo() {
template<class ELFT>
void ELFDumper<ELFT>::printDynamicTable() {
typedef typename ELFO::Elf_Dyn_iterator EDI;
EDI Start = Obj->begin_dynamic_table(),
End = Obj->end_dynamic_table(true);
typedef typename ELFO::Elf_Dyn_Iter EDI;
EDI Start = Obj->begin_dynamic_table(), End = Obj->end_dynamic_table(true);
if (Start == End)
return;
@ -776,7 +743,7 @@ void ELFDumper<ELFT>::printDynamicTable() {
raw_ostream &OS = W.getOStream();
W.startLine() << "DynamicSection [ (" << Total << " entries)\n";
bool Is64 = Obj->getBytesInAddress() == 8;
bool Is64 = ELFT::Is64Bits;
W.startLine()
<< " Tag" << (Is64 ? " " : " ") << "Type"
@ -793,38 +760,25 @@ void ELFDumper<ELFT>::printDynamicTable() {
W.startLine() << "]\n";
}
static bool compareLibraryName(const LibraryRef &L, const LibraryRef &R) {
StringRef LPath, RPath;
L.getPath(LPath);
R.getPath(RPath);
return LPath < RPath;
}
template<class ELFT>
void ELFDumper<ELFT>::printNeededLibraries() {
ListScope D(W, "NeededLibraries");
error_code EC;
typedef std::vector<LibraryRef> LibsTy;
typedef std::vector<StringRef> LibsTy;
LibsTy Libs;
for (library_iterator I = Obj->begin_libraries_needed(),
E = Obj->end_libraries_needed();
I != E; I.increment(EC)) {
if (EC)
report_fatal_error("Needed libraries iteration failed");
for (typename ELFO::Elf_Dyn_Iter DynI = Obj->begin_dynamic_table(),
DynE = Obj->end_dynamic_table();
DynI != DynE; ++DynI)
if (DynI->d_tag == ELF::DT_NEEDED)
Libs.push_back(Obj->getDynamicString(DynI->d_un.d_val));
Libs.push_back(*I);
}
std::stable_sort(Libs.begin(), Libs.end());
std::sort(Libs.begin(), Libs.end(), &compareLibraryName);
for (LibsTy::const_iterator I = Libs.begin(), E = Libs.end();
I != E; ++I) {
StringRef Path;
I->getPath(Path);
outs() << " " << Path << "\n";
for (LibsTy::const_iterator I = Libs.begin(), E = Libs.end(); I != E; ++I) {
outs() << " " << *I << "\n";
}
}

View File

@ -1,4 +1,4 @@
//===- llvm-readobj.cpp - Dump contents of an Object File -----------------===//
//===- llvm-readobj.cpp - Dump contents of an Object File -----------------===//
//
// The LLVM Compiler Infrastructure
//
@ -130,12 +130,15 @@ namespace opts {
cl::desc("Expand each shown relocation to multiple lines"));
} // namespace opts
static int ReturnValue = EXIT_SUCCESS;
namespace llvm {
bool error(error_code EC) {
if (!EC)
return false;
ReturnValue = EXIT_FAILURE;
outs() << "\nError reading file: " << EC.message() << ".\n";
outs().flush();
return true;
@ -157,6 +160,7 @@ static void reportError(StringRef Input, error_code EC) {
errs() << Input << ": " << EC.message() << "\n";
errs().flush();
ReturnValue = EXIT_FAILURE;
}
static void reportError(StringRef Input, StringRef Message) {
@ -164,6 +168,7 @@ static void reportError(StringRef Input, StringRef Message) {
Input = "<stdin>";
errs() << Input << ": " << Message << "\n";
ReturnValue = EXIT_FAILURE;
}
/// @brief Creates an format-specific object file dumper.
@ -289,5 +294,5 @@ int main(int argc, const char *argv[]) {
std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
dumpInput);
return 0;
return ReturnValue;
}

View File

@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//
#include "yaml2obj.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/ELFYAML.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/MemoryBuffer.h"
@ -157,7 +157,7 @@ class ELFState {
unsigned DotStrtabSecNo;
/// \brief The accumulated contents of all sections so far.
ContiguousBlobAccumulator &SectionContentAccum;
typedef typename object::ELFObjectFile<ELFT>::Elf_Ehdr Elf_Ehdr;
typedef typename object::ELFFile<ELFT>::Elf_Ehdr Elf_Ehdr;
/// \brief The ELF file header.
Elf_Ehdr &Header;
@ -185,9 +185,9 @@ public:
template <class ELFT>
static void
addSymbols(const std::vector<ELFYAML::Symbol> &Symbols, ELFState<ELFT> &State,
std::vector<typename object::ELFObjectFile<ELFT>::Elf_Sym> &Syms,
std::vector<typename object::ELFFile<ELFT>::Elf_Sym> &Syms,
unsigned SymbolBinding) {
typedef typename object::ELFObjectFile<ELFT>::Elf_Sym Elf_Sym;
typedef typename object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
for (unsigned i = 0, e = Symbols.size(); i != e; ++i) {
const ELFYAML::Symbol &Sym = Symbols[i];
Elf_Sym Symbol;
@ -211,11 +211,12 @@ addSymbols(const std::vector<ELFYAML::Symbol> &Symbols, ELFState<ELFT> &State,
}
template <class ELFT>
static void handleSymtabSectionHeader(
const ELFYAML::LocalGlobalWeakSymbols &Symbols, ELFState<ELFT> &State,
typename object::ELFObjectFile<ELFT>::Elf_Shdr &SHeader) {
static void
handleSymtabSectionHeader(const ELFYAML::LocalGlobalWeakSymbols &Symbols,
ELFState<ELFT> &State,
typename object::ELFFile<ELFT>::Elf_Shdr &SHeader) {
typedef typename object::ELFObjectFile<ELFT>::Elf_Sym Elf_Sym;
typedef typename object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
SHeader.sh_type = ELF::SHT_SYMTAB;
SHeader.sh_link = State.getDotStrTabSecNo();
// One greater than symbol table index of the last local symbol.
@ -241,8 +242,8 @@ static void handleSymtabSectionHeader(
template <class ELFT>
static int writeELF(raw_ostream &OS, const ELFYAML::Object &Doc) {
using namespace llvm::ELF;
typedef typename object::ELFObjectFile<ELFT>::Elf_Ehdr Elf_Ehdr;
typedef typename object::ELFObjectFile<ELFT>::Elf_Shdr Elf_Shdr;
typedef typename object::ELFFile<ELFT>::Elf_Ehdr Elf_Ehdr;
typedef typename object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
const ELFYAML::FileHeader &Hdr = Doc.Header;