diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h --- a/llvm/include/llvm/Object/ELF.h +++ b/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); diff --git a/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test b/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test --- a/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test +++ b/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. diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/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(); } }