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

Paul Kirth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 7 17:37:26 PST 2022


paulkirth updated this revision to Diff 481119.
paulkirth retitled this revision from "[readobj] Fix JSON output for Relocations" to "[llvm-readobj] Fix JSON output for Relocations".
paulkirth edited the summary of this revision.
paulkirth added a comment.
Herald added a subscriber: pengfei.

Rebase and update summary with example


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137089/new/

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
@@ -729,6 +729,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;
 };
@@ -7590,3 +7593,19 @@
   W.printFlags("Other", Symbol.st_other, makeArrayRef(SymOtherFlags), 0x3u);
   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.481119.patch
Type: text/x-patch
Size: 1259 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221208/def1e2ee/attachment.bin>


More information about the llvm-commits mailing list