[llvm-readobj] Fix JSON output for Relocations
authorPaul Kirth <paulkirth@google.com>
Fri, 17 Mar 2023 23:40:23 +0000 (23:40 +0000)
committerPaul Kirth <paulkirth@google.com>
Fri, 17 Mar 2023 23:57:58 +0000 (23:57 +0000)
commit23fd6e360c2cfe1263474c65c5cb605dfbf0dfeb
tree861a58f57533e2ef5fae8090256f14f17c63656a
parent8e1746faa3574df8fc8a3d4d26c9bff6f7859d04
[llvm-readobj] Fix JSON output for Relocations

The existing JSON incorrectly outputs line breaks and other invalid JSON.

Example Before this patch:

```
...
"Relocations":[Section (9) .rela.dyn {
  0xA3B0 R_X86_64_RELATIVE - 0x43D0
  0xA3B8 R_X86_64_RELATIVE - 0x4A30
...
```

Example After this patch:

```
...
"Relocations":[Section (9) .rela.dyn {
{"Relocation":{"Offset":41904,"Type":{"Value":"R_X86_64_RELATIVE","RawValue":8},
"Symbol":{"Value":"","RawValue":0},"Addend":17360}},
{"Relocation":{"Offset":41912,"Type":{"Value":"R_X86_64_RELATIVE","RawValue":8},
"Symbol":{"Value":"","RawValue":0},"Addend":18992}},
{"Relocation":{"Offset":41920,"Type":{"Value":"R_X86_64_RELATIVE","RawValue":8},
"Symbol":{"Value":"","RawValue":0},"Addend":17440}},
...
```

Note there are still issues with the Section, but each Relocation is
now a valid JSON object that can be parsed. Future patches will address
the issues regarding JSON output for the Section.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D137089
llvm/test/tools/llvm-readobj/ELF/relocations.test
llvm/tools/llvm-readobj/ELFDumper.cpp