[PATCH] D83801: [MC] Pass the section to onSymbolStart() for more context

Ronak Chauhan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 14 11:34:56 PDT 2020


rochauha created this revision.
rochauha added reviewers: scott.linder, t-tye.
Herald added subscribers: llvm-commits, rupprecht, MaskRay, aheejin, hiraditya, jgravelle-google, sbc100, dschuff.
Herald added a reviewer: jhenderson.
Herald added a reviewer: MaskRay.
Herald added a project: LLVM.

This allows the disassembler to have more context regarding how to treat a particular symbol during disassembly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83801

Files:
  llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
  llvm/lib/MC/MCDisassembler/MCDisassembler.cpp
  llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
  llvm/tools/llvm-objdump/llvm-objdump.cpp


Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1827,7 +1827,7 @@
         continue;
       }
 
-      auto Status = DisAsm->onSymbolStart(Symbols[SI], Size,
+      auto Status = DisAsm->onSymbolStart(Symbols[SI], Section, Size,
                                           Bytes.slice(Start, End - Start),
                                           SectionAddr + Start, CommentStream);
       // To have round trippable disassembly, we fall back to decoding the
Index: llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
+++ llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
@@ -46,8 +46,9 @@
   DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
                               ArrayRef<uint8_t> Bytes, uint64_t Address,
                               raw_ostream &CStream) const override;
-  Optional<DecodeStatus> onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
-                                       ArrayRef<uint8_t> Bytes,
+  Optional<DecodeStatus> onSymbolStart(SymbolInfoTy &Symbol,
+                                       const object::SectionRef &Section,
+                                       uint64_t &Size, ArrayRef<uint8_t> Bytes,
                                        uint64_t Address,
                                        raw_ostream &CStream) const override;
 
@@ -122,8 +123,8 @@
 }
 
 Optional<MCDisassembler::DecodeStatus> WebAssemblyDisassembler::onSymbolStart(
-    SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef<uint8_t> Bytes,
-    uint64_t Address, raw_ostream &CStream) const {
+    SymbolInfoTy &Symbol, const object::SectionRef &Section, uint64_t &Size,
+    ArrayRef<uint8_t> Bytes, uint64_t Address, raw_ostream &CStream) const {
   Size = 0;
   if (Address == 0) {
     // Start of a code section: we're parsing only the function count.
Index: llvm/lib/MC/MCDisassembler/MCDisassembler.cpp
===================================================================
--- llvm/lib/MC/MCDisassembler/MCDisassembler.cpp
+++ llvm/lib/MC/MCDisassembler/MCDisassembler.cpp
@@ -16,10 +16,9 @@
 
 MCDisassembler::~MCDisassembler() = default;
 
-Optional<MCDisassembler::DecodeStatus>
-MCDisassembler::onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
-                              ArrayRef<uint8_t> Bytes, uint64_t Address,
-                              raw_ostream &CStream) const {
+Optional<MCDisassembler::DecodeStatus> MCDisassembler::onSymbolStart(
+    SymbolInfoTy &Symbol, const object::SectionRef &Section, uint64_t &Size,
+    ArrayRef<uint8_t> Bytes, uint64_t Address, raw_ostream &CStream) const {
   return None;
 }
 
Index: llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
===================================================================
--- llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
+++ llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
@@ -13,6 +13,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/XCOFF.h"
 #include "llvm/MC/MCDisassembler/MCSymbolizer.h"
+#include "llvm/Object/ObjectFile.h"
 #include <cstdint>
 #include <memory>
 #include <vector>
@@ -136,6 +137,7 @@
   /// treat symbols separately.
   ///
   /// \param Symbol   - The symbol.
+  /// \param Section  - Section containing the symbol.
   /// \param Size     - The number of bytes consumed.
   /// \param Address  - The address, in the memory space of region, of the first
   ///                   byte of the symbol.
@@ -151,8 +153,9 @@
   ///                 - None if the target doesn't want to handle the symbol
   ///                   separately. Value of Size is ignored in this case.
   virtual Optional<DecodeStatus>
-  onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef<uint8_t> Bytes,
-                uint64_t Address, raw_ostream &CStream) const;
+  onSymbolStart(SymbolInfoTy &Symbol, const object::SectionRef &Section,
+                uint64_t &Size, ArrayRef<uint8_t> Bytes, uint64_t Address,
+                raw_ostream &CStream) const;
   // TODO:
   // Implement similar hooks that can be used at other points during
   // disassembly. Something along the following lines:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83801.277918.patch
Type: text/x-patch
Size: 4404 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200714/fc2f99d9/attachment.bin>


More information about the llvm-commits mailing list