[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 10 16:12:18 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL348811: llvm-objcopy: Improve/simplify llvm::Error handling during notes iteration (authored by dblaikie, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55235?vs=176490&id=177613#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55235/new/

https://reviews.llvm.org/D55235

Files:
  llvm/trunk/include/llvm/Object/ELFTypes.h
  llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp


Index: llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
===================================================================
--- llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ llvm/trunk/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: llvm/trunk/include/llvm/Object/ELFTypes.h
===================================================================
--- llvm/trunk/include/llvm/Object/ELFTypes.h
+++ llvm/trunk/include/llvm/Object/ELFTypes.h
@@ -642,14 +642,19 @@
   // 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);
       if (Nhdr->getSize() > RemainingSize)
         stopWithOverflowError();
+      else
+        *Err = Error::success();
     }
   }
 
@@ -657,6 +662,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);
   }
@@ -670,6 +676,10 @@
     return *this;
   }
   bool operator==(Elf_Note_Iterator_Impl Other) const {
+    if (!Nhdr)
+      (void)(bool)(*Other.Err);
+    if (!Other.Nhdr)
+      (void)(bool)(*Err);
     return Nhdr == Other.Nhdr;
   }
   bool operator!=(Elf_Note_Iterator_Impl Other) const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55235.177613.patch
Type: text/x-patch
Size: 2303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181211/5470f836/attachment.bin>


More information about the llvm-commits mailing list