[llvm] [llvm-readobj][ELF] Implement JSON output for --dynamic-table (PR #95976)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 24 00:59:58 PDT 2024


================
@@ -7365,6 +7369,62 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printDynamicTable() {
   W.startLine() << "]\n";
 }
 
+template <class ELFT>
+void JSONELFDumper<ELFT>::printAuxillaryDynamicTableEntryInfo(
+    const Elf_Dyn &Entry) {
+  auto FormatFlags = [this, Value = Entry.getVal()](auto Flags) {
+    ListScope L(this->W, "Flags");
+    for (const auto &Flag : Flags) {
+      if (Flag.Value != 0 && (Value & Flag.Value) == Flag.Value)
+        this->W.printString(Flag.Name);
+    }
+  };
+  switch (Entry.getTag()) {
+  case DT_SONAME:
+    this->W.printString("Name", this->getDynamicString(Entry.getVal()));
+    break;
+  case DT_AUXILIARY:
+  case DT_FILTER:
+  case DT_NEEDED:
+    this->W.printString("Library", this->getDynamicString(Entry.getVal()));
+    break;
+  case DT_USED:
+    this->W.printString("Object", this->getDynamicString(Entry.getVal()));
+    break;
+  case DT_RPATH:
+  case DT_RUNPATH: {
+    StringRef Value = this->getDynamicString(Entry.getVal());
+    ListScope L(this->W, "Path");
+    while (!Value.empty()) {
+      auto [front, back] = Value.split(':');
+      this->W.printString(front);
+      Value = back;
+    }
+  } break;
----------------
jh7370 wrote:

Nit: I'd put the break inside the brace. Having it here feels wrong syntactically, even if it's not invalid.

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


More information about the llvm-commits mailing list