[llvm] r369169 - [llvm-readobj] Fallback to PT_NOTE if file doesn't have sections
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 16 16:15:40 PDT 2019
Author: phosek
Date: Fri Aug 16 16:15:40 2019
New Revision: 369169
URL: http://llvm.org/viewvc/llvm-project?rev=369169&view=rev
Log:
[llvm-readobj] Fallback to PT_NOTE if file doesn't have sections
This is useful when trying to read notes from stripped files and matches
the behavior of GNU readelf and eu-readelf.
Differential Revision: https://reviews.llvm.org/D66358
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=369169&r1=369168&r2=369169&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/gnu-notes.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/gnu-notes.test Fri Aug 16 16:15:40 2019
@@ -3,18 +3,21 @@
# RUN: yaml2obj --docnum=1 %s > %t1.so
# RUN: llvm-readelf --notes %t1.so | FileCheck %s --check-prefix=GNU --strict-whitespace --match-full-lines
# RUN: llvm-readobj --notes %t1.so | FileCheck %s --check-prefix=LLVM
+# RUN: llvm-objcopy --strip-sections %t1.so %t1.stripped.so
+# RUN: llvm-readelf --notes %t1.stripped.so | FileCheck %s --check-prefix=GNU-STRIPPED --strict-whitespace --match-full-lines
+# RUN: llvm-readobj --notes %t1.stripped.so | FileCheck %s --check-prefix=LLVM-STRIPPED
-# GNU:Displaying notes found at file offset 0x00000200 with length 0x00000020:
+# GNU:Displaying notes found at file offset 0x00000238 with length 0x00000020:
# GNU-NEXT: Owner Data size Description
# GNU-NEXT: GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)
# GNU-NEXT: OS: Linux, ABI: 2.6.32
-# GNU:Displaying notes found at file offset 0x00000220 with length 0x00000020:
+# GNU:Displaying notes found at file offset 0x00000258 with length 0x00000020:
# GNU-NEXT: Owner Data size Description
# GNU-NEXT: GNU 0x00000010 NT_GNU_BUILD_ID (unique build ID bitstring)
# GNU-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b
-# GNU:Displaying notes found at file offset 0x00000240 with length 0x0000001c:
+# GNU:Displaying notes found at file offset 0x00000278 with length 0x0000001c:
# GNU-NEXT: Owner Data size Description
# GNU-NEXT: GNU 0x00000009 NT_GNU_GOLD_VERSION (gold version)
# GNU-NEXT: Version: gold 1.11
@@ -53,6 +56,24 @@
# LLVM-NEXT: }
# LLVM-NEXT: ]
+# LLVM-STRIPPED: Notes [
+# LLVM-STRIPPED-NEXT: NoteSection {
+# LLVM-STRIPPED-NEXT: Offset: 0x40
+# LLVM-STRIPPED-NEXT: Size: 0x20
+# LLVM-STRIPPED-NEXT: Note {
+# LLVM-STRIPPED-NEXT: Owner: GNU
+# LLVM-STRIPPED-NEXT: Data size: 0x10
+# LLVM-STRIPPED-NEXT: Type: NT_GNU_BUILD_ID (unique build ID bitstring)
+# LLVM-STRIPPED-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b
+# LLVM-STRIPPED-NEXT: }
+# LLVM-STRIPPED-NEXT: }
+# LLVM-STRIPPED-NEXT: ]
+
+# GNU-STRIPPED:Displaying notes found at file offset 0x00000040 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
+
--- !ELF
FileHeader:
Class: ELFCLASS64
@@ -74,6 +95,11 @@ Sections:
Type: SHT_NOTE
AddressAlign: 0x0000000000000004
Content: 040000000900000004000000474E5500676F6C6420312E3131000000
+ProgramHeaders:
+ - Type: PT_NOTE
+ FileSize: 0x20
+ Sections:
+ - Section: .note.gnu.build-id
## Test tools report an error if a note section has an invalid offset
## that goes past the end of file.
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=369169&r1=369168&r2=369169&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Fri Aug 16 16:15:40 2019
@@ -4502,7 +4502,7 @@ void GNUStyle<ELFT>::printNotes(const EL
}
};
- if (Obj->getHeader()->e_type == ELF::ET_CORE) {
+ 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)
@@ -5703,7 +5703,7 @@ void LLVMStyle<ELFT>::printNotes(const E
}
};
- if (Obj->getHeader()->e_type == ELF::ET_CORE) {
+ 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)
More information about the llvm-commits
mailing list