[llvm-readobj] Unwrap the value first to avoid the error

This addresses the issue introduced in r369169, we need to unwrap
the value first before we can check whether it's empty. This also
swaps the two branches to put the common path first which should
be NFC.

llvm-svn: 369177
This commit is contained in:
Petr Hosek 2019-08-17 00:07:26 +00:00
parent 43c8b19546
commit 0b5ecef299
2 changed files with 32 additions and 31 deletions

View File

@ -24,7 +24,7 @@
# LLVM: Notes [
# LLVM-NEXT: NoteSection {
# LLVM-NEXT: Offset: 0x200
# LLVM-NEXT: Offset: 0x238
# LLVM-NEXT: Size: 0x20
# LLVM-NEXT: Note {
# LLVM-NEXT: Owner: GNU
@ -35,7 +35,7 @@
# LLVM-NEXT: }
# LLVM-NEXT: }
# LLVM-NEXT: NoteSection {
# LLVM-NEXT: Offset: 0x220
# LLVM-NEXT: Offset: 0x258
# LLVM-NEXT: Size: 0x20
# LLVM-NEXT: Note {
# LLVM-NEXT: Owner: GNU
@ -45,7 +45,7 @@
# LLVM-NEXT: }
# LLVM-NEXT: }
# LLVM-NEXT: NoteSection {
# LLVM-NEXT: Offset: 0x240
# LLVM-NEXT: Offset: 0x278
# LLVM-NEXT: Size: 0x1C
# LLVM-NEXT: Note {
# LLVM-NEXT: Owner: GNU
@ -58,7 +58,7 @@
# LLVM-STRIPPED: Notes [
# LLVM-STRIPPED-NEXT: NoteSection {
# LLVM-STRIPPED-NEXT: Offset: 0x40
# LLVM-STRIPPED-NEXT: Offset: 0x78
# LLVM-STRIPPED-NEXT: Size: 0x20
# LLVM-STRIPPED-NEXT: Note {
# LLVM-STRIPPED-NEXT: Owner: GNU
@ -69,7 +69,7 @@
# LLVM-STRIPPED-NEXT: }
# LLVM-STRIPPED-NEXT: ]
# GNU-STRIPPED:Displaying notes found at file offset 0x00000040 with length 0x00000020:
# GNU-STRIPPED:Displaying notes found at file offset 0x00000078 with length 0x00000020:
# GNU-STRIPPED-NEXT: Owner Data size Description
# GNU-STRIPPED-NEXT: GNU 0x00000010 NT_GNU_BUILD_ID (unique build ID bitstring)
# GNU-STRIPPED-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b

View File

@ -4502,7 +4502,19 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
}
};
if (Obj->getHeader()->e_type == ELF::ET_CORE || Obj->sections()->empty()) {
ArrayRef<Elf_Shdr> Sections = unwrapOrError(this->FileName, Obj->sections());
if (Obj->getHeader()->e_type != ELF::ET_CORE && !Sections.empty()) {
for (const auto &S : Sections) {
if (S.sh_type != SHT_NOTE)
continue;
PrintHeader(S.sh_offset, S.sh_size);
Error Err = Error::success();
for (const auto &Note : Obj->notes(S, Err))
ProcessNote(Note);
if (Err)
reportError(std::move(Err), this->FileName);
}
} else {
for (const auto &P :
unwrapOrError(this->FileName, Obj->program_headers())) {
if (P.p_type != PT_NOTE)
@ -4514,18 +4526,6 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
if (Err)
reportError(std::move(Err), this->FileName);
}
} else {
for (const auto &S :
unwrapOrError(this->FileName, Obj->sections())) {
if (S.sh_type != SHT_NOTE)
continue;
PrintHeader(S.sh_offset, S.sh_size);
Error Err = Error::success();
for (const auto &Note : Obj->notes(S, Err))
ProcessNote(Note);
if (Err)
reportError(std::move(Err), this->FileName);
}
}
}
@ -5703,7 +5703,20 @@ void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
}
};
if (Obj->getHeader()->e_type == ELF::ET_CORE || Obj->sections()->empty()) {
ArrayRef<Elf_Shdr> Sections = unwrapOrError(this->FileName, Obj->sections());
if (Obj->getHeader()->e_type != ELF::ET_CORE && !Sections.empty()) {
for (const auto &S : Sections) {
if (S.sh_type != SHT_NOTE)
continue;
DictScope D(W, "NoteSection");
PrintHeader(S.sh_offset, S.sh_size);
Error Err = Error::success();
for (const auto &Note : Obj->notes(S, Err))
ProcessNote(Note);
if (Err)
reportError(std::move(Err), this->FileName);
}
} else {
for (const auto &P :
unwrapOrError(this->FileName, Obj->program_headers())) {
if (P.p_type != PT_NOTE)
@ -5716,18 +5729,6 @@ void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
if (Err)
reportError(std::move(Err), this->FileName);
}
} else {
for (const auto &S : unwrapOrError(this->FileName, Obj->sections())) {
if (S.sh_type != SHT_NOTE)
continue;
DictScope D(W, "NoteSection");
PrintHeader(S.sh_offset, S.sh_size);
Error Err = Error::success();
for (const auto &Note : Obj->notes(S, Err))
ProcessNote(Note);
if (Err)
reportError(std::move(Err), this->FileName);
}
}
}