Skip to content

Commit

Permalink
[llvm-readobj][ELF] Alter JSON/LLVM output on note sections to allow …
Browse files Browse the repository at this point in the history
…for multiple notes per section in JSON (#96813)

It turns out that the notes section for corefiles (or really any elf
file with multiple notes) is set up in such a way for LLVM formatted
output that the JSON equivalent only has the last note since the notes
are held in a dictionary with every key being Note. This pr alters the
layout for the notes to a list of dictionaries to sidestep this issue
for JSON output. Prior to this pr a note section in the output looked
like (for LLVM output):

```
Notes [
  NoteSection {
    Name: <?>
    Offset: 0x2148
    Size: 0x1F864
    Note {
      Owner: CORE
      Data size: 0x150
      Type: NT_PRSTATUS (prstatus structure)
      Description data (
        0000: 06000000 00000000 00000000 06000000  |................|
        ...
      )
    }
    Note {
      Owner: CORE
      Data size: 0x88
      Type: NT_PRPSINFO (prpsinfo structure)
      Description data (
        0000: 02440000 00000000 04054040 00000000  |.D........@@....|
	....
```

But is now:

```
NoteSections [
  NoteSection {
    Name: <?>
    Offset: 0x2148
    Size: 0x1F864
    Notes [
      {
        Owner: CORE
        Data size: 0x150
        Type: NT_PRSTATUS (prstatus structure)
        Description data (
          0000: 06000000 00000000 00000000 06000000  |................|
          ...
        )
      }
      {
        Owner: CORE
        Data size: 0x88
        Type: NT_PRPSINFO (prpsinfo structure)
        Description data (
          0000: 02440000 00000000 04054040 00000000  |.D........@@....|
	  ...
```
  • Loading branch information
feg208 authored Jul 3, 2024
1 parent 584e431 commit ab930ee
Show file tree
Hide file tree
Showing 31 changed files with 574 additions and 399 deletions.
4 changes: 3 additions & 1 deletion lld/test/ELF/gnu-property-align-32.s
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
# CHECK-NEXT: Info: 0
# CHECK-NEXT: AddressAlignment: 4

# CHECK: Note {
# CHECK: Size: 0x1C
# CHECK-NEXT: Notes [
# CHECK-NEXT: {
# CHECK-NEXT: Owner: GNU
# CHECK-NEXT: Data size: 0xC
# CHECK-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
Expand Down
4 changes: 3 additions & 1 deletion lld/test/ELF/gnu-property-align.s
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
# CHECK-NEXT: Info: 0
# CHECK-NEXT: AddressAlignment: 8

# CHECK: Note {
# CHECK: Size: 0x20
# CHECK-NEXT: Notes [
# CHECK-NEXT: {
# CHECK-NEXT: Owner: GNU
# CHECK-NEXT: Data size: 0x10
# CHECK-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
Expand Down
10 changes: 7 additions & 3 deletions lld/test/ELF/partition-notes.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,34 @@
// CHECK: Type: PT_NOTE
// CHECK-NEXT: Offset: 0x{{0*}}[[NOTE_OFFSET:[^ ]*]]

// CHECK: Notes [
// CHECK: NoteSections [
// CHECK-NEXT: NoteSection {
// CHECK-NEXT: Name: .note.obj
// CHECK-NEXT: Offset: 0x{{0*}}[[NOTE_OFFSET]]
// CHECK-NEXT: Size:
// CHECK-NEXT: Note {
// CHECK-NEXT: Notes [
// CHECK-NEXT: {
// 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: }
// CHECK-NEXT: NoteSection {
// CHECK-NEXT: Name: .note.gnu.build-id
// CHECK-NEXT: Offset:
// CHECK-NEXT: Size:
// CHECK-NEXT: Note {
// CHECK-NEXT: Notes [
// CHECK-NEXT: {
// CHECK-NEXT: Owner: GNU
// CHECK-NEXT: Data size:
// CHECK-NEXT: Type: NT_GNU_BUILD_ID (unique build ID bitstring)
// CHECK-NEXT: Build ID: d5101cb9d03b7e836ba9b64f5768a0b31980920f{{$}}
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]

Expand Down
6 changes: 4 additions & 2 deletions llvm/test/tools/llvm-objcopy/ELF/add-note.test
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ FileHeader:
Type: ET_REL
Machine: EM_X86_64

