[PATCH] D92081: [libObject,llvm-readelf] - Stop describing a section/segment in `notes_begin()`.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 25 01:58:55 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGfee910e522c9: [libObject,llvm-readelf] - Stop describing a section/segment in `notes_begin()`. (authored by grimar).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92081

Files:
  llvm/include/llvm/Object/ELF.h
  llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
  llvm/tools/llvm-readobj/ELFDumper.cpp


Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -5562,7 +5562,10 @@
       for (const typename ELFT::Note &Note : Obj.notes(S, Err))
         ProcessNoteFn(Note);
       if (Err)
-        reportError(std::move(Err), Dumper.getElfObject().getFileName());
+        reportError(createError("unable to read notes from the " +
+                                describe(Obj, S) + ": " +
+                                toString(std::move(Err))),
+                    Dumper.getElfObject().getFileName());
       FinishNotesFn();
     }
     return;
@@ -5584,7 +5587,10 @@
     for (const typename ELFT::Note Note : Obj.notes(P, Err))
       ProcessNoteFn(Note);
     if (Err)
-      reportError(std::move(Err), Dumper.getElfObject().getFileName());
+      reportError(
+          createError("unable to read notes from the PT_NOTE segment: " +
+                      toString(std::move(Err))),
+          Dumper.getElfObject().getFileName());
     FinishNotesFn();
   }
 }
Index: llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
===================================================================
--- llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
+++ llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
@@ -116,7 +116,7 @@
 # RUN: not llvm-readelf --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1
 # RUN: not llvm-readobj --notes %t2.so 2>&1 | FileCheck -DFILE=%t2.so %s --check-prefix=ERR1
 
-# ERR1: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0xffff0000) or size (0x0)
+# ERR1: error: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0xffff0000) or size (0x0)
 
 --- !ELF
 FileHeader:
@@ -137,7 +137,7 @@
 # RUN: not llvm-readelf --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2
 # RUN: not llvm-readobj --notes %t3.so 2>&1 | FileCheck -DFILE=%t3.so %s --check-prefix=ERR2
 
-# ERR2: error: '[[FILE]]': SHT_NOTE section [index 1] has invalid offset (0x40) or size (0xffff0000)
+# ERR2: error: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0x40) or size (0xffff0000)
 
 ## Test tools report an error if a note program header has an invalid offset that
 ## goes past the end of file.
@@ -146,7 +146,7 @@
 # RUN: not llvm-readelf --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
 # RUN: not llvm-readobj --notes %t4.so 2>&1 | FileCheck -DFILE=%t4.so %s --check-prefix=ERR3
 
-# ERR3: error: '[[FILE]]': PT_NOTE header has invalid offset (0xffff0000) or size (0x0)
+# ERR3: error: '[[FILE]]': unable to read notes from the PT_NOTE segment: invalid offset (0xffff0000) or size (0x0)
 
 --- !ELF
 FileHeader:
@@ -165,7 +165,7 @@
 # RUN: not llvm-readelf --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so  %s --check-prefix=ERR4
 # RUN: not llvm-readobj --notes %t5.so 2>&1 | FileCheck -DFILE=%t5.so %s --check-prefix=ERR4
 
-# ERR4: error: '[[FILE]]': PT_NOTE header has invalid offset (0x0) or size (0xffff0000)
+# ERR4: error: '[[FILE]]': unable to read notes from the PT_NOTE segment: invalid offset (0x0) or size (0xffff0000)
 
 ## Check we report a warning when we are unable to locate the PT_NOTE
 ## segment because of broken program headers.
Index: llvm/include/llvm/Object/ELF.h
===================================================================
--- llvm/include/llvm/Object/ELF.h
+++ llvm/include/llvm/Object/ELF.h
@@ -238,9 +238,9 @@
     assert(Phdr.p_type == ELF::PT_NOTE && "Phdr is not of type PT_NOTE");
     ErrorAsOutParameter ErrAsOutParam(&Err);
     if (Phdr.p_offset + Phdr.p_filesz > getBufSize()) {
-      Err = createError("PT_NOTE header has invalid offset (0x" +
-                        Twine::utohexstr(Phdr.p_offset) + ") or size (0x" +
-                        Twine::utohexstr(Phdr.p_filesz) + ")");
+      Err =
+          createError("invalid offset (0x" + Twine::utohexstr(Phdr.p_offset) +
+                      ") or size (0x" + Twine::utohexstr(Phdr.p_filesz) + ")");
       return Elf_Note_Iterator(Err);
     }
     return Elf_Note_Iterator(base() + Phdr.p_offset, Phdr.p_filesz, Err);
@@ -257,10 +257,9 @@
     assert(Shdr.sh_type == ELF::SHT_NOTE && "Shdr is not of type SHT_NOTE");
     ErrorAsOutParameter ErrAsOutParam(&Err);
     if (Shdr.sh_offset + Shdr.sh_size > getBufSize()) {
-      Err = createError("SHT_NOTE section " + getSecIndexForError(*this, Shdr) +
-                        " has invalid offset (0x" +
-                        Twine::utohexstr(Shdr.sh_offset) + ") or size (0x" +
-                        Twine::utohexstr(Shdr.sh_size) + ")");
+      Err =
+          createError("invalid offset (0x" + Twine::utohexstr(Shdr.sh_offset) +
+                      ") or size (0x" + Twine::utohexstr(Shdr.sh_size) + ")");
       return Elf_Note_Iterator(Err);
     }
     return Elf_Note_Iterator(base() + Shdr.sh_offset, Shdr.sh_size, Err);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92081.307544.patch
Type: text/x-patch
Size: 5002 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201125/cc78708d/attachment.bin>


More information about the llvm-commits mailing list