diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h index 7ebe6869c7b5..d47c8f7809fe 100644 --- a/llvm/include/llvm/Object/ELF.h +++ b/llvm/include/llvm/Object/ELF.h @@ -238,9 +238,9 @@ public: 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 @@ public: 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 index 04430577daaf..530a4a87293b 100644 --- a/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test +++ b/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test @@ -116,7 +116,7 @@ ProgramHeaders: # 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 @@ Sections: # 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 @@ Sections: # 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 @@ ProgramHeaders: # 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 index c5f506bb21f8..e80e2c3db95d 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -5562,7 +5562,10 @@ static void printNotesHelper( 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 @@ static void printNotesHelper( 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(); } }