[llvm] [llvm-readobj] Emit valid JSON for Verdef Predecessors (PR #200069)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 00:09:47 PDT 2026


================
@@ -8074,9 +8074,10 @@ void LLVMELFDumper<ELFT>::printVersionDefinitionSection(const Elf_Shdr *Sec) {
     W.printNumber("Index", D.Ndx);
     W.printNumber("Hash", D.Hash);
     W.printString("Name", D.Name);
-    W.printList(
-        "Predecessors", D.AuxV,
-        [](raw_ostream &OS, const VerdAux &Aux) { OS << Aux.Name.c_str(); });
+    std::vector<std::string> Predecessors;
+    for (const VerdAux &Aux : D.AuxV)
+      Predecessors.push_back(Aux.Name);
----------------
jh7370 wrote:

I don't know how many such entries there are, but this feels needlessly inefficient.

A quick search in LLVM suggests that the three argument version of `printList` is only called in two places, here and its unit test. As such, it should be fine to change it. I'd change it to take a lambda that extracts the desired value for printing, then internally the `printList` function would do the printing like in the other `printList` cases. So, at the call site, it would look something like:
```
W.printList(
  "Predecessors", D.AuxV,
  [](const VerdAux &Aux) { return Aux.Name; });
```

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


More information about the llvm-commits mailing list