}
// Given a symbol sym this functions returns the address and section of it.
-static std::error_code
-resolveSectionAndAddress(const COFFObjectFile *Obj, const SymbolRef &Sym,
- const coff_section *&ResolvedSection,
- uint64_t &ResolvedAddr) {
+static Error resolveSectionAndAddress(const COFFObjectFile *Obj,
+ const SymbolRef &Sym,
+ const coff_section *&ResolvedSection,
+ uint64_t &ResolvedAddr) {
Expected<uint64_t> ResolvedAddrOrErr = Sym.getAddress();
if (!ResolvedAddrOrErr)
- return errorToErrorCode(ResolvedAddrOrErr.takeError());
+ return ResolvedAddrOrErr.takeError();
ResolvedAddr = *ResolvedAddrOrErr;
Expected<section_iterator> Iter = Sym.getSection();
if (!Iter)
- return errorToErrorCode(Iter.takeError());
+ return Iter.takeError();
ResolvedSection = Obj->getCOFFSection(**Iter);
- return std::error_code();
+ return Error::success();
}
// 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 std::error_code resolveSymbol(const std::vector<RelocationRef> &Rels,
+static Error resolveSymbol(const std::vector<RelocationRef> &Rels,
uint64_t Offset, SymbolRef &Sym) {
for (auto &R : Rels) {
uint64_t Ofs = R.getOffset();
if (Ofs == Offset) {
Sym = *R.getSymbol();
- return std::error_code();
+ return Error::success();
}
}
- return object_error::parse_failed;
+ return make_error<BinaryError>();
}
// Given a vector of relocations for a section and an offset into this section
// 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 std::error_code
+static Error
getSectionContents(const COFFObjectFile *Obj,
const std::vector<RelocationRef> &Rels, uint64_t Offset,
ArrayRef<uint8_t> &Contents, uint64_t &Addr) {
SymbolRef Sym;
- if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
- return EC;
+ if (Error E = resolveSymbol(Rels, Offset, Sym))
+ return E;
const coff_section *Section;
- if (std::error_code EC = resolveSectionAndAddress(Obj, Sym, Section, Addr))
- return EC;
+ if (Error E = resolveSectionAndAddress(Obj, Sym, Section, Addr))
+ return E;
if (std::error_code EC = Obj->getSectionContents(Section, Contents))
- return EC;
- return std::error_code();
+ return errorCodeToError(EC);
+ return Error::success();
}
// 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 std::error_code resolveSymbolName(const std::vector<RelocationRef> &Rels,
- uint64_t Offset, StringRef &Name) {
+static Error resolveSymbolName(const std::vector<RelocationRef> &Rels,
+ uint64_t Offset, StringRef &Name) {
SymbolRef Sym;
- if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
+ if (Error EC = resolveSymbol(Rels, Offset, Sym))
return EC;
Expected<StringRef> NameOrErr = Sym.getName();
if (!NameOrErr)
- return errorToErrorCode(NameOrErr.takeError());
+ return NameOrErr.takeError();
Name = *NameOrErr;
- return std::error_code();
+ return Error::success();
}
static void printCOFFSymbolAddress(llvm::raw_ostream &Out,
for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) {
Expected<COFFSymbolRef> Symbol = coff->getSymbol(SI);
StringRef Name;
- error(errorToErrorCode(Symbol.takeError()));
+ error(Symbol.takeError());
error(coff->getSymbolName(*Symbol, Name));
outs() << "[" << format("%2d", SI) << "]"
exit(1);
}
-LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef File,
- std::error_code EC) {
- assert(EC);
- WithColor::error(errs(), ToolName)
- << "'" << File << "': " << EC.message() << ".\n";
- exit(1);
-}
-
LLVM_ATTRIBUTE_NORETURN void llvm::report_error(Error E, StringRef File) {
assert(E);
std::string Buf;
else if (COFFImportFile *I = dyn_cast<COFFImportFile>(&*ChildOrErr.get()))
dumpObject(I, A, &C);
else
- report_error(A->getFileName(), object_error::invalid_file_type);
+ report_error(errorCodeToError(object_error::invalid_file_type),
+ A->getFileName());
}
if (Err)
report_error(std::move(Err), A->getFileName());
else if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(&Binary))
parseInputMachO(UB);
else
- report_error(file, object_error::invalid_file_type);
+ report_error(errorCodeToError(object_error::invalid_file_type), file);
}
int main(int argc, char **argv) {