From f29065d0c656d00410edb28c3e531cb629b19f28 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 2 Aug 2013 21:10:17 +0000 Subject: [PATCH] [PECOFF] Return an error_code instead of calling report_fatal_error(). For an invalid input we should not call report_fatal_error(), because when LLD is used as a library, we don't want to kill the whole app because of a malformed input. llvm-svn: 187673 --- lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp index 1148c2e..7621685 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp @@ -314,13 +314,17 @@ private: /// Find the atom that is at \p targetOffset in \p section. It is assumed /// that \p atoms are sorted by position in the section. - COFFDefinedFileAtom * - findAtomAt(uint32_t targetOffset, - const vector &atoms) const { - for (COFFDefinedFileAtom *atom : atoms) - if (targetOffset < atom->originalOffset() + atom->size()) - return atom; - llvm::report_fatal_error("Relocation target out of range"); + error_code findAtomAt(uint32_t targetOffset, + const vector &atoms, + COFFDefinedFileAtom *&result) const { + for (COFFDefinedFileAtom *atom : atoms) { + if (targetOffset < atom->originalOffset() + atom->size()) { + result = atom; + return error_code::success(); + } + } + // Relocation target is out of range + return llvm::object::object_error::parse_failed; } /// Find the atom for the symbol that was at the \p index in the symbol @@ -351,7 +355,9 @@ private: if (error_code ec = getAtomBySymbolIndex(rel->SymbolTableIndex, targetAtom)) return ec; - COFFDefinedFileAtom *atom = findAtomAt(rel->VirtualAddress, atoms); + COFFDefinedFileAtom *atom; + if (error_code ec = findAtomAt(rel->VirtualAddress, atoms, atom)) + return ec; uint32_t offsetInAtom = itemAddress - atom->originalOffset(); assert(offsetInAtom < atom->size()); atom->addReference(std::unique_ptr( -- 2.7.4