[PATCH v2 2/3] RISC-V: Per-section private data initialization

Tsukasa OI research_trasio@irq.a4lg.com
Mon Nov 28 04:47:22 GMT 2022


From: Tsukasa OI <research_trasio@irq.a4lg.com>

This is one more preparation for mapping symbol optimization.  It adds a
separate function that is called when the section to disassemble is changed.

This commit enables tracking per-section state management required for the
next optimization ("RISC-V: Optimized search on mapping symbols").

opcodes/ChangeLog:

	* riscv-dis.c (struct riscv_private_data): Add last_section.
	(init_riscv_dis_private_data): Initialize last_section.
	(init_riscv_dis_private_data_for_section): New function. update
	last_section here.
	(print_insn_riscv): Track section changes.
---
 opcodes/riscv-dis.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index bb7c03ad5fbf..ba9b16afeb46 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -89,6 +89,7 @@ struct riscv_private_data
   bfd_vma gp;
   bfd_vma print_addr;
   bfd_vma hi_addr[NGPR];
+  void* last_section;
   bool to_print_addr;
   bool has_gp;
 };
@@ -245,6 +246,7 @@ init_riscv_dis_private_data (struct disassemble_info *info)
   pd->print_addr = 0;
   for (int i = 0; i < (int)ARRAY_SIZE (pd->hi_addr); i++)
     pd->hi_addr[i] = -1;
+  pd->last_section = NULL;
   pd->to_print_addr = false;
   pd->has_gp = false;
 
@@ -256,6 +258,15 @@ init_riscv_dis_private_data (struct disassemble_info *info)
       }
 }
 
+/* Initialize private data when the section to disassemble is changed.  */
+
+static void
+init_riscv_dis_private_data_for_section (struct disassemble_info *info)
+{
+  struct riscv_private_data *pd = info->private_data;
+  pd->last_section = info->section;
+}
+
 /* Update architecture for disassembler with its context.
    Call initialization functions if either:
    -  the architecture for current context is changed or
@@ -1312,7 +1323,13 @@ print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info)
 
   /* Initialize the private data.  */
   if (info->private_data == NULL)
-    init_riscv_dis_private_data (info);
+    {
+      init_riscv_dis_private_data (info);
+      init_riscv_dis_private_data_for_section (info);
+    }
+  struct riscv_private_data *pd = info->private_data;
+  if (info->section != pd->last_section)
+    init_riscv_dis_private_data_for_section (info);
 
   /* Guess and update XLEN if we haven't determined it yet.  */
   if (xlen == 0)
-- 
2.38.1



More information about the Binutils mailing list