[llvm] [llvm-readobj][ELF] Fix broken JSON output with --dynamic-table (PR #95976)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 19 00:30:56 PDT 2024


================
@@ -7365,6 +7367,19 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printDynamicTable() {
   W.startLine() << "]\n";
 }
 
+template <class ELFT> void JSONELFDumper<ELFT>::printDynamicTable() {
+  Elf_Dyn_Range Table = this->dynamic_table();
+  ListScope L(this->W, "DynamicSection");
+  for (const auto &Entry : Table) {
+    DictScope D(this->W);
+    uintX_t Tag = Entry.getTag();
+    std::string Value = this->getDynamicEntry(Tag, Entry.getVal());
+    this->W.printHex("Tag", Tag);
+    this->W.printString("Value", Value);
+    this->W.printString("Type", this->Obj.getDynamicTagAsString(Tag));
----------------
jh7370 wrote:

I think we need to give this output a bit more consideration, given that this is JSON and therefore intended to be machine-readable (otherwise, we could just use LLVM-style output). In particular, I have the following two thoughts:
1) Tag/Type fields are just different ways of representing the same information. Do we need both of them?
2) The Value field is a string, yet this is almost never the "natural" representation of the value for a dynamic tag. It also is rarely the actual value, because it is an interpretation of that value. In my opinion, this potentially deserves splitting into two fields: a raw integer value (which is just the "bytes on disk" numeric value for the entry), and an interpreted value, in a format that is appropriate for the interpretation, e.g. a list of strings, or an integer (in the latter case, arguably the interpreted field may not be necessary).

Thoughts?

https://github.com/llvm/llvm-project/pull/95976


More information about the llvm-commits mailing list