forked from OSchip/llvm-project
[libObject,llvm-readelf] - Stop describing a section/segment in `notes_begin()`.
`notes_begin()` is used for iterating over notes. This API in some cases might print section type and index. At the same time during iterating, the `Elf_Note_Iterator` might omit it as it doesn't have this info. Because of above we might have the redundant duplication of information in warnings: (See D92021). ``` warning: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: SHT_NOTE section [index 1] has invalid offset (0x40) or size (0xffff0000) ``` This change stops reporting section index/type in Object/ELF.h/notes_begin(). (FTR, this was introduced by me for llvm-readobj in D64470). Instead we can describe sections/program headers on the caller side. Differential revision: https://reviews.llvm.org/D92081
This commit is contained in:
parent
fb6f425d1b
commit
fee910e522
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue