[PATCH] D55235: llvm-objcopy: Improve/simplify llvm::Error handling during notes iteration
David Blaikie via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 3 14:54:13 PST 2018
dblaikie updated this revision to Diff 176490.
dblaikie added a comment.
Strengthen require error checking from the iterator
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D55235/new/
https://reviews.llvm.org/D55235
Files:
include/llvm/Object/ELFTypes.h
tools/llvm-objcopy/ELF/ELFObjcopy.cpp
Index: tools/llvm-objcopy/ELF/ELFObjcopy.cpp
===================================================================
--- tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -123,14 +123,9 @@
if (Phdr.p_type != PT_NOTE)
continue;
Error Err = Error::success();
- if (Err)
- llvm_unreachable("Error::success() was an error.");
- for (const auto &Note : In.notes(Phdr, Err)) {
- if (Err)
- return std::move(Err);
+ for (const auto &Note : In.notes(Phdr, Err))
if (Note.getType() == NT_GNU_BUILD_ID && Note.getName() == ELF_NOTE_GNU)
return Note.getDesc();
- }
if (Err)
return std::move(Err);
}
Index: include/llvm/Object/ELFTypes.h
===================================================================
--- include/llvm/Object/ELFTypes.h
+++ include/llvm/Object/ELFTypes.h
@@ -631,6 +631,7 @@
// Stop iteration and indicate an overflow.
void stopWithOverflowError() {
Nhdr = nullptr;
+ ErrorAsOutParameter EAOP(Err);
*Err = make_error<StringError>("ELF note overflows container",
object_error::parse_failed);
}
@@ -642,9 +643,12 @@
// container, either cleanly or with an overflow error.
void advanceNhdr(const uint8_t *NhdrPos, size_t NoteSize) {
RemainingSize -= NoteSize;
- if (RemainingSize == 0u)
+ if (RemainingSize == 0u) {
+ // Ensure that if the iterator walks to the end, the error is checked
+ // afterwards.
+ *Err = Error::success();
Nhdr = nullptr;
- else if (sizeof(*Nhdr) > RemainingSize)
+ } else if (sizeof(*Nhdr) > RemainingSize)
stopWithOverflowError();
else {
Nhdr = reinterpret_cast<const Elf_Nhdr_Impl<ELFT> *>(NhdrPos + NoteSize);
@@ -657,6 +661,7 @@
explicit Elf_Note_Iterator_Impl(Error &Err) : Err(&Err) {}
Elf_Note_Iterator_Impl(const uint8_t *Start, size_t Size, Error &Err)
: RemainingSize(Size), Err(&Err) {
+ consumeError(std::move(Err));
assert(Start && "ELF note iterator starting at NULL");
advanceNhdr(Start, 0u);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55235.176490.patch
Type: text/x-patch
Size: 2100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181203/584888da/attachment.bin>
More information about the llvm-commits
mailing list