From 7528c1963f2d374b4ccbd47c43f1cc99cd5e2391 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 23 Jul 2015 08:48:14 +0000 Subject: [PATCH] Use typdef to simplify the code. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242995 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-readobj/ELFDumper.cpp | 81 ++++++++++++++++---------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index c8e744b8a3a..6e4eaec475c 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -71,10 +71,12 @@ private: typedef typename ELFO::Elf_Sym Elf_Sym; typedef typename ELFO::Elf_Dyn Elf_Dyn; 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_Range Elf_Rela_Range; typedef typename ELFO::Elf_Phdr Elf_Phdr; typedef typename ELFO::Elf_Hash Elf_Hash; + typedef typename ELFO::Elf_Ehdr Elf_Ehdr; typedef typename ELFO::uintX_t uintX_t; /// \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 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); const Elf_Rela *dyn_rela_begin() const; @@ -203,18 +205,18 @@ getSectionNameIndex(const ELFO &Obj, const typename ELFO::Elf_Sym *Symbol, } } -template -static const typename ELFFile::Elf_Shdr * -findSectionByAddress(const ELFFile *Obj, uint64_t Addr) { +template +static const typename ELFO::Elf_Shdr *findSectionByAddress(const ELFO *Obj, + uint64_t Addr) { for (const auto &Shdr : Obj->sections()) if (Shdr.sh_addr == Addr) return &Shdr; return nullptr; } -template -static const typename ELFFile::Elf_Shdr * -findSectionByName(const ELFFile &Obj, StringRef Name) { +template +static const typename ELFO::Elf_Shdr *findSectionByName(const ELFO &Obj, + StringRef Name) { for (const auto &Shdr : Obj.sections()) { if (Name == errorOrDefault(Obj.getSectionName(&Shdr))) return &Shdr; @@ -703,7 +705,7 @@ ELFDumper::dynamic_table_end() const { template void ELFDumper::printFileHeaders() { - const typename ELFO::Elf_Ehdr *Header = Obj->getHeader(); + const Elf_Ehdr *Header = Obj->getHeader(); { DictScope D(W, "ElfHeader"); @@ -754,7 +756,7 @@ void ELFDumper::printSections() { ListScope SectionsD(W, "Sections"); int SectionIndex = -1; - for (const typename ELFO::Elf_Shdr &Sec : Obj->sections()) { + for (const Elf_Shdr &Sec : Obj->sections()) { ++SectionIndex; StringRef Name = errorOrDefault(Obj->getSectionName(&Sec)); @@ -786,7 +788,7 @@ void ELFDumper::printSections() { error(StrTableOrErr.getError()); StringRef StrTable = *StrTableOrErr; - for (const typename ELFO::Elf_Sym &Sym : Obj->symbols()) { + for (const Elf_Sym &Sym : Obj->symbols()) { ErrorOr SymSec = Obj->getSection(&Sym); if (!SymSec) continue; @@ -808,7 +810,7 @@ void ELFDumper::printRelocations() { ListScope D(W, "Relocations"); int SectionNumber = -1; - for (const typename ELFO::Elf_Shdr &Sec : Obj->sections()) { + for (const Elf_Shdr &Sec : Obj->sections()) { ++SectionNumber; if (Sec.sh_type != ELF::SHT_REL && Sec.sh_type != ELF::SHT_RELA) @@ -830,12 +832,12 @@ template void ELFDumper::printDynamicRelocations() { W.startLine() << "Dynamic Relocations {\n"; W.indent(); - for (const typename ELFO::Elf_Rela &Rel : dyn_relas()) { + for (const Elf_Rela &Rel : dyn_relas()) { SmallString<32> RelocName; Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName); StringRef SymbolName; 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)); if (opts::ExpandRelocs) { DictScope Group(W, "Relocation"); @@ -859,8 +861,8 @@ template void ELFDumper::printRelocations(const Elf_Shdr *Sec) { switch (Sec->sh_type) { case ELF::SHT_REL: - for (const typename ELFO::Elf_Rel &R : Obj->rels(Sec)) { - typename ELFO::Elf_Rela Rela; + for (const Elf_Rel &R : Obj->rels(Sec)) { + Elf_Rela Rela; Rela.r_offset = R.r_offset; Rela.r_info = R.r_info; Rela.r_addend = 0; @@ -868,15 +870,14 @@ void ELFDumper::printRelocations(const Elf_Shdr *Sec) { } break; 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); break; } } template -void ELFDumper::printRelocation(const Elf_Shdr *Sec, - typename ELFO::Elf_Rela Rel) { +void ELFDumper::printRelocation(const Elf_Shdr *Sec, Elf_Rela Rel) { SmallString<32> RelocName; Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName); StringRef TargetName; @@ -918,7 +919,7 @@ void ELFDumper::printSymbols() { ErrorOr StrTableOrErr = Obj->getStringTableForSymtab(*Symtab); error(StrTableOrErr.getError()); StringRef StrTable = *StrTableOrErr; - for (const typename ELFO::Elf_Sym &Sym : Obj->symbols()) + for (const Elf_Sym &Sym : Obj->symbols()) printSymbol(&Sym, StrTable, false); } @@ -930,13 +931,13 @@ void ELFDumper::printDynamicSymbols() { ErrorOr StrTableOrErr = Obj->getStringTableForSymtab(*Symtab); error(StrTableOrErr.getError()); 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); } template -void ELFDumper::printSymbol(const typename ELFO::Elf_Sym *Symbol, - StringRef StrTable, bool IsDynamic) { +void ELFDumper::printSymbol(const Elf_Sym *Symbol, StringRef StrTable, + bool IsDynamic) { unsigned SectionIndex = 0; StringRef SectionName; getSectionNameIndex(*Obj, Symbol, SectionName, SectionIndex); @@ -1226,7 +1227,7 @@ void ELFDumper::printDynamicTable() { << " Tag" << (Is64 ? " " : " ") << "Type" << " " << "Name/Value\n"; while (I != E) { - const typename ELFO::Elf_Dyn &Entry = *I; + const Elf_Dyn &Entry = *I; ++I; W.startLine() << " " @@ -1261,7 +1262,7 @@ template void ELFDumper::printProgramHeaders() { 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"); W.printHex("Type", getElfSegmentType(Obj->getHeader()->e_machine, Phdr.p_type), @@ -1330,20 +1331,21 @@ template <> void ELFDumper>::printAttributes() { namespace { template class MipsGOTParser { public: - typedef object::ELFFile ObjectFile; - typedef typename ObjectFile::Elf_Shdr Elf_Shdr; - typedef typename ObjectFile::Elf_Sym Elf_Sym; - typedef typename ObjectFile::Elf_Dyn_Range Elf_Dyn_Range; + typedef object::ELFFile 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; - MipsGOTParser(const ObjectFile *Obj, Elf_Dyn_Range DynTable, StreamWriter &W); + MipsGOTParser(const ELFO *Obj, Elf_Dyn_Range DynTable, StreamWriter &W); void parseGOT(); void parsePLT(); private: - typedef typename ObjectFile::Elf_Addr GOTEntry; - - const ObjectFile *Obj; + const ELFO *Obj; StreamWriter &W; llvm::Optional DtPltGot; llvm::Optional DtLocalGotNum; @@ -1368,8 +1370,8 @@ private: } template -MipsGOTParser::MipsGOTParser(const ObjectFile *Obj, - Elf_Dyn_Range DynTable, StreamWriter &W) +MipsGOTParser::MipsGOTParser(const ELFO *Obj, Elf_Dyn_Range DynTable, + StreamWriter &W) : Obj(Obj), W(W) { for (const auto &Entry : DynTable) { switch (Entry.getTag()) { @@ -1539,8 +1541,8 @@ template void MipsGOTParser::parsePLT() { switch (PLTRelShdr->sh_type) { case ELF::SHT_REL: - for (const typename ObjectFile::Elf_Rel *RI = Obj->rel_begin(PLTRelShdr), - *RE = Obj->rel_end(PLTRelShdr); + for (const Elf_Rel *RI = Obj->rel_begin(PLTRelShdr), + *RE = Obj->rel_end(PLTRelShdr); RI != RE && It != PLTEnd; ++RI, ++It) { const Elf_Sym *Sym = Obj->getRelocationSymbol(&*PLTRelShdr, &*RI).second; @@ -1548,9 +1550,8 @@ template void MipsGOTParser::parsePLT() { } break; case ELF::SHT_RELA: - for (const typename ObjectFile::Elf_Rela - *RI = Obj->rela_begin(PLTRelShdr), - *RE = Obj->rela_end(PLTRelShdr); + for (const Elf_Rela *RI = Obj->rela_begin(PLTRelShdr), + *RE = Obj->rela_end(PLTRelShdr); RI != RE && It != PLTEnd; ++RI, ++It) { const Elf_Sym *Sym = Obj->getRelocationSymbol(&*PLTRelShdr, &*RI).second; @@ -1782,7 +1783,7 @@ template void ELFDumper::printMipsReginfo() { } template void ELFDumper::printStackMap() const { - const typename ELFFile::Elf_Shdr *StackMapSection = nullptr; + const Elf_Shdr *StackMapSection = nullptr; for (const auto &Sec : Obj->sections()) { ErrorOr Name = Obj->getSectionName(&Sec); if (*Name == ".llvm_stackmaps") {