[lld] [llvm] [llvm-readobj][ELF] Alter JSON/LLVM output on note sections to allow for multiple notes per section in JSON (PR #96813)
Roland McGrath via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 6 13:20:42 PDT 2024
frobtech wrote:
> > It's unfortunate that this left the useless `Notesection` dictionary key in each element of the `NoteSections` list, rather than removing the useless dictionary layer consistent with the new `Notes` list.
>
> Could you give an example of what you'd prefer the output to be? In the presence of potentially multiple note sections, each with multiple notes, I can't see any redundant layering.
Here's an example object file:
```
.section .note.a, "a", %note
.int 4, 4, 1
.string "foo"
.string "123"
.int 4, 4, 1
.string "bar"
.string "456"
.section .note.b, "a", %note
.int 4, 4, 1
.string "boo"
.string "789"
.int 4, 4, 1
.string "far"
.string "012"
```
Here's the current output for that:
```
[
{
"FileSummary": {
"File": "foo.o",
"Format": "elf64-x86-64",
"Arch": "x86_64",
"AddressSize": "64bit",
"LoadName": "<Not found>"
},
"Notes": [
{
"NoteSection": {
"Name": ".note.a",
"Offset": 64,
"Size": 40,
"Note": {
"Owner": "foo",
"Data size": 4,
"Type": "NT_VERSION (version)",
"Description data": {
"Offset": 0,
"Bytes": [
49,
50,
51,
0
]
}
},
"Note": {
"Owner": "bar",
"Data size": 4,
"Type": "NT_VERSION (version)",
"Description data": {
"Offset": 0,
"Bytes": [
52,
53,
54,
0
]
}
}
}
},
{
"NoteSection": {
"Name": ".note.b",
"Offset": 104,
"Size": 40,
"Note": {
"Owner": "boo",
"Data size": 4,
"Type": "NT_VERSION (version)",
"Description data": {
"Offset": 0,
"Bytes": [
55,
56,
57,
0
]
}
},
"Note": {
"Owner": "far",
"Data size": 4,
"Type": "NT_VERSION (version)",
"Description data": {
"Offset": 0,
"Bytes": [
48,
49,
50,
0
]
}
}
}
}
]
}
]
```
What purpose is served by having a dictionary in each element of the "Notes" array, each having only one entry with one key of "NoteSection"?
Here's one possible alternate schema that avoids single-entry dictionaries, and also avoids dictionaries with multiple identical keys used in place of lists (which is awkward for many JSON-ingesting programming situations, where dictionaries are usually accessed with the expectation of only a single match for each key):
```
[
{
"FileSummary": {
"File": "foo.o",
"Format": "elf64-x86-64",
"Arch": "x86_64",
"AddressSize": "64bit",
"LoadName": "<Not found>"
},
"NoteSections": [
{
"Name": ".note.a",
"Offset": 64,
"Size": 40,
"Notes": [
{
"Owner": "foo",
"Data size": 4,
"Type": "NT_VERSION (version)",
"Description data": {
"Offset": 0,
"Bytes": [
49,
50,
51,
0
]
}
},
{
"Owner": "bar",
"Data size": 4,
"Type": "NT_VERSION (version)",
"Description data": {
"Offset": 0,
"Bytes": [
52,
53,
54,
0
]
}
}
]
},
{
"Name": ".note.b",
"Offset": 104,
"Size": 40,
"Notes": [
{
"Owner": "boo",
"Data size": 4,
"Type": "NT_VERSION (version)",
"Description data": {
"Offset": 0,
"Bytes": [
55,
56,
57,
0
]
}
},
{
"Owner": "far",
"Data size": 4,
"Type": "NT_VERSION (version)",
"Description data": {
"Offset": 0,
"Bytes": [
48,
49,
50,
0
]
}
}
]
}
]
}
]
```
I don't have strong opinions about the exact schema. But layers of dictionary that add no information seems like an anti-pattern, and multiple identical keys in a dictionary also seems like an anti-pattern.
https://github.com/llvm/llvm-project/pull/96813
More information about the llvm-commits
mailing list