# CHECK: Notes [
# CHECK: NoteSections [
# CHECK-NEXT: NoteSection {
# CHECK-NEXT: Name: .note.gnu.build-id
# CHECK-NEXT: Offset:
# CHECK-NEXT: Size:
# CHECK-NEXT: Note {
# CHECK-NEXT: Notes [
# CHECK-NEXT: {
# CHECK-NEXT: Owner: GNU
# CHECK-NEXT: Data size: 0x10
# CHECK-NEXT: Type: NT_GNU_BUILD_ID
# CHECK-NEXT: Build ID: 000102030405060708090a0b0c0d0e0f
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: }
# CHECK-NEXT: ]
12 changes: 8 additions & 4 deletions llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-feature-pauth.s
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,21 @@ end:
# ELF-NEXT: GNU 0x00000018 NT_GNU_PROPERTY_TYPE_0 (property note)
# ELF-NEXT: AArch64 PAuth ABI core info: platform [[PLATFORM]], version [[VERSION]]

# OBJ: Notes [
# OBJ: NoteSections [
# OBJ-NEXT: NoteSection {
# OBJ-NEXT: Name: .note.gnu.property
# OBJ-NEXT: Offset: 0x40
# OBJ-NEXT: Size: 0x28
# OBJ-NEXT: Note {
# OBJ-NEXT: Notes [
# OBJ-NEXT: {
# OBJ-NEXT: Owner: GNU
# OBJ-NEXT: Data size: 0x18
# OBJ-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
# OBJ-NEXT: Property [
# OBJ-NEXT: AArch64 PAuth ABI core info: platform [[PLATFORM]], version [[VERSION]]
# OBJ-NEXT: ]
# OBJ-NEXT: }
# OBJ-NEXT: ]
# OBJ-NEXT: }
# OBJ-NEXT: ]

Expand Down Expand Up @@ -162,19 +164,21 @@ end:
# ELF-ERR-NEXT: GNU 0x000000[[DATASIZE]] NT_GNU_PROPERTY_TYPE_0 (property note)
# ELF-ERR-NEXT: AArch64 PAuth ABI core info: [[ERR]]

# OBJ-ERR: Notes [
# OBJ-ERR: NoteSections [
# OBJ-ERR-NEXT: NoteSection {
# OBJ-ERR-NEXT: Name: .note.gnu.property
# OBJ-ERR-NEXT: Offset: 0x40
# OBJ-ERR-NEXT: Size: 0x[[SIZE]]
# OBJ-ERR-NEXT: Note {
# OBJ-ERR-NEXT: Notes [
# OBJ-ERR-NEXT: {
# OBJ-ERR-NEXT: Owner: GNU
# OBJ-ERR-NEXT: Data size: 0x[[DATASIZE]]
# OBJ-ERR-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
# OBJ-ERR-NEXT: Property [
# OBJ-ERR-NEXT: AArch64 PAuth ABI core info: [[ERR]]
# OBJ-ERR-NEXT: ]
# OBJ-ERR-NEXT: }
# OBJ-ERR-NEXT: ]
# OBJ-ERR-NEXT: }
# OBJ-ERR-NEXT: ]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@
// GNU-NEXT: GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 (property note)
// GNU-NEXT: Properties: aarch64 feature: BTI, PAC, GCS

// LLVM: Notes [
// LLVM: NoteSections [
// LLVM-NEXT: NoteSection {
// LLVM-NEXT: Name: .note.gnu.property
// LLVM-NEXT: Offset: 0x40
// LLVM-NEXT: Size: 0x20
// LLVM-NEXT: Note {
// LLVM-NEXT: Notes [
// LLVM-NEXT: {
// LLVM-NEXT: Owner: GNU
// LLVM-NEXT: Data size: 0x10
// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
// LLVM-NEXT: Property [
// LLVM-NEXT: aarch64 feature: BTI, PAC, GCS
// LLVM-NEXT: ]
// LLVM-NEXT: }
// LLVM-NEXT: ]
// LLVM-NEXT: }
// LLVM-NEXT: ]

Expand Down
6 changes: 4 additions & 2 deletions llvm/test/tools/llvm-readobj/ELF/AArch64/memtag.test
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@
# GNU-OK-NEXT: Android 0x00000004 NT_ANDROID_TYPE_MEMTAG (Android memory tagging information)
# GNU-BAD-NEXT: Android 0x00000000 NT_ANDROID_TYPE_MEMTAG (Android memory tagging information)

# LLVM: Notes [
# LLVM: NoteSections [
# LLVM-NEXT: NoteSection {
# LLVM-NEXT: Name: .note.android.memtag
# LLVM-NEXT: Offset: 0x40
# LLVM-OK-NEXT: Size: 0x18
# LLVM-BAD-NEXT: Size: 0x14
# LLVM-NEXT: Note {
# LLVM-NEXT: Notes [
# LLVM-NEXT: {
# LLVM-NEXT: Owner: Android
# LLVM-OK-NEXT: Data size: 0x4
# LLVM-BAD-NEXT: Data size: 0x0
Expand All @@ -114,6 +115,7 @@
# NOSTACK-NEXT: Stack: Disabled

