X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvm-readobj%2FARMEHABIPrinter.h;h=beb5fd4ea042b4aafcd20b62b6c62ad40e92fe40;hb=813f44a29fd0fd140127023222d0633e23783bcc;hp=716c9a1a48e99a1c27f9733b112dbbb9f15bdb15;hpb=5c792faa0e5560bc148c973f3df658eb3bb2061e;p=oota-llvm.git diff --git a/tools/llvm-readobj/ARMEHABIPrinter.h b/tools/llvm-readobj/ARMEHABIPrinter.h index 716c9a1a48e..beb5fd4ea04 100644 --- a/tools/llvm-readobj/ARMEHABIPrinter.h +++ b/tools/llvm-readobj/ARMEHABIPrinter.h @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_READOBJ_ARMEHABI_PRINTER_H -#define LLVM_READOBJ_ARMEHABI_PRINTER_H +#ifndef LLVM_TOOLS_LLVM_READOBJ_ARMEHABIPRINTER_H +#define LLVM_TOOLS_LLVM_READOBJ_ARMEHABIPRINTER_H #include "Error.h" #include "StreamWriter.h" @@ -22,7 +22,6 @@ #include "llvm/Support/type_traits.h" namespace llvm { -using std::error_code; namespace ARM { namespace EHABI { @@ -306,15 +305,15 @@ void OpcodeDecoder::Decode(const uint8_t *Opcodes, off_t Offset, size_t Length) template class PrinterContext { - StreamWriter &SW; - const object::ELFFile *ELF; - typedef typename object::ELFFile::Elf_Sym Elf_Sym; typedef typename object::ELFFile::Elf_Shdr Elf_Shdr; + typedef typename object::ELFFile::Elf_Rel Elf_Rel; + typedef typename object::ELFFile::Elf_Word Elf_Word; - typedef typename object::ELFFile::Elf_Rel_Iter Elf_Rel_iterator; - typedef typename object::ELFFile::Elf_Sym_Iter Elf_Sym_iterator; - typedef typename object::ELFFile::Elf_Shdr_Iter Elf_Shdr_iterator; + StreamWriter &SW; + const object::ELFFile *ELF; + const Elf_Shdr *Symtab; + ArrayRef ShndxTable; static const size_t IndexTableEntrySize; @@ -335,8 +334,9 @@ class PrinterContext { void PrintOpcodes(const uint8_t *Entry, size_t Length, off_t Offset) const; public: - PrinterContext(StreamWriter &Writer, const object::ELFFile *File) - : SW(Writer), ELF(File) {} + PrinterContext(StreamWriter &SW, const object::ELFFile *ELF, + const Elf_Shdr *Symtab) + : SW(SW), ELF(ELF), Symtab(Symtab) {} void PrintUnwindInformation() const; }; @@ -345,13 +345,17 @@ template const size_t PrinterContext::IndexTableEntrySize = 8; template -ErrorOr PrinterContext::FunctionAtAddress(unsigned Section, - uint64_t Address) const { - for (Elf_Sym_iterator SI = ELF->begin_symbols(), SE = ELF->end_symbols(); - SI != SE; ++SI) - if (SI->st_shndx == Section && SI->st_value == Address && - SI->getType() == ELF::STT_FUNC) - return ELF->getSymbolName(SI); +ErrorOr +PrinterContext::FunctionAtAddress(unsigned Section, + uint64_t Address) const { + ErrorOr StrTableOrErr = ELF->getStringTableForSymtab(*Symtab); + error(StrTableOrErr.getError()); + StringRef StrTable = *StrTableOrErr; + + for (const Elf_Sym &Sym : ELF->symbols(Symtab)) + if (Sym.st_shndx == Section && Sym.st_value == Address && + Sym.getType() == ELF::STT_FUNC) + return Sym.getName(StrTable); return readobj_error::unknown_symbol; } @@ -367,23 +371,30 @@ PrinterContext::FindExceptionTable(unsigned IndexSectionIndex, /// handling table. Use this symbol to recover the actual exception handling /// table. - for (Elf_Shdr_iterator SI = ELF->begin_sections(), SE = ELF->end_sections(); - SI != SE; ++SI) { - if (SI->sh_type == ELF::SHT_REL && SI->sh_info == IndexSectionIndex) { - for (Elf_Rel_iterator RI = ELF->begin_rel(&*SI), RE = ELF->end_rel(&*SI); - RI != RE; ++RI) { - if (RI->r_offset == static_cast(IndexTableOffset)) { - typename object::ELFFile::Elf_Rela RelA; - RelA.r_offset = RI->r_offset; - RelA.r_info = RI->r_info; - RelA.r_addend = 0; - - std::pair Symbol = - ELF->getRelocationSymbol(&(*SI), &RelA); - - return ELF->getSection(Symbol.second); - } - } + for (const Elf_Shdr &Sec : ELF->sections()) { + if (Sec.sh_type != ELF::SHT_REL || Sec.sh_info != IndexSectionIndex) + continue; + + ErrorOr SymTabOrErr = ELF->getSection(Sec.sh_link); + error(SymTabOrErr.getError()); + const Elf_Shdr *SymTab = *SymTabOrErr; + + for (const Elf_Rel &R : ELF->rels(&Sec)) { + if (R.r_offset != static_cast(IndexTableOffset)) + continue; + + typename object::ELFFile::Elf_Rela RelA; + RelA.r_offset = R.r_offset; + RelA.r_info = R.r_info; + RelA.r_addend = 0; + + const Elf_Sym *Symbol = ELF->getRelocationSymbol(&RelA, SymTab); + + ErrorOr Ret = + ELF->getSection(Symbol, SymTab, ShndxTable); + if (std::error_code EC = Ret.getError()) + report_fatal_error(EC.message()); + return *Ret; } } return nullptr; @@ -529,20 +540,18 @@ void PrinterContext::PrintUnwindInformation() const { DictScope UI(SW, "UnwindInformation"); int SectionIndex = 0; - for (Elf_Shdr_iterator SI = ELF->begin_sections(), SE = ELF->end_sections(); - SI != SE; ++SI, ++SectionIndex) { - if (SI->sh_type == ELF::SHT_ARM_EXIDX) { - const Elf_Shdr *IT = &(*SI); - + for (const Elf_Shdr &Sec : ELF->sections()) { + if (Sec.sh_type == ELF::SHT_ARM_EXIDX) { DictScope UIT(SW, "UnwindIndexTable"); SW.printNumber("SectionIndex", SectionIndex); - if (ErrorOr SectionName = ELF->getSectionName(IT)) + if (ErrorOr SectionName = ELF->getSectionName(&Sec)) SW.printString("SectionName", *SectionName); - SW.printHex("SectionOffset", IT->sh_offset); + SW.printHex("SectionOffset", Sec.sh_offset); - PrintIndexTable(SectionIndex, IT); + PrintIndexTable(SectionIndex, &Sec); } + ++SectionIndex; } } }