Produce another specific error message for a malformed Mach-O file when a symbol’s
section index is more than the number of sections. The existing test case in test/Object/macho-invalid.test
for macho-invalid-section-index-getSectionRawName now reports the error with the message indicating
that a symbol at a specific index has a bad section index and that bad section index value.
Again converting interfaces to Expected<> from ErrorOr<> does involve
touching a number of places. Where the existing code reported the error with a
string message or an error code it was converted to do the same.
Also there some were bugs in the existing code that did not deal with the
old ErrorOr<> return values. So now with Expected<> since they must be
checked and the error handled, I added a TODO and a comment:
"// TODO: Actually report errors helpfully" and a call something like
consumeError(NameOrErr.takeError()) so the buggy code will not crash
since needed to deal with the Error.
llvm-svn: 268298
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
- ErrorOr<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
- ErrorOr<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
+ Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
+ Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
void moveSectionNext(DataRefImpl &Sec) const override;
std::error_code getSectionName(DataRefImpl Sec,
StringRef &Res) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
uint8_t getSymbolOther(DataRefImpl Symb) const override;
uint8_t getSymbolELFType(DataRefImpl Symb) const override;
- ErrorOr<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
- ErrorOr<section_iterator> getSymbolSection(const Elf_Sym *Symb,
- const Elf_Shdr *SymTab) const;
- ErrorOr<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
+ Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
+ Expected<section_iterator> getSymbolSection(const Elf_Sym *Symb,
+ const Elf_Shdr *SymTab) const;
+ Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
void moveSectionNext(DataRefImpl &Sec) const override;
std::error_code getSectionName(DataRefImpl Sec,
}
template <class ELFT>
-ErrorOr<SymbolRef::Type>
+Expected<SymbolRef::Type>
ELFObjectFile<ELFT>::getSymbolType(DataRefImpl Symb) const {
const Elf_Sym *ESym = getSymbol(Symb);
}
template <class ELFT>
-ErrorOr<section_iterator>
+Expected<section_iterator>
ELFObjectFile<ELFT>::getSymbolSection(const Elf_Sym *ESym,
const Elf_Shdr *SymTab) const {
ErrorOr<const Elf_Shdr *> ESecOrErr = EF.getSection(ESym, SymTab, ShndxTable);
if (std::error_code EC = ESecOrErr.getError())
- return EC;
+ return errorCodeToError(EC);
const Elf_Shdr *ESec = *ESecOrErr;
if (!ESec)
}
template <class ELFT>
-ErrorOr<section_iterator>
+Expected<section_iterator>
ELFObjectFile<ELFT>::getSymbolSection(DataRefImpl Symb) const {
const Elf_Sym *Sym = getSymbol(Symb);
const Elf_Shdr *SymTab = *EF.getSection(Symb.d.a);
ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
- ErrorOr<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
+ Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
- ErrorOr<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
+ Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
unsigned getSymbolSectionID(SymbolRef Symb) const;
unsigned getSectionID(SectionRef Sec) const;
/// @brief Get the alignment of this symbol as the actual value (not log 2).
uint32_t getAlignment() const;
uint64_t getCommonSize() const;
- ErrorOr<SymbolRef::Type> getType() const;
+ Expected<SymbolRef::Type> getType() const;
/// @brief Get section this symbol is defined in reference to. Result is
/// end_sections() if it is undefined or is an absolute symbol.
- ErrorOr<section_iterator> getSection() const;
+ Expected<section_iterator> getSection() const;
const ObjectFile *getObject() const;
};
virtual uint64_t getSymbolValueImpl(DataRefImpl Symb) const = 0;
virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const = 0;
- virtual ErrorOr<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const = 0;
- virtual ErrorOr<section_iterator>
+ virtual Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const = 0;
+ virtual Expected<section_iterator>
getSymbolSection(DataRefImpl Symb) const = 0;
// Same as above for SectionRef.
return getObject()->getCommonSymbolSize(getRawDataRefImpl());
}
-inline ErrorOr<section_iterator> SymbolRef::getSection() const {
+inline Expected<section_iterator> SymbolRef::getSection() const {
return getObject()->getSymbolSection(getRawDataRefImpl());
}
-inline ErrorOr<SymbolRef::Type> SymbolRef::getType() const {
+inline Expected<SymbolRef::Type> SymbolRef::getType() const {
return getObject()->getSymbolType(getRawDataRefImpl());
}
}
SymAddr = *SymAddrOrErr;
// Also remember what section this symbol is in for later
- RSec = *Sym->getSection();
+ auto SectOrErr = Sym->getSection();
+ if (!SectOrErr) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(SectOrErr.takeError(), OS, "");
+ OS.flush();
+ errs() << "error: failed to get symbol section: "
+ << Buf << '\n';
+ continue;
+ }
+ RSec = *SectOrErr;
} else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
// MachO also has relocations that point to sections and
// scattered relocations.
uint64_t SymbolSize,
DataExtractor *OpdExtractor,
uint64_t OpdAddress) {
- ErrorOr<SymbolRef::Type> SymbolTypeOrErr = Symbol.getType();
- if (auto EC = SymbolTypeOrErr.getError())
- return EC;
+ Expected<SymbolRef::Type> SymbolTypeOrErr = Symbol.getType();
+ if (!SymbolTypeOrErr)
+ return errorToErrorCode(SymbolTypeOrErr.takeError());
SymbolRef::Type SymbolType = *SymbolTypeOrErr;
if (SymbolType != SymbolRef::ST_Function && SymbolType != SymbolRef::ST_Data)
return std::error_code();
std::vector<LineNumberInfo> LineInfo;
std::string SourceFileName;
- ErrorOr<SymbolRef::Type> SymTypeOrErr = Sym.getType();
- if (!SymTypeOrErr)
+ Expected<SymbolRef::Type> SymTypeOrErr = Sym.getType();
+ if (!SymTypeOrErr) {
+ // TODO: Actually report errors helpfully.
+ consumeError(SymTypeOrErr.takeError());
continue;
+ }
SymbolRef::Type SymType = *SymTypeOrErr;
if (SymType != SymbolRef::ST_Function)
continue;
if (auto SymTypeOrErr = I->getType())
SymType = *SymTypeOrErr;
else
- return errorCodeToError(SymTypeOrErr.getError());
+ return SymTypeOrErr.takeError();
// Get symbol name.
StringRef Name;
if (auto SIOrErr = I->getSection())
SI = *SIOrErr;
else
- return errorCodeToError(SIOrErr.getError());
+ return SIOrErr.takeError();
if (SI == Obj.section_end())
continue;
if (auto TSIOrErr = TargetSymbol->getSection())
TSI = *TSIOrErr;
else
- return errorCodeToError(TSIOrErr.getError());
+ return TSIOrErr.takeError();
assert(TSI != Obj.section_end() && "TSI should refer to a valid section");
bool IsCode = TSI->isText();
RTDyldSymbolTable::const_iterator gsi = GlobalSymbolTable.end();
if (Symbol != Obj.symbol_end()) {
gsi = GlobalSymbolTable.find(TargetName.data());
- ErrorOr<SymbolRef::Type> SymTypeOrErr = Symbol->getType();
- if (std::error_code EC = SymTypeOrErr.getError())
- report_fatal_error(EC.message());
+ Expected<SymbolRef::Type> SymTypeOrErr = Symbol->getType();
+ if (!SymTypeOrErr) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(SymTypeOrErr.takeError(), OS, "");
+ OS.flush();
+ report_fatal_error(Buf);
+ }
SymType = *SymTypeOrErr;
}
if (gsi != GlobalSymbolTable.end()) {
// TODO: Now ELF SymbolRef::ST_Debug = STT_SECTION, it's not obviously
// and can be changed by another developers. Maybe best way is add
// a new symbol type ST_Section to SymbolRef and use it.
- section_iterator si = *Symbol->getSection();
+ auto SectionOrErr = Symbol->getSection();
+ if (!SectionOrErr) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(SectionOrErr.takeError(), OS, "");
+ OS.flush();
+ report_fatal_error(Buf);
+ }
+ section_iterator si = *SectionOrErr;
if (si == Obj.section_end())
llvm_unreachable("Symbol section not found, bad object file format!");
DEBUG(dbgs() << "\t\tThis is section symbol\n");
}
StringRef TargetName = *TargetNameOrErr;
- auto Section = *Symbol->getSection();
+ auto SectionOrErr = Symbol->getSection();
+ if (!SectionOrErr) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(SectionOrErr.takeError(), OS, "");
+ OS.flush();
+ report_fatal_error(Buf);
+ }
+ auto Section = *SectionOrErr;
uint64_t RelType = RelI->getType();
uint64_t Offset = RelI->getOffset();
symbol_iterator Symbol = RelI->getSymbol();
if (Symbol == Obj.symbol_end())
report_fatal_error("Unknown symbol in relocation");
- section_iterator SecI = *Symbol->getSection();
+ auto SectionOrError = Symbol->getSection();
+ if (!SectionOrError) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(SectionOrError.takeError(), OS, "");
+ OS.flush();
+ report_fatal_error(Buf);
+ }
+ section_iterator SecI = *SectionOrError;
// If there is no section, this must be an external reference.
const bool IsExtern = SecI == Obj.section_end();
return Result;
}
-ErrorOr<SymbolRef::Type> COFFObjectFile::getSymbolType(DataRefImpl Ref) const {
+Expected<SymbolRef::Type> COFFObjectFile::getSymbolType(DataRefImpl Ref) const {
COFFSymbolRef Symb = getCOFFSymbol(Ref);
int32_t SectionNumber = Symb.getSectionNumber();
return Symb.getValue();
}
-ErrorOr<section_iterator>
+Expected<section_iterator>
COFFObjectFile::getSymbolSection(DataRefImpl Ref) const {
COFFSymbolRef Symb = getCOFFSymbol(Ref);
if (COFF::isReservedSectionNumber(Symb.getSectionNumber()))
return section_end();
const coff_section *Sec = nullptr;
if (std::error_code EC = getSection(Symb.getSectionNumber(), Sec))
- return EC;
+ return errorCodeToError(EC);
DataRefImpl Ret;
Ret.p = reinterpret_cast<uintptr_t>(Sec);
return section_iterator(SectionRef(Ret, this));
return getNValue(DRI);
}
-ErrorOr<SymbolRef::Type>
+Expected<SymbolRef::Type>
MachOObjectFile::getSymbolType(DataRefImpl Symb) const {
MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
uint8_t n_type = Entry.n_type;
case MachO::N_UNDF :
return SymbolRef::ST_Unknown;
case MachO::N_SECT :
- ErrorOr<section_iterator> SecOrError = getSymbolSection(Symb);
+ Expected<section_iterator> SecOrError = getSymbolSection(Symb);
if (!SecOrError)
- return SecOrError.getError();
+ return SecOrError.takeError();
section_iterator Sec = *SecOrError;
if (Sec->isData() || Sec->isBSS())
return SymbolRef::ST_Data;
return Result;
}
-ErrorOr<section_iterator>
+Expected<section_iterator>
MachOObjectFile::getSymbolSection(DataRefImpl Symb) const {
MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
uint8_t index = Entry.n_sect;
DataRefImpl DRI;
DRI.d.a = index - 1;
if (DRI.d.a >= Sections.size()){
- // Diagnostic("bad section index (" + index + ") for symbol at index " +
- // SymbolIndex);
- return object_error::parse_failed;
+ return malformedError(*this, Twine("truncated or malformed object (bad "
+ "section index: ") + Twine((int)index) + Twine(" for "
+ "symbol at index ") + Twine(getSymbolIndex(Symb)) +
+ Twine(")"));
}
return section_iterator(SectionRef(DRI, this));
}
void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
LLVMSymbolIteratorRef Sym) {
- ErrorOr<section_iterator> SecOrErr = (*unwrap(Sym))->getSection();
- if (std::error_code ec = SecOrErr.getError())
- report_fatal_error(ec.message());
+ Expected<section_iterator> SecOrErr = (*unwrap(Sym))->getSection();
+ if (!SecOrErr) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(SecOrErr.takeError(), OS, "");
+ OS.flush();
+ report_fatal_error(Buf);
+ }
*unwrap(Sect) = *SecOrErr;
}
: SymbolicFile(Type, Source) {}
bool SectionRef::containsSymbol(SymbolRef S) const {
- ErrorOr<section_iterator> SymSec = S.getSection();
- if (!SymSec)
+ Expected<section_iterator> SymSec = S.getSection();
+ if (!SymSec) {
+ // TODO: Actually report errors helpfully.
+ consumeError(SymSec.takeError());
return false;
+ }
return *this == **SymSec;
}
INVALID-SECTION-IDX-SYMBOL-SEC-pax: 0000000100000000 0f 42 0010 00000065 __mh_execute_header
RUN: not llvm-objdump -t %p/Inputs/macho-invalid-section-index-getSectionRawName 2>&1 \
RUN: | FileCheck -check-prefix INVALID-SECTION-IDX-SYMBOL-SEC-objdump %s
-INVALID-SECTION-IDX-SYMBOL-SEC-objdump: Invalid data was encountered while parsing the file.
+INVALID-SECTION-IDX-SYMBOL-SEC-objdump: truncated or malformed object (bad section index: 66 for symbol at index 8)
RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-header 2>&1 | FileCheck -check-prefix INVALID-HEADER %s
INVALID-HEADER: The file was not recognized as a valid object file
section_iterator Section = MainBinary.section_end();
MainBinarySymbolAddresses.clear();
for (const auto &Sym : MainBinary.symbols()) {
- ErrorOr<SymbolRef::Type> TypeOrErr = Sym.getType();
- if (!TypeOrErr)
+ Expected<SymbolRef::Type> TypeOrErr = Sym.getType();
+ if (!TypeOrErr) {
+ // TODO: Actually report errors helpfully.
+ consumeError(TypeOrErr.takeError());
continue;
+ }
SymbolRef::Type Type = *TypeOrErr;
// Skip undefined and STAB entries.
if ((Type & SymbolRef::ST_Debug) || (Type & SymbolRef::ST_Unknown))
// addresses should be fetched for the debug map.
if (!(Sym.getFlags() & SymbolRef::SF_Global))
continue;
- ErrorOr<section_iterator> SectionOrErr = Sym.getSection();
- if (!SectionOrErr)
+ Expected<section_iterator> SectionOrErr = Sym.getSection();
+ if (!SectionOrErr) {
+ // TODO: Actually report errors helpfully.
+ consumeError(SectionOrErr.takeError());
continue;
+ }
Section = *SectionOrErr;
if (Section == MainBinary.section_end() || Section->isText())
continue;
Expected<StringRef> SymNameOrErr = Sym.getName();
error(errorToErrorCode(SymNameOrErr.takeError()));
StringRef SymName = *SymNameOrErr;
- ErrorOr<object::section_iterator> SecIOrErr = Sym.getSection();
- error(SecIOrErr.getError());
+ Expected<object::section_iterator> SecIOrErr = Sym.getSection();
+ error(errorToErrorCode(SecIOrErr.takeError()));
object::section_iterator SecI = *SecIOrErr;
// Skip external symbols.
if (SecI == Obj->section_end())
outs() << "(?,?) ";
break;
}
- ErrorOr<section_iterator> SecOrErr =
+ Expected<section_iterator> SecOrErr =
MachO->getSymbolSection(I->Sym.getRawDataRefImpl());
- if (SecOrErr.getError()) {
+ if (!SecOrErr) {
+ consumeError(SecOrErr.takeError());
outs() << "(?,?) ";
break;
}
// OK, this is ELF
elf_symbol_iterator SymI(I);
- ErrorOr<elf_section_iterator> SecIOrErr = SymI->getSection();
- if (error(SecIOrErr.getError()))
+ Expected<elf_section_iterator> SecIOrErr = SymI->getSection();
+ if (!SecIOrErr) {
+ consumeError(SecIOrErr.takeError());
return '?';
+ }
elf_section_iterator SecI = *SecIOrErr;
if (SecI != Obj.section_end()) {
uint32_t Characteristics = 0;
if (!COFF::isReservedSectionNumber(Symb.getSectionNumber())) {
- ErrorOr<section_iterator> SecIOrErr = SymI->getSection();
- if (error(SecIOrErr.getError()))
+ Expected<section_iterator> SecIOrErr = SymI->getSection();
+ if (!SecIOrErr) {
+ consumeError(SecIOrErr.takeError());
return '?';
+ }
section_iterator SecI = *SecIOrErr;
const coff_section *Section = Obj.getCOFFSection(*SecI);
Characteristics = Section->Characteristics;
case MachO::N_INDR:
return 'i';
case MachO::N_SECT: {
- ErrorOr<section_iterator> SecOrErr = Obj.getSymbolSection(Symb);
- if (SecOrErr.getError())
+ Expected<section_iterator> SecOrErr = Obj.getSymbolSection(Symb);
+ if (!SecOrErr) {
+ consumeError(SecOrErr.takeError());
return 's';
+ }
section_iterator Sec = *SecOrErr;
DataRefImpl Ref = Sec->getRawDataRefImpl();
StringRef SectionName;
if (std::error_code EC = ResolvedAddrOrErr.getError())
return EC;
ResolvedAddr = *ResolvedAddrOrErr;
- ErrorOr<section_iterator> Iter = Sym.getSection();
- if (std::error_code EC = Iter.getError())
- return EC;
+ Expected<section_iterator> Iter = Sym.getSection();
+ if (!Iter)
+ return errorToErrorCode(Iter.takeError());
ResolvedSection = Obj->getCOFFSection(**Iter);
return std::error_code();
}
struct SymbolSorter {
bool operator()(const SymbolRef &A, const SymbolRef &B) {
- ErrorOr<SymbolRef::Type> ATypeOrErr = A.getType();
- if (std::error_code EC = ATypeOrErr.getError())
- report_fatal_error(EC.message());
+ Expected<SymbolRef::Type> ATypeOrErr = A.getType();
+ if (!ATypeOrErr) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(ATypeOrErr.takeError(), OS, "");
+ OS.flush();
+ report_fatal_error(Buf);
+ }
SymbolRef::Type AType = *ATypeOrErr;
- ErrorOr<SymbolRef::Type> BTypeOrErr = B.getType();
- if (std::error_code EC = BTypeOrErr.getError())
- report_fatal_error(EC.message());
+ Expected<SymbolRef::Type> BTypeOrErr = B.getType();
+ if (!BTypeOrErr) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(BTypeOrErr.takeError(), OS, "");
+ OS.flush();
+ report_fatal_error(Buf);
+ }
SymbolRef::Type BType = *BTypeOrErr;
uint64_t AAddr = (AType != SymbolRef::ST_Function) ? 0 : A.getValue();
uint64_t BAddr = (BType != SymbolRef::ST_Function) ? 0 : B.getValue();
SymbolAddressMap *AddrMap) {
// Create a map of symbol addresses to symbol names.
for (const SymbolRef &Symbol : O->symbols()) {
- ErrorOr<SymbolRef::Type> STOrErr = Symbol.getType();
- if (std::error_code EC = STOrErr.getError())
- report_fatal_error(EC.message());
+ Expected<SymbolRef::Type> STOrErr = Symbol.getType();
+ if (!STOrErr) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(STOrErr.takeError(), OS, "");
+ OS.flush();
+ report_fatal_error(Buf);
+ }
SymbolRef::Type ST = *STOrErr;
if (ST == SymbolRef::ST_Function || ST == SymbolRef::ST_Data ||
ST == SymbolRef::ST_Other) {
SymbolAddressMap AddrMap;
bool DisSymNameFound = false;
for (const SymbolRef &Symbol : MachOOF->symbols()) {
- ErrorOr<SymbolRef::Type> STOrErr = Symbol.getType();
- if (std::error_code EC = STOrErr.getError())
- report_fatal_error(EC.message());
+ Expected<SymbolRef::Type> STOrErr = Symbol.getType();
+ if (!STOrErr) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(STOrErr.takeError(), OS, "");
+ OS.flush();
+ report_fatal_error(Buf);
+ }
SymbolRef::Type ST = *STOrErr;
if (ST == SymbolRef::ST_Function || ST == SymbolRef::ST_Data ||
ST == SymbolRef::ST_Other) {
}
StringRef SymName = *SymNameOrErr;
- ErrorOr<SymbolRef::Type> STOrErr = Symbols[SymIdx].getType();
- if (std::error_code EC = STOrErr.getError())
- report_fatal_error(EC.message());
+ Expected<SymbolRef::Type> STOrErr = Symbols[SymIdx].getType();
+ if (!STOrErr) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(STOrErr.takeError(), OS, "");
+ OS.flush();
+ report_fatal_error(Buf);
+ }
SymbolRef::Type ST = *STOrErr;
if (ST != SymbolRef::ST_Function && ST != SymbolRef::ST_Data)
continue;
uint64_t NextSym = 0;
uint64_t NextSymIdx = SymIdx + 1;
while (Symbols.size() > NextSymIdx) {
- ErrorOr<SymbolRef::Type> STOrErr = Symbols[NextSymIdx].getType();
- if (std::error_code EC = STOrErr.getError())
- report_fatal_error(EC.message());
+ Expected<SymbolRef::Type> STOrErr = Symbols[NextSymIdx].getType();
+ if (!STOrErr) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(STOrErr.takeError(), OS, "");
+ OS.flush();
+ report_fatal_error(Buf);
+ }
SymbolRef::Type NextSymType = *STOrErr;
if (NextSymType == SymbolRef::ST_Function) {
containsNextSym =
// Go back one so that SymbolAddress <= Addr.
--Sym;
- section_iterator SymSection = *Sym->second.getSection();
+ auto SectOrErr = Sym->second.getSection();
+ if (!SectOrErr) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(SectOrErr.takeError(), OS, "");
+ OS.flush();
+ report_fatal_error(Buf);
+ }
+ section_iterator SymSection = *SectOrErr;
if (RelocSection == *SymSection) {
// There's a valid symbol in the same section before this reference.
Expected<StringRef> NameOrErr = Sym->second.getName();
for (const SymbolRef &SymRef : Obj->symbols()) {
// Discard any undefined or absolute symbols. They're not going to take part
// in the convenience lookup for unwind info and just take up resources.
- section_iterator Section = *SymRef.getSection();
+ auto SectOrErr = SymRef.getSection();
+ if (!SectOrErr) {
+ // TODO: Actually report errors helpfully.
+ consumeError(SectOrErr.takeError());
+ continue;
+ }
+ section_iterator Section = *SectOrErr;
if (Section == Obj->section_end())
continue;
const Elf_Sym *symb = Obj->getSymbol(SI->getRawDataRefImpl());
StringRef Target;
if (symb->getType() == ELF::STT_SECTION) {
- ErrorOr<section_iterator> SymSI = SI->getSection();
- if (std::error_code EC = SymSI.getError())
- return EC;
+ Expected<section_iterator> SymSI = SI->getSection();
+ if (!SymSI)
+ return errorToErrorCode(SymSI.takeError());
const Elf_Shdr *SymSec = Obj->getSection((*SymSI)->getRawDataRefImpl());
ErrorOr<StringRef> SecName = EF.getSectionName(SymSec);
if (std::error_code EC = SecName.getError())
if (Name->empty())
continue;
- ErrorOr<section_iterator> SectionOrErr = Symbol.getSection();
- error(SectionOrErr.getError());
+ Expected<section_iterator> SectionOrErr = Symbol.getSection();
+ error(errorToErrorCode(SectionOrErr.takeError()));
section_iterator SecI = *SectionOrErr;
if (SecI == Obj->section_end())
continue;
ErrorOr<uint64_t> AddressOrError = Symbol.getAddress();
error(AddressOrError.getError());
uint64_t Address = *AddressOrError;
- ErrorOr<SymbolRef::Type> TypeOrError = Symbol.getType();
- error(TypeOrError.getError());
+ Expected<SymbolRef::Type> TypeOrError = Symbol.getType();
+ if (!TypeOrError)
+ report_error(o->getFileName(), TypeOrError.takeError());
SymbolRef::Type Type = *TypeOrError;
uint32_t Flags = Symbol.getFlags();
- ErrorOr<section_iterator> SectionOrErr = Symbol.getSection();
- error(SectionOrErr.getError());
+ Expected<section_iterator> SectionOrErr = Symbol.getSection();
+ error(errorToErrorCode(SectionOrErr.takeError()));
section_iterator Section = *SectionOrErr;
StringRef Name;
if (Type == SymbolRef::ST_Debug && Section != o->section_end()) {
ErrorOr<object::SymbolRef> Decoder::getSymbol(const COFFObjectFile &COFF,
uint64_t VA, bool FunctionOnly) {
for (const auto &Symbol : COFF.symbols()) {
- ErrorOr<SymbolRef::Type> Type = Symbol.getType();
- if (std::error_code EC = Type.getError())
- return EC;
+ Expected<SymbolRef::Type> Type = Symbol.getType();
+ if (!Type)
+ return errorToErrorCode(Type.takeError());
if (FunctionOnly && *Type != SymbolRef::ST_Function)
continue;
SW.printString("ExceptionRecord", formatSymbol(*Name, Address));
- ErrorOr<section_iterator> SIOrErr = XDataRecord->getSection();
- if (!SIOrErr)
+ Expected<section_iterator> SIOrErr = XDataRecord->getSection();
+ if (!SIOrErr) {
+ // TODO: Actually report errors helpfully.
+ consumeError(SIOrErr.takeError());
return false;
+ }
section_iterator SI = *SIOrErr;
return dumpXDataRecord(COFF, *SI, FunctionAddress, Address);
getSymbol(Obj, Symbol.getRawDataRefImpl(), MOSymbol);
StringRef SectionName = "";
- ErrorOr<section_iterator> SecIOrErr = Symbol.getSection();
- error(SecIOrErr.getError());
+ Expected<section_iterator> SecIOrErr = Symbol.getSection();
+ error(errorToErrorCode(SecIOrErr.takeError()));
section_iterator SecI = *SecIOrErr;
if (SecI != Obj->section_end())
error(SecI->getName(SectionName));
return EC;
ResolvedAddress = *ResolvedAddressOrErr;
- ErrorOr<section_iterator> SI = Symbol.getSection();
+ Expected<section_iterator> SI = Symbol.getSection();
+ if (!SI)
+ return errorToErrorCode(SI.takeError());
ResolvedSection = Ctx.COFF.getCOFFSection(**SI);
return std::error_code();
}
// Use symbol info to iterate functions in the object.
for (const auto &P : SymAddr) {
object::SymbolRef Sym = P.first;
- ErrorOr<SymbolRef::Type> TypeOrErr = Sym.getType();
- if (!TypeOrErr)
+ Expected<SymbolRef::Type> TypeOrErr = Sym.getType();
+ if (!TypeOrErr) {
+ // TODO: Actually report errors helpfully.
+ consumeError(TypeOrErr.takeError());
continue;
+ }
SymbolRef::Type Type = *TypeOrErr;
if (Type == object::SymbolRef::ST_Function) {
Expected<StringRef> Name = Sym.getName();
// symbol in memory (rather than that in the unrelocated object file)
// and use that to query the DWARFContext.
if (!UseDebugObj && LoadObjects) {
- object::section_iterator Sec = *Sym.getSection();
+ auto SecOrErr = Sym.getSection();
+ if (!SecOrErr) {
+ // TODO: Actually report errors helpfully.
+ consumeError(SecOrErr.takeError());
+ continue;
+ }
+ object::section_iterator Sec = *SecOrErr;
StringRef SecName;
Sec->getName(SecName);
uint64_t SectionLoadAddress =