2013-04-03 20:31:38 +02:00
|
|
|
//===-- ELFDumper.cpp - ELF-specific dumper ---------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief This file implements the ELF-specific dumper for llvm-readobj.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm-readobj.h"
|
2014-01-30 05:46:33 +01:00
|
|
|
#include "ARMAttributeParser.h"
|
2014-01-13 09:04:33 +01:00
|
|
|
#include "ARMEHABIPrinter.h"
|
2013-04-03 20:31:38 +02:00
|
|
|
#include "Error.h"
|
|
|
|
#include "ObjDumper.h"
|
2015-06-27 01:56:53 +02:00
|
|
|
#include "StackMapPrinter.h"
|
2013-04-03 20:31:38 +02:00
|
|
|
#include "StreamWriter.h"
|
2014-06-18 10:47:09 +02:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2013-04-03 20:31:38 +02:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2014-01-30 05:46:33 +01:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2013-08-09 00:27:13 +02:00
|
|
|
#include "llvm/Object/ELFObjectFile.h"
|
2014-01-30 05:46:33 +01:00
|
|
|
#include "llvm/Support/ARMBuildAttributes.h"
|
2013-04-03 20:31:38 +02:00
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
2015-05-07 17:40:35 +02:00
|
|
|
#include "llvm/Support/MipsABIFlags.h"
|
2013-04-03 20:31:38 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::object;
|
|
|
|
using namespace ELF;
|
|
|
|
|
|
|
|
#define LLVM_READOBJ_ENUM_CASE(ns, enum) \
|
|
|
|
case ns::enum: return #enum;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
template<typename ELFT>
|
|
|
|
class ELFDumper : public ObjDumper {
|
|
|
|
public:
|
2015-07-21 22:50:53 +02:00
|
|
|
ELFDumper(const ELFFile<ELFT> *Obj, StreamWriter &Writer);
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2014-03-08 09:27:28 +01:00
|
|
|
void printFileHeaders() override;
|
|
|
|
void printSections() override;
|
|
|
|
void printRelocations() override;
|
2015-06-25 23:47:32 +02:00
|
|
|
void printDynamicRelocations() override;
|
2014-03-08 09:27:28 +01:00
|
|
|
void printSymbols() override;
|
|
|
|
void printDynamicSymbols() override;
|
|
|
|
void printUnwindInfo() override;
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2014-03-08 09:27:28 +01:00
|
|
|
void printDynamicTable() override;
|
|
|
|
void printNeededLibraries() override;
|
|
|
|
void printProgramHeaders() override;
|
2015-07-10 00:32:24 +02:00
|
|
|
void printHashTable() override;
|
2015-10-14 14:11:50 +02:00
|
|
|
void printGnuHashTable() override;
|
2015-07-21 15:48:41 +02:00
|
|
|
void printLoadName() override;
|
2015-10-17 01:19:01 +02:00
|
|
|
void printVersionInfo() override;
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2014-03-08 09:27:28 +01:00
|
|
|
void printAttributes() override;
|
2014-06-18 10:47:09 +02:00
|
|
|
void printMipsPLTGOT() override;
|
2015-05-07 17:40:35 +02:00
|
|
|
void printMipsABIFlags() override;
|
2015-06-16 23:47:43 +02:00
|
|
|
void printMipsReginfo() override;
|
2014-01-30 05:46:33 +01:00
|
|
|
|
2015-06-27 01:56:53 +02:00
|
|
|
void printStackMap() const override;
|
|
|
|
|
2013-04-03 20:31:38 +02:00
|
|
|
private:
|
2013-08-09 00:27:13 +02:00
|
|
|
typedef ELFFile<ELFT> ELFO;
|
2013-04-12 06:07:39 +02:00
|
|
|
typedef typename ELFO::Elf_Shdr Elf_Shdr;
|
|
|
|
typedef typename ELFO::Elf_Sym Elf_Sym;
|
2015-07-21 22:50:53 +02:00
|
|
|
typedef typename ELFO::Elf_Dyn Elf_Dyn;
|
|
|
|
typedef typename ELFO::Elf_Dyn_Range Elf_Dyn_Range;
|
2015-07-23 10:48:14 +02:00
|
|
|
typedef typename ELFO::Elf_Rel Elf_Rel;
|
2015-07-21 22:50:53 +02:00
|
|
|
typedef typename ELFO::Elf_Rela Elf_Rela;
|
|
|
|
typedef typename ELFO::Elf_Rela_Range Elf_Rela_Range;
|
|
|
|
typedef typename ELFO::Elf_Phdr Elf_Phdr;
|
2015-10-17 01:19:01 +02:00
|
|
|
typedef typename ELFO::Elf_Half Elf_Half;
|
2015-07-21 22:50:53 +02:00
|
|
|
typedef typename ELFO::Elf_Hash Elf_Hash;
|
2015-10-14 14:11:50 +02:00
|
|
|
typedef typename ELFO::Elf_GnuHash Elf_GnuHash;
|
2015-07-23 10:48:14 +02:00
|
|
|
typedef typename ELFO::Elf_Ehdr Elf_Ehdr;
|
2015-08-10 23:29:35 +02:00
|
|
|
typedef typename ELFO::Elf_Word Elf_Word;
|
2015-07-21 22:50:53 +02:00
|
|
|
typedef typename ELFO::uintX_t uintX_t;
|
2015-08-06 23:54:37 +02:00
|
|
|
typedef typename ELFO::Elf_Versym Elf_Versym;
|
|
|
|
typedef typename ELFO::Elf_Verneed Elf_Verneed;
|
|
|
|
typedef typename ELFO::Elf_Vernaux Elf_Vernaux;
|
|
|
|
typedef typename ELFO::Elf_Verdef Elf_Verdef;
|
2015-10-17 01:19:01 +02:00
|
|
|
typedef typename ELFO::Elf_Verdaux Elf_Verdaux;
|
2015-07-21 22:50:53 +02:00
|
|
|
|
|
|
|
/// \brief Represents a region described by entries in the .dynamic table.
|
|
|
|
struct DynRegionInfo {
|
|
|
|
DynRegionInfo() : Addr(nullptr), Size(0), EntSize(0) {}
|
|
|
|
/// \brief Address in current address space.
|
|
|
|
const void *Addr;
|
|
|
|
/// \brief Size in bytes of the region.
|
|
|
|
uintX_t Size;
|
|
|
|
/// \brief Size of each entity in the region.
|
|
|
|
uintX_t EntSize;
|
|
|
|
};
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2015-08-23 16:06:40 +02:00
|
|
|
void printSymbolsHelper(bool IsDynamic);
|
2015-08-10 23:29:35 +02:00
|
|
|
void printSymbol(const Elf_Sym *Symbol, const Elf_Shdr *SymTab,
|
|
|
|
StringRef StrTable, bool IsDynamic);
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2013-08-09 00:27:13 +02:00
|
|
|
void printRelocations(const Elf_Shdr *Sec);
|
2015-09-02 17:07:39 +02:00
|
|
|
void printRelocation(Elf_Rela Rel, const Elf_Shdr *SymTab);
|
2015-07-21 21:57:43 +02:00
|
|
|
void printValue(uint64_t Type, uint64_t Value);
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2015-07-21 22:50:53 +02:00
|
|
|
const Elf_Rela *dyn_rela_begin() const;
|
|
|
|
const Elf_Rela *dyn_rela_end() const;
|
|
|
|
Elf_Rela_Range dyn_relas() const;
|
|
|
|
StringRef getDynamicString(uint64_t Offset) const;
|
2015-08-07 17:25:20 +02:00
|
|
|
const Elf_Dyn *dynamic_table_begin() const {
|
|
|
|
ErrorOr<const Elf_Dyn *> Ret = Obj->dynamic_table_begin(DynamicProgHeader);
|
|
|
|
error(Ret.getError());
|
|
|
|
return *Ret;
|
|
|
|
}
|
|
|
|
const Elf_Dyn *dynamic_table_end() const {
|
|
|
|
ErrorOr<const Elf_Dyn *> Ret = Obj->dynamic_table_end(DynamicProgHeader);
|
|
|
|
error(Ret.getError());
|
|
|
|
return *Ret;
|
|
|
|
}
|
2015-08-06 23:54:37 +02:00
|
|
|
StringRef getSymbolVersion(StringRef StrTab, const Elf_Sym *symb,
|
|
|
|
bool &IsDefault);
|
|
|
|
void LoadVersionMap();
|
|
|
|
void LoadVersionNeeds(const Elf_Shdr *ec) const;
|
|
|
|
void LoadVersionDefs(const Elf_Shdr *sec) const;
|
|
|
|
|
2013-04-12 06:07:39 +02:00
|
|
|
const ELFO *Obj;
|
2015-07-21 22:50:53 +02:00
|
|
|
DynRegionInfo DynRelaRegion;
|
2015-08-07 17:25:20 +02:00
|
|
|
const Elf_Phdr *DynamicProgHeader = nullptr;
|
2015-07-21 22:50:53 +02:00
|
|
|
StringRef DynamicStringTable;
|
2015-07-23 11:11:05 +02:00
|
|
|
const Elf_Sym *DynSymStart = nullptr;
|
2015-07-21 22:50:53 +02:00
|
|
|
StringRef SOName;
|
|
|
|
const Elf_Hash *HashTable = nullptr;
|
2015-10-14 14:11:50 +02:00
|
|
|
const Elf_GnuHash *GnuHashTable = nullptr;
|
2015-08-07 22:11:08 +02:00
|
|
|
const Elf_Shdr *DotDynSymSec = nullptr;
|
2015-08-10 22:25:04 +02:00
|
|
|
const Elf_Shdr *DotSymtabSec = nullptr;
|
2015-08-10 23:29:35 +02:00
|
|
|
ArrayRef<Elf_Word> ShndxTable;
|
2015-08-06 23:54:37 +02:00
|
|
|
|
|
|
|
const Elf_Shdr *dot_gnu_version_sec = nullptr; // .gnu.version
|
|
|
|
const Elf_Shdr *dot_gnu_version_r_sec = nullptr; // .gnu.version_r
|
|
|
|
const Elf_Shdr *dot_gnu_version_d_sec = nullptr; // .gnu.version_d
|
|
|
|
|
|
|
|
// Records for each version index the corresponding Verdef or Vernaux entry.
|
|
|
|
// This is filled the first time LoadVersionMap() is called.
|
|
|
|
class VersionMapEntry : public PointerIntPair<const void *, 1> {
|
|
|
|
public:
|
|
|
|
// If the integer is 0, this is an Elf_Verdef*.
|
|
|
|
// If the integer is 1, this is an Elf_Vernaux*.
|
|
|
|
VersionMapEntry() : PointerIntPair<const void *, 1>(nullptr, 0) {}
|
|
|
|
VersionMapEntry(const Elf_Verdef *verdef)
|
|
|
|
: PointerIntPair<const void *, 1>(verdef, 0) {}
|
|
|
|
VersionMapEntry(const Elf_Vernaux *vernaux)
|
|
|
|
: PointerIntPair<const void *, 1>(vernaux, 1) {}
|
|
|
|
bool isNull() const { return getPointer() == nullptr; }
|
|
|
|
bool isVerdef() const { return !isNull() && getInt() == 0; }
|
|
|
|
bool isVernaux() const { return !isNull() && getInt() == 1; }
|
|
|
|
const Elf_Verdef *getVerdef() const {
|
|
|
|
return isVerdef() ? (const Elf_Verdef *)getPointer() : nullptr;
|
|
|
|
}
|
|
|
|
const Elf_Vernaux *getVernaux() const {
|
|
|
|
return isVernaux() ? (const Elf_Vernaux *)getPointer() : nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mutable SmallVector<VersionMapEntry, 16> VersionMap;
|
|
|
|
|
|
|
|
public:
|
2015-10-17 01:19:01 +02:00
|
|
|
Elf_Dyn_Range dynamic_table() const {
|
|
|
|
ErrorOr<Elf_Dyn_Range> Ret = Obj->dynamic_table(DynamicProgHeader);
|
|
|
|
error(Ret.getError());
|
|
|
|
return *Ret;
|
|
|
|
}
|
|
|
|
|
2015-08-06 23:54:37 +02:00
|
|
|
std::string getFullSymbolName(const Elf_Sym *Symbol, StringRef StrTable,
|
|
|
|
bool IsDynamic);
|
2015-08-07 22:11:08 +02:00
|
|
|
const Elf_Shdr *getDotDynSymSec() const { return DotDynSymSec; }
|
2015-08-10 23:29:35 +02:00
|
|
|
const Elf_Shdr *getDotSymtabSec() const { return DotSymtabSec; }
|
|
|
|
ArrayRef<Elf_Word> getShndxTable() { return ShndxTable; }
|
2013-04-03 20:31:38 +02:00
|
|
|
};
|
|
|
|
|
2013-08-09 00:27:13 +02:00
|
|
|
template <class T> T errorOrDefault(ErrorOr<T> Val, T Default = T()) {
|
|
|
|
if (!Val) {
|
2014-01-08 23:03:39 +01:00
|
|
|
error(Val.getError());
|
2013-08-09 00:27:13 +02:00
|
|
|
return Default;
|
|
|
|
}
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2013-08-09 00:27:13 +02:00
|
|
|
return *Val;
|
|
|
|
}
|
|
|
|
} // namespace
|
2013-04-03 20:31:38 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2013-05-09 15:13:28 +02:00
|
|
|
template <class ELFT>
|
2014-06-13 05:07:50 +02:00
|
|
|
static std::error_code createELFDumper(const ELFFile<ELFT> *Obj,
|
|
|
|
StreamWriter &Writer,
|
|
|
|
std::unique_ptr<ObjDumper> &Result) {
|
2013-05-09 15:13:28 +02:00
|
|
|
Result.reset(new ELFDumper<ELFT>(Obj, Writer));
|
|
|
|
return readobj_error::success;
|
|
|
|
}
|
|
|
|
|
2014-06-13 05:07:50 +02:00
|
|
|
std::error_code createELFDumper(const object::ObjectFile *Obj,
|
|
|
|
StreamWriter &Writer,
|
|
|
|
std::unique_ptr<ObjDumper> &Result) {
|
2013-04-03 20:31:38 +02:00
|
|
|
// Little-endian 32-bit
|
2013-05-09 15:13:28 +02:00
|
|
|
if (const ELF32LEObjectFile *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
|
2013-08-09 00:27:13 +02:00
|
|
|
return createELFDumper(ELFObj->getELFFile(), Writer, Result);
|
2013-04-03 20:31:38 +02:00
|
|
|
|
|
|
|
// Big-endian 32-bit
|
2013-05-09 15:13:28 +02:00
|
|
|
if (const ELF32BEObjectFile *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj))
|
2013-08-09 00:27:13 +02:00
|
|
|
return createELFDumper(ELFObj->getELFFile(), Writer, Result);
|
2013-04-03 20:31:38 +02:00
|
|
|
|
|
|
|
// Little-endian 64-bit
|
2013-05-09 15:13:28 +02:00
|
|
|
if (const ELF64LEObjectFile *ELFObj = dyn_cast<ELF64LEObjectFile>(Obj))
|
2013-08-09 00:27:13 +02:00
|
|
|
return createELFDumper(ELFObj->getELFFile(), Writer, Result);
|
2013-04-03 20:31:38 +02:00
|
|
|
|
|
|
|
// Big-endian 64-bit
|
2013-05-09 15:13:28 +02:00
|
|
|
if (const ELF64BEObjectFile *ELFObj = dyn_cast<ELF64BEObjectFile>(Obj))
|
2013-08-09 00:27:13 +02:00
|
|
|
return createELFDumper(ELFObj->getELFFile(), Writer, Result);
|
2013-04-03 20:31:38 +02:00
|
|
|
|
|
|
|
return readobj_error::unsupported_obj_file_format;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace llvm
|
|
|
|
|
2015-08-06 23:54:37 +02:00
|
|
|
// Iterate through the versions needed section, and place each Elf_Vernaux
|
|
|
|
// in the VersionMap according to its index.
|
|
|
|
template <class ELFT>
|
|
|
|
void ELFDumper<ELFT>::LoadVersionNeeds(const Elf_Shdr *sec) const {
|
|
|
|
unsigned vn_size = sec->sh_size; // Size of section in bytes
|
|
|
|
unsigned vn_count = sec->sh_info; // Number of Verneed entries
|
|
|
|
const char *sec_start = (const char *)Obj->base() + sec->sh_offset;
|
|
|
|
const char *sec_end = sec_start + vn_size;
|
|
|
|
// The first Verneed entry is at the start of the section.
|
|
|
|
const char *p = sec_start;
|
|
|
|
for (unsigned i = 0; i < vn_count; i++) {
|
|
|
|
if (p + sizeof(Elf_Verneed) > sec_end)
|
|
|
|
report_fatal_error("Section ended unexpectedly while scanning "
|
|
|
|
"version needed records.");
|
|
|
|
const Elf_Verneed *vn = reinterpret_cast<const Elf_Verneed *>(p);
|
|
|
|
if (vn->vn_version != ELF::VER_NEED_CURRENT)
|
|
|
|
report_fatal_error("Unexpected verneed version");
|
|
|
|
// Iterate through the Vernaux entries
|
|
|
|
const char *paux = p + vn->vn_aux;
|
|
|
|
for (unsigned j = 0; j < vn->vn_cnt; j++) {
|
|
|
|
if (paux + sizeof(Elf_Vernaux) > sec_end)
|
|
|
|
report_fatal_error("Section ended unexpected while scanning auxiliary "
|
|
|
|
"version needed records.");
|
|
|
|
const Elf_Vernaux *vna = reinterpret_cast<const Elf_Vernaux *>(paux);
|
|
|
|
size_t index = vna->vna_other & ELF::VERSYM_VERSION;
|
|
|
|
if (index >= VersionMap.size())
|
|
|
|
VersionMap.resize(index + 1);
|
|
|
|
VersionMap[index] = VersionMapEntry(vna);
|
|
|
|
paux += vna->vna_next;
|
|
|
|
}
|
|
|
|
p += vn->vn_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through the version definitions, and place each Elf_Verdef
|
|
|
|
// in the VersionMap according to its index.
|
|
|
|
template <class ELFT>
|
|
|
|
void ELFDumper<ELFT>::LoadVersionDefs(const Elf_Shdr *sec) const {
|
|
|
|
unsigned vd_size = sec->sh_size; // Size of section in bytes
|
|
|
|
unsigned vd_count = sec->sh_info; // Number of Verdef entries
|
|
|
|
const char *sec_start = (const char *)Obj->base() + sec->sh_offset;
|
|
|
|
const char *sec_end = sec_start + vd_size;
|
|
|
|
// The first Verdef entry is at the start of the section.
|
|
|
|
const char *p = sec_start;
|
|
|
|
for (unsigned i = 0; i < vd_count; i++) {
|
|
|
|
if (p + sizeof(Elf_Verdef) > sec_end)
|
|
|
|
report_fatal_error("Section ended unexpectedly while scanning "
|
|
|
|
"version definitions.");
|
|
|
|
const Elf_Verdef *vd = reinterpret_cast<const Elf_Verdef *>(p);
|
|
|
|
if (vd->vd_version != ELF::VER_DEF_CURRENT)
|
|
|
|
report_fatal_error("Unexpected verdef version");
|
|
|
|
size_t index = vd->vd_ndx & ELF::VERSYM_VERSION;
|
|
|
|
if (index >= VersionMap.size())
|
|
|
|
VersionMap.resize(index + 1);
|
|
|
|
VersionMap[index] = VersionMapEntry(vd);
|
|
|
|
p += vd->vd_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT> void ELFDumper<ELFT>::LoadVersionMap() {
|
|
|
|
// If there is no dynamic symtab or version table, there is nothing to do.
|
|
|
|
if (!DynSymStart || !dot_gnu_version_sec)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Has the VersionMap already been loaded?
|
|
|
|
if (VersionMap.size() > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// The first two version indexes are reserved.
|
|
|
|
// Index 0 is LOCAL, index 1 is GLOBAL.
|
|
|
|
VersionMap.push_back(VersionMapEntry());
|
|
|
|
VersionMap.push_back(VersionMapEntry());
|
|
|
|
|
|
|
|
if (dot_gnu_version_d_sec)
|
|
|
|
LoadVersionDefs(dot_gnu_version_d_sec);
|
|
|
|
|
|
|
|
if (dot_gnu_version_r_sec)
|
|
|
|
LoadVersionNeeds(dot_gnu_version_r_sec);
|
|
|
|
}
|
|
|
|
|
2015-10-17 01:19:01 +02:00
|
|
|
|
|
|
|
template <typename ELFO, class ELFT>
|
|
|
|
static void printVersionSymbolSection(ELFDumper<ELFT> *Dumper,
|
|
|
|
const ELFO *Obj,
|
|
|
|
const typename ELFO::Elf_Shdr *Sec,
|
|
|
|
StreamWriter &W) {
|
|
|
|
DictScope SS(W, "Version symbols");
|
|
|
|
if (!Sec)
|
|
|
|
return;
|
|
|
|
StringRef Name = errorOrDefault(Obj->getSectionName(Sec));
|
|
|
|
W.printNumber("Section Name", Name, Sec->sh_name);
|
|
|
|
W.printHex("Address", Sec->sh_addr);
|
|
|
|
W.printHex("Offset", Sec->sh_offset);
|
|
|
|
W.printNumber("Link", Sec->sh_link);
|
|
|
|
|
|
|
|
const typename ELFO::Elf_Shdr *DynSymSec = Dumper->getDotDynSymSec();
|
2015-10-23 18:52:22 +02:00
|
|
|
const uint8_t *P = (const uint8_t *)Obj->base() + Sec->sh_offset;
|
2015-10-17 01:19:01 +02:00
|
|
|
ErrorOr<StringRef> StrTableOrErr =
|
|
|
|
Obj->getStringTableForSymtab(*DynSymSec);
|
|
|
|
error(StrTableOrErr.getError());
|
|
|
|
|
|
|
|
// Same number of entries in the dynamic symbol table (DT_SYMTAB).
|
|
|
|
ListScope Syms(W, "Symbols");
|
|
|
|
for (const typename ELFO::Elf_Sym &Sym : Obj->symbols(DynSymSec)) {
|
|
|
|
DictScope S(W, "Symbol");
|
|
|
|
std::string FullSymbolName =
|
|
|
|
Dumper->getFullSymbolName(&Sym, *StrTableOrErr, true /* IsDynamic */);
|
|
|
|
W.printNumber("Version", *P);
|
|
|
|
W.printString("Name", FullSymbolName);
|
|
|
|
P += sizeof(typename ELFO::Elf_Half);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ELFO, class ELFT>
|
|
|
|
static void printVersionDefinitionSection(ELFDumper<ELFT> *Dumper,
|
|
|
|
const ELFO *Obj,
|
|
|
|
const typename ELFO::Elf_Shdr *Sec,
|
|
|
|
StreamWriter &W) {
|
|
|
|
DictScope SD(W, "Version definition");
|
|
|
|
if (!Sec)
|
|
|
|
return;
|
|
|
|
StringRef Name = errorOrDefault(Obj->getSectionName(Sec));
|
|
|
|
W.printNumber("Section Name", Name, Sec->sh_name);
|
|
|
|
W.printHex("Address", Sec->sh_addr);
|
|
|
|
W.printHex("Offset", Sec->sh_offset);
|
|
|
|
W.printNumber("Link", Sec->sh_link);
|
|
|
|
|
|
|
|
unsigned verdef_entries = 0;
|
|
|
|
// The number of entries in the section SHT_GNU_verdef
|
|
|
|
// is determined by DT_VERDEFNUM tag.
|
|
|
|
for (const typename ELFO::Elf_Dyn &Dyn : Dumper->dynamic_table()) {
|
|
|
|
if (Dyn.d_tag == DT_VERDEFNUM)
|
|
|
|
verdef_entries = Dyn.d_un.d_val;
|
|
|
|
}
|
2015-10-23 18:52:22 +02:00
|
|
|
const uint8_t *SecStartAddress =
|
|
|
|
(const uint8_t *)Obj->base() + Sec->sh_offset;
|
|
|
|
const uint8_t *SecEndAddress = SecStartAddress + Sec->sh_size;
|
|
|
|
const uint8_t *P = SecStartAddress;
|
2015-10-17 01:19:01 +02:00
|
|
|
ErrorOr<const typename ELFO::Elf_Shdr *> StrTabOrErr =
|
|
|
|
Obj->getSection(Sec->sh_link);
|
|
|
|
error(StrTabOrErr.getError());
|
|
|
|
|
|
|
|
ListScope Entries(W, "Entries");
|
|
|
|
for (unsigned i = 0; i < verdef_entries; ++i) {
|
|
|
|
if (P + sizeof(typename ELFO::Elf_Verdef) > SecEndAddress)
|
|
|
|
report_fatal_error("invalid offset in the section");
|
|
|
|
auto *VD = reinterpret_cast<const typename ELFO::Elf_Verdef *>(P);
|
|
|
|
DictScope Entry(W, "Entry");
|
|
|
|
W.printHex("Offset", (uintptr_t)P - (uintptr_t)SecStartAddress);
|
|
|
|
W.printNumber("Rev", VD->vd_version);
|
|
|
|
// FIXME: print something more readable.
|
|
|
|
W.printNumber("Flags", VD->vd_flags);
|
|
|
|
W.printNumber("Index", VD->vd_ndx);
|
|
|
|
W.printNumber("Cnt", VD->vd_cnt);
|
2015-10-23 18:52:22 +02:00
|
|
|
W.printString("Name", StringRef((const char *)(Obj->base() +
|
|
|
|
(*StrTabOrErr)->sh_offset +
|
|
|
|
VD->getAux()->vda_name)));
|
2015-10-17 01:19:01 +02:00
|
|
|
P += VD->vd_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ELFT> void ELFDumper<ELFT>::printVersionInfo() {
|
|
|
|
// Dump version symbol section.
|
|
|
|
printVersionSymbolSection(this, Obj, dot_gnu_version_sec, W);
|
|
|
|
|
|
|
|
// Dump version definition section.
|
|
|
|
printVersionDefinitionSection(this, Obj, dot_gnu_version_d_sec, W);
|
|
|
|
}
|
|
|
|
|
2015-08-06 23:54:37 +02:00
|
|
|
template <typename ELFT>
|
|
|
|
StringRef ELFDumper<ELFT>::getSymbolVersion(StringRef StrTab,
|
|
|
|
const Elf_Sym *symb,
|
|
|
|
bool &IsDefault) {
|
|
|
|
// This is a dynamic symbol. Look in the GNU symbol version table.
|
|
|
|
if (!dot_gnu_version_sec) {
|
|
|
|
// No version table.
|
|
|
|
IsDefault = false;
|
|
|
|
return StringRef("");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine the position in the symbol table of this entry.
|
|
|
|
size_t entry_index = (reinterpret_cast<uintptr_t>(symb) -
|
|
|
|
reinterpret_cast<uintptr_t>(DynSymStart)) /
|
|
|
|
sizeof(Elf_Sym);
|
|
|
|
|
|
|
|
// Get the corresponding version index entry
|
|
|
|
const Elf_Versym *vs =
|
|
|
|
Obj->template getEntry<Elf_Versym>(dot_gnu_version_sec, entry_index);
|
|
|
|
size_t version_index = vs->vs_index & ELF::VERSYM_VERSION;
|
|
|
|
|
|
|
|
// Special markers for unversioned symbols.
|
|
|
|
if (version_index == ELF::VER_NDX_LOCAL ||
|
|
|
|
version_index == ELF::VER_NDX_GLOBAL) {
|
|
|
|
IsDefault = false;
|
|
|
|
return StringRef("");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lookup this symbol in the version table
|
|
|
|
LoadVersionMap();
|
|
|
|
if (version_index >= VersionMap.size() || VersionMap[version_index].isNull())
|
|
|
|
reportError("Invalid version entry");
|
|
|
|
const VersionMapEntry &entry = VersionMap[version_index];
|
|
|
|
|
|
|
|
// Get the version name string
|
|
|
|
size_t name_offset;
|
|
|
|
if (entry.isVerdef()) {
|
|
|
|
// The first Verdaux entry holds the name.
|
|
|
|
name_offset = entry.getVerdef()->getAux()->vda_name;
|
|
|
|
} else {
|
|
|
|
name_offset = entry.getVernaux()->vna_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set IsDefault
|
|
|
|
if (entry.isVerdef()) {
|
|
|
|
IsDefault = !(vs->vs_index & ELF::VERSYM_HIDDEN);
|
|
|
|
} else {
|
|
|
|
IsDefault = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name_offset >= StrTab.size())
|
|
|
|
reportError("Invalid string offset");
|
|
|
|
return StringRef(StrTab.data() + name_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ELFT>
|
|
|
|
std::string ELFDumper<ELFT>::getFullSymbolName(const Elf_Sym *Symbol,
|
|
|
|
StringRef StrTable,
|
|
|
|
bool IsDynamic) {
|
2015-07-21 18:02:10 +02:00
|
|
|
StringRef SymbolName = errorOrDefault(Symbol->getName(StrTable));
|
2015-06-29 14:38:31 +02:00
|
|
|
if (!IsDynamic)
|
2014-06-10 07:59:15 +02:00
|
|
|
return SymbolName;
|
|
|
|
|
|
|
|
std::string FullSymbolName(SymbolName);
|
|
|
|
|
|
|
|
bool IsDefault;
|
2015-08-06 23:54:37 +02:00
|
|
|
StringRef Version = getSymbolVersion(StrTable, &*Symbol, IsDefault);
|
|
|
|
FullSymbolName += (IsDefault ? "@@" : "@");
|
|
|
|
FullSymbolName += Version;
|
2014-06-10 07:59:15 +02:00
|
|
|
return FullSymbolName;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ELFO>
|
|
|
|
static void
|
2015-06-29 14:38:31 +02:00
|
|
|
getSectionNameIndex(const ELFO &Obj, const typename ELFO::Elf_Sym *Symbol,
|
2015-08-10 23:29:35 +02:00
|
|
|
const typename ELFO::Elf_Shdr *SymTab,
|
|
|
|
ArrayRef<typename ELFO::Elf_Word> ShndxTable,
|
2014-06-10 07:59:15 +02:00
|
|
|
StringRef &SectionName, unsigned &SectionIndex) {
|
|
|
|
SectionIndex = Symbol->st_shndx;
|
2015-06-08 06:55:29 +02:00
|
|
|
if (Symbol->isUndefined())
|
2014-06-10 07:59:15 +02:00
|
|
|
SectionName = "Undefined";
|
2015-06-08 06:55:29 +02:00
|
|
|
else if (Symbol->isProcessorSpecific())
|
2014-06-10 07:59:15 +02:00
|
|
|
SectionName = "Processor Specific";
|
2015-06-08 06:55:29 +02:00
|
|
|
else if (Symbol->isOSSpecific())
|
2014-06-10 07:59:15 +02:00
|
|
|
SectionName = "Operating System Specific";
|
2015-06-08 06:55:29 +02:00
|
|
|
else if (Symbol->isAbsolute())
|
2014-06-10 07:59:15 +02:00
|
|
|
SectionName = "Absolute";
|
2015-06-08 06:55:29 +02:00
|
|
|
else if (Symbol->isCommon())
|
2014-06-10 07:59:15 +02:00
|
|
|
SectionName = "Common";
|
2015-06-12 19:23:39 +02:00
|
|
|
else if (Symbol->isReserved() && SectionIndex != SHN_XINDEX)
|
|
|
|
SectionName = "Reserved";
|
2015-06-08 06:55:29 +02:00
|
|
|
else {
|
2014-06-10 07:59:15 +02:00
|
|
|
if (SectionIndex == SHN_XINDEX)
|
2015-08-10 23:29:35 +02:00
|
|
|
SectionIndex =
|
|
|
|
Obj.getExtendedSymbolTableIndex(Symbol, SymTab, ShndxTable);
|
2015-07-01 14:56:27 +02:00
|
|
|
ErrorOr<const typename ELFO::Elf_Shdr *> Sec = Obj.getSection(SectionIndex);
|
2015-07-20 05:23:55 +02:00
|
|
|
error(Sec.getError());
|
|
|
|
SectionName = errorOrDefault(Obj.getSectionName(*Sec));
|
2014-06-10 07:59:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 10:48:14 +02:00
|
|
|
template <class ELFO>
|
|
|
|
static const typename ELFO::Elf_Shdr *findSectionByAddress(const ELFO *Obj,
|
|
|
|
uint64_t Addr) {
|
2014-06-18 10:47:09 +02:00
|
|
|
for (const auto &Shdr : Obj->sections())
|
|
|
|
if (Shdr.sh_addr == Addr)
|
|
|
|
return &Shdr;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-07-23 10:48:14 +02:00
|
|
|
template <class ELFO>
|
|
|
|
static const typename ELFO::Elf_Shdr *findSectionByName(const ELFO &Obj,
|
|
|
|
StringRef Name) {
|
2015-05-07 17:40:35 +02:00
|
|
|
for (const auto &Shdr : Obj.sections()) {
|
|
|
|
if (Name == errorOrDefault(Obj.getSectionName(&Shdr)))
|
|
|
|
return &Shdr;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-04-03 20:31:38 +02:00
|
|
|
static const EnumEntry<unsigned> ElfClass[] = {
|
|
|
|
{ "None", ELF::ELFCLASSNONE },
|
|
|
|
{ "32-bit", ELF::ELFCLASS32 },
|
|
|
|
{ "64-bit", ELF::ELFCLASS64 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const EnumEntry<unsigned> ElfDataEncoding[] = {
|
|
|
|
{ "None", ELF::ELFDATANONE },
|
|
|
|
{ "LittleEndian", ELF::ELFDATA2LSB },
|
|
|
|
{ "BigEndian", ELF::ELFDATA2MSB },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const EnumEntry<unsigned> ElfObjectFileType[] = {
|
|
|
|
{ "None", ELF::ET_NONE },
|
|
|
|
{ "Relocatable", ELF::ET_REL },
|
|
|
|
{ "Executable", ELF::ET_EXEC },
|
|
|
|
{ "SharedObject", ELF::ET_DYN },
|
|
|
|
{ "Core", ELF::ET_CORE },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const EnumEntry<unsigned> ElfOSABI[] = {
|
|
|
|
{ "SystemV", ELF::ELFOSABI_NONE },
|
|
|
|
{ "HPUX", ELF::ELFOSABI_HPUX },
|
|
|
|
{ "NetBSD", ELF::ELFOSABI_NETBSD },
|
|
|
|
{ "GNU/Linux", ELF::ELFOSABI_LINUX },
|
|
|
|
{ "GNU/Hurd", ELF::ELFOSABI_HURD },
|
|
|
|
{ "Solaris", ELF::ELFOSABI_SOLARIS },
|
|
|
|
{ "AIX", ELF::ELFOSABI_AIX },
|
|
|
|
{ "IRIX", ELF::ELFOSABI_IRIX },
|
|
|
|
{ "FreeBSD", ELF::ELFOSABI_FREEBSD },
|
|
|
|
{ "TRU64", ELF::ELFOSABI_TRU64 },
|
|
|
|
{ "Modesto", ELF::ELFOSABI_MODESTO },
|
|
|
|
{ "OpenBSD", ELF::ELFOSABI_OPENBSD },
|
|
|
|
{ "OpenVMS", ELF::ELFOSABI_OPENVMS },
|
|
|
|
{ "NSK", ELF::ELFOSABI_NSK },
|
|
|
|
{ "AROS", ELF::ELFOSABI_AROS },
|
|
|
|
{ "FenixOS", ELF::ELFOSABI_FENIXOS },
|
2015-03-09 19:40:45 +01:00
|
|
|
{ "CloudABI", ELF::ELFOSABI_CLOUDABI },
|
2013-04-03 20:31:38 +02:00
|
|
|
{ "C6000_ELFABI", ELF::ELFOSABI_C6000_ELFABI },
|
|
|
|
{ "C6000_LINUX" , ELF::ELFOSABI_C6000_LINUX },
|
|
|
|
{ "ARM", ELF::ELFOSABI_ARM },
|
|
|
|
{ "Standalone" , ELF::ELFOSABI_STANDALONE }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const EnumEntry<unsigned> ElfMachineType[] = {
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_NONE ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_M32 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_SPARC ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_386 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_68K ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_88K ),
|
2015-06-19 16:34:12 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_IAMCU ),
|
2013-04-03 20:31:38 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_860 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_MIPS ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_S370 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_MIPS_RS3_LE ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_PARISC ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_VPP500 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_SPARC32PLUS ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_960 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_PPC ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_PPC64 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_S390 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_SPU ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_V800 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_FR20 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_RH32 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_RCE ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ARM ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ALPHA ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_SH ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_SPARCV9 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_TRICORE ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ARC ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_H8_300 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_H8_300H ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_H8S ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_H8_500 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_IA_64 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_MIPS_X ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_COLDFIRE ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_68HC12 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_MMA ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_PCP ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_NCPU ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_NDR1 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_STARCORE ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ME16 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ST100 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_TINYJ ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_X86_64 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_PDSP ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_PDP10 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_PDP11 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_FX66 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ST9PLUS ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ST7 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_68HC16 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_68HC11 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_68HC08 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_68HC05 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_SVX ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ST19 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_VAX ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_CRIS ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_JAVELIN ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_FIREPATH ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ZSP ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_MMIX ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_HUANY ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_PRISM ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_AVR ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_FR30 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_D10V ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_D30V ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_V850 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_M32R ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_MN10300 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_MN10200 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_PJ ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_OPENRISC ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ARC_COMPACT ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_XTENSA ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_VIDEOCORE ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_TMM_GPP ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_NS32K ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_TPC ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_SNP1K ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ST200 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_IP2K ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_MAX ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_CR ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_F2MC16 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_MSP430 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_BLACKFIN ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_SE_C33 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_SEP ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ARCA ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_UNICORE ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_EXCESS ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_DXP ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ALTERA_NIOS2 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_CRX ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_XGATE ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_C166 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_M16C ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_DSPIC30F ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_CE ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_M32C ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_TSK3000 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_RS08 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_SHARC ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ECOG2 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_SCORE7 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_DSP24 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_VIDEOCORE3 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_LATTICEMICO32),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_SE_C17 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_TI_C6000 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_TI_C2000 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_TI_C5500 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_MMDSP_PLUS ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_CYPRESS_M8C ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_R32C ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_TRIMEDIA ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_HEXAGON ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_8051 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_STXP7X ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_NDS32 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ECOG1 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ECOG1X ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_MAXQ30 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_XIMO16 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_MANIK ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_CRAYNV2 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_RX ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_METAG ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_MCST_ELBRUS ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ECOG16 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_CR16 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ETPU ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_SLE9X ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_L10M ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_K10M ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_AARCH64 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_AVR32 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_STM8 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_TILE64 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_TILEPRO ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_CUDA ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_TILEGX ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_CLOUDSHIELD ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_COREA_1ST ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_COREA_2ND ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_ARC_COMPACT2 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_OPEN8 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_RL78 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_VIDEOCORE5 ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_78KOR ),
|
2015-06-22 23:03:47 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_56800EX ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EM_AMDGPU )
|
2013-04-03 20:31:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const EnumEntry<unsigned> ElfSymbolBindings[] = {
|
2015-01-23 05:44:35 +01:00
|
|
|
{ "Local", ELF::STB_LOCAL },
|
|
|
|
{ "Global", ELF::STB_GLOBAL },
|
|
|
|
{ "Weak", ELF::STB_WEAK },
|
|
|
|
{ "Unique", ELF::STB_GNU_UNIQUE }
|
2013-04-03 20:31:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const EnumEntry<unsigned> ElfSymbolTypes[] = {
|
|
|
|
{ "None", ELF::STT_NOTYPE },
|
|
|
|
{ "Object", ELF::STT_OBJECT },
|
|
|
|
{ "Function", ELF::STT_FUNC },
|
|
|
|
{ "Section", ELF::STT_SECTION },
|
|
|
|
{ "File", ELF::STT_FILE },
|
|
|
|
{ "Common", ELF::STT_COMMON },
|
|
|
|
{ "TLS", ELF::STT_TLS },
|
|
|
|
{ "GNU_IFunc", ELF::STT_GNU_IFUNC }
|
|
|
|
};
|
|
|
|
|
2015-08-07 03:35:24 +02:00
|
|
|
static const EnumEntry<unsigned> AMDGPUSymbolTypes[] = {
|
|
|
|
{ "AMDGPU_HSA_KERNEL", ELF::STT_AMDGPU_HSA_KERNEL },
|
|
|
|
{ "AMDGPU_HSA_INDIRECT_FUNCTION", ELF::STT_AMDGPU_HSA_INDIRECT_FUNCTION },
|
|
|
|
{ "AMDGPU_HSA_METADATA", ELF::STT_AMDGPU_HSA_METADATA }
|
|
|
|
};
|
|
|
|
|
2013-04-03 20:31:38 +02:00
|
|
|
static const char *getElfSectionType(unsigned Arch, unsigned Type) {
|
|
|
|
switch (Arch) {
|
2013-08-09 00:27:13 +02:00
|
|
|
case ELF::EM_ARM:
|
2013-04-03 20:31:38 +02:00
|
|
|
switch (Type) {
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_EXIDX);
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_PREEMPTMAP);
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_ATTRIBUTES);
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_DEBUGOVERLAY);
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_OVERLAYSECTION);
|
|
|
|
}
|
2013-08-09 00:27:13 +02:00
|
|
|
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:
|
2013-04-03 20:31:38 +02:00
|
|
|
switch (Type) {
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_MIPS_REGINFO);
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_MIPS_OPTIONS);
|
2014-07-13 17:28:54 +02:00
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_MIPS_ABIFLAGS);
|
2013-04-03 20:31:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Type) {
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_NULL );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_PROGBITS );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_SYMTAB );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_STRTAB );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_RELA );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_HASH );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_DYNAMIC );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_NOTE );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_NOBITS );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_REL );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_SHLIB );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_DYNSYM );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_INIT_ARRAY );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_FINI_ARRAY );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_PREINIT_ARRAY );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_GROUP );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_SYMTAB_SHNDX );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_GNU_ATTRIBUTES );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_GNU_HASH );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_GNU_verdef );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_GNU_verneed );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, SHT_GNU_versym );
|
|
|
|
default: return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const EnumEntry<unsigned> ElfSectionFlags[] = {
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_WRITE ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_ALLOC ),
|
2013-09-15 21:53:20 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_EXCLUDE ),
|
2013-04-03 20:31:38 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_EXECINSTR ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_MERGE ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_STRINGS ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_INFO_LINK ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_LINK_ORDER ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_OS_NONCONFORMING),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_GROUP ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_TLS ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, XCORE_SHF_CP_SECTION),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, XCORE_SHF_DP_SECTION),
|
2015-08-07 03:35:24 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NOSTRIP ),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_AMDGPU_HSA_GLOBAL),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_AMDGPU_HSA_READONLY),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_AMDGPU_HSA_CODE),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, SHF_AMDGPU_HSA_AGENT)
|
2013-04-03 20:31:38 +02:00
|
|
|
};
|
|
|
|
|
2013-10-07 10:58:27 +02:00
|
|
|
static const char *getElfSegmentType(unsigned Arch, unsigned Type) {
|
|
|
|
// Check potentially overlapped processor-specific
|
|
|
|
// program header type.
|
|
|
|
switch (Arch) {
|
2015-08-07 03:35:24 +02:00
|
|
|
case ELF::EM_AMDGPU:
|
|
|
|
switch (Type) {
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_GLOBAL_PROGRAM);
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_GLOBAL_AGENT);
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_READONLY_AGENT);
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_CODE_AGENT);
|
|
|
|
}
|
2013-10-07 10:58:27 +02:00
|
|
|
case ELF::EM_ARM:
|
|
|
|
switch (Type) {
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_ARM_EXIDX);
|
|
|
|
}
|
|
|
|
case ELF::EM_MIPS:
|
|
|
|
case ELF::EM_MIPS_RS3_LE:
|
|
|
|
switch (Type) {
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_REGINFO);
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_RTPROC);
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_OPTIONS);
|
2015-05-15 17:59:22 +02:00
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_ABIFLAGS);
|
2013-10-07 10:58:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Type) {
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_NULL );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_LOAD );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_DYNAMIC);
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_INTERP );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_NOTE );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_SHLIB );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_PHDR );
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_TLS );
|
|
|
|
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_EH_FRAME);
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_SUNW_UNWIND);
|
|
|
|
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_STACK);
|
|
|
|
LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_RELRO);
|
|
|
|
default: return "";
|
|
|
|
}
|
|
|
|
}
|
2013-04-12 06:07:39 +02:00
|
|
|
|
|
|
|
static const EnumEntry<unsigned> ElfSegmentFlags[] = {
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, PF_X),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, PF_W),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, PF_R)
|
|
|
|
};
|
|
|
|
|
2014-05-01 13:07:19 +02:00
|
|
|
static const EnumEntry<unsigned> ElfHeaderMipsFlags[] = {
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_NOREORDER),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_PIC),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_CPIC),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI2),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_32BITMODE),
|
2015-05-07 16:04:44 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_FP64),
|
2014-05-01 13:07:19 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_NAN2008),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI_O32),
|
2015-05-07 16:04:44 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI_O64),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI_EABI32),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI_EABI64),
|
2015-05-08 09:04:59 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_3900),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4010),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4100),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4650),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4120),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4111),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_SB1),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_OCTEON),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_XLR),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_OCTEON2),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_OCTEON3),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_5400),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_5900),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_5500),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_9000),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_LS2E),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_LS2F),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_LS3A),
|
2014-05-01 13:07:19 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MICROMIPS),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_ASE_M16),
|
2015-05-07 16:04:44 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_ASE_MDMX),
|
2014-05-01 13:07:19 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_1),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_2),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_3),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_4),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_5),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_32),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_64),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_32R2),
|
2014-05-20 11:27:49 +02:00
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_64R2),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_32R6),
|
|
|
|
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_64R6)
|
2014-05-01 13:07:19 +02:00
|
|
|
};
|
|
|
|
|
2015-07-21 22:50:53 +02:00
|
|
|
template <typename ELFT>
|
|
|
|
ELFDumper<ELFT>::ELFDumper(const ELFFile<ELFT> *Obj, StreamWriter &Writer)
|
|
|
|
: ObjDumper(Writer), Obj(Obj) {
|
|
|
|
|
|
|
|
SmallVector<const Elf_Phdr *, 4> LoadSegments;
|
|
|
|
for (const Elf_Phdr &Phdr : Obj->program_headers()) {
|
|
|
|
if (Phdr.p_type == ELF::PT_DYNAMIC) {
|
2015-08-07 17:25:20 +02:00
|
|
|
DynamicProgHeader = &Phdr;
|
2015-07-21 22:50:53 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Phdr.p_type != ELF::PT_LOAD || Phdr.p_filesz == 0)
|
|
|
|
continue;
|
|
|
|
LoadSegments.push_back(&Phdr);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto toMappedAddr = [&](uint64_t VAddr) -> const uint8_t * {
|
|
|
|
const Elf_Phdr **I = std::upper_bound(
|
|
|
|
LoadSegments.begin(), LoadSegments.end(), VAddr, compareAddr<ELFT>);
|
|
|
|
if (I == LoadSegments.begin())
|
|
|
|
report_fatal_error("Virtual address is not in any segment");
|
|
|
|
--I;
|
|
|
|
const Elf_Phdr &Phdr = **I;
|
|
|
|
uint64_t Delta = VAddr - Phdr.p_vaddr;
|
|
|
|
if (Delta >= Phdr.p_filesz)
|
|
|
|
report_fatal_error("Virtual address is not in any segment");
|
|
|
|
return Obj->base() + Phdr.p_offset + Delta;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint64_t SONameOffset = 0;
|
|
|
|
const char *StringTableBegin = nullptr;
|
|
|
|
uint64_t StringTableSize = 0;
|
|
|
|
for (const Elf_Dyn &Dyn : dynamic_table()) {
|
|
|
|
switch (Dyn.d_tag) {
|
|
|
|
case ELF::DT_HASH:
|
|
|
|
HashTable =
|
|
|
|
reinterpret_cast<const Elf_Hash *>(toMappedAddr(Dyn.getPtr()));
|
|
|
|
break;
|
2015-10-14 14:11:50 +02:00
|
|
|
case ELF::DT_GNU_HASH:
|
|
|
|
GnuHashTable =
|
|
|
|
reinterpret_cast<const Elf_GnuHash *>(toMappedAddr(Dyn.getPtr()));
|
|
|
|
break;
|
2015-07-21 22:50:53 +02:00
|
|
|
case ELF::DT_RELA:
|
|
|
|
DynRelaRegion.Addr = toMappedAddr(Dyn.getPtr());
|
|
|
|
break;
|
|
|
|
case ELF::DT_RELASZ:
|
|
|
|
DynRelaRegion.Size = Dyn.getVal();
|
|
|
|
break;
|
|
|
|
case ELF::DT_RELAENT:
|
|
|
|
DynRelaRegion.EntSize = Dyn.getVal();
|
|
|
|
break;
|
|
|
|
case ELF::DT_SONAME:
|
|
|
|
SONameOffset = Dyn.getVal();
|
|
|
|
break;
|
|
|
|
case ELF::DT_STRTAB:
|
|
|
|
StringTableBegin = (const char *)toMappedAddr(Dyn.getPtr());
|
|
|
|
break;
|
|
|
|
case ELF::DT_STRSZ:
|
|
|
|
StringTableSize = Dyn.getVal();
|
|
|
|
break;
|
2015-07-23 11:11:05 +02:00
|
|
|
case ELF::DT_SYMTAB:
|
|
|
|
DynSymStart =
|
|
|
|
reinterpret_cast<const Elf_Sym *>(toMappedAddr(Dyn.getPtr()));
|
|
|
|
break;
|
2015-07-21 22:50:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringTableBegin)
|
|
|
|
DynamicStringTable = StringRef(StringTableBegin, StringTableSize);
|
|
|
|
if (SONameOffset)
|
|
|
|
SOName = getDynamicString(SONameOffset);
|
2015-08-06 23:54:37 +02:00
|
|
|
|
|
|
|
for (const Elf_Shdr &Sec : Obj->sections()) {
|
|
|
|
switch (Sec.sh_type) {
|
|
|
|
case ELF::SHT_GNU_versym:
|
|
|
|
if (dot_gnu_version_sec != nullptr)
|
|
|
|
reportError("Multiple SHT_GNU_versym");
|
|
|
|
dot_gnu_version_sec = &Sec;
|
|
|
|
break;
|
|
|
|
case ELF::SHT_GNU_verdef:
|
|
|
|
if (dot_gnu_version_d_sec != nullptr)
|
|
|
|
reportError("Multiple SHT_GNU_verdef");
|
|
|
|
dot_gnu_version_d_sec = &Sec;
|
|
|
|
break;
|
|
|
|
case ELF::SHT_GNU_verneed:
|
|
|
|
if (dot_gnu_version_r_sec != nullptr)
|
|
|
|
reportError("Multilpe SHT_GNU_verneed");
|
|
|
|
dot_gnu_version_r_sec = &Sec;
|
|
|
|
break;
|
2015-08-07 22:11:08 +02:00
|
|
|
case ELF::SHT_DYNSYM:
|
|
|
|
if (DotDynSymSec != nullptr)
|
|
|
|
reportError("Multilpe SHT_DYNSYM");
|
|
|
|
DotDynSymSec = &Sec;
|
|
|
|
break;
|
2015-08-10 22:25:04 +02:00
|
|
|
case ELF::SHT_SYMTAB:
|
|
|
|
if (DotSymtabSec != nullptr)
|
|
|
|
reportError("Multilpe SHT_SYMTAB");
|
|
|
|
DotSymtabSec = &Sec;
|
|
|
|
break;
|
2015-08-10 23:29:35 +02:00
|
|
|
case ELF::SHT_SYMTAB_SHNDX: {
|
|
|
|
ErrorOr<ArrayRef<Elf_Word>> TableOrErr = Obj->getSHNDXTable(Sec);
|
|
|
|
error(TableOrErr.getError());
|
|
|
|
ShndxTable = *TableOrErr;
|
|
|
|
break;
|
|
|
|
}
|
2015-08-06 23:54:37 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-21 22:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ELFT>
|
|
|
|
const typename ELFDumper<ELFT>::Elf_Rela *
|
|
|
|
ELFDumper<ELFT>::dyn_rela_begin() const {
|
|
|
|
if (DynRelaRegion.Size && DynRelaRegion.EntSize != sizeof(Elf_Rela))
|
|
|
|
report_fatal_error("Invalid relocation entry size");
|
|
|
|
return reinterpret_cast<const Elf_Rela *>(DynRelaRegion.Addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ELFT>
|
|
|
|
const typename ELFDumper<ELFT>::Elf_Rela *
|
|
|
|
ELFDumper<ELFT>::dyn_rela_end() const {
|
|
|
|
uint64_t Size = DynRelaRegion.Size;
|
|
|
|
if (Size % sizeof(Elf_Rela))
|
|
|
|
report_fatal_error("Invalid relocation table size");
|
|
|
|
return dyn_rela_begin() + Size / sizeof(Elf_Rela);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ELFT>
|
|
|
|
typename ELFDumper<ELFT>::Elf_Rela_Range ELFDumper<ELFT>::dyn_relas() const {
|
|
|
|
return make_range(dyn_rela_begin(), dyn_rela_end());
|
|
|
|
}
|
|
|
|
|
2013-04-03 20:31:38 +02:00
|
|
|
template<class ELFT>
|
|
|
|
void ELFDumper<ELFT>::printFileHeaders() {
|
2015-07-23 10:48:14 +02:00
|
|
|
const Elf_Ehdr *Header = Obj->getHeader();
|
2013-04-03 20:31:38 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
DictScope D(W, "ElfHeader");
|
|
|
|
{
|
|
|
|
DictScope D(W, "Ident");
|
|
|
|
W.printBinary("Magic", makeArrayRef(Header->e_ident).slice(ELF::EI_MAG0,
|
|
|
|
4));
|
|
|
|
W.printEnum ("Class", Header->e_ident[ELF::EI_CLASS],
|
|
|
|
makeArrayRef(ElfClass));
|
|
|
|
W.printEnum ("DataEncoding", Header->e_ident[ELF::EI_DATA],
|
|
|
|
makeArrayRef(ElfDataEncoding));
|
|
|
|
W.printNumber("FileVersion", Header->e_ident[ELF::EI_VERSION]);
|
2015-06-26 23:15:11 +02:00
|
|
|
|
|
|
|
// Handle architecture specific OS/ABI values.
|
|
|
|
if (Header->e_machine == ELF::EM_AMDGPU &&
|
|
|
|
Header->e_ident[ELF::EI_OSABI] == ELF::ELFOSABI_AMDGPU_HSA)
|
|
|
|
W.printHex("OS/ABI", "AMDGPU_HSA", ELF::ELFOSABI_AMDGPU_HSA);
|
|
|
|
else
|
|
|
|
W.printEnum ("OS/ABI", Header->e_ident[ELF::EI_OSABI],
|
2013-04-03 20:31:38 +02:00
|
|
|
makeArrayRef(ElfOSABI));
|
|
|
|
W.printNumber("ABIVersion", Header->e_ident[ELF::EI_ABIVERSION]);
|
|
|
|
W.printBinary("Unused", makeArrayRef(Header->e_ident).slice(ELF::EI_PAD));
|
|
|
|
}
|
|
|
|
|
|
|
|
W.printEnum ("Type", Header->e_type, makeArrayRef(ElfObjectFileType));
|
|
|
|
W.printEnum ("Machine", Header->e_machine, makeArrayRef(ElfMachineType));
|
|
|
|
W.printNumber("Version", Header->e_version);
|
|
|
|
W.printHex ("Entry", Header->e_entry);
|
|
|
|
W.printHex ("ProgramHeaderOffset", Header->e_phoff);
|
|
|
|
W.printHex ("SectionHeaderOffset", Header->e_shoff);
|
2014-05-01 13:57:40 +02:00
|
|
|
if (Header->e_machine == EM_MIPS)
|
2014-05-01 13:07:19 +02:00
|
|
|
W.printFlags("Flags", Header->e_flags, makeArrayRef(ElfHeaderMipsFlags),
|
2015-05-08 09:04:59 +02:00
|
|
|
unsigned(ELF::EF_MIPS_ARCH), unsigned(ELF::EF_MIPS_ABI),
|
|
|
|
unsigned(ELF::EF_MIPS_MACH));
|
2014-05-01 13:57:40 +02:00
|
|
|
else
|
2014-05-01 13:07:19 +02:00
|
|
|
W.printFlags("Flags", Header->e_flags);
|
2013-04-03 20:31:38 +02:00
|
|
|
W.printNumber("HeaderSize", Header->e_ehsize);
|
|
|
|
W.printNumber("ProgramHeaderEntrySize", Header->e_phentsize);
|
|
|
|
W.printNumber("ProgramHeaderCount", Header->e_phnum);
|
|
|
|
W.printNumber("SectionHeaderEntrySize", Header->e_shentsize);
|
|
|
|
W.printNumber("SectionHeaderCount", Header->e_shnum);
|
|
|
|
W.printNumber("StringTableSectionIndex", Header->e_shstrndx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class ELFT>
|
|
|
|
void ELFDumper<ELFT>::printSections() {
|
|
|
|
ListScope SectionsD(W, "Sections");
|
|
|
|
|
|
|
|
int SectionIndex = -1;
|
2015-07-23 10:48:14 +02:00
|
|
|
for (const Elf_Shdr &Sec : Obj->sections()) {
|
2013-04-03 20:31:38 +02:00
|
|
|
++SectionIndex;
|
|
|
|
|
2015-06-30 21:24:51 +02:00
|
|
|
StringRef Name = errorOrDefault(Obj->getSectionName(&Sec));
|
2013-04-03 20:31:38 +02:00
|
|
|
|
|
|
|
DictScope SectionD(W, "Section");
|
|
|
|
W.printNumber("Index", SectionIndex);
|
2015-06-30 21:24:51 +02:00
|
|
|
W.printNumber("Name", Name, Sec.sh_name);
|
2013-08-09 00:27:13 +02:00
|
|
|
W.printHex("Type",
|
2015-06-30 21:24:51 +02:00
|
|
|
getElfSectionType(Obj->getHeader()->e_machine, Sec.sh_type),
|
|
|
|
Sec.sh_type);
|
|
|
|
W.printFlags("Flags", Sec.sh_flags, makeArrayRef(ElfSectionFlags));
|
|
|
|
W.printHex("Address", Sec.sh_addr);
|
|
|
|
W.printHex("Offset", Sec.sh_offset);
|
|
|
|
W.printNumber("Size", Sec.sh_size);
|
|
|
|
W.printNumber("Link", Sec.sh_link);
|
|
|
|
W.printNumber("Info", Sec.sh_info);
|
|
|
|
W.printNumber("AddressAlignment", Sec.sh_addralign);
|
|
|
|
W.printNumber("EntrySize", Sec.sh_entsize);
|
2013-04-03 20:31:38 +02:00
|
|
|
|
|
|
|
if (opts::SectionRelocations) {
|
|
|
|
ListScope D(W, "Relocations");
|
2015-06-30 21:24:51 +02:00
|
|
|
printRelocations(&Sec);
|
2013-04-03 20:31:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (opts::SectionSymbols) {
|
|
|
|
ListScope D(W, "Symbols");
|
2015-08-10 22:25:04 +02:00
|
|
|
const Elf_Shdr *Symtab = DotSymtabSec;
|
2015-07-21 18:02:10 +02:00
|
|
|
ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*Symtab);
|
|
|
|
error(StrTableOrErr.getError());
|
|
|
|
StringRef StrTable = *StrTableOrErr;
|
|
|
|
|
2015-08-07 22:07:27 +02:00
|
|
|
for (const Elf_Sym &Sym : Obj->symbols(Symtab)) {
|
2015-08-10 23:29:35 +02:00
|
|
|
ErrorOr<const Elf_Shdr *> SymSec =
|
|
|
|
Obj->getSection(&Sym, Symtab, ShndxTable);
|
2015-07-01 14:56:27 +02:00
|
|
|
if (!SymSec)
|
|
|
|
continue;
|
|
|
|
if (*SymSec == &Sec)
|
2015-08-10 23:29:35 +02:00
|
|
|
printSymbol(&Sym, Symtab, StrTable, false);
|
2013-04-03 20:31:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-30 21:24:51 +02:00
|
|
|
if (opts::SectionData && Sec.sh_type != ELF::SHT_NOBITS) {
|
|
|
|
ArrayRef<uint8_t> Data = errorOrDefault(Obj->getSectionContents(&Sec));
|
2013-08-09 00:27:13 +02:00
|
|
|
W.printBinaryBlock("SectionData",
|
|
|
|
StringRef((const char *)Data.data(), Data.size()));
|
2013-04-03 20:31:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class ELFT>
|
|
|
|
void ELFDumper<ELFT>::printRelocations() {
|
|
|
|
ListScope D(W, "Relocations");
|
|
|
|
|
|
|
|
int SectionNumber = -1;
|
2015-07-23 10:48:14 +02:00
|
|
|
for (const Elf_Shdr &Sec : Obj->sections()) {
|
2013-04-03 20:31:38 +02:00
|
|
|
++SectionNumber;
|
2013-08-09 00:27:13 +02:00
|
|
|
|
2015-06-30 21:24:51 +02:00
|
|
|
if (Sec.sh_type != ELF::SHT_REL && Sec.sh_type != ELF::SHT_RELA)
|
2013-04-03 20:31:38 +02:00
|
|
|
continue;
|
|
|
|
|
2015-06-30 21:24:51 +02:00
|
|
|
StringRef Name = errorOrDefault(Obj->getSectionName(&Sec));
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2013-08-09 00:27:13 +02:00
|
|
|
W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n";
|
|
|
|
W.indent();
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2015-06-30 21:24:51 +02:00
|
|
|
printRelocations(&Sec);
|
2013-08-09 00:27:13 +02:00
|
|
|
|
|
|
|
W.unindent();
|
|
|
|
W.startLine() << "}\n";
|
|
|
|
}
|
|
|
|
}
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2015-06-25 23:47:32 +02:00
|
|
|
template<class ELFT>
|
|
|
|
void ELFDumper<ELFT>::printDynamicRelocations() {
|
|
|
|
W.startLine() << "Dynamic Relocations {\n";
|
|
|
|
W.indent();
|
2015-07-23 10:48:14 +02:00
|
|
|
for (const Elf_Rela &Rel : dyn_relas()) {
|
2015-06-25 23:47:32 +02:00
|
|
|
SmallString<32> RelocName;
|
2015-07-20 22:07:50 +02:00
|
|
|
Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName);
|
2015-06-25 23:47:32 +02:00
|
|
|
StringRef SymbolName;
|
2015-07-20 22:07:50 +02:00
|
|
|
uint32_t SymIndex = Rel.getSymbol(Obj->isMips64EL());
|
2015-07-23 11:11:05 +02:00
|
|
|
const Elf_Sym *Sym = DynSymStart + SymIndex;
|
2015-07-21 22:50:53 +02:00
|
|
|
SymbolName = errorOrDefault(Sym->getName(DynamicStringTable));
|
2015-06-25 23:47:32 +02:00
|
|
|
if (opts::ExpandRelocs) {
|
|
|
|
DictScope Group(W, "Relocation");
|
2015-07-20 22:07:50 +02:00
|
|
|
W.printHex("Offset", Rel.r_offset);
|
|
|
|
W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL()));
|
2015-06-25 23:47:32 +02:00
|
|
|
W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
|
2015-07-20 22:07:50 +02:00
|
|
|
W.printHex("Addend", Rel.r_addend);
|
2015-06-25 23:47:32 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
raw_ostream& OS = W.startLine();
|
2015-07-20 22:07:50 +02:00
|
|
|
OS << W.hex(Rel.r_offset) << " " << RelocName << " "
|
|
|
|
<< (SymbolName.size() > 0 ? SymbolName : "-") << " "
|
|
|
|
<< W.hex(Rel.r_addend) << "\n";
|
2015-06-25 23:47:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
W.unindent();
|
|
|
|
W.startLine() << "}\n";
|
|
|
|
}
|
|
|
|
|
2013-08-09 00:27:13 +02:00
|
|
|
template <class ELFT>
|
|
|
|
void ELFDumper<ELFT>::printRelocations(const Elf_Shdr *Sec) {
|
2015-09-02 17:07:39 +02:00
|
|
|
ErrorOr<const Elf_Shdr *> SymTabOrErr = Obj->getSection(Sec->sh_link);
|
|
|
|
error(SymTabOrErr.getError());
|
|
|
|
const Elf_Shdr *SymTab = *SymTabOrErr;
|
|
|
|
|
2013-08-09 00:27:13 +02:00
|
|
|
switch (Sec->sh_type) {
|
|
|
|
case ELF::SHT_REL:
|
2015-07-23 10:48:14 +02:00
|
|
|
for (const Elf_Rel &R : Obj->rels(Sec)) {
|
|
|
|
Elf_Rela Rela;
|
2015-07-20 22:07:50 +02:00
|
|
|
Rela.r_offset = R.r_offset;
|
|
|
|
Rela.r_info = R.r_info;
|
2013-08-09 00:27:13 +02:00
|
|
|
Rela.r_addend = 0;
|
2015-09-02 17:07:39 +02:00
|
|
|
printRelocation(Rela, SymTab);
|
2013-08-09 00:27:13 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ELF::SHT_RELA:
|
2015-07-23 10:48:14 +02:00
|
|
|
for (const Elf_Rela &R : Obj->relas(Sec))
|
2015-09-02 17:07:39 +02:00
|
|
|
printRelocation(R, SymTab);
|
2013-08-09 00:27:13 +02:00
|
|
|
break;
|
2013-04-03 20:31:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 00:27:13 +02:00
|
|
|
template <class ELFT>
|
2015-09-02 17:07:39 +02:00
|
|
|
void ELFDumper<ELFT>::printRelocation(Elf_Rela Rel, const Elf_Shdr *SymTab) {
|
2013-04-03 20:31:38 +02:00
|
|
|
SmallString<32> RelocName;
|
2013-08-09 00:27:13 +02:00
|
|
|
Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName);
|
2015-06-03 07:14:22 +02:00
|
|
|
StringRef TargetName;
|
2015-09-02 17:07:39 +02:00
|
|
|
const Elf_Sym *Sym = Obj->getRelocationSymbol(&Rel, SymTab);
|
|
|
|
if (Sym && Sym->getType() == ELF::STT_SECTION) {
|
|
|
|
ErrorOr<const Elf_Shdr *> Sec = Obj->getSection(Sym, SymTab, ShndxTable);
|
2015-07-20 05:23:55 +02:00
|
|
|
error(Sec.getError());
|
|
|
|
ErrorOr<StringRef> SecName = Obj->getSectionName(*Sec);
|
|
|
|
if (SecName)
|
|
|
|
TargetName = SecName.get();
|
2015-09-02 17:07:39 +02:00
|
|
|
} else if (Sym) {
|
|
|
|
ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*SymTab);
|
2015-07-20 05:23:55 +02:00
|
|
|
error(StrTableOrErr.getError());
|
2015-09-02 17:07:39 +02:00
|
|
|
TargetName = errorOrDefault(Sym->getName(*StrTableOrErr));
|
2015-06-03 07:14:22 +02:00
|
|
|
}
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2013-04-12 06:01:52 +02:00
|
|
|
if (opts::ExpandRelocs) {
|
|
|
|
DictScope Group(W, "Relocation");
|
2013-08-09 00:27:13 +02:00
|
|
|
W.printHex("Offset", Rel.r_offset);
|
|
|
|
W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL()));
|
2015-06-03 07:14:22 +02:00
|
|
|
W.printNumber("Symbol", TargetName.size() > 0 ? TargetName : "-",
|
2014-10-17 03:34:23 +02:00
|
|
|
Rel.getSymbol(Obj->isMips64EL()));
|
2013-08-09 00:27:13 +02:00
|
|
|
W.printHex("Addend", Rel.r_addend);
|
2013-04-12 06:01:52 +02:00
|
|
|
} else {
|
|
|
|
raw_ostream& OS = W.startLine();
|
2015-06-03 07:14:22 +02:00
|
|
|
OS << W.hex(Rel.r_offset) << " " << RelocName << " "
|
|
|
|
<< (TargetName.size() > 0 ? TargetName : "-") << " "
|
|
|
|
<< W.hex(Rel.r_addend) << "\n";
|
2013-04-12 06:01:52 +02:00
|
|
|
}
|
2013-04-03 20:31:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class ELFT>
|
2015-08-23 16:06:40 +02:00
|
|
|
void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) {
|
|
|
|
const Elf_Shdr *Symtab = (IsDynamic) ? DotDynSymSec : DotSymtabSec;
|
2015-09-21 21:17:18 +02:00
|
|
|
if (!Symtab)
|
|
|
|
return;
|
2015-07-21 18:02:10 +02:00
|
|
|
ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*Symtab);
|
|
|
|
error(StrTableOrErr.getError());
|
|
|
|
StringRef StrTable = *StrTableOrErr;
|
2015-08-07 22:07:27 +02:00
|
|
|
for (const Elf_Sym &Sym : Obj->symbols(Symtab))
|
2015-08-23 16:06:40 +02:00
|
|
|
printSymbol(&Sym, Symtab, StrTable, IsDynamic);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class ELFT>
|
|
|
|
void ELFDumper<ELFT>::printSymbols() {
|
|
|
|
ListScope Group(W, "Symbols");
|
|
|
|
printSymbolsHelper(false);
|
2013-04-03 20:31:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class ELFT>
|
|
|
|
void ELFDumper<ELFT>::printDynamicSymbols() {
|
|
|
|
ListScope Group(W, "DynamicSymbols");
|
2015-08-23 16:06:40 +02:00
|
|
|
printSymbolsHelper(true);
|
2013-04-03 20:31:38 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 00:27:13 +02:00
|
|
|
template <class ELFT>
|
2015-08-10 23:29:35 +02:00
|
|
|
void ELFDumper<ELFT>::printSymbol(const Elf_Sym *Symbol, const Elf_Shdr *SymTab,
|
|
|
|
StringRef StrTable, bool IsDynamic) {
|
2014-06-10 07:59:15 +02:00
|
|
|
unsigned SectionIndex = 0;
|
2014-03-24 06:00:34 +01:00
|
|
|
StringRef SectionName;
|
2015-08-10 23:29:35 +02:00
|
|
|
getSectionNameIndex(*Obj, Symbol, SymTab, ShndxTable, SectionName,
|
|
|
|
SectionIndex);
|
2015-08-06 23:54:37 +02:00
|
|
|
std::string FullSymbolName = getFullSymbolName(Symbol, StrTable, IsDynamic);
|
2015-08-07 03:35:24 +02:00
|
|
|
unsigned char SymbolType = Symbol->getType();
|
2013-04-03 20:31:38 +02:00
|
|
|
|
|
|
|
DictScope D(W, "Symbol");
|
|
|
|
W.printNumber("Name", FullSymbolName, Symbol->st_name);
|
|
|
|
W.printHex ("Value", Symbol->st_value);
|
|
|
|
W.printNumber("Size", Symbol->st_size);
|
|
|
|
W.printEnum ("Binding", Symbol->getBinding(),
|
|
|
|
makeArrayRef(ElfSymbolBindings));
|
2015-08-07 03:35:24 +02:00
|
|
|
if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU &&
|
|
|
|
SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS)
|
|
|
|
W.printEnum ("Type", SymbolType, makeArrayRef(AMDGPUSymbolTypes));
|
|
|
|
else
|
|
|
|
W.printEnum ("Type", SymbolType, makeArrayRef(ElfSymbolTypes));
|
2013-04-03 20:31:38 +02:00
|
|
|
W.printNumber("Other", Symbol->st_other);
|
2014-03-26 00:44:25 +01:00
|
|
|
W.printHex("Section", SectionName, SectionIndex);
|
2013-04-03 20:31:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define LLVM_READOBJ_TYPE_CASE(name) \
|
|
|
|
case DT_##name: return #name
|
|
|
|
|
|
|
|
static const char *getTypeString(uint64_t Type) {
|
|
|
|
switch (Type) {
|
|
|
|
LLVM_READOBJ_TYPE_CASE(BIND_NOW);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(DEBUG);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(FINI);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(FINI_ARRAY);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(FINI_ARRAYSZ);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(FLAGS);
|
2015-05-25 21:12:18 +02:00
|
|
|
LLVM_READOBJ_TYPE_CASE(FLAGS_1);
|
2013-04-03 20:31:38 +02:00
|
|
|
LLVM_READOBJ_TYPE_CASE(HASH);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(INIT);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(INIT_ARRAY);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(INIT_ARRAYSZ);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(PREINIT_ARRAY);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(PREINIT_ARRAYSZ);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(JMPREL);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(NEEDED);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(NULL);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(PLTGOT);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(PLTREL);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(PLTRELSZ);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(REL);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(RELA);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(RELENT);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(RELSZ);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(RELAENT);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(RELASZ);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(RPATH);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(RUNPATH);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(SONAME);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(STRSZ);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(STRTAB);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(SYMBOLIC);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(SYMENT);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(SYMTAB);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(TEXTREL);
|
2015-10-16 00:04:55 +02:00
|
|
|
LLVM_READOBJ_TYPE_CASE(VERDEF);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(VERDEFNUM);
|
2013-11-11 21:51:48 +01:00
|
|
|
LLVM_READOBJ_TYPE_CASE(VERNEED);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(VERNEEDNUM);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(VERSYM);
|
2014-05-11 10:48:09 +02:00
|
|
|
LLVM_READOBJ_TYPE_CASE(RELCOUNT);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(GNU_HASH);
|
2013-11-11 21:51:48 +01:00
|
|
|
LLVM_READOBJ_TYPE_CASE(MIPS_RLD_VERSION);
|
2015-08-01 14:02:02 +02:00
|
|
|
LLVM_READOBJ_TYPE_CASE(MIPS_RLD_MAP_REL);
|
2013-11-11 21:51:48 +01:00
|
|
|
LLVM_READOBJ_TYPE_CASE(MIPS_FLAGS);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(MIPS_BASE_ADDRESS);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(MIPS_LOCAL_GOTNO);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(MIPS_SYMTABNO);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(MIPS_UNREFEXTNO);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(MIPS_GOTSYM);
|
2014-01-05 14:40:27 +01:00
|
|
|
LLVM_READOBJ_TYPE_CASE(MIPS_RLD_MAP);
|
|
|
|
LLVM_READOBJ_TYPE_CASE(MIPS_PLTGOT);
|
2015-04-20 07:34:48 +02:00
|
|
|
LLVM_READOBJ_TYPE_CASE(MIPS_OPTIONS);
|
2013-04-03 20:31:38 +02:00
|
|
|
default: return "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef LLVM_READOBJ_TYPE_CASE
|
|
|
|
|
2014-05-11 10:48:09 +02:00
|
|
|
#define LLVM_READOBJ_DT_FLAG_ENT(prefix, enum) \
|
|
|
|
{ #enum, prefix##_##enum }
|
|
|
|
|
|
|
|
static const EnumEntry<unsigned> ElfDynamicDTFlags[] = {
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF, ORIGIN),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF, SYMBOLIC),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF, TEXTREL),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF, BIND_NOW),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF, STATIC_TLS)
|
|
|
|
};
|
|
|
|
|
2015-05-25 21:12:18 +02:00
|
|
|
static const EnumEntry<unsigned> ElfDynamicDTFlags1[] = {
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOW),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, GLOBAL),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, GROUP),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODELETE),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, LOADFLTR),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, INITFIRST),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOOPEN),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, ORIGIN),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, DIRECT),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, TRANS),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, INTERPOSE),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODEFLIB),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODUMP),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, CONFALT),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, ENDFILTEE),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, DISPRELDNE),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODIRECT),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, IGNMULDEF),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOKSYMS),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOHDR),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, EDITED),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, NORELOC),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, SYMINTPOSE),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, GLOBAUDIT),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(DF_1, SINGLETON)
|
|
|
|
};
|
|
|
|
|
2014-05-11 10:48:09 +02:00
|
|
|
static const EnumEntry<unsigned> ElfDynamicDTMipsFlags[] = {
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, NONE),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, QUICKSTART),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, NOTPOT),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHS, NO_LIBRARY_REPLACEMENT),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, NO_MOVE),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, SGI_ONLY),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, GUARANTEE_INIT),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, DELTA_C_PLUS_PLUS),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, GUARANTEE_START_INIT),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, PIXIE),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, DEFAULT_DELAY_LOAD),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, REQUICKSTART),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, REQUICKSTARTED),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, CORD),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, NO_UNRES_UNDEF),
|
|
|
|
LLVM_READOBJ_DT_FLAG_ENT(RHF, RLD_ORDER_SAFE)
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef LLVM_READOBJ_DT_FLAG_ENT
|
|
|
|
|
|
|
|
template <typename T, typename TFlag>
|
|
|
|
void printFlags(T Value, ArrayRef<EnumEntry<TFlag>> Flags, raw_ostream &OS) {
|
|
|
|
typedef EnumEntry<TFlag> FlagEntry;
|
|
|
|
typedef SmallVector<FlagEntry, 10> FlagVector;
|
|
|
|
FlagVector SetFlags;
|
|
|
|
|
|
|
|
for (const auto &Flag : Flags) {
|
|
|
|
if (Flag.Value == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((Value & Flag.Value) == Flag.Value)
|
|
|
|
SetFlags.push_back(Flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &Flag : SetFlags) {
|
|
|
|
OS << Flag.Name << " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-20 05:38:17 +02:00
|
|
|
template <class ELFT>
|
2015-07-21 22:50:53 +02:00
|
|
|
StringRef ELFDumper<ELFT>::getDynamicString(uint64_t Value) const {
|
|
|
|
if (Value >= DynamicStringTable.size())
|
2015-07-20 05:38:17 +02:00
|
|
|
reportError("Invalid dynamic string table reference");
|
2015-07-21 22:50:53 +02:00
|
|
|
return StringRef(DynamicStringTable.data() + Value);
|
2015-07-20 05:38:17 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 00:27:13 +02:00
|
|
|
template <class ELFT>
|
2015-07-21 21:57:43 +02:00
|
|
|
void ELFDumper<ELFT>::printValue(uint64_t Type, uint64_t Value) {
|
|
|
|
raw_ostream &OS = W.getOStream();
|
2013-04-03 20:31:38 +02:00
|
|
|
switch (Type) {
|
|
|
|
case DT_PLTREL:
|
|
|
|
if (Value == DT_REL) {
|
|
|
|
OS << "REL";
|
|
|
|
break;
|
|
|
|
} else if (Value == DT_RELA) {
|
|
|
|
OS << "RELA";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Fallthrough.
|
|
|
|
case DT_PLTGOT:
|
|
|
|
case DT_HASH:
|
|
|
|
case DT_STRTAB:
|
|
|
|
case DT_SYMTAB:
|
|
|
|
case DT_RELA:
|
|
|
|
case DT_INIT:
|
|
|
|
case DT_FINI:
|
|
|
|
case DT_REL:
|
|
|
|
case DT_JMPREL:
|
|
|
|
case DT_INIT_ARRAY:
|
|
|
|
case DT_FINI_ARRAY:
|
|
|
|
case DT_PREINIT_ARRAY:
|
|
|
|
case DT_DEBUG:
|
2015-10-16 00:04:55 +02:00
|
|
|
case DT_VERDEF:
|
2013-11-11 21:51:48 +01:00
|
|
|
case DT_VERNEED:
|
|
|
|
case DT_VERSYM:
|
2014-05-11 10:48:09 +02:00
|
|
|
case DT_GNU_HASH:
|
2013-04-03 20:31:38 +02:00
|
|
|
case DT_NULL:
|
2013-11-11 21:51:48 +01:00
|
|
|
case DT_MIPS_BASE_ADDRESS:
|
|
|
|
case DT_MIPS_GOTSYM:
|
2014-01-05 14:40:27 +01:00
|
|
|
case DT_MIPS_RLD_MAP:
|
2015-08-01 14:02:02 +02:00
|
|
|
case DT_MIPS_RLD_MAP_REL:
|
2014-01-05 14:40:27 +01:00
|
|
|
case DT_MIPS_PLTGOT:
|
2015-04-20 07:34:48 +02:00
|
|
|
case DT_MIPS_OPTIONS:
|
2013-04-03 20:31:38 +02:00
|
|
|
OS << format("0x%" PRIX64, Value);
|
|
|
|
break;
|
2014-05-11 10:48:09 +02:00
|
|
|
case DT_RELCOUNT:
|
2015-10-16 00:04:55 +02:00
|
|
|
case DT_VERDEFNUM:
|
2013-11-11 21:51:48 +01:00
|
|
|
case DT_VERNEEDNUM:
|
|
|
|
case DT_MIPS_RLD_VERSION:
|
|
|
|
case DT_MIPS_LOCAL_GOTNO:
|
|
|
|
case DT_MIPS_SYMTABNO:
|
|
|
|
case DT_MIPS_UNREFEXTNO:
|
|
|
|
OS << Value;
|
|
|
|
break;
|
2013-04-03 20:31:38 +02:00
|
|
|
case DT_PLTRELSZ:
|
|
|
|
case DT_RELASZ:
|
|
|
|
case DT_RELAENT:
|
|
|
|
case DT_STRSZ:
|
|
|
|
case DT_SYMENT:
|
|
|
|
case DT_RELSZ:
|
|
|
|
case DT_RELENT:
|
|
|
|
case DT_INIT_ARRAYSZ:
|
|
|
|
case DT_FINI_ARRAYSZ:
|
|
|
|
case DT_PREINIT_ARRAYSZ:
|
|
|
|
OS << Value << " (bytes)";
|
|
|
|
break;
|
|
|
|
case DT_NEEDED:
|
2015-07-21 22:50:53 +02:00
|
|
|
OS << "SharedLibrary (" << getDynamicString(Value) << ")";
|
2013-04-03 20:31:38 +02:00
|
|
|
break;
|
|
|
|
case DT_SONAME:
|
2015-07-21 22:50:53 +02:00
|
|
|
OS << "LibrarySoname (" << getDynamicString(Value) << ")";
|
2013-04-03 20:31:38 +02:00
|
|
|
break;
|
2013-09-03 19:13:53 +02:00
|
|
|
case DT_RPATH:
|
|
|
|
case DT_RUNPATH:
|
2015-07-21 22:50:53 +02:00
|
|
|
OS << getDynamicString(Value);
|
2013-09-03 19:13:53 +02:00
|
|
|
break;
|
2014-05-11 10:48:09 +02:00
|
|
|
case DT_MIPS_FLAGS:
|
|
|
|
printFlags(Value, makeArrayRef(ElfDynamicDTMipsFlags), OS);
|
|
|
|
break;
|
|
|
|
case DT_FLAGS:
|
|
|
|
printFlags(Value, makeArrayRef(ElfDynamicDTFlags), OS);
|
|
|
|
break;
|
2015-05-25 21:12:18 +02:00
|
|
|
case DT_FLAGS_1:
|
|
|
|
printFlags(Value, makeArrayRef(ElfDynamicDTFlags1), OS);
|
|
|
|
break;
|
2015-06-25 23:47:32 +02:00
|
|
|
default:
|
|
|
|
OS << format("0x%" PRIX64, Value);
|
|
|
|
break;
|
2013-04-03 20:31:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class ELFT>
|
|
|
|
void ELFDumper<ELFT>::printUnwindInfo() {
|
|
|
|
W.startLine() << "UnwindInfo not implemented.\n";
|
|
|
|
}
|
|
|
|
|
2014-01-08 04:28:09 +01:00
|
|
|
namespace {
|
2015-06-02 14:05:27 +02:00
|
|
|
template <> void ELFDumper<ELFType<support::little, false>>::printUnwindInfo() {
|
2014-01-08 04:28:09 +01:00
|
|
|
const unsigned Machine = Obj->getHeader()->e_machine;
|
|
|
|
if (Machine == EM_ARM) {
|
2015-08-10 22:25:04 +02:00
|
|
|
ARM::EHABI::PrinterContext<ELFType<support::little, false>> Ctx(
|
|
|
|
W, Obj, DotSymtabSec);
|
2014-01-08 04:28:09 +01:00
|
|
|
return Ctx.PrintUnwindInformation();
|
|
|
|
}
|
|
|
|
W.startLine() << "UnwindInfo not implemented.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-03 20:31:38 +02:00
|
|
|
template<class ELFT>
|
|
|
|
void ELFDumper<ELFT>::printDynamicTable() {
|
2015-07-21 22:50:53 +02:00
|
|
|
auto I = dynamic_table_begin();
|
|
|
|
auto E = dynamic_table_end();
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2015-07-20 23:45:56 +02:00
|
|
|
if (I == E)
|
|
|
|
return;
|
|
|
|
|
|
|
|
--E;
|
|
|
|
while (I != E && E->getTag() == ELF::DT_NULL)
|
|
|
|
--E;
|
|
|
|
if (E->getTag() != ELF::DT_NULL)
|
|
|
|
++E;
|
|
|
|
++E;
|
|
|
|
|
|
|
|
ptrdiff_t Total = std::distance(I, E);
|
2014-06-04 07:51:44 +02:00
|
|
|
if (Total == 0)
|
2013-04-03 20:31:38 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
raw_ostream &OS = W.getOStream();
|
|
|
|
W.startLine() << "DynamicSection [ (" << Total << " entries)\n";
|
|
|
|
|
2013-08-09 00:27:13 +02:00
|
|
|
bool Is64 = ELFT::Is64Bits;
|
2013-04-03 20:31:38 +02:00
|
|
|
|
|
|
|
W.startLine()
|
|
|
|
<< " Tag" << (Is64 ? " " : " ") << "Type"
|
|
|
|
<< " " << "Name/Value\n";
|
2015-07-20 23:45:56 +02:00
|
|
|
while (I != E) {
|
2015-07-23 10:48:14 +02:00
|
|
|
const Elf_Dyn &Entry = *I;
|
2015-10-01 19:57:31 +02:00
|
|
|
uintX_t Tag = Entry.getTag();
|
2015-07-20 23:45:56 +02:00
|
|
|
++I;
|
2015-10-01 19:57:31 +02:00
|
|
|
W.startLine() << " " << format_hex(Tag, Is64 ? 18 : 10, true) << " "
|
|
|
|
<< format("%-21s", getTypeString(Tag));
|
|
|
|
printValue(Tag, Entry.getVal());
|
2013-04-03 20:31:38 +02:00
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
W.startLine() << "]\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class ELFT>
|
|
|
|
void ELFDumper<ELFT>::printNeededLibraries() {
|
|
|
|
ListScope D(W, "NeededLibraries");
|
|
|
|
|
2013-08-09 00:27:13 +02:00
|
|
|
typedef std::vector<StringRef> LibsTy;
|
2013-04-03 20:31:38 +02:00
|
|
|
LibsTy Libs;
|
|
|
|
|
2015-07-21 22:50:53 +02:00
|
|
|
for (const auto &Entry : dynamic_table())
|
2014-06-04 07:51:44 +02:00
|
|
|
if (Entry.d_tag == ELF::DT_NEEDED)
|
2015-07-21 22:50:53 +02:00
|
|
|
Libs.push_back(getDynamicString(Entry.d_un.d_val));
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2013-08-09 00:27:13 +02:00
|
|
|
std::stable_sort(Libs.begin(), Libs.end());
|
2013-04-03 20:31:38 +02:00
|
|
|
|
2015-08-07 02:35:28 +02:00
|
|
|
for (const auto &L : Libs) {
|
|
|
|
outs() << " " << L << "\n";
|
2013-04-03 20:31:38 +02:00
|
|
|
}
|
|
|
|
}
|
2013-04-12 06:07:39 +02:00
|
|
|
|
|
|
|
template<class ELFT>
|
|
|
|
void ELFDumper<ELFT>::printProgramHeaders() {
|
|
|
|
ListScope L(W, "ProgramHeaders");
|
|
|
|
|
2015-07-23 10:48:14 +02:00
|
|
|
for (const Elf_Phdr &Phdr : Obj->program_headers()) {
|
2013-04-12 06:07:39 +02:00
|
|
|
DictScope P(W, "ProgramHeader");
|
2015-07-20 15:35:33 +02:00
|
|
|
W.printHex("Type",
|
|
|
|
getElfSegmentType(Obj->getHeader()->e_machine, Phdr.p_type),
|
|
|
|
Phdr.p_type);
|
|
|
|
W.printHex("Offset", Phdr.p_offset);
|
|
|
|
W.printHex("VirtualAddress", Phdr.p_vaddr);
|
|
|
|
W.printHex("PhysicalAddress", Phdr.p_paddr);
|
|
|
|
W.printNumber("FileSize", Phdr.p_filesz);
|
|
|
|
W.printNumber("MemSize", Phdr.p_memsz);
|
|
|
|
W.printFlags("Flags", Phdr.p_flags, makeArrayRef(ElfSegmentFlags));
|
|
|
|
W.printNumber("Alignment", Phdr.p_align);
|
2013-04-12 06:07:39 +02:00
|
|
|
}
|
|
|
|
}
|
2014-01-30 05:46:33 +01:00
|
|
|
|
2015-07-10 00:32:24 +02:00
|
|
|
template <typename ELFT>
|
|
|
|
void ELFDumper<ELFT>::printHashTable() {
|
|
|
|
DictScope D(W, "HashTable");
|
2015-07-21 22:50:53 +02:00
|
|
|
if (!HashTable)
|
2015-07-10 00:32:24 +02:00
|
|
|
return;
|
2015-07-21 22:50:53 +02:00
|
|
|
W.printNumber("Num Buckets", HashTable->nbucket);
|
|
|
|
W.printNumber("Num Chains", HashTable->nchain);
|
|
|
|
W.printList("Buckets", HashTable->buckets());
|
|
|
|
W.printList("Chains", HashTable->chains());
|
2015-07-10 00:32:24 +02:00
|
|
|
}
|
|
|
|
|
2015-10-14 14:11:50 +02:00
|
|
|
template <typename ELFT>
|
|
|
|
void ELFDumper<ELFT>::printGnuHashTable() {
|
|
|
|
DictScope D(W, "GnuHashTable");
|
|
|
|
if (!GnuHashTable)
|
|
|
|
return;
|
|
|
|
W.printNumber("Num Buckets", GnuHashTable->nbuckets);
|
|
|
|
W.printNumber("First Hashed Symbol Index", GnuHashTable->symndx);
|
|
|
|
W.printNumber("Num Mask Words", GnuHashTable->maskwords);
|
|
|
|
W.printNumber("Shift Count", GnuHashTable->shift2);
|
|
|
|
W.printHexList("Bloom Filter", GnuHashTable->filter());
|
|
|
|
W.printList("Buckets", GnuHashTable->buckets());
|
|
|
|
if (!DotDynSymSec)
|
|
|
|
reportError("No dynamic symbol section");
|
|
|
|
W.printHexList("Values",
|
|
|
|
GnuHashTable->values(DotDynSymSec->getEntityCount()));
|
|
|
|
}
|
|
|
|
|
2015-07-21 15:48:41 +02:00
|
|
|
template <typename ELFT> void ELFDumper<ELFT>::printLoadName() {
|
2015-07-21 22:50:53 +02:00
|
|
|
outs() << "LoadName: " << SOName << '\n';
|
2015-07-21 15:48:41 +02:00
|
|
|
}
|
|
|
|
|
2014-01-30 05:46:33 +01:00
|
|
|
template <class ELFT>
|
|
|
|
void ELFDumper<ELFT>::printAttributes() {
|
|
|
|
W.startLine() << "Attributes not implemented.\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2015-06-02 14:05:27 +02:00
|
|
|
template <> void ELFDumper<ELFType<support::little, false>>::printAttributes() {
|
2014-01-30 05:46:33 +01:00
|
|
|
if (Obj->getHeader()->e_machine != EM_ARM) {
|
|
|
|
W.startLine() << "Attributes not implemented.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DictScope BA(W, "BuildAttributes");
|
2015-06-30 21:24:51 +02:00
|
|
|
for (const ELFO::Elf_Shdr &Sec : Obj->sections()) {
|
|
|
|
if (Sec.sh_type != ELF::SHT_ARM_ATTRIBUTES)
|
2014-01-30 05:46:33 +01:00
|
|
|
continue;
|
|
|
|
|
2015-06-30 21:24:51 +02:00
|
|
|
ErrorOr<ArrayRef<uint8_t>> Contents = Obj->getSectionContents(&Sec);
|
2014-01-30 05:46:33 +01:00
|
|
|
if (!Contents)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((*Contents)[0] != ARMBuildAttrs::Format_Version) {
|
|
|
|
errs() << "unrecognised FormatVersion: 0x" << utohexstr((*Contents)[0])
|
|
|
|
<< '\n';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
W.printHex("FormatVersion", (*Contents)[0]);
|
|
|
|
if (Contents->size() == 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ARMAttributeParser(W).Parse(*Contents);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-18 10:47:09 +02:00
|
|
|
namespace {
|
|
|
|
template <class ELFT> class MipsGOTParser {
|
|
|
|
public:
|
2015-07-23 10:48:14 +02:00
|
|
|
typedef object::ELFFile<ELFT> ELFO;
|
|
|
|
typedef typename ELFO::Elf_Shdr Elf_Shdr;
|
|
|
|
typedef typename ELFO::Elf_Sym Elf_Sym;
|
|
|
|
typedef typename ELFO::Elf_Dyn_Range Elf_Dyn_Range;
|
|
|
|
typedef typename ELFO::Elf_Addr GOTEntry;
|
|
|
|
typedef typename ELFO::Elf_Rel Elf_Rel;
|
|
|
|
typedef typename ELFO::Elf_Rela Elf_Rela;
|
2014-06-18 10:47:09 +02:00
|
|
|
|
2015-08-06 23:54:37 +02:00
|
|
|
MipsGOTParser(ELFDumper<ELFT> *Dumper, const ELFO *Obj,
|
|
|
|
Elf_Dyn_Range DynTable, StreamWriter &W);
|
2014-06-18 10:47:09 +02:00
|
|
|
|
2015-07-09 20:23:10 +02:00
|
|
|
void parseGOT();
|
|
|
|
void parsePLT();
|
2014-06-18 10:47:09 +02:00
|
|
|
|
|
|
|
private:
|
2015-08-06 23:54:37 +02:00
|
|
|
ELFDumper<ELFT> *Dumper;
|
2015-07-23 10:48:14 +02:00
|
|
|
const ELFO *Obj;
|
2014-06-18 10:47:09 +02:00
|
|
|
StreamWriter &W;
|
2015-07-09 20:23:10 +02:00
|
|
|
llvm::Optional<uint64_t> DtPltGot;
|
|
|
|
llvm::Optional<uint64_t> DtLocalGotNum;
|
|
|
|
llvm::Optional<uint64_t> DtGotSym;
|
|
|
|
llvm::Optional<uint64_t> DtMipsPltGot;
|
|
|
|
llvm::Optional<uint64_t> DtJmpRel;
|
2014-06-18 10:47:09 +02:00
|
|
|
|
2014-06-18 11:24:01 +02:00
|
|
|
std::size_t getGOTTotal(ArrayRef<uint8_t> GOT) const;
|
2015-07-22 16:09:20 +02:00
|
|
|
const GOTEntry *makeGOTIter(ArrayRef<uint8_t> GOT, std::size_t EntryNum);
|
|
|
|
|
|
|
|
void printGotEntry(uint64_t GotAddr, const GOTEntry *BeginIt,
|
|
|
|
const GOTEntry *It);
|
|
|
|
void printGlobalGotEntry(uint64_t GotAddr, const GOTEntry *BeginIt,
|
|
|
|
const GOTEntry *It, const Elf_Sym *Sym,
|
|
|
|
StringRef StrTable, bool IsDynamic);
|
|
|
|
void printPLTEntry(uint64_t PLTAddr, const GOTEntry *BeginIt,
|
|
|
|
const GOTEntry *It, StringRef Purpose);
|
|
|
|
void printPLTEntry(uint64_t PLTAddr, const GOTEntry *BeginIt,
|
|
|
|
const GOTEntry *It, StringRef StrTable,
|
|
|
|
const Elf_Sym *Sym);
|
2014-06-18 10:47:09 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
2015-08-06 23:54:37 +02:00
|
|
|
MipsGOTParser<ELFT>::MipsGOTParser(ELFDumper<ELFT> *Dumper, const ELFO *Obj,
|
|
|
|
Elf_Dyn_Range DynTable, StreamWriter &W)
|
|
|
|
: Dumper(Dumper), Obj(Obj), W(W) {
|
2015-07-21 22:50:53 +02:00
|
|
|
for (const auto &Entry : DynTable) {
|
2015-07-09 20:23:10 +02:00
|
|
|
switch (Entry.getTag()) {
|
|
|
|
case ELF::DT_PLTGOT:
|
|
|
|
DtPltGot = Entry.getVal();
|
|
|
|
break;
|
|
|
|
case ELF::DT_MIPS_LOCAL_GOTNO:
|
|
|
|
DtLocalGotNum = Entry.getVal();
|
|
|
|
break;
|
|
|
|
case ELF::DT_MIPS_GOTSYM:
|
|
|
|
DtGotSym = Entry.getVal();
|
|
|
|
break;
|
|
|
|
case ELF::DT_MIPS_PLTGOT:
|
|
|
|
DtMipsPltGot = Entry.getVal();
|
|
|
|
break;
|
|
|
|
case ELF::DT_JMPREL:
|
|
|
|
DtJmpRel = Entry.getVal();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT> void MipsGOTParser<ELFT>::parseGOT() {
|
2014-06-18 10:47:09 +02:00
|
|
|
// See "Global Offset Table" in Chapter 5 in the following document
|
|
|
|
// for detailed GOT description.
|
|
|
|
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
|
2015-07-09 20:23:10 +02:00
|
|
|
if (!DtPltGot) {
|
|
|
|
W.startLine() << "Cannot find PLTGOT dynamic table tag.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!DtLocalGotNum) {
|
|
|
|
W.startLine() << "Cannot find MIPS_LOCAL_GOTNO dynamic table tag.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!DtGotSym) {
|
|
|
|
W.startLine() << "Cannot find MIPS_GOTSYM dynamic table tag.\n";
|
|
|
|
return;
|
|
|
|
}
|
2014-06-18 10:47:09 +02:00
|
|
|
|
2015-07-09 20:23:10 +02:00
|
|
|
const Elf_Shdr *GOTShdr = findSectionByAddress(Obj, *DtPltGot);
|
|
|
|
if (!GOTShdr) {
|
|
|
|
W.startLine() << "There is no .got section in the file.\n";
|
2014-06-18 10:47:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-09 20:23:10 +02:00
|
|
|
ErrorOr<ArrayRef<uint8_t>> GOT = Obj->getSectionContents(GOTShdr);
|
|
|
|
if (!GOT) {
|
|
|
|
W.startLine() << "The .got section is empty.\n";
|
2014-06-18 10:47:09 +02:00
|
|
|
return;
|
2015-07-09 20:23:10 +02:00
|
|
|
}
|
2014-06-18 10:47:09 +02:00
|
|
|
|
2015-07-09 20:23:10 +02:00
|
|
|
if (*DtLocalGotNum > getGOTTotal(*GOT)) {
|
2014-06-18 10:47:09 +02:00
|
|
|
W.startLine() << "MIPS_LOCAL_GOTNO exceeds a number of GOT entries.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-07 22:11:08 +02:00
|
|
|
const Elf_Shdr *DynSymSec = Dumper->getDotDynSymSec();
|
2015-07-21 18:02:10 +02:00
|
|
|
ErrorOr<StringRef> StrTable = Obj->getStringTableForSymtab(*DynSymSec);
|
|
|
|
error(StrTable.getError());
|
2015-07-23 11:11:05 +02:00
|
|
|
const Elf_Sym *DynSymBegin = Obj->symbol_begin(DynSymSec);
|
|
|
|
const Elf_Sym *DynSymEnd = Obj->symbol_end(DynSymSec);
|
2014-06-18 10:47:09 +02:00
|
|
|
std::size_t DynSymTotal = std::size_t(std::distance(DynSymBegin, DynSymEnd));
|
|
|
|
|
2015-07-09 20:23:10 +02:00
|
|
|
if (*DtGotSym > DynSymTotal) {
|
2014-06-18 10:47:09 +02:00
|
|
|
W.startLine() << "MIPS_GOTSYM exceeds a number of dynamic symbols.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-09 20:23:10 +02:00
|
|
|
std::size_t GlobalGotNum = DynSymTotal - *DtGotSym;
|
2014-06-18 10:47:09 +02:00
|
|
|
|
2015-07-09 20:23:10 +02:00
|
|
|
if (*DtLocalGotNum + GlobalGotNum > getGOTTotal(*GOT)) {
|
2014-06-18 10:47:09 +02:00
|
|
|
W.startLine() << "Number of global GOT entries exceeds the size of GOT.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-22 16:09:20 +02:00
|
|
|
const GOTEntry *GotBegin = makeGOTIter(*GOT, 0);
|
|
|
|
const GOTEntry *GotLocalEnd = makeGOTIter(*GOT, *DtLocalGotNum);
|
|
|
|
const GOTEntry *It = GotBegin;
|
2014-06-18 10:47:09 +02:00
|
|
|
|
|
|
|
DictScope GS(W, "Primary GOT");
|
|
|
|
|
2015-07-09 20:23:10 +02:00
|
|
|
W.printHex("Canonical gp value", GOTShdr->sh_addr + 0x7ff0);
|
2014-06-18 10:47:09 +02:00
|
|
|
{
|
|
|
|
ListScope RS(W, "Reserved entries");
|
|
|
|
|
|
|
|
{
|
|
|
|
DictScope D(W, "Entry");
|
2015-07-09 20:23:10 +02:00
|
|
|
printGotEntry(GOTShdr->sh_addr, GotBegin, It++);
|
2014-06-18 10:47:09 +02:00
|
|
|
W.printString("Purpose", StringRef("Lazy resolver"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (It != GotLocalEnd && (*It >> (sizeof(GOTEntry) * 8 - 1)) != 0) {
|
|
|
|
DictScope D(W, "Entry");
|
2015-07-09 20:23:10 +02:00
|
|
|
printGotEntry(GOTShdr->sh_addr, GotBegin, It++);
|
2014-06-18 10:47:09 +02:00
|
|
|
W.printString("Purpose", StringRef("Module pointer (GNU extension)"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
ListScope LS(W, "Local entries");
|
|
|
|
for (; It != GotLocalEnd; ++It) {
|
|
|
|
DictScope D(W, "Entry");
|
2015-07-09 20:23:10 +02:00
|
|
|
printGotEntry(GOTShdr->sh_addr, GotBegin, It);
|
2014-06-18 10:47:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
ListScope GS(W, "Global entries");
|
|
|
|
|
2015-07-22 16:09:20 +02:00
|
|
|
const GOTEntry *GotGlobalEnd =
|
|
|
|
makeGOTIter(*GOT, *DtLocalGotNum + GlobalGotNum);
|
2015-07-09 20:23:10 +02:00
|
|
|
const Elf_Sym *GotDynSym = DynSymBegin + *DtGotSym;
|
2014-06-18 10:47:09 +02:00
|
|
|
for (; It != GotGlobalEnd; ++It) {
|
|
|
|
DictScope D(W, "Entry");
|
2015-07-21 18:02:10 +02:00
|
|
|
printGlobalGotEntry(GOTShdr->sh_addr, GotBegin, It, GotDynSym++,
|
|
|
|
*StrTable, true);
|
2014-06-18 10:47:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-09 20:23:10 +02:00
|
|
|
std::size_t SpecGotNum = getGOTTotal(*GOT) - *DtLocalGotNum - GlobalGotNum;
|
2014-06-18 11:23:55 +02:00
|
|
|
W.printNumber("Number of TLS and multi-GOT entries", uint64_t(SpecGotNum));
|
2014-06-18 10:47:09 +02:00
|
|
|
}
|
|
|
|
|
2015-07-09 20:23:10 +02:00
|
|
|
template <class ELFT> void MipsGOTParser<ELFT>::parsePLT() {
|
|
|
|
if (!DtMipsPltGot) {
|
|
|
|
W.startLine() << "Cannot find MIPS_PLTGOT dynamic table tag.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!DtJmpRel) {
|
|
|
|
W.startLine() << "Cannot find JMPREL dynamic table tag.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Elf_Shdr *PLTShdr = findSectionByAddress(Obj, *DtMipsPltGot);
|
|
|
|
if (!PLTShdr) {
|
|
|
|
W.startLine() << "There is no .got.plt section in the file.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ErrorOr<ArrayRef<uint8_t>> PLT = Obj->getSectionContents(PLTShdr);
|
|
|
|
if (!PLT) {
|
|
|
|
W.startLine() << "The .got.plt section is empty.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Elf_Shdr *PLTRelShdr = findSectionByAddress(Obj, *DtJmpRel);
|
|
|
|
if (!PLTShdr) {
|
|
|
|
W.startLine() << "There is no .rel.plt section in the file.\n";
|
|
|
|
return;
|
|
|
|
}
|
2015-07-21 18:02:10 +02:00
|
|
|
ErrorOr<const Elf_Shdr *> SymTableOrErr =
|
|
|
|
Obj->getSection(PLTRelShdr->sh_link);
|
|
|
|
error(SymTableOrErr.getError());
|
2015-09-02 17:07:39 +02:00
|
|
|
const Elf_Shdr *SymTable = *SymTableOrErr;
|
|
|
|
ErrorOr<StringRef> StrTable = Obj->getStringTableForSymtab(*SymTable);
|
2015-07-21 18:02:10 +02:00
|
|
|
error(StrTable.getError());
|
2015-07-09 20:23:10 +02:00
|
|
|
|
2015-07-22 16:09:20 +02:00
|
|
|
const GOTEntry *PLTBegin = makeGOTIter(*PLT, 0);
|
|
|
|
const GOTEntry *PLTEnd = makeGOTIter(*PLT, getGOTTotal(*PLT));
|
|
|
|
const GOTEntry *It = PLTBegin;
|
2015-07-09 20:23:10 +02:00
|
|
|
|
|
|
|
DictScope GS(W, "PLT GOT");
|
|
|
|
{
|
|
|
|
ListScope RS(W, "Reserved entries");
|
|
|
|
printPLTEntry(PLTShdr->sh_addr, PLTBegin, It++, "PLT lazy resolver");
|
|
|
|
if (It != PLTEnd)
|
|
|
|
printPLTEntry(PLTShdr->sh_addr, PLTBegin, It++, "Module pointer");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
ListScope GS(W, "Entries");
|
|
|
|
|
|
|
|
switch (PLTRelShdr->sh_type) {
|
|
|
|
case ELF::SHT_REL:
|
2015-07-23 10:48:14 +02:00
|
|
|
for (const Elf_Rel *RI = Obj->rel_begin(PLTRelShdr),
|
|
|
|
*RE = Obj->rel_end(PLTRelShdr);
|
2015-07-09 20:23:10 +02:00
|
|
|
RI != RE && It != PLTEnd; ++RI, ++It) {
|
2015-09-02 17:07:39 +02:00
|
|
|
const Elf_Sym *Sym = Obj->getRelocationSymbol(&*RI, SymTable);
|
2015-07-21 18:02:10 +02:00
|
|
|
printPLTEntry(PLTShdr->sh_addr, PLTBegin, It, *StrTable, Sym);
|
2015-07-09 20:23:10 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ELF::SHT_RELA:
|
2015-07-23 10:48:14 +02:00
|
|
|
for (const Elf_Rela *RI = Obj->rela_begin(PLTRelShdr),
|
|
|
|
*RE = Obj->rela_end(PLTRelShdr);
|
2015-07-09 20:23:10 +02:00
|
|
|
RI != RE && It != PLTEnd; ++RI, ++It) {
|
2015-09-02 17:07:39 +02:00
|
|
|
const Elf_Sym *Sym = Obj->getRelocationSymbol(&*RI, SymTable);
|
2015-07-21 18:02:10 +02:00
|
|
|
printPLTEntry(PLTShdr->sh_addr, PLTBegin, It, *StrTable, Sym);
|
2015-07-09 20:23:10 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-18 10:47:09 +02:00
|
|
|
template <class ELFT>
|
2014-06-18 11:24:01 +02:00
|
|
|
std::size_t MipsGOTParser<ELFT>::getGOTTotal(ArrayRef<uint8_t> GOT) const {
|
2014-06-18 10:47:09 +02:00
|
|
|
return GOT.size() / sizeof(GOTEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
2015-07-22 16:09:20 +02:00
|
|
|
const typename MipsGOTParser<ELFT>::GOTEntry *
|
2014-06-18 11:24:01 +02:00
|
|
|
MipsGOTParser<ELFT>::makeGOTIter(ArrayRef<uint8_t> GOT, std::size_t EntryNum) {
|
2014-06-18 10:47:09 +02:00
|
|
|
const char *Data = reinterpret_cast<const char *>(GOT.data());
|
2015-07-22 16:09:20 +02:00
|
|
|
return reinterpret_cast<const GOTEntry *>(Data + EntryNum * sizeof(GOTEntry));
|
2014-06-18 10:47:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
2015-07-22 16:09:20 +02:00
|
|
|
void MipsGOTParser<ELFT>::printGotEntry(uint64_t GotAddr,
|
|
|
|
const GOTEntry *BeginIt,
|
|
|
|
const GOTEntry *It) {
|
2014-06-18 10:47:09 +02:00
|
|
|
int64_t Offset = std::distance(BeginIt, It) * sizeof(GOTEntry);
|
|
|
|
W.printHex("Address", GotAddr + Offset);
|
|
|
|
W.printNumber("Access", Offset - 0x7ff0);
|
|
|
|
W.printHex("Initial", *It);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
2015-07-22 16:09:20 +02:00
|
|
|
void MipsGOTParser<ELFT>::printGlobalGotEntry(
|
|
|
|
uint64_t GotAddr, const GOTEntry *BeginIt, const GOTEntry *It,
|
|
|
|
const Elf_Sym *Sym, StringRef StrTable, bool IsDynamic) {
|
2014-06-18 10:47:09 +02:00
|
|
|
printGotEntry(GotAddr, BeginIt, It);
|
|
|
|
|
|
|
|
W.printHex("Value", Sym->st_value);
|
|
|
|
W.printEnum("Type", Sym->getType(), makeArrayRef(ElfSymbolTypes));
|
|
|
|
|
|
|
|
unsigned SectionIndex = 0;
|
|
|
|
StringRef SectionName;
|
2015-08-10 23:29:35 +02:00
|
|
|
getSectionNameIndex(*Obj, Sym, Dumper->getDotDynSymSec(),
|
|
|
|
Dumper->getShndxTable(), SectionName, SectionIndex);
|
2014-06-18 10:47:09 +02:00
|
|
|
W.printHex("Section", SectionName, SectionIndex);
|
|
|
|
|
2015-07-21 18:02:10 +02:00
|
|
|
std::string FullSymbolName =
|
2015-08-06 23:54:37 +02:00
|
|
|
Dumper->getFullSymbolName(Sym, StrTable, IsDynamic);
|
2014-06-18 10:47:09 +02:00
|
|
|
W.printNumber("Name", FullSymbolName, Sym->st_name);
|
|
|
|
}
|
|
|
|
|
2015-07-09 20:23:10 +02:00
|
|
|
template <class ELFT>
|
2015-07-22 16:09:20 +02:00
|
|
|
void MipsGOTParser<ELFT>::printPLTEntry(uint64_t PLTAddr,
|
|
|
|
const GOTEntry *BeginIt,
|
|
|
|
const GOTEntry *It, StringRef Purpose) {
|
2015-07-09 20:23:10 +02:00
|
|
|
DictScope D(W, "Entry");
|
|
|
|
int64_t Offset = std::distance(BeginIt, It) * sizeof(GOTEntry);
|
|
|
|
W.printHex("Address", PLTAddr + Offset);
|
|
|
|
W.printHex("Initial", *It);
|
|
|
|
W.printString("Purpose", Purpose);
|
|
|
|
}
|
2014-06-18 10:47:09 +02:00
|
|
|
|
2015-07-09 20:23:10 +02:00
|
|
|
template <class ELFT>
|
2015-07-22 16:09:20 +02:00
|
|
|
void MipsGOTParser<ELFT>::printPLTEntry(uint64_t PLTAddr,
|
|
|
|
const GOTEntry *BeginIt,
|
|
|
|
const GOTEntry *It, StringRef StrTable,
|
2015-07-21 18:02:10 +02:00
|
|
|
const Elf_Sym *Sym) {
|
2015-07-09 20:23:10 +02:00
|
|
|
DictScope D(W, "Entry");
|
|
|
|
int64_t Offset = std::distance(BeginIt, It) * sizeof(GOTEntry);
|
|
|
|
W.printHex("Address", PLTAddr + Offset);
|
|
|
|
W.printHex("Initial", *It);
|
|
|
|
W.printHex("Value", Sym->st_value);
|
|
|
|
W.printEnum("Type", Sym->getType(), makeArrayRef(ElfSymbolTypes));
|
2014-06-18 10:47:09 +02:00
|
|
|
|
2015-07-09 20:23:10 +02:00
|
|
|
unsigned SectionIndex = 0;
|
|
|
|
StringRef SectionName;
|
2015-08-10 23:29:35 +02:00
|
|
|
getSectionNameIndex(*Obj, Sym, Dumper->getDotDynSymSec(),
|
|
|
|
Dumper->getShndxTable(), SectionName, SectionIndex);
|
2015-07-09 20:23:10 +02:00
|
|
|
W.printHex("Section", SectionName, SectionIndex);
|
2014-06-18 10:47:09 +02:00
|
|
|
|
2015-08-06 23:54:37 +02:00
|
|
|
std::string FullSymbolName = Dumper->getFullSymbolName(Sym, StrTable, true);
|
2015-07-09 20:23:10 +02:00
|
|
|
W.printNumber("Name", FullSymbolName, Sym->st_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT> void ELFDumper<ELFT>::printMipsPLTGOT() {
|
|
|
|
if (Obj->getHeader()->e_machine != EM_MIPS) {
|
|
|
|
W.startLine() << "MIPS PLT GOT is available for MIPS targets only.\n";
|
2014-06-18 10:47:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-06 23:54:37 +02:00
|
|
|
MipsGOTParser<ELFT> GOTParser(this, Obj, dynamic_table(), W);
|
2015-07-09 20:23:10 +02:00
|
|
|
GOTParser.parseGOT();
|
|
|
|
GOTParser.parsePLT();
|
2014-06-18 10:47:09 +02:00
|
|
|
}
|
2015-05-07 17:40:35 +02:00
|
|
|
|
|
|
|
static const EnumEntry<unsigned> ElfMipsISAExtType[] = {
|
|
|
|
{"None", Mips::AFL_EXT_NONE},
|
|
|
|
{"Broadcom SB-1", Mips::AFL_EXT_SB1},
|
|
|
|
{"Cavium Networks Octeon", Mips::AFL_EXT_OCTEON},
|
|
|
|
{"Cavium Networks Octeon2", Mips::AFL_EXT_OCTEON2},
|
|
|
|
{"Cavium Networks OcteonP", Mips::AFL_EXT_OCTEONP},
|
|
|
|
{"Cavium Networks Octeon3", Mips::AFL_EXT_OCTEON3},
|
|
|
|
{"LSI R4010", Mips::AFL_EXT_4010},
|
|
|
|
{"Loongson 2E", Mips::AFL_EXT_LOONGSON_2E},
|
|
|
|
{"Loongson 2F", Mips::AFL_EXT_LOONGSON_2F},
|
|
|
|
{"Loongson 3A", Mips::AFL_EXT_LOONGSON_3A},
|
|
|
|
{"MIPS R4650", Mips::AFL_EXT_4650},
|
|
|
|
{"MIPS R5900", Mips::AFL_EXT_5900},
|
|
|
|
{"MIPS R10000", Mips::AFL_EXT_10000},
|
|
|
|
{"NEC VR4100", Mips::AFL_EXT_4100},
|
|
|
|
{"NEC VR4111/VR4181", Mips::AFL_EXT_4111},
|
|
|
|
{"NEC VR4120", Mips::AFL_EXT_4120},
|
|
|
|
{"NEC VR5400", Mips::AFL_EXT_5400},
|
|
|
|
{"NEC VR5500", Mips::AFL_EXT_5500},
|
|
|
|
{"RMI Xlr", Mips::AFL_EXT_XLR},
|
|
|
|
{"Toshiba R3900", Mips::AFL_EXT_3900}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const EnumEntry<unsigned> ElfMipsASEFlags[] = {
|
|
|
|
{"DSP", Mips::AFL_ASE_DSP},
|
|
|
|
{"DSPR2", Mips::AFL_ASE_DSPR2},
|
|
|
|
{"Enhanced VA Scheme", Mips::AFL_ASE_EVA},
|
|
|
|
{"MCU", Mips::AFL_ASE_MCU},
|
|
|
|
{"MDMX", Mips::AFL_ASE_MDMX},
|
|
|
|
{"MIPS-3D", Mips::AFL_ASE_MIPS3D},
|
|
|
|
{"MT", Mips::AFL_ASE_MT},
|
|
|
|
{"SmartMIPS", Mips::AFL_ASE_SMARTMIPS},
|
|
|
|
{"VZ", Mips::AFL_ASE_VIRT},
|
|
|
|
{"MSA", Mips::AFL_ASE_MSA},
|
|
|
|
{"MIPS16", Mips::AFL_ASE_MIPS16},
|
|
|
|
{"microMIPS", Mips::AFL_ASE_MICROMIPS},
|
|
|
|
{"XPA", Mips::AFL_ASE_XPA}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const EnumEntry<unsigned> ElfMipsFpABIType[] = {
|
|
|
|
{"Hard or soft float", Mips::Val_GNU_MIPS_ABI_FP_ANY},
|
|
|
|
{"Hard float (double precision)", Mips::Val_GNU_MIPS_ABI_FP_DOUBLE},
|
|
|
|
{"Hard float (single precision)", Mips::Val_GNU_MIPS_ABI_FP_SINGLE},
|
|
|
|
{"Soft float", Mips::Val_GNU_MIPS_ABI_FP_SOFT},
|
|
|
|
{"Hard float (MIPS32r2 64-bit FPU 12 callee-saved)",
|
|
|
|
Mips::Val_GNU_MIPS_ABI_FP_OLD_64},
|
|
|
|
{"Hard float (32-bit CPU, Any FPU)", Mips::Val_GNU_MIPS_ABI_FP_XX},
|
|
|
|
{"Hard float (32-bit CPU, 64-bit FPU)", Mips::Val_GNU_MIPS_ABI_FP_64},
|
|
|
|
{"Hard float compat (32-bit CPU, 64-bit FPU)",
|
|
|
|
Mips::Val_GNU_MIPS_ABI_FP_64A}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const EnumEntry<unsigned> ElfMipsFlags1[] {
|
|
|
|
{"ODDSPREG", Mips::AFL_FLAGS1_ODDSPREG},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int getMipsRegisterSize(uint8_t Flag) {
|
|
|
|
switch (Flag) {
|
|
|
|
case Mips::AFL_REG_NONE:
|
|
|
|
return 0;
|
|
|
|
case Mips::AFL_REG_32:
|
|
|
|
return 32;
|
|
|
|
case Mips::AFL_REG_64:
|
|
|
|
return 64;
|
|
|
|
case Mips::AFL_REG_128:
|
|
|
|
return 128;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT> void ELFDumper<ELFT>::printMipsABIFlags() {
|
|
|
|
const Elf_Shdr *Shdr = findSectionByName(*Obj, ".MIPS.abiflags");
|
|
|
|
if (!Shdr) {
|
|
|
|
W.startLine() << "There is no .MIPS.abiflags section in the file.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ErrorOr<ArrayRef<uint8_t>> Sec = Obj->getSectionContents(Shdr);
|
|
|
|
if (!Sec) {
|
|
|
|
W.startLine() << "The .MIPS.abiflags section is empty.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Sec->size() != sizeof(Elf_Mips_ABIFlags<ELFT>)) {
|
|
|
|
W.startLine() << "The .MIPS.abiflags section has a wrong size.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto *Flags = reinterpret_cast<const Elf_Mips_ABIFlags<ELFT> *>(Sec->data());
|
|
|
|
|
|
|
|
raw_ostream &OS = W.getOStream();
|
|
|
|
DictScope GS(W, "MIPS ABI Flags");
|
|
|
|
|
|
|
|
W.printNumber("Version", Flags->version);
|
|
|
|
W.startLine() << "ISA: ";
|
|
|
|
if (Flags->isa_rev <= 1)
|
|
|
|
OS << format("MIPS%u", Flags->isa_level);
|
|
|
|
else
|
|
|
|
OS << format("MIPS%ur%u", Flags->isa_level, Flags->isa_rev);
|
|
|
|
OS << "\n";
|
|
|
|
W.printEnum("ISA Extension", Flags->isa_ext, makeArrayRef(ElfMipsISAExtType));
|
|
|
|
W.printFlags("ASEs", Flags->ases, makeArrayRef(ElfMipsASEFlags));
|
|
|
|
W.printEnum("FP ABI", Flags->fp_abi, makeArrayRef(ElfMipsFpABIType));
|
|
|
|
W.printNumber("GPR size", getMipsRegisterSize(Flags->gpr_size));
|
|
|
|
W.printNumber("CPR1 size", getMipsRegisterSize(Flags->cpr1_size));
|
|
|
|
W.printNumber("CPR2 size", getMipsRegisterSize(Flags->cpr2_size));
|
|
|
|
W.printFlags("Flags 1", Flags->flags1, makeArrayRef(ElfMipsFlags1));
|
|
|
|
W.printHex("Flags 2", Flags->flags2);
|
|
|
|
}
|
2015-06-16 23:47:43 +02:00
|
|
|
|
|
|
|
template <class ELFT> void ELFDumper<ELFT>::printMipsReginfo() {
|
|
|
|
const Elf_Shdr *Shdr = findSectionByName(*Obj, ".reginfo");
|
|
|
|
if (!Shdr) {
|
|
|
|
W.startLine() << "There is no .reginfo section in the file.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ErrorOr<ArrayRef<uint8_t>> Sec = Obj->getSectionContents(Shdr);
|
|
|
|
if (!Sec) {
|
|
|
|
W.startLine() << "The .reginfo section is empty.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Sec->size() != sizeof(Elf_Mips_RegInfo<ELFT>)) {
|
|
|
|
W.startLine() << "The .reginfo section has a wrong size.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto *Reginfo = reinterpret_cast<const Elf_Mips_RegInfo<ELFT> *>(Sec->data());
|
|
|
|
|
|
|
|
DictScope GS(W, "MIPS RegInfo");
|
|
|
|
W.printHex("GP", Reginfo->ri_gp_value);
|
|
|
|
W.printHex("General Mask", Reginfo->ri_gprmask);
|
|
|
|
W.printHex("Co-Proc Mask0", Reginfo->ri_cprmask[0]);
|
|
|
|
W.printHex("Co-Proc Mask1", Reginfo->ri_cprmask[1]);
|
|
|
|
W.printHex("Co-Proc Mask2", Reginfo->ri_cprmask[2]);
|
|
|
|
W.printHex("Co-Proc Mask3", Reginfo->ri_cprmask[3]);
|
|
|
|
}
|
2015-06-27 01:56:53 +02:00
|
|
|
|
|
|
|
template <class ELFT> void ELFDumper<ELFT>::printStackMap() const {
|
2015-07-23 10:48:14 +02:00
|
|
|
const Elf_Shdr *StackMapSection = nullptr;
|
2015-06-27 01:56:53 +02:00
|
|
|
for (const auto &Sec : Obj->sections()) {
|
|
|
|
ErrorOr<StringRef> Name = Obj->getSectionName(&Sec);
|
|
|
|
if (*Name == ".llvm_stackmaps") {
|
|
|
|
StackMapSection = &Sec;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!StackMapSection)
|
|
|
|
return;
|
|
|
|
|
|
|
|
StringRef StackMapContents;
|
|
|
|
ErrorOr<ArrayRef<uint8_t>> StackMapContentsArray =
|
|
|
|
Obj->getSectionContents(StackMapSection);
|
|
|
|
|
|
|
|
prettyPrintStackMap(
|
|
|
|
llvm::outs(),
|
|
|
|
StackMapV1Parser<ELFT::TargetEndianness>(*StackMapContentsArray));
|
|
|
|
}
|