// RUN: llvm-objcopy --extract-main-partition %t %t0
// RUN: llvm-objcopy --extract-partition=part1 %t %t1
-// RUN: llvm-readelf --all %t0 | FileCheck --check-prefixes=CHECK,PART0 %s
-// RUN: llvm-readelf --all %t1 | FileCheck --check-prefixes=CHECK,PART1 %s
-
-// CHECK: Program Headers:
-// CHECK: NOTE 0x{{0*}}[[NOTE_OFFSET:[^ ]*]]
-
-// CHECK: Displaying notes found at file offset 0x{{0*}}[[NOTE_OFFSET]]
-// CHECK-NEXT: Owner
-// CHECK-NEXT: foo 0x00000004 NT_VERSION (version)
-// CHECK-NEXT: description data: 62 61 72 00
-// CHECK-NEXT: Displaying notes
-// CHECK-NEXT: Owner
-// CHECK-NEXT: GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring)
-// CHECK-NEXT: Build ID: 08b93eab87177a2356d1b0d1148339463f98dac2
+// RUN: llvm-readobj --all %t0 | FileCheck --check-prefixes=CHECK,PART0 %s
+// RUN: llvm-readobj --all %t1 | FileCheck --check-prefixes=CHECK,PART1 %s
+
+// CHECK: Type: PT_NOTE
+// CHECK-NEXT: Offset: 0x{{0*}}[[NOTE_OFFSET:[^ ]*]]
+
+// CHECK: Notes [
+// CHECK-NEXT: NoteSection {
+// CHECK-NEXT: Name: .note.obj
+// CHECK-NEXT: Offset: 0x{{0*}}[[NOTE_OFFSET]]
+// CHECK-NEXT: Size:
+// CHECK-NEXT: Note {
+// CHECK-NEXT: Owner: foo
+// CHECK-NEXT: Data size: 0x4
+// CHECK-NEXT: Type: NT_VERSION (version)
+// CHECK-NEXT: Description data (
+// CHECK-NEXT: 0000: 62617200 |bar.|
+// CHECK-NEXT: )
+// CHECK-NEXT: }
+// CHECK-NEXT: }
+// CHECK-NEXT: NoteSection {
+// CHECK-NEXT: Name: .note.gnu.build-id
+// CHECK-NEXT: Offset:
+// CHECK-NEXT: Size:
+// CHECK-NEXT: Note {
+// CHECK-NEXT: Owner: GNU
+// CHECK-NEXT: Data size:
+// CHECK-NEXT: Type: NT_GNU_BUILD_ID (unique build ID bitstring)
+// CHECK-NEXT: Build ID: 08b93eab87177a2356d1b0d1148339463f98dac2
+// CHECK-NEXT: }
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
.section .llvm_sympart,"",@llvm_sympart
.asciz "part1"
; OSABI-AMDHSA-ELF: {{[0-9]+}}: 0000000000000100 {{[0-9]+}} FUNC GLOBAL PROTECTED {{[0-9]+}} fsub
; OSABI-AMDHSA-ELF: {{[0-9]+}}: 0000000000000040 64 OBJECT GLOBAL DEFAULT {{[0-9]+}} fsub.kd
-; OSABI-AMDHSA-ELF: Displaying notes found at file offset
+; OSABI-AMDHSA-ELF: Displaying notes found in: .note
; OSABI-AMDHSA-ELF: AMDGPU 0x{{[0-9a-f]+}} NT_AMDGPU_METADATA (AMDGPU Metadata)
define amdgpu_kernel void @fadd(
# CHECK: Notes [
# CHECK-NEXT: NoteSection {
+# CHECK-NEXT: Name: .note.gnu.build-id
# CHECK-NEXT: Offset:
# CHECK-NEXT: Size:
# CHECK-NEXT: Note {
// RUN: llvm-readelf --notes %t | FileCheck %s --check-prefix=GNU
// RUN: llvm-readobj --notes %t | FileCheck %s --check-prefix=LLVM
-// GNU: Displaying notes found at file offset 0x00000040 with length 0x00000020:
+// GNU: Displaying notes found in: .note.gnu.property
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 (property note)
// GNU-NEXT: Properties: aarch64 feature: BTI, PAC
// LLVM: Notes [
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.gnu.property
// LLVM-NEXT: Offset: 0x40
// LLVM-NEXT: Size: 0x20
// LLVM-NEXT: Note {
# GNU-ALL: Version needs section '.gnu.version_r' contains {{.*}} entries:
# GNU-ALL: There are no section groups in this file.
# GNU-ALL: Histogram for bucket list length (total of 1 buckets)
-# GNU-ALL: Displaying notes found at file offset {{.*}} with length {{.*}}:
+# GNU-ALL: Displaying notes found
--- !ELF
FileHeader:
# RUN: llvm-readelf --notes %t | FileCheck %s --check-prefix=GNU
# RUN: llvm-readobj --elf-output-style LLVM --notes %t | FileCheck %s --check-prefix=LLVM
-# GNU: Owner Data size Description
+# GNU: Displaying notes found in: .note.ABI-tag
+# GNU-NEXT: Owner Data size Description
# GNU-NEXT: GNU 0x00000004 NT_GNU_ABI_TAG (ABI version tag)
# GNU-NEXT: <corrupt GNU_ABI_TAG>
# LLVM: Notes [
# LLVM-NEXT: NoteSection {
+# LLVM-NEXT: Name: .note.ABI-tag
# LLVM-NEXT: Offset:
# LLVM-NEXT: Size: 0x14
# LLVM-NEXT: Note {
# 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 0x00000078 with length 0x00000020:
+# GNU:Displaying notes found in: .note.ABI-tag
# 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 0x00000098 with length 0x00000020:
+# GNU:Displaying notes found in: .note.gnu.build-id
# 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 0x000000b8 with length 0x0000001c:
+# GNU:Displaying notes found in: .note.gnu.gold-version
# GNU-NEXT: Owner Data size Description
# GNU-NEXT: GNU 0x00000009 NT_GNU_GOLD_VERSION (gold version)
# GNU-NEXT: Version: gold 1.11
# LLVM: Notes [
# LLVM-NEXT: NoteSection {
+# LLVM-NEXT: Name: .note.ABI-tag
# LLVM-NEXT: Offset: 0x78
# LLVM-NEXT: Size: 0x20
# LLVM-NEXT: Note {
# LLVM-NEXT: }
# LLVM-NEXT: }
# LLVM-NEXT: NoteSection {
+# LLVM-NEXT: Name: .note.gnu.build-id
# LLVM-NEXT: Offset: 0x98
# LLVM-NEXT: Size: 0x20
# LLVM-NEXT: Note {
# LLVM-NEXT: }
# LLVM-NEXT: }
# LLVM-NEXT: NoteSection {
+# LLVM-NEXT: Name: .note.gnu.gold-version
# LLVM-NEXT: Offset: 0xB8
# LLVM-NEXT: Size: 0x1C
# LLVM-NEXT: Note {
# LLVM-NEXT: }
# LLVM-NEXT: ]
+## Note: the section name is <?> here because the section header table is not present.
# LLVM-STRIPPED: Notes [
# LLVM-STRIPPED-NEXT: NoteSection {
+# LLVM-STRIPPED-NEXT: Name: <?>
# LLVM-STRIPPED-NEXT: Offset: 0x78
# LLVM-STRIPPED-NEXT: Size: 0x20
# LLVM-STRIPPED-NEXT: Note {
# LLVM-STRIPPED-NEXT: }
# LLVM-STRIPPED-NEXT: ]
+## Note: offset and length printed instead of "found in: .note.gnu.build-id"
+## because the section header table is not present.
# 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)
// RUN: llvm-readobj --notes %t.o | FileCheck %s --check-prefix=LLVM
// RUN: llvm-readelf --notes %t.o | FileCheck %s --check-prefix=GNU
-// GNU: Displaying notes found
+// GNU: Displaying notes found in: .note.no.desc
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: AMD 0x00000000 NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata)
// GNU-NEXT: HSA Metadata:
// GNU-NEXT: AMD 0x00000000 NT_AMD_AMDGPU_ISA (ISA Version)
// GNU-NEXT: ISA Version:
// GNU-NEXT: {{^ +$}}
-// GNU-NEXT: Displaying notes found
+// GNU-NEXT: Displaying notes found in: .note.desc
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: AMD 0x0000000a NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata)
// GNU-NEXT: HSA Metadata:
// GNU-NEXT: AMD 0x00000009 NT_AMD_AMDGPU_ISA (ISA Version)
// GNU-NEXT: ISA Version:
// GNU-NEXT: isa_blah
-// GNU-NEXT: Displaying notes found
+// GNU-NEXT: Displaying notes found in: .note.other
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: AMD 0x00000000 NT_AMD_AMDGPU_PAL_METADATA (PAL Metadata)
// LLVM: Notes [
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.no.desc
// LLVM-NEXT: Offset:
// LLVM-NEXT: Size:
// LLVM-NEXT: Note {
// LLVM-NEXT: }
// LLVM-NEXT: }
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.desc
// LLVM-NEXT: Offset:
// LLVM-NEXT: Size:
// LLVM-NEXT: Note {
// LLVM-NEXT: }
// LLVM-NEXT: }
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.other
// LLVM-NEXT: Offset:
// LLVM-NEXT: Size:
// LLVM-NEXT: Note {
# RUN: llvm-readobj --notes %t.o | FileCheck %s --check-prefix=LLVM
# RUN: llvm-readelf --notes %t.o | FileCheck %s --check-prefix=GNU
-# GNU: Displaying notes found
+# GNU: Displaying notes found in: .note.foo
# GNU-NEXT: Owner Data size Description
# GNU-NEXT: AMDGPU 0x000000e6 NT_AMDGPU_METADATA (AMDGPU Metadata)
# GNU-NEXT: AMDGPU Metadata:
# LLVM: Notes [
# LLVM-NEXT: NoteSection {
+# LLVM-NEXT: Name: .note.foo
# LLVM-NEXT: Offset:
# LLVM-NEXT: Size:
# LLVM-NEXT: Note {
# LLVM: Notes [
# LLVM-NEXT: NoteSection {
+# LLVM-NEXT: Name: <?>
# LLVM-NEXT: Offset:
# LLVM-NEXT: Size:
# LLVM-NEXT: Note {
# LLVM: Notes [
# LLVM-NEXT: NoteSection {
+# LLVM-NEXT: Name: <?>
# LLVM-NEXT: Offset:
# LLVM-NEXT: Size:
# LLVM-NEXT: Note {
// RUN: llvm-readobj --notes %t.o | FileCheck %s --check-prefix=LLVM
// RUN: llvm-readelf --notes %t.o | FileCheck %s --check-prefix=GNU
-// GNU: Displaying notes found
+// GNU: Displaying notes found in: .note.foo
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: FreeBSD 0x00000000 NT_THRMISC (thrmisc structure)
// GNU-NEXT: FreeBSD 0x00000000 NT_PROCSTAT_PROC (proc data)
-// GNU-NEXT: Displaying notes found
+// GNU-NEXT: Displaying notes found in: .note.bar
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: FreeBSD 0x00000000 NT_PROCSTAT_FILES (files data)
-// GNU-NEXT: Displaying notes found
+// GNU-NEXT: Displaying notes found in: .note.baz
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: FreeBSD 0x0000001c Unknown note type (0x00000003)
// GNU-NEXT: description data: 4c 6f 72 65 6d 20 69 70 73 75 6d 20 64 6f 6c 6f 72 20 73 69 74 20 61 6d 65 74 00 00
// LLVM: Notes [
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.foo
// LLVM-NEXT: Offset:
// LLVM-NEXT: Size:
// LLVM-NEXT: Note {
// LLVM-NEXT: }
// LLVM-NEXT: }
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.bar
// LLVM-NEXT: Offset: 0x68
// LLVM-NEXT: Size: 0x14
// LLVM-NEXT: Note {
// LLVM-NEXT: }
// LLVM-NEXT: }
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.baz
// LLVM-NEXT: Offset: 0x7C
// LLVM-NEXT: Size: 0x30
// LLVM-NEXT: Note {
// RUN: llvm-readobj --notes %t.o | FileCheck %s --check-prefix=LLVM
// RUN: llvm-readelf --notes %t.o | FileCheck %s --check-prefix=GNU
-// GNU: Displaying notes found at file offset 0x00000040 with length 0x00000010:
+// GNU: Displaying notes found in: .note.version
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: XYZ 0x00000000 NT_VERSION (version)
-// GNU: Displaying notes found at file offset 0x00000050 with length 0x00000010:
+// GNU: Displaying notes found in: .note.arch
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: XYZ 0x00000000 NT_ARCH (architecture)
-// GNU: Displaying notes found at file offset 0x00000060 with length 0x00000010:
+// GNU: Displaying notes found in: .note.open
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: XYZ 0x00000000 OPEN
-// GNU: Displaying notes found at file offset 0x00000070 with length 0x00000010:
+// GNU: Displaying notes found in: .note.func
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: XYZ 0x00000000 func
// LLVM: Notes [
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.version
// LLVM-NEXT: Offset: 0x40
// LLVM-NEXT: Size: 0x10
// LLVM-NEXT: Note {
// LLVM-NEXT: }
// LLVM-NEXT: }
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.arch
// LLVM-NEXT: Offset: 0x50
// LLVM-NEXT: Size: 0x10
// LLVM-NEXT: Note {
// LLVM-NEXT: }
// LLVM-NEXT: }
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.open
// LLVM-NEXT: Offset: 0x60
// LLVM-NEXT: Size: 0x10
// LLVM-NEXT: Note {
// LLVM-NEXT: }
// LLVM-NEXT: }
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.func
// LLVM-NEXT: Offset: 0x70
// LLVM-NEXT: Size: 0x10
// LLVM-NEXT: Note {
// RUN: llvm-readelf --notes %t | FileCheck %s --check-prefix=GNU
// RUN: llvm-readobj --elf-output-style LLVM --notes %t | FileCheck %s --check-prefix=LLVM
-// GNU: Displaying notes found at file offset 0x00000040 with length 0x000000f8:
+// GNU: Displaying notes found in: .note.gnu.property
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: GNU 0x000000e8 NT_GNU_PROPERTY_TYPE_0 (property note)
// GNU-NEXT: Properties: stack size: 0x100
// LLVM: Notes [
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.gnu.property
// LLVM-NEXT: Offset: 0x40
// LLVM-NEXT: Size: 0xF8
// LLVM-NEXT: Note {
// RUN: llvm-readelf --notes %t | FileCheck %s --check-prefix=GNU
// RUN: llvm-readobj --elf-output-style LLVM --notes %t | FileCheck %s --check-prefix=LLVM
-// GNU: Displaying notes found at file offset 0x00000040 with length 0x00000014:
+// GNU: Displaying notes found in: .note.gnu.property
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: GNU 0x00000004 NT_GNU_PROPERTY_TYPE_0 (property note)
// GNU-NEXT: Properties: <corrupted GNU_PROPERTY_TYPE_0>
// LLVM: Notes [
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.gnu.property
// LLVM-NEXT: Offset: 0x40
// LLVM-NEXT: Size: 0x14
// LLVM-NEXT: Note {
// RUN: llvm-readobj --notes %t.o | FileCheck %s --check-prefix=LLVM
// RUN: llvm-readelf --notes %t.o | FileCheck %s --check-prefix=GNU
-// GNU: Displaying notes found at file offset 0x00000040 with length 0x00000010:
+// GNU: Displaying notes found in: .note.foo
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: XYZ 0x00000000 Unknown note type: (0x00000003)
-// GNU-NEXT: Displaying notes found at file offset 0x00000050 with length 0x0000002c:
+// GNU-NEXT: Displaying notes found in: .note.bar
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: XYZ 0x0000001c Unknown note type: (0x00000003)
// GNU-NEXT: description data: 4c 6f 72 65 6d 20 69 70 73 75 6d 20 64 6f 6c 6f 72 20 73 69 74 20 61 6d 65 74 00 00
// LLVM: Notes [
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.foo
// LLVM-NEXT: Offset: 0x40
// LLVM-NEXT: Size: 0x10
// LLVM-NEXT: Note {
// LLVM-NEXT: }
// LLVM-NEXT: }
// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.bar
// LLVM-NEXT: Offset: 0x50
// LLVM-NEXT: Size: 0x2C
// LLVM-NEXT: Note {
template <class ELFT>
void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
- auto PrintHeader = [&](const typename ELFT::Off Offset,
+ auto PrintHeader = [&](Optional<StringRef> SecName,
+ const typename ELFT::Off Offset,
const typename ELFT::Addr Size) {
- OS << "Displaying notes found at file offset " << format_hex(Offset, 10)
- << " with length " << format_hex(Size, 10) << ":\n"
- << " Owner Data size \tDescription\n";
+ OS << "Displaying notes found ";
+
+ if (SecName)
+ OS << "in: " << *SecName << "\n";
+ else
+ OS << "at file offset " << format_hex(Offset, 10) << " with length "
+ << format_hex(Size, 10) << ":\n";
+
+ OS << " Owner Data size \tDescription\n";
};
auto ProcessNote = [&](const Elf_Note &Note) {
for (const auto &S : Sections) {
if (S.sh_type != SHT_NOTE)
continue;
- PrintHeader(S.sh_offset, S.sh_size);
+ PrintHeader(expectedToOptional(Obj->getSectionName(&S)), S.sh_offset,
+ S.sh_size);
Error Err = Error::success();
for (auto Note : Obj->notes(S, Err))
ProcessNote(Note);
unwrapOrError(this->FileName, Obj->program_headers())) {
if (P.p_type != PT_NOTE)
continue;
- PrintHeader(P.p_offset, P.p_filesz);
+ PrintHeader(/*SecName=*/None, P.p_offset, P.p_filesz);
Error Err = Error::success();
for (auto Note : Obj->notes(P, Err))
ProcessNote(Note);
void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
ListScope L(W, "Notes");
- auto PrintHeader = [&](const typename ELFT::Off Offset,
+ auto PrintHeader = [&](Optional<StringRef> SecName,
+ const typename ELFT::Off Offset,
const typename ELFT::Addr Size) {
+ W.printString("Name", SecName ? *SecName : "<?>");
W.printHex("Offset", Offset);
W.printHex("Size", Size);
};
if (S.sh_type != SHT_NOTE)
continue;
DictScope D(W, "NoteSection");
- PrintHeader(S.sh_offset, S.sh_size);
+ PrintHeader(expectedToOptional(Obj->getSectionName(&S)), S.sh_offset,
+ S.sh_size);
Error Err = Error::success();
for (auto Note : Obj->notes(S, Err))
ProcessNote(Note);
if (P.p_type != PT_NOTE)
continue;
DictScope D(W, "NoteSection");
- PrintHeader(P.p_offset, P.p_filesz);
+ PrintHeader(/*SecName=*/None, P.p_offset, P.p_filesz);
Error Err = Error::success();
for (auto Note : Obj->notes(P, Err))
ProcessNote(Note);