[PATCH] D137089: [readobj] Fix JSON output for Relocations

Paul Kirth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 31 10:26:53 PDT 2022


paulkirth created this revision.
Herald added a reviewer: jhenderson.
Herald added a project: All.
paulkirth requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137089

Files:
  llvm/tools/llvm-readobj/ELFDumper.cpp


Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -725,6 +725,9 @@
                    Optional<StringRef> StrTable, bool IsDynamic,
                    bool /*NonVisibilityBitsUsed*/) const override;
 
+  void printRelRelaReloc(const Relocation<ELFT> &R,
+                         const RelSymbol<ELFT> &RelSym) override;
+
 private:
   std::unique_ptr<DictScope> FileScope;
 };
@@ -7547,6 +7550,7 @@
       std::string(formatv("{0}bit", 8 * Obj.getBytesInAddress())));
   this->printLoadName();
 }
+
 template <class ELFT>
 void JSONELFDumper<ELFT>::printSymbol(const Elf_Sym &Symbol, unsigned SymIndex,
                                       DataRegion<Elf_Word> ShndxTable,
@@ -7600,3 +7604,19 @@
   }
   this->printSymbolSection(Symbol, SymIndex, ShndxTable);
 }
+
+template <class ELFT>
+void JSONELFDumper<ELFT>::printRelRelaReloc(const Relocation<ELFT> &R,
+                                            const RelSymbol<ELFT> &RelSym) {
+  StringRef SymbolName = RelSym.Name;
+  SmallString<32> RelocName;
+  this->Obj.getRelocationTypeName(R.Type, RelocName);
+  ScopedPrinter &W = this->W;
+
+  DictScope Group(W, "Relocation");
+  W.printHex("Offset", R.Offset);
+  W.printNumber("Type", RelocName, R.Type);
+  W.printNumber("Symbol", SymbolName, R.Symbol);
+  if (R.Addend)
+    W.printHex("Addend", (uintX_t)*R.Addend);
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137089.472057.patch
Type: text/x-patch
Size: 1484 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221031/e33d4f5f/attachment.bin>


More information about the llvm-commits mailing list