forked from OSchip/llvm-project
[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 llvm-svn: 369169
This commit is contained in:
parent
acceedb15f
commit
7da81b5e4d
|
@ -3,18 +3,21 @@
|
||||||
# RUN: yaml2obj --docnum=1 %s > %t1.so
|
# 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-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-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: Owner Data size Description
|
||||||
# GNU-NEXT: GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)
|
# GNU-NEXT: GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)
|
||||||
# GNU-NEXT: OS: Linux, ABI: 2.6.32
|
# 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: Owner Data size Description
|
||||||
# GNU-NEXT: GNU 0x00000010 NT_GNU_BUILD_ID (unique build ID bitstring)
|
# GNU-NEXT: GNU 0x00000010 NT_GNU_BUILD_ID (unique build ID bitstring)
|
||||||
# GNU-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b
|
# 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: Owner Data size Description
|
||||||
# GNU-NEXT: GNU 0x00000009 NT_GNU_GOLD_VERSION (gold version)
|
# GNU-NEXT: GNU 0x00000009 NT_GNU_GOLD_VERSION (gold version)
|
||||||
# GNU-NEXT: Version: gold 1.11
|
# GNU-NEXT: Version: gold 1.11
|
||||||
|
@ -53,6 +56,24 @@
|
||||||
# LLVM-NEXT: }
|
# LLVM-NEXT: }
|
||||||
# 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
|
--- !ELF
|
||||||
FileHeader:
|
FileHeader:
|
||||||
Class: ELFCLASS64
|
Class: ELFCLASS64
|
||||||
|
@ -74,6 +95,11 @@ Sections:
|
||||||
Type: SHT_NOTE
|
Type: SHT_NOTE
|
||||||
AddressAlign: 0x0000000000000004
|
AddressAlign: 0x0000000000000004
|
||||||
Content: 040000000900000004000000474E5500676F6C6420312E3131000000
|
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
|
## Test tools report an error if a note section has an invalid offset
|
||||||
## that goes past the end of file.
|
## that goes past the end of file.
|
||||||
|
|
|
@ -4502,7 +4502,7 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Obj->getHeader()->e_type == ELF::ET_CORE) {
|
if (Obj->getHeader()->e_type == ELF::ET_CORE || Obj->sections()->empty()) {
|
||||||
for (const auto &P :
|
for (const auto &P :
|
||||||
unwrapOrError(this->FileName, Obj->program_headers())) {
|
unwrapOrError(this->FileName, Obj->program_headers())) {
|
||||||
if (P.p_type != PT_NOTE)
|
if (P.p_type != PT_NOTE)
|
||||||
|
@ -5703,7 +5703,7 @@ void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Obj->getHeader()->e_type == ELF::ET_CORE) {
|
if (Obj->getHeader()->e_type == ELF::ET_CORE || Obj->sections()->empty()) {
|
||||||
for (const auto &P :
|
for (const auto &P :
|
||||||
unwrapOrError(this->FileName, Obj->program_headers())) {
|
unwrapOrError(this->FileName, Obj->program_headers())) {
|
||||||
if (P.p_type != PT_NOTE)
|
if (P.p_type != PT_NOTE)
|
||||||
|
|
Loading…
Reference in New Issue