Return ErrorOr from SymbolRef::getName.

This function can really fail since the string table offset can be out of
bounds.

Using ErrorOr makes sure the error is checked.

Hopefully a lot of the boilerplate code in tools/* can go away once we have
a diagnostic manager in Object.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241297 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2015-07-02 20:55:21 +00:00
parent 397fac95d5
commit 8a80641a85
30 changed files with 244 additions and 168 deletions

View File

@ -97,12 +97,12 @@ static bool collectRelocatedSymbols(const ObjectFile *Obj,
const object::symbol_iterator RelocSymI = Reloc.getSymbol();
if (RelocSymI == Obj->symbol_end())
continue;
StringRef RelocSymName;
if (error(RelocSymI->getName(RelocSymName)))
ErrorOr<StringRef> RelocSymName = RelocSymI->getName();
if (error(RelocSymName.getError()))
return true;
uint64_t Offset = Reloc.getOffset();
if (Offset >= SymOffset && Offset < SymEnd) {
*I = RelocSymName;
*I = *RelocSymName;
++I;
}
}
@ -121,12 +121,12 @@ static bool collectRelocationOffsets(
const object::symbol_iterator RelocSymI = Reloc.getSymbol();
if (RelocSymI == Obj->symbol_end())
continue;
StringRef RelocSymName;
if (error(RelocSymI->getName(RelocSymName)))
ErrorOr<StringRef> RelocSymName = RelocSymI->getName();
if (error(RelocSymName.getError()))
return true;
uint64_t Offset = Reloc.getOffset();
if (Offset >= SymOffset && Offset < SymEnd)
Collection[std::make_pair(SymName, Offset - SymOffset)] = RelocSymName;
Collection[std::make_pair(SymName, Offset - SymOffset)] = *RelocSymName;
}
}
return false;
@ -190,9 +190,10 @@ static void dumpCXXData(const ObjectFile *Obj) {
for (auto &P : SymAddr) {
object::SymbolRef Sym = P.first;
uint64_t SymSize = P.second;
StringRef SymName;
if (error(Sym.getName(SymName)))
ErrorOr<StringRef> SymNameOrErr = Sym.getName();
if (error(SymNameOrErr.getError()))
return;
StringRef SymName = *SymNameOrErr;
object::section_iterator SecI(Obj->section_begin());
if (error(Sym.getSection(SecI)))
return;