Skip to content

Commit 0b5ecef

Browse files
committed
[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
1 parent 43c8b19 commit 0b5ecef

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

llvm/test/tools/llvm-readobj/gnu-notes.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
# LLVM: Notes [
2626
# LLVM-NEXT: NoteSection {
27-
# LLVM-NEXT: Offset: 0x200
27+
# LLVM-NEXT: Offset: 0x238
2828
# LLVM-NEXT: Size: 0x20
2929
# LLVM-NEXT: Note {
3030
# LLVM-NEXT: Owner: GNU
@@ -35,7 +35,7 @@
3535
# LLVM-NEXT: }
3636
# LLVM-NEXT: }
3737
# LLVM-NEXT: NoteSection {
38-
# LLVM-NEXT: Offset: 0x220
38+
# LLVM-NEXT: Offset: 0x258
3939
# LLVM-NEXT: Size: 0x20
4040
# LLVM-NEXT: Note {
4141
# LLVM-NEXT: Owner: GNU
@@ -45,7 +45,7 @@
4545
# LLVM-NEXT: }
4646
# LLVM-NEXT: }
4747
# LLVM-NEXT: NoteSection {
48-
# LLVM-NEXT: Offset: 0x240
48+
# LLVM-NEXT: Offset: 0x278
4949
# LLVM-NEXT: Size: 0x1C
5050
# LLVM-NEXT: Note {
5151
# LLVM-NEXT: Owner: GNU
@@ -58,7 +58,7 @@
5858

5959
# LLVM-STRIPPED: Notes [
6060
# LLVM-STRIPPED-NEXT: NoteSection {
61-
# LLVM-STRIPPED-NEXT: Offset: 0x40
61+
# LLVM-STRIPPED-NEXT: Offset: 0x78
6262
# LLVM-STRIPPED-NEXT: Size: 0x20
6363
# LLVM-STRIPPED-NEXT: Note {
6464
# LLVM-STRIPPED-NEXT: Owner: GNU
@@ -69,7 +69,7 @@
6969
# LLVM-STRIPPED-NEXT: }
7070
# LLVM-STRIPPED-NEXT: ]
7171

72-
# GNU-STRIPPED:Displaying notes found at file offset 0x00000040 with length 0x00000020:
72+
# GNU-STRIPPED:Displaying notes found at file offset 0x00000078 with length 0x00000020:
7373
# GNU-STRIPPED-NEXT: Owner Data size Description
7474
# GNU-STRIPPED-NEXT: GNU 0x00000010 NT_GNU_BUILD_ID (unique build ID bitstring)
7575
# GNU-STRIPPED-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4502,26 +4502,26 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
45024502
}
45034503
};
45044504

4505-
if (Obj->getHeader()->e_type == ELF::ET_CORE || Obj->sections()->empty()) {
4506-
for (const auto &P :
4507-
unwrapOrError(this->FileName, Obj->program_headers())) {
4508-
if (P.p_type != PT_NOTE)
4505+
ArrayRef<Elf_Shdr> Sections = unwrapOrError(this->FileName, Obj->sections());
4506+
if (Obj->getHeader()->e_type != ELF::ET_CORE && !Sections.empty()) {
4507+
for (const auto &S : Sections) {
4508+
if (S.sh_type != SHT_NOTE)
45094509
continue;
4510-
PrintHeader(P.p_offset, P.p_filesz);
4510+
PrintHeader(S.sh_offset, S.sh_size);
45114511
Error Err = Error::success();
4512-
for (const auto &Note : Obj->notes(P, Err))
4512+
for (const auto &Note : Obj->notes(S, Err))
45134513
ProcessNote(Note);
45144514
if (Err)
45154515
reportError(std::move(Err), this->FileName);
45164516
}
45174517
} else {
4518-
for (const auto &S :
4519-
unwrapOrError(this->FileName, Obj->sections())) {
4520-
if (S.sh_type != SHT_NOTE)
4518+
for (const auto &P :
4519+
unwrapOrError(this->FileName, Obj->program_headers())) {
4520+
if (P.p_type != PT_NOTE)
45214521
continue;
4522-
PrintHeader(S.sh_offset, S.sh_size);
4522+
PrintHeader(P.p_offset, P.p_filesz);
45234523
Error Err = Error::success();
4524-
for (const auto &Note : Obj->notes(S, Err))
4524+
for (const auto &Note : Obj->notes(P, Err))
45254525
ProcessNote(Note);
45264526
if (Err)
45274527
reportError(std::move(Err), this->FileName);
@@ -5703,27 +5703,28 @@ void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
57035703
}
57045704
};
57055705

5706-
if (Obj->getHeader()->e_type == ELF::ET_CORE || Obj->sections()->empty()) {
5707-
for (const auto &P :
5708-
unwrapOrError(this->FileName, Obj->program_headers())) {
5709-
if (P.p_type != PT_NOTE)
5706+
ArrayRef<Elf_Shdr> Sections = unwrapOrError(this->FileName, Obj->sections());
5707+
if (Obj->getHeader()->e_type != ELF::ET_CORE && !Sections.empty()) {
5708+
for (const auto &S : Sections) {
5709+
if (S.sh_type != SHT_NOTE)
57105710
continue;
57115711
DictScope D(W, "NoteSection");
5712-
PrintHeader(P.p_offset, P.p_filesz);
5712+
PrintHeader(S.sh_offset, S.sh_size);
57135713
Error Err = Error::success();
5714-
for (const auto &Note : Obj->notes(P, Err))
5714+
for (const auto &Note : Obj->notes(S, Err))
57155715
ProcessNote(Note);
57165716
if (Err)
57175717
reportError(std::move(Err), this->FileName);
57185718
}
57195719
} else {
5720-
for (const auto &S : unwrapOrError(this->FileName, Obj->sections())) {
5721-
if (S.sh_type != SHT_NOTE)
5720+
for (const auto &P :
5721+
unwrapOrError(this->FileName, Obj->program_headers())) {
5722+
if (P.p_type != PT_NOTE)
57225723
continue;
57235724
DictScope D(W, "NoteSection");
5724-
PrintHeader(S.sh_offset, S.sh_size);
5725+
PrintHeader(P.p_offset, P.p_filesz);
57255726
Error Err = Error::success();
5726-
for (const auto &Note : Obj->notes(S, Err))
5727+
for (const auto &Note : Obj->notes(P, Err))
57275728
ProcessNote(Note);
57285729
if (Err)
57295730
reportError(std::move(Err), this->FileName);

0 commit comments

Comments
 (0)