diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-11-17 11:17:17 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-11-17 11:17:17 +0000 |
commit | a18e46cbc92cde1b5eaa8eea83df6d5821d22680 (patch) | |
tree | 3177bb2a62031a6a525615ab4bec085bfa81bd4e /tools/llvm-readobj | |
parent | d9d2703b712b121eaee4c0ada57ee989812fe8f1 (diff) |
Object, COFF: Tighten the object file parser
We were a little lax in a few areas:
- We pretended that import libraries were like any old COFF file, they
are not. In fact, they aren't really COFF files at all, we should
probably grow some specialized functionality to handle them smarter.
- Our symbol iterators were more than happy to attempt to go past the
end of the symbol table if you had a symbol with a bad list of
auxiliary symbols.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222124 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-readobj')
-rw-r--r-- | tools/llvm-readobj/COFFDumper.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index 1506f06136e..c5469db98af 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -825,22 +825,22 @@ void COFFDumper::printSymbols() { void COFFDumper::printDynamicSymbols() { ListScope Group(W, "DynamicSymbols"); } -static StringRef getSectionName(const llvm::object::COFFObjectFile *Obj, - COFFSymbolRef Symbol, - const coff_section *Section) { +static ErrorOr<StringRef> +getSectionName(const llvm::object::COFFObjectFile *Obj, int32_t SectionNumber, + const coff_section *Section) { if (Section) { StringRef SectionName; - Obj->getSectionName(Section, SectionName); + if (std::error_code EC = Obj->getSectionName(Section, SectionName)) + return EC; return SectionName; } - int32_t SectionNumber = Symbol.getSectionNumber(); if (SectionNumber == llvm::COFF::IMAGE_SYM_DEBUG) - return "IMAGE_SYM_DEBUG"; + return StringRef("IMAGE_SYM_DEBUG"); if (SectionNumber == llvm::COFF::IMAGE_SYM_ABSOLUTE) - return "IMAGE_SYM_ABSOLUTE"; + return StringRef("IMAGE_SYM_ABSOLUTE"); if (SectionNumber == llvm::COFF::IMAGE_SYM_UNDEFINED) - return "IMAGE_SYM_UNDEFINED"; - return ""; + return StringRef("IMAGE_SYM_UNDEFINED"); + return StringRef(""); } void COFFDumper::printSymbol(const SymbolRef &Sym) { @@ -858,7 +858,11 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) { if (Obj->getSymbolName(Symbol, SymbolName)) SymbolName = ""; - StringRef SectionName = getSectionName(Obj, Symbol, Section); + StringRef SectionName = ""; + ErrorOr<StringRef> Res = + getSectionName(Obj, Symbol.getSectionNumber(), Section); + if (Res) + SectionName = *Res; W.printString("Name", SymbolName); W.printNumber("Value", Symbol.getValue()); @@ -929,10 +933,14 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) { if (Section && Section->Characteristics & COFF::IMAGE_SCN_LNK_COMDAT && Aux->Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) { const coff_section *Assoc; - StringRef AssocName; - std::error_code EC; - if ((EC = Obj->getSection(AuxNumber, Assoc)) || - (EC = Obj->getSectionName(Assoc, AssocName))) { + StringRef AssocName = ""; + std::error_code EC = Obj->getSection(AuxNumber, Assoc); + ErrorOr<StringRef> Res = getSectionName(Obj, AuxNumber, Assoc); + if (Res) + AssocName = *Res; + if (!EC) + EC = Res.getError(); + if (EC) { AssocName = ""; error(EC); } |