[llvm] c140810 - [llvm-readobj] Include section name of notes.

Jordan Rupprecht via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 5 09:54:45 PST 2020


Author: Jordan Rupprecht
Date: 2020-03-05T09:53:14-08:00
New Revision: c140810ea158074c97bff4d3bd66c0e06aed6d93

URL: https://github.com/llvm/llvm-project/commit/c140810ea158074c97bff4d3bd66c0e06aed6d93
DIFF: https://github.com/llvm/llvm-project/commit/c140810ea158074c97bff4d3bd66c0e06aed6d93.diff

LOG: [llvm-readobj] Include section name of notes.

This changes the output of `llvm-readelf -n` from:

```
Displaying notes found at file offset 0x<...> with length 0x<...>:
```

to:

```
Displaying notes found in: .note.foo
```

And similarly, adds a `Name:` field to the `llvm-readobj -n` output for notes.

This change not only increases GNU compatibility, it also makes it much easier to read notes. Note that we still fall back to printing the file offset/length in cases where we don't have a section name, such as when printing notes in program headers or printing notes in a partially stripped file (GNU readelf does the same).

Fixes llvm.org/PR41339.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D75647

Added: 
    

Modified: 
    lld/test/ELF/partition-notes.s
    llvm/test/CodeGen/AMDGPU/code-object-v3.ll
    llvm/test/tools/llvm-objcopy/ELF/add-note.test
    llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-note-gnu-property.s
    llvm/test/tools/llvm-readobj/ELF/all.test
    llvm/test/tools/llvm-readobj/ELF/gnu-note-size.test
    llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
    llvm/test/tools/llvm-readobj/ELF/note-amd.s
    llvm/test/tools/llvm-readobj/ELF/note-amdgpu.test
    llvm/test/tools/llvm-readobj/ELF/note-core-ntfile.test
    llvm/test/tools/llvm-readobj/ELF/note-core.test
    llvm/test/tools/llvm-readobj/ELF/note-freebsd.s
    llvm/test/tools/llvm-readobj/ELF/note-generic.s
    llvm/test/tools/llvm-readobj/ELF/note-gnu-property.s
    llvm/test/tools/llvm-readobj/ELF/note-gnu-property2.s
    llvm/test/tools/llvm-readobj/ELF/note-unknown.s
    llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 
    


################################################################################
diff  --git a/lld/test/ELF/partition-notes.s b/lld/test/ELF/partition-notes.s
index fd9803bbe595..4db8c3ce9a3d 100644
--- a/lld/test/ELF/partition-notes.s
+++ b/lld/test/ELF/partition-notes.s
@@ -9,20 +9,38 @@
 // 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,"", at llvm_sympart
 .asciz "part1"

