[llvm] r369177 - [llvm-readobj] Unwrap the value first to avoid the error
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 16 17:07:26 PDT 2019
Author: phosek
Date: Fri Aug 16 17:07:26 2019
New Revision: 369177
URL: http://llvm.org/viewvc/llvm-project?rev=369177&view=rev
Log:
[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.
Modified:
llvm/trunk/test/tools/llvm-readobj/gnu-notes.test
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
Modified: llvm/trunk/test/tools/llvm-readobj/gnu-notes.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/gnu-notes.test?rev=369177&r1=369176&r2=369177&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/gnu-notes.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/gnu-notes.test Fri Aug 16 17:07:26 2019
@@ -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
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=369177&r1=369176&r2=369177&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Fri Aug 16 17:07:26 2019
@@ -4502,26 +4502,26 @@ void GNUStyle<ELFT>::printNotes(const EL
}
};
- if (Obj->getHeader()->e_type == ELF::ET_CORE || Obj->sections()->empty()) {
- for (const auto &P :
- unwrapOrError(this->FileName, Obj->program_headers())) {
- if (P.p_type != PT_NOTE)
+ 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(P.p_offset, P.p_filesz);
+ PrintHeader(S.sh_offset, S.sh_size);
Error Err = Error::success();
- for (const auto &Note : Obj->notes(P, Err))
+ for (const auto &Note : Obj->notes(S, Err))
ProcessNote(Note);
if (Err)
reportError(std::move(Err), this->FileName);
}
} else {
- for (const auto &S :
- unwrapOrError(this->FileName, Obj->sections())) {
- if (S.sh_type != SHT_NOTE)
+ for (const auto &P :
+ unwrapOrError(this->FileName, Obj->program_headers())) {
+ if (P.p_type != PT_NOTE)
continue;
- PrintHeader(S.sh_offset, S.sh_size);
+ PrintHeader(P.p_offset, P.p_filesz);
Error Err = Error::success();
- for (const auto &Note : Obj->notes(S, Err))
+ for (const auto &Note : Obj->notes(P, Err))
ProcessNote(Note);
if (Err)
reportError(std::move(Err), this->FileName);
@@ -5703,27 +5703,28 @@ void LLVMStyle<ELFT>::printNotes(const E
}
};
- if (Obj->getHeader()->e_type == ELF::ET_CORE || Obj->sections()->empty()) {
- for (const auto &P :
- unwrapOrError(this->FileName, Obj->program_headers())) {
- if (P.p_type != PT_NOTE)
+ 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(P.p_offset, P.p_filesz);
+ PrintHeader(S.sh_offset, S.sh_size);
Error Err = Error::success();
- for (const auto &Note : Obj->notes(P, Err))
+ for (const auto &Note : Obj->notes(S, Err))
ProcessNote(Note);
if (Err)
reportError(std::move(Err), this->FileName);
}
} else {
- for (const auto &S : unwrapOrError(this->FileName, Obj->sections())) {
- if (S.sh_type != SHT_NOTE)
+ for (const auto &P :
+ unwrapOrError(this->FileName, Obj->program_headers())) {
+ if (P.p_type != PT_NOTE)
continue;
DictScope D(W, "NoteSection");
- PrintHeader(S.sh_offset, S.sh_size);
+ PrintHeader(P.p_offset, P.p_filesz);
Error Err = Error::success();
- for (const auto &Note : Obj->notes(S, Err))
+ for (const auto &Note : Obj->notes(P, Err))
ProcessNote(Note);
if (Err)
reportError(std::move(Err), this->FileName);
More information about the llvm-commits
mailing list