X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvm-objdump%2FCOFFDump.cpp;h=001e352c8d0b8f31cdd2067cfd782a0ea393ea20;hb=35da61aba143cc6d35224ed008b30e07bc6486c3;hp=3df443149a6a56103bbbadb4d1d5674a1973de04;hpb=1da08cb171c0684d47bf37d4a10f4e53dcb229c5;p=oota-llvm.git diff --git a/tools/llvm-objdump/COFFDump.cpp b/tools/llvm-objdump/COFFDump.cpp index 3df443149a6..001e352c8d0 100644 --- a/tools/llvm-objdump/COFFDump.cpp +++ b/tools/llvm-objdump/COFFDump.cpp @@ -22,9 +22,9 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Support/Win64EH.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/system_error.h" #include #include +#include using namespace llvm; using namespace object; @@ -151,38 +151,38 @@ static void printAllUnwindCodes(ArrayRef UCs) { << " remaining in buffer"; return ; } - printUnwindCode(ArrayRef(I, E)); + printUnwindCode(makeArrayRef(I, E)); I += UsedSlots; } } // Given a symbol sym this functions returns the address and section of it. -static error_code resolveSectionAndAddress(const COFFObjectFile *Obj, - const SymbolRef &Sym, - const coff_section *&ResolvedSection, - uint64_t &ResolvedAddr) { - if (error_code EC = Sym.getAddress(ResolvedAddr)) +static std::error_code +resolveSectionAndAddress(const COFFObjectFile *Obj, const SymbolRef &Sym, + const coff_section *&ResolvedSection, + uint64_t &ResolvedAddr) { + ErrorOr ResolvedAddrOrErr = Sym.getAddress(); + if (std::error_code EC = ResolvedAddrOrErr.getError()) return EC; - section_iterator iter(Obj->section_begin()); - if (error_code EC = Sym.getSection(iter)) + ResolvedAddr = *ResolvedAddrOrErr; + ErrorOr Iter = Sym.getSection(); + if (std::error_code EC = Iter.getError()) return EC; - ResolvedSection = Obj->getCOFFSection(iter); - return object_error::success; + ResolvedSection = Obj->getCOFFSection(**Iter); + return std::error_code(); } // Given a vector of relocations for a section and an offset into this section // the function returns the symbol used for the relocation at the offset. -static error_code resolveSymbol(const std::vector &Rels, - uint64_t Offset, SymbolRef &Sym) { +static std::error_code resolveSymbol(const std::vector &Rels, + uint64_t Offset, SymbolRef &Sym) { for (std::vector::const_iterator I = Rels.begin(), E = Rels.end(); I != E; ++I) { - uint64_t Ofs; - if (error_code EC = I->getOffset(Ofs)) - return EC; + uint64_t Ofs = I->getOffset(); if (Ofs == Offset) { Sym = *I->getSymbol(); - return object_error::success; + return std::error_code(); } } return object_error::parse_failed; @@ -192,33 +192,34 @@ static error_code resolveSymbol(const std::vector &Rels, // the function resolves the symbol used for the relocation at the offset and // returns the section content and the address inside the content pointed to // by the symbol. -static error_code getSectionContents(const COFFObjectFile *Obj, - const std::vector &Rels, - uint64_t Offset, - ArrayRef &Contents, - uint64_t &Addr) { +static std::error_code +getSectionContents(const COFFObjectFile *Obj, + const std::vector &Rels, uint64_t Offset, + ArrayRef &Contents, uint64_t &Addr) { SymbolRef Sym; - if (error_code EC = resolveSymbol(Rels, Offset, Sym)) + if (std::error_code EC = resolveSymbol(Rels, Offset, Sym)) return EC; const coff_section *Section; - if (error_code EC = resolveSectionAndAddress(Obj, Sym, Section, Addr)) + if (std::error_code EC = resolveSectionAndAddress(Obj, Sym, Section, Addr)) return EC; - if (error_code EC = Obj->getSectionContents(Section, Contents)) + if (std::error_code EC = Obj->getSectionContents(Section, Contents)) return EC; - return object_error::success; + return std::error_code(); } // Given a vector of relocations for a section and an offset into this section // the function returns the name of the symbol used for the relocation at the // offset. -static error_code resolveSymbolName(const std::vector &Rels, - uint64_t Offset, StringRef &Name) { +static std::error_code resolveSymbolName(const std::vector &Rels, + uint64_t Offset, StringRef &Name) { SymbolRef Sym; - if (error_code EC = resolveSymbol(Rels, Offset, Sym)) + if (std::error_code EC = resolveSymbol(Rels, Offset, Sym)) return EC; - if (error_code EC = Sym.getName(Name)) + ErrorOr NameOrErr = Sym.getName(); + if (std::error_code EC = NameOrErr.getError()) return EC; - return object_error::success; + Name = *NameOrErr; + return std::error_code(); } static void printCOFFSymbolAddress(llvm::raw_ostream &Out, @@ -240,12 +241,10 @@ printSEHTable(const COFFObjectFile *Obj, uint32_t TableVA, int Count) { return; const pe32_header *PE32Header; - if (error(Obj->getPE32Header(PE32Header))) - return; + error(Obj->getPE32Header(PE32Header)); uint32_t ImageBase = PE32Header->ImageBase; uintptr_t IntPtr = 0; - if (error(Obj->getVaPtr(TableVA, IntPtr))) - return; + error(Obj->getVaPtr(TableVA, IntPtr)); const support::ulittle32_t *P = (const support::ulittle32_t *)IntPtr; outs() << "SEH Table:"; for (int I = 0; I < Count; ++I) @@ -256,26 +255,20 @@ printSEHTable(const COFFObjectFile *Obj, uint32_t TableVA, int Count) { static void printLoadConfiguration(const COFFObjectFile *Obj) { // Skip if it's not executable. const pe32_header *PE32Header; - if (error(Obj->getPE32Header(PE32Header))) - return; + error(Obj->getPE32Header(PE32Header)); if (!PE32Header) return; - const coff_file_header *Header; - if (error(Obj->getCOFFHeader(Header))) - return; // Currently only x86 is supported - if (Header->Machine != COFF::IMAGE_FILE_MACHINE_I386) + if (Obj->getMachine() != COFF::IMAGE_FILE_MACHINE_I386) return; const data_directory *DataDir; - if (error(Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE, DataDir))) - return; + error(Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE, DataDir)); uintptr_t IntPtr = 0; if (DataDir->RelativeVirtualAddress == 0) return; - if (error(Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr))) - return; + error(Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr)); auto *LoadConf = reinterpret_cast(IntPtr); outs() << "Load configuration:" @@ -326,7 +319,7 @@ static void printImportTables(const COFFObjectFile *Obj) { const import_lookup_table_entry32 *entry; if (I->getImportLookupEntry(entry)) return; - for (; entry->data; ++entry) { + for (; entry->Data; ++entry) { if (entry->isOrdinal()) { outs() << format(" % 6d\n", entry->getOrdinal()); continue; @@ -381,26 +374,21 @@ static void printExportTable(const COFFObjectFile *Obj) { static bool getPDataSection(const COFFObjectFile *Obj, std::vector &Rels, const RuntimeFunction *&RFStart, int &NumRFs) { - for (section_iterator SI = Obj->section_begin(), SE = Obj->section_end(); - SI != SE; ++SI) { + for (const SectionRef &Section : Obj->sections()) { StringRef Name; - if (error(SI->getName(Name))) - continue; + error(Section.getName(Name)); if (Name != ".pdata") continue; - const coff_section *Pdata = Obj->getCOFFSection(SI); - for (relocation_iterator RI = SI->relocation_begin(), - RE = SI->relocation_end(); - RI != RE; ++RI) - Rels.push_back(*RI); + const coff_section *Pdata = Obj->getCOFFSection(Section); + for (const RelocationRef &Reloc : Section.relocations()) + Rels.push_back(Reloc); // Sort relocations by address. std::sort(Rels.begin(), Rels.end(), RelocAddressLess); ArrayRef Contents; - if (error(Obj->getSectionContents(Pdata, Contents))) - continue; + error(Obj->getSectionContents(Pdata, Contents)); if (Contents.empty()) continue; @@ -445,7 +433,7 @@ static void printWin64EHUnwindInfo(const Win64EH::UnwindInfo *UI) { if (UI->NumCodes) outs() << " Unwind Codes:\n"; - printAllUnwindCodes(ArrayRef(&UI->UnwindCodes[0], UI->NumCodes)); + printAllUnwindCodes(makeArrayRef(&UI->UnwindCodes[0], UI->NumCodes)); outs() << "\n"; outs().flush(); @@ -504,11 +492,10 @@ static void printRuntimeFunctionRels(const COFFObjectFile *Obj, ArrayRef XContents; uint64_t UnwindInfoOffset = 0; - if (error(getSectionContents( + error(getSectionContents( Obj, Rels, SectionOffset + /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8, - XContents, UnwindInfoOffset))) - return; + XContents, UnwindInfoOffset)); if (XContents.empty()) return; @@ -522,11 +509,7 @@ static void printRuntimeFunctionRels(const COFFObjectFile *Obj, } void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) { - const coff_file_header *Header; - if (error(Obj->getCOFFHeader(Header))) - return; - - if (Header->Machine != COFF::IMAGE_FILE_MACHINE_AMD64) { + if (Obj->getMachine() != COFF::IMAGE_FILE_MACHINE_AMD64) { errs() << "Unsupported image machine type " "(currently only AMD64 is supported).\n"; return;