[llvm-readobj] Standardize JSON output for `Other` field
authorPaul Kirth <paulkirth@google.com>
Fri, 17 Mar 2023 23:32:00 +0000 (23:32 +0000)
committerPaul Kirth <paulkirth@google.com>
Fri, 17 Mar 2023 23:38:31 +0000 (23:38 +0000)
commit8e1746faa3574df8fc8a3d4d26c9bff6f7859d04
tree4bb76c77ad64458b8a39b3f69ddb5e398a1a74ec
parent308bcb3f7babcf324d8f7b5dd9002bc1d967a92f
[llvm-readobj] Standardize JSON output for `Other` field

Today, the LLVM output uses special handling when the Other field is 0.
This output makes sense for a command line utility that a human will
read, but JSON is a machine readable format, so being consistent is more
important. Prior to this change, any consumer of the JSON output would
need to handle the Other field specially, since the structure of the
JSON would no longer be consistent.

Changes to JSON output when Other flag == 0:
```
"Other": 0,   ->   "Other": {
                      "RawFlags": 0,
                       "Flags": []
                    },
```

There are no changes to when Other flag != 0:
```
"Other": {        ->   "Other": {
  "RawFlags": 1,          "RawFlags": 1,
  "Flags": [              "Flags": [
      ...                     ...
  ]                       ]
},                     },
```

This patch adds a overload for the JSONELFDumper's printSymbol() method,
that uses consistent output formatting, regardless of the value of the
Other field.

Depends on D137092

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D137088
llvm/test/tools/llvm-readobj/ELF/aarch64-symbols-stother.test
llvm/test/tools/llvm-readobj/ELF/mips-symbols-stother.test
llvm/test/tools/llvm-readobj/ELF/symbol-visibility.test
llvm/tools/llvm-readobj/ELFDumper.cpp