1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

Use typdef to simplify the code. NFC.

llvm-svn: 242995
This commit is contained in:
Rafael Espindola 2015-07-23 08:48:14 +00:00
parent 60c86dad61
commit 61c30ffea6

View File

@ -71,10 +71,12 @@ private:
typedef typename ELFO::Elf_Sym Elf_Sym; typedef typename ELFO::Elf_Sym Elf_Sym;
typedef typename ELFO::Elf_Dyn Elf_Dyn; typedef typename ELFO::Elf_Dyn Elf_Dyn;
typedef typename ELFO::Elf_Dyn_Range Elf_Dyn_Range; typedef typename ELFO::Elf_Dyn_Range Elf_Dyn_Range;
typedef typename ELFO::Elf_Rel Elf_Rel;
typedef typename ELFO::Elf_Rela Elf_Rela; typedef typename ELFO::Elf_Rela Elf_Rela;
typedef typename ELFO::Elf_Rela_Range Elf_Rela_Range; typedef typename ELFO::Elf_Rela_Range Elf_Rela_Range;
typedef typename ELFO::Elf_Phdr Elf_Phdr; typedef typename ELFO::Elf_Phdr Elf_Phdr;
typedef typename ELFO::Elf_Hash Elf_Hash; typedef typename ELFO::Elf_Hash Elf_Hash;
typedef typename ELFO::Elf_Ehdr Elf_Ehdr;
typedef typename ELFO::uintX_t uintX_t; typedef typename ELFO::uintX_t uintX_t;
/// \brief Represents a region described by entries in the .dynamic table. /// \brief Represents a region described by entries in the .dynamic table.
@ -91,7 +93,7 @@ private:
void printSymbol(const Elf_Sym *Symbol, StringRef StrTable, bool IsDynamic); void printSymbol(const Elf_Sym *Symbol, StringRef StrTable, bool IsDynamic);
void printRelocations(const Elf_Shdr *Sec); void printRelocations(const Elf_Shdr *Sec);
void printRelocation(const Elf_Shdr *Sec, typename ELFO::Elf_Rela Rel); void printRelocation(const Elf_Shdr *Sec, Elf_Rela Rel);
void printValue(uint64_t Type, uint64_t Value); void printValue(uint64_t Type, uint64_t Value);
const Elf_Rela *dyn_rela_begin() const; const Elf_Rela *dyn_rela_begin() const;
@ -203,18 +205,18 @@ getSectionNameIndex(const ELFO &Obj, const typename ELFO::Elf_Sym *Symbol,
} }
} }
template <class ELFT> template <class ELFO>
static const typename ELFFile<ELFT>::Elf_Shdr * static const typename ELFO::Elf_Shdr *findSectionByAddress(const ELFO *Obj,
findSectionByAddress(const ELFFile<ELFT> *Obj, uint64_t Addr) { uint64_t Addr) {
for (const auto &Shdr : Obj->sections()) for (const auto &Shdr : Obj->sections())
if (Shdr.sh_addr == Addr) if (Shdr.sh_addr == Addr)
return &Shdr; return &Shdr;
return nullptr; return nullptr;
} }
template <class ELFT> template <class ELFO>
static const typename ELFFile<ELFT>::Elf_Shdr * static const typename ELFO::Elf_Shdr *findSectionByName(const ELFO &Obj,
findSectionByName(const ELFFile<ELFT> &Obj, StringRef Name) { StringRef Name) {
for (const auto &Shdr : Obj.sections()) { for (const auto &Shdr : Obj.sections()) {
if (Name == errorOrDefault(Obj.getSectionName(&Shdr))) if (Name == errorOrDefault(Obj.getSectionName(&Shdr)))
return &Shdr; return &Shdr;
@ -703,7 +705,7 @@ ELFDumper<ELFT>::dynamic_table_end() const {
template<class ELFT> template<class ELFT>
void ELFDumper<ELFT>::printFileHeaders() { void ELFDumper<ELFT>::printFileHeaders() {
const typename ELFO::Elf_Ehdr *Header = Obj->getHeader(); const Elf_Ehdr *Header = Obj->getHeader();
{ {
DictScope D(W, "ElfHeader"); DictScope D(W, "ElfHeader");
@ -754,7 +756,7 @@ void ELFDumper<ELFT>::printSections() {
ListScope SectionsD(W, "Sections"); ListScope SectionsD(W, "Sections");
int SectionIndex = -1; int SectionIndex = -1;
for (const typename ELFO::Elf_Shdr &Sec : Obj->sections()) { for (const Elf_Shdr &Sec : Obj->sections()) {
++SectionIndex; ++SectionIndex;
StringRef Name = errorOrDefault(Obj->getSectionName(&Sec)); StringRef Name = errorOrDefault(Obj->getSectionName(&Sec));
@ -786,7 +788,7 @@ void ELFDumper<ELFT>::printSections() {
error(StrTableOrErr.getError()); error(StrTableOrErr.getError());
StringRef StrTable = *StrTableOrErr; StringRef StrTable = *StrTableOrErr;
for (const typename ELFO::Elf_Sym &Sym : Obj->symbols()) { for (const Elf_Sym &Sym : Obj->symbols()) {
ErrorOr<const Elf_Shdr *> SymSec = Obj->getSection(&Sym); ErrorOr<const Elf_Shdr *> SymSec = Obj->getSection(&Sym);
if (!SymSec) if (!SymSec)
continue; continue;
@ -808,7 +810,7 @@ void ELFDumper<ELFT>::printRelocations() {
ListScope D(W, "Relocations"); ListScope D(W, "Relocations");
int SectionNumber = -1; int SectionNumber = -1;
for (const typename ELFO::Elf_Shdr &Sec : Obj->sections()) { for (const Elf_Shdr &Sec : Obj->sections()) {
++SectionNumber; ++SectionNumber;
if (Sec.sh_type != ELF::SHT_REL && Sec.sh_type != ELF::SHT_RELA) if (Sec.sh_type != ELF::SHT_REL && Sec.sh_type != ELF::SHT_RELA)
@ -830,12 +832,12 @@ template<class ELFT>
void ELFDumper<ELFT>::printDynamicRelocations() { void ELFDumper<ELFT>::printDynamicRelocations() {
W.startLine() << "Dynamic Relocations {\n"; W.startLine() << "Dynamic Relocations {\n";
W.indent(); W.indent();
for (const typename ELFO::Elf_Rela &Rel : dyn_relas()) { for (const Elf_Rela &Rel : dyn_relas()) {
SmallString<32> RelocName; SmallString<32> RelocName;
Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName); Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName);
StringRef SymbolName; StringRef SymbolName;
uint32_t SymIndex = Rel.getSymbol(Obj->isMips64EL()); uint32_t SymIndex = Rel.getSymbol(Obj->isMips64EL());
const typename ELFO::Elf_Sym *Sym = Obj->dynamic_symbol_begin() + SymIndex; const Elf_Sym *Sym = Obj->dynamic_symbol_begin() + SymIndex;
SymbolName = errorOrDefault(Sym->getName(DynamicStringTable)); SymbolName = errorOrDefault(Sym->getName(DynamicStringTable));
if (opts::ExpandRelocs) { if (opts::ExpandRelocs) {
DictScope Group(W, "Relocation"); DictScope Group(W, "Relocation");
@ -859,8 +861,8 @@ template <class ELFT>
void ELFDumper<ELFT>::printRelocations(const Elf_Shdr *Sec) { void ELFDumper<ELFT>::printRelocations(const Elf_Shdr *Sec) {
switch (Sec->sh_type) { switch (Sec->sh_type) {
case ELF::SHT_REL: case ELF::SHT_REL:
for (const typename ELFO::Elf_Rel &R : Obj->rels(Sec)) { for (const Elf_Rel &R : Obj->rels(Sec)) {
typename ELFO::Elf_Rela Rela; Elf_Rela Rela;
Rela.r_offset = R.r_offset; Rela.r_offset = R.r_offset;
Rela.r_info = R.r_info; Rela.r_info = R.r_info;
Rela.r_addend = 0; Rela.r_addend = 0;
@ -868,15 +870,14 @@ void ELFDumper<ELFT>::printRelocations(const Elf_Shdr *Sec) {
} }
break; break;
case ELF::SHT_RELA: case ELF::SHT_RELA:
for (const typename ELFO::Elf_Rela &R : Obj->relas(Sec)) for (const Elf_Rela &R : Obj->relas(Sec))
printRelocation(Sec, R); printRelocation(Sec, R);
break; break;
} }
} }
template <class ELFT> template <class ELFT>
void ELFDumper<ELFT>::printRelocation(const Elf_Shdr *Sec, void ELFDumper<ELFT>::printRelocation(const Elf_Shdr *Sec, Elf_Rela Rel) {
typename ELFO::Elf_Rela Rel) {
SmallString<32> RelocName; SmallString<32> RelocName;
Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName); Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName);
StringRef TargetName; StringRef TargetName;
@ -918,7 +919,7 @@ void ELFDumper<ELFT>::printSymbols() {
ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*Symtab); ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*Symtab);
error(StrTableOrErr.getError()); error(StrTableOrErr.getError());
StringRef StrTable = *StrTableOrErr; StringRef StrTable = *StrTableOrErr;
for (const typename ELFO::Elf_Sym &Sym : Obj->symbols()) for (const Elf_Sym &Sym : Obj->symbols())
printSymbol(&Sym, StrTable, false); printSymbol(&Sym, StrTable, false);
} }
@ -930,13 +931,13 @@ void ELFDumper<ELFT>::printDynamicSymbols() {
ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*Symtab); ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*Symtab);
error(StrTableOrErr.getError()); error(StrTableOrErr.getError());
StringRef StrTable = *StrTableOrErr; StringRef StrTable = *StrTableOrErr;
for (const typename ELFO::Elf_Sym &Sym : Obj->dynamic_symbols()) for (const Elf_Sym &Sym : Obj->dynamic_symbols())
printSymbol(&Sym, StrTable, true); printSymbol(&Sym, StrTable, true);
} }
template <class ELFT> template <class ELFT>
void ELFDumper<ELFT>::printSymbol(const typename ELFO::Elf_Sym *Symbol, void ELFDumper<ELFT>::printSymbol(const Elf_Sym *Symbol, StringRef StrTable,
StringRef StrTable, bool IsDynamic) { bool IsDynamic) {
unsigned SectionIndex = 0; unsigned SectionIndex = 0;
StringRef SectionName; StringRef SectionName;
getSectionNameIndex(*Obj, Symbol, SectionName, SectionIndex); getSectionNameIndex(*Obj, Symbol, SectionName, SectionIndex);
@ -1226,7 +1227,7 @@ void ELFDumper<ELFT>::printDynamicTable() {
<< " Tag" << (Is64 ? " " : " ") << "Type" << " Tag" << (Is64 ? " " : " ") << "Type"
<< " " << "Name/Value\n"; << " " << "Name/Value\n";
while (I != E) { while (I != E) {
const typename ELFO::Elf_Dyn &Entry = *I; const Elf_Dyn &Entry = *I;
++I; ++I;
W.startLine() W.startLine()
<< " " << " "
@ -1261,7 +1262,7 @@ template<class ELFT>
void ELFDumper<ELFT>::printProgramHeaders() { void ELFDumper<ELFT>::printProgramHeaders() {
ListScope L(W, "ProgramHeaders"); ListScope L(W, "ProgramHeaders");
for (const typename ELFO::Elf_Phdr &Phdr : Obj->program_headers()) { for (const Elf_Phdr &Phdr : Obj->program_headers()) {
DictScope P(W, "ProgramHeader"); DictScope P(W, "ProgramHeader");
W.printHex("Type", W.printHex("Type",
getElfSegmentType(Obj->getHeader()->e_machine, Phdr.p_type), getElfSegmentType(Obj->getHeader()->e_machine, Phdr.p_type),
@ -1330,20 +1331,21 @@ template <> void ELFDumper<ELFType<support::little, false>>::printAttributes() {
namespace { namespace {
template <class ELFT> class MipsGOTParser { template <class ELFT> class MipsGOTParser {
public: public:
typedef object::ELFFile<ELFT> ObjectFile; typedef object::ELFFile<ELFT> ELFO;
typedef typename ObjectFile::Elf_Shdr Elf_Shdr; typedef typename ELFO::Elf_Shdr Elf_Shdr;
typedef typename ObjectFile::Elf_Sym Elf_Sym; typedef typename ELFO::Elf_Sym Elf_Sym;
typedef typename ObjectFile::Elf_Dyn_Range Elf_Dyn_Range; 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;
MipsGOTParser(const ObjectFile *Obj, Elf_Dyn_Range DynTable, StreamWriter &W); MipsGOTParser(const ELFO *Obj, Elf_Dyn_Range DynTable, StreamWriter &W);
void parseGOT(); void parseGOT();
void parsePLT(); void parsePLT();
private: private:
typedef typename ObjectFile::Elf_Addr GOTEntry; const ELFO *Obj;
const ObjectFile *Obj;
StreamWriter &W; StreamWriter &W;
llvm::Optional<uint64_t> DtPltGot; llvm::Optional<uint64_t> DtPltGot;
llvm::Optional<uint64_t> DtLocalGotNum; llvm::Optional<uint64_t> DtLocalGotNum;
@ -1368,8 +1370,8 @@ private:
} }
template <class ELFT> template <class ELFT>
MipsGOTParser<ELFT>::MipsGOTParser(const ObjectFile *Obj, MipsGOTParser<ELFT>::MipsGOTParser(const ELFO *Obj, Elf_Dyn_Range DynTable,
Elf_Dyn_Range DynTable, StreamWriter &W) StreamWriter &W)
: Obj(Obj), W(W) { : Obj(Obj), W(W) {
for (const auto &Entry : DynTable) { for (const auto &Entry : DynTable) {
switch (Entry.getTag()) { switch (Entry.getTag()) {
@ -1539,8 +1541,8 @@ template <class ELFT> void MipsGOTParser<ELFT>::parsePLT() {
switch (PLTRelShdr->sh_type) { switch (PLTRelShdr->sh_type) {
case ELF::SHT_REL: case ELF::SHT_REL:
for (const typename ObjectFile::Elf_Rel *RI = Obj->rel_begin(PLTRelShdr), for (const Elf_Rel *RI = Obj->rel_begin(PLTRelShdr),
*RE = Obj->rel_end(PLTRelShdr); *RE = Obj->rel_end(PLTRelShdr);
RI != RE && It != PLTEnd; ++RI, ++It) { RI != RE && It != PLTEnd; ++RI, ++It) {
const Elf_Sym *Sym = const Elf_Sym *Sym =
Obj->getRelocationSymbol(&*PLTRelShdr, &*RI).second; Obj->getRelocationSymbol(&*PLTRelShdr, &*RI).second;
@ -1548,9 +1550,8 @@ template <class ELFT> void MipsGOTParser<ELFT>::parsePLT() {
} }
break; break;
case ELF::SHT_RELA: case ELF::SHT_RELA:
for (const typename ObjectFile::Elf_Rela for (const Elf_Rela *RI = Obj->rela_begin(PLTRelShdr),
*RI = Obj->rela_begin(PLTRelShdr), *RE = Obj->rela_end(PLTRelShdr);
*RE = Obj->rela_end(PLTRelShdr);
RI != RE && It != PLTEnd; ++RI, ++It) { RI != RE && It != PLTEnd; ++RI, ++It) {
const Elf_Sym *Sym = const Elf_Sym *Sym =
Obj->getRelocationSymbol(&*PLTRelShdr, &*RI).second; Obj->getRelocationSymbol(&*PLTRelShdr, &*RI).second;
@ -1782,7 +1783,7 @@ template <class ELFT> void ELFDumper<ELFT>::printMipsReginfo() {
} }
template <class ELFT> void ELFDumper<ELFT>::printStackMap() const { template <class ELFT> void ELFDumper<ELFT>::printStackMap() const {
const typename ELFFile<ELFT>::Elf_Shdr *StackMapSection = nullptr; const Elf_Shdr *StackMapSection = nullptr;
for (const auto &Sec : Obj->sections()) { for (const auto &Sec : Obj->sections()) {
ErrorOr<StringRef> Name = Obj->getSectionName(&Sec); ErrorOr<StringRef> Name = Obj->getSectionName(&Sec);
if (*Name == ".llvm_stackmaps") { if (*Name == ".llvm_stackmaps") {