diff  --git a/llvm/test/CodeGen/AMDGPU/code-object-v3.ll b/llvm/test/CodeGen/AMDGPU/code-object-v3.ll
index c3a2911f714d..2dc41a965962 100644
--- a/llvm/test/CodeGen/AMDGPU/code-object-v3.ll
+++ b/llvm/test/CodeGen/AMDGPU/code-object-v3.ll
@@ -59,7 +59,7 @@
 ; 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(

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/add-note.test b/llvm/test/tools/llvm-objcopy/ELF/add-note.test
index 84cb7db1788f..b68103b665db 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/add-note.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/add-note.test
@@ -24,6 +24,7 @@ FileHeader:
 
 # CHECK:      Notes [
 # CHECK-NEXT:   NoteSection {
+# CHECK-NEXT:     Name: .note.gnu.build-id
 # CHECK-NEXT:     Offset:
 # CHECK-NEXT:     Size:
 # CHECK-NEXT:     Note {

diff  --git a/llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-note-gnu-property.s b/llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-note-gnu-property.s
index 693b6c93f35a..4f280ff41a91 100644
--- a/llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-note-gnu-property.s
+++ b/llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-note-gnu-property.s
@@ -2,13 +2,14 @@
 // 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 {

diff  --git a/llvm/test/tools/llvm-readobj/ELF/all.test b/llvm/test/tools/llvm-readobj/ELF/all.test
index 5d29cce548ac..f792143b9537 100644
--- a/llvm/test/tools/llvm-readobj/ELF/all.test
+++ b/llvm/test/tools/llvm-readobj/ELF/all.test
@@ -36,7 +36,7 @@
 # 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:

diff  --git a/llvm/test/tools/llvm-readobj/ELF/gnu-note-size.test b/llvm/test/tools/llvm-readobj/ELF/gnu-note-size.test
index d7421da5e0ee..a1b340ffc8d7 100644
--- a/llvm/test/tools/llvm-readobj/ELF/gnu-note-size.test
+++ b/llvm/test/tools/llvm-readobj/ELF/gnu-note-size.test
@@ -2,12 +2,14 @@
 # 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 {

diff  --git a/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test b/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
index 211f79a0cab8..cb4ea1da48f7 100644
--- a/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
+++ b/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
@@ -7,23 +7,24 @@
 # 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 {
@@ -35,6 +36,7 @@
 # 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 {
@@ -45,6 +47,7 @@
 # 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 {
@@ -56,8 +59,10 @@
 # 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 {
@@ -69,6 +74,8 @@
 # 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)

diff  --git a/llvm/test/tools/llvm-readobj/ELF/note-amd.s b/llvm/test/tools/llvm-readobj/ELF/note-amd.s
index df82b16b7825..94feaa27d8a9 100644
--- a/llvm/test/tools/llvm-readobj/ELF/note-amd.s
+++ b/llvm/test/tools/llvm-readobj/ELF/note-amd.s
@@ -4,7 +4,7 @@
 // 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:
@@ -12,7 +12,7 @@
 // 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:
@@ -20,12 +20,13 @@
 // 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 {
@@ -42,6 +43,7 @@
 // LLVM-NEXT:     }
 // LLVM-NEXT:   }
 // LLVM-NEXT:   NoteSection {
+// LLVM-NEXT:     Name: .note.desc
 // LLVM-NEXT:     Offset:
 // LLVM-NEXT:     Size:
 // LLVM-NEXT:     Note {
@@ -58,6 +60,7 @@
 // LLVM-NEXT:     }
 // LLVM-NEXT:   }
 // LLVM-NEXT:   NoteSection {
+// LLVM-NEXT:     Name: .note.other
 // LLVM-NEXT:     Offset:
 // LLVM-NEXT:     Size:
 // LLVM-NEXT:     Note {

diff  --git a/llvm/test/tools/llvm-readobj/ELF/note-amdgpu.test b/llvm/test/tools/llvm-readobj/ELF/note-amdgpu.test
index 097dbfbbe08b..d789ce2e5d2d 100644
--- a/llvm/test/tools/llvm-readobj/ELF/note-amdgpu.test
+++ b/llvm/test/tools/llvm-readobj/ELF/note-amdgpu.test
@@ -2,7 +2,7 @@
 # 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:
@@ -25,6 +25,7 @@
 
 # LLVM:      Notes [
 # LLVM-NEXT:   NoteSection {
+# LLVM-NEXT:     Name: .note.foo
 # LLVM-NEXT:     Offset:
 # LLVM-NEXT:     Size:
 # LLVM-NEXT:     Note {

diff  --git a/llvm/test/tools/llvm-readobj/ELF/note-core-ntfile.test b/llvm/test/tools/llvm-readobj/ELF/note-core-ntfile.test
index a1a5725af52d..fa5b82a2c4b7 100644
--- a/llvm/test/tools/llvm-readobj/ELF/note-core-ntfile.test
+++ b/llvm/test/tools/llvm-readobj/ELF/note-core-ntfile.test
@@ -65,6 +65,7 @@ ProgramHeaders:
 
 # LLVM:      Notes [
 # LLVM-NEXT:   NoteSection {
+# LLVM-NEXT:     Name: <?>
 # LLVM-NEXT:     Offset:
 # LLVM-NEXT:     Size:
 # LLVM-NEXT:     Note {

diff  --git a/llvm/test/tools/llvm-readobj/ELF/note-core.test b/llvm/test/tools/llvm-readobj/ELF/note-core.test
index 0aa163dbaf8a..f4da4a4f04fd 100644
--- a/llvm/test/tools/llvm-readobj/ELF/note-core.test
+++ b/llvm/test/tools/llvm-readobj/ELF/note-core.test
@@ -30,6 +30,7 @@ ProgramHeaders:
 
 # LLVM:      Notes [
 # LLVM-NEXT:   NoteSection {
+# LLVM-NEXT:     Name: <?>
 # LLVM-NEXT:     Offset:
 # LLVM-NEXT:     Size:
 # LLVM-NEXT:     Note {

diff  --git a/llvm/test/tools/llvm-readobj/ELF/note-freebsd.s b/llvm/test/tools/llvm-readobj/ELF/note-freebsd.s
index fbb7ac147d91..3d4b461f1feb 100644
--- a/llvm/test/tools/llvm-readobj/ELF/note-freebsd.s
+++ b/llvm/test/tools/llvm-readobj/ELF/note-freebsd.s
@@ -4,20 +4,21 @@
 // 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 {
@@ -32,6 +33,7 @@
 // LLVM-NEXT:     }
 // LLVM-NEXT:   }
 // LLVM-NEXT:   NoteSection {
+// LLVM-NEXT:     Name: .note.bar
 // LLVM-NEXT:     Offset: 0x68
 // LLVM-NEXT:     Size: 0x14
 // LLVM-NEXT:     Note {
@@ -41,6 +43,7 @@
 // LLVM-NEXT:     }
 // LLVM-NEXT:   }
 // LLVM-NEXT:   NoteSection {
+// LLVM-NEXT:     Name: .note.baz
 // LLVM-NEXT:     Offset: 0x7C
 // LLVM-NEXT:     Size: 0x30
 // LLVM-NEXT:     Note {

diff  --git a/llvm/test/tools/llvm-readobj/ELF/note-generic.s b/llvm/test/tools/llvm-readobj/ELF/note-generic.s
index 7b3b85fc56b9..d5b750534f44 100644
--- a/llvm/test/tools/llvm-readobj/ELF/note-generic.s
+++ b/llvm/test/tools/llvm-readobj/ELF/note-generic.s
@@ -4,24 +4,25 @@
 // 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 {
@@ -31,6 +32,7 @@
 // LLVM-NEXT:     }
 // LLVM-NEXT:   }
 // LLVM-NEXT:   NoteSection {
+// LLVM-NEXT:     Name: .note.arch
 // LLVM-NEXT:     Offset: 0x50
 // LLVM-NEXT:     Size: 0x10
 // LLVM-NEXT:     Note {
@@ -40,6 +42,7 @@
 // LLVM-NEXT:     }
 // LLVM-NEXT:   }
 // LLVM-NEXT:   NoteSection {
+// LLVM-NEXT:     Name: .note.open
 // LLVM-NEXT:     Offset: 0x60
 // LLVM-NEXT:     Size: 0x10
 // LLVM-NEXT:     Note {
@@ -49,6 +52,7 @@
 // LLVM-NEXT:     }
 // LLVM-NEXT:   }
 // LLVM-NEXT:   NoteSection {
+// LLVM-NEXT:     Name: .note.func
 // LLVM-NEXT:     Offset: 0x70
 // LLVM-NEXT:     Size: 0x10
 // LLVM-NEXT:     Note {

diff  --git a/llvm/test/tools/llvm-readobj/ELF/note-gnu-property.s b/llvm/test/tools/llvm-readobj/ELF/note-gnu-property.s
index 931dce6ba8fb..8c3a40ad2f69 100644
--- a/llvm/test/tools/llvm-readobj/ELF/note-gnu-property.s
+++ b/llvm/test/tools/llvm-readobj/ELF/note-gnu-property.s
@@ -3,7 +3,7 @@
 // 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
@@ -26,6 +26,7 @@
 
 // LLVM:      Notes [
 // LLVM-NEXT:   NoteSection {
+// LLVM-NEXT:     Name: .note.gnu.property
 // LLVM-NEXT:     Offset: 0x40
 // LLVM-NEXT:     Size: 0xF8
 // LLVM-NEXT:     Note {

diff  --git a/llvm/test/tools/llvm-readobj/ELF/note-gnu-property2.s b/llvm/test/tools/llvm-readobj/ELF/note-gnu-property2.s
index 899f6cdbd756..b6c0104077de 100644
--- a/llvm/test/tools/llvm-readobj/ELF/note-gnu-property2.s
+++ b/llvm/test/tools/llvm-readobj/ELF/note-gnu-property2.s
@@ -3,13 +3,14 @@
 // 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 {

diff  --git a/llvm/test/tools/llvm-readobj/ELF/note-unknown.s b/llvm/test/tools/llvm-readobj/ELF/note-unknown.s
index 632db2880ea3..9b35908d2b52 100644
--- a/llvm/test/tools/llvm-readobj/ELF/note-unknown.s
+++ b/llvm/test/tools/llvm-readobj/ELF/note-unknown.s
@@ -4,16 +4,17 @@
 // 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 {
@@ -23,6 +24,7 @@
 // LLVM-NEXT:     }
 // LLVM-NEXT:   }
 // LLVM-NEXT:   NoteSection {
+// LLVM-NEXT:     Name: .note.bar
 // LLVM-NEXT:     Offset: 0x50
 // LLVM-NEXT:     Size: 0x2C
 // LLVM-NEXT:     Note {

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index bad5f7185074..314244dce4ea 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -5042,11 +5042,18 @@ static void printCoreNote(raw_ostream &OS, const CoreNote &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) {
@@ -5111,7 +5118,8 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
     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);
@@ -5123,7 +5131,7 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
          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);
@@ -6263,8 +6271,10 @@ template <class ELFT>
 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);
   };
@@ -6331,7 +6341,8 @@ void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
       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);
@@ -6344,7 +6355,7 @@ void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
       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);


        


More information about the llvm-commits mailing list