# LLVM-NEXT: }
# LLVM-NEXT: ]
# LLVM-NEXT: }
# LLVM-NEXT: ]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
# GNU-NEXT: Android 0x00000005 Unknown note type: (0x00001337)
# GNU-NEXT: description data: 01 23 45 67 89

# LLVM: Notes [
# LLVM: NoteSections [
# LLVM-NEXT: NoteSection {
# LLVM-NEXT: Name: .note.android.unknown
# LLVM-NEXT: Offset: 0x40
# LLVM-NEXT: Size: 0x1C
# LLVM-NEXT: Note {
# LLVM-NEXT: Notes [
# LLVM-NEXT: {
# LLVM-NEXT: Owner: Android
# LLVM-NEXT: Data size: 0x5
# LLVM-NEXT: Type: Unknown (0x00001337)
# LLVM-NEXT: Description data (
# LLVM-NEXT: 0000: 01234567 89
# LLVM-NEXT: )
# LLVM-NEXT: }
# LLVM-NEXT: ]
# LLVM-NEXT: }
# LLVM-NEXT: ]

Expand Down
6 changes: 4 additions & 2 deletions llvm/test/tools/llvm-readobj/ELF/gnu-note-size.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
# GNU-NEXT: <corrupt GNU_ABI_TAG>
# GNU-EMPTY:

# LLVM: Notes [
# LLVM: NoteSections [
# LLVM-NEXT: NoteSection {
# LLVM-NEXT: Name: .note.ABI-tag
# LLVM-NEXT: Offset:
# LLVM-NEXT: Size: 0x14
# LLVM-NEXT: Note {
# LLVM-NEXT: Notes [
# LLVM-NEXT: {
# LLVM-NEXT: Owner: GNU
# LLVM-NEXT: Data size: 0x4
# LLVM-NEXT: Type: NT_GNU_ABI_TAG (ABI version tag)
Expand All @@ -25,6 +26,7 @@
# LLVM-NEXT: 0000: 00000000 |....|
# LLVM-NEXT: )
# LLVM-NEXT: }
# LLVM-NEXT: ]
# LLVM-NEXT: }
# LLVM-NEXT: ]

Expand Down
42 changes: 30 additions & 12 deletions llvm/test/tools/llvm-readobj/ELF/gnu-notes.test
Original file line number Diff line number Diff line change
Expand Up @@ -28,68 +28,78 @@
# GNU-NEXT: description data: 61 62 63 64
# GNU-EMPTY:

# LLVM: Notes [
# LLVM: NoteSections [
# LLVM-NEXT: NoteSection {
# LLVM-NEXT: Name: .note.ABI-tag
# LLVM-NEXT: Offset: 0x78
# LLVM-NEXT: Size: 0x20
# LLVM-NEXT: Note {
# LLVM-NEXT: Notes [
# LLVM-NEXT: {
# LLVM-NEXT: Owner: GNU
# LLVM-NEXT: Data size: 0x10
# LLVM-NEXT: Type: NT_GNU_ABI_TAG (ABI version tag)
# LLVM-NEXT: OS: Linux
# LLVM-NEXT: ABI: 2.6.32
# LLVM-NEXT: }
# 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: Notes [
# LLVM-NEXT: {
# LLVM-NEXT: Owner: GNU
# LLVM-NEXT: Data size: 0x10
# LLVM-NEXT: Type: NT_GNU_BUILD_ID (unique build ID bitstring)
# LLVM-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b
# LLVM-NEXT: }
# 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: Notes [
# LLVM-NEXT: {
# LLVM-NEXT: Owner: GNU
# LLVM-NEXT: Data size: 0x9
# LLVM-NEXT: Type: NT_GNU_GOLD_VERSION (gold version)
# LLVM-NEXT: Version: gold 1.11
# LLVM-NEXT: }
# LLVM-NEXT: ]
# LLVM-NEXT: }
# LLVM-NEXT: NoteSection {
# LLVM-NEXT: Name: .note.gnu.unknown
# LLVM-NEXT: Offset: 0xD4
# LLVM-NEXT: Size: 0x14
# LLVM-NEXT: Note {
# LLVM-NEXT: Notes [
# LLVM-NEXT: {
# LLVM-NEXT: Owner: GNU
# LLVM-NEXT: Data size: 0x4
# LLVM-NEXT: Type: Unknown (0x0000abcd)
# LLVM-NEXT: Description data (
# LLVM-NEXT: 0000: 61626364 |abcd|
# LLVM-NEXT: )
# LLVM-NEXT: }
# LLVM-NEXT: ]
# LLVM-NEXT: }
# LLVM-NEXT: ]

## Note: the section name is <?> here because the section header table is not present.
# LLVM-STRIPPED: Notes [
# LLVM-STRIPPED: NoteSections [
# 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: Notes [
# LLVM-STRIPPED-NEXT: {
# 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: }
# LLVM-STRIPPED-NEXT: ]

Expand Down Expand Up @@ -144,12 +154,14 @@ ProgramHeaders:
# ERR1-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0xffff0000) or size (0x0)
# ERR1-GNU-EMPTY:

# ERR1-LLVM: Notes [
# ERR1-LLVM: NoteSections [
# ERR1-LLVM-NEXT: NoteSection {
# ERR1-LLVM-NEXT: Name: .note
# ERR1-LLVM-NEXT: Offset: 0xFFFF0000
# ERR1-LLVM-NEXT: Size: 0x0
# ERR1-LLVM-NEXT: Notes [
# ERR1-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0xffff0000) or size (0x0)
# ERR1-LLVM-NEXT: ]
# ERR1-LLVM-NEXT: }
# ERR1-LLVM-NEXT: ]

Expand Down Expand Up @@ -177,12 +189,14 @@ Sections:
# ERR2-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0x40) or size (0xffff0000)
# ERR2-GNU-EMPTY:

# ERR2-LLVM: Notes [
# ERR2-LLVM: NoteSections [
# ERR2-LLVM-NEXT: NoteSection {
# ERR2-LLVM-NEXT: Name: .note
# ERR2-LLVM-NEXT: Offset: 0x40
# ERR2-LLVM-NEXT: Size: 0xFFFF0000
# ERR2-LLVM-NEXT: Notes [
# ERR2-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the SHT_NOTE section with index 1: invalid offset (0x40) or size (0xffff0000)
# ERR2-LLVM-NEXT: ]
# ERR2-LLVM-NEXT: }
# ERR2-LLVM-NEXT: ]

Expand All @@ -198,12 +212,14 @@ Sections:
# ERR3-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 0: invalid offset (0xffff0000) or size (0x0)
# ERR3-GNU-NOT: {{.}}

# ERR3-LLVM: Notes [
# ERR3-LLVM: NoteSections [
# ERR3-LLVM-NEXT: NoteSection {
# ERR3-LLVM-NEXT: Name: <?>
# ERR3-LLVM-NEXT: Offset: 0xFFFF0000
# ERR3-LLVM-NEXT: Size: 0x0
# ERR3-LLVM-NEXT: Notes [
# ERR3-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 0: invalid offset (0xffff0000) or size (0x0)
# ERR3-LLVM-NEXT: ]
# ERR3-LLVM-NEXT: }
# ERR3-LLVM-NEXT: ]

Expand All @@ -229,12 +245,14 @@ ProgramHeaders:
# ERR4-GNU-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 0: invalid offset (0x0) or size (0xffff0000)
# ERR4-GNU-EMPTY:

# ERR4-LLVM: Notes [
# ERR4-LLVM: NoteSections [
# ERR4-LLVM-NEXT: NoteSection {
# ERR4-LLVM-NEXT: Name: <?>
# ERR4-LLVM-NEXT: Offset: 0x0
# ERR4-LLVM-NEXT: Size: 0xFFFF0000
# ERR4-LLVM-NEXT: Notes [
# ERR4-LLVM-NEXT: warning: '[[FILE]]': unable to read notes from the PT_NOTE segment with index 0: invalid offset (0x0) or size (0xffff0000)
# ERR4-LLVM-NEXT: ]
# ERR4-LLVM-NEXT: }
# ERR4-LLVM-NEXT: ]

Expand All @@ -247,6 +265,6 @@ ProgramHeaders:
# PHENTSIZE-WARN-GNU: warning: '[[FILE]]': unable to read program headers to locate the PT_DYNAMIC segment: invalid e_phentsize: 1
# PHENTSIZE-WARN-GNU: warning: '[[FILE]]': unable to read program headers to locate the PT_NOTE segment: invalid e_phentsize: 1

# PHENTSIZE-WARN-LLVM: Notes [
# PHENTSIZE-WARN-LLVM: NoteSections [
# PHENTSIZE-WARN-LLVM-NEXT: warning: '[[FILE]]': unable to read program headers to locate the PT_NOTE segment: invalid e_phentsize: 1
# PHENTSIZE-WARN-LLVM-NEXT: ]
Loading

0 comments on commit ab930ee

Please sign in to comment.