From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7803) id 505703858D28; Tue, 18 Apr 2023 03:41:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 505703858D28 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Nelson Chu To: bfd-cvs@sourceware.org Subject: [binutils-gdb] RISC-V: Cache the latest mapping symbol and its boundary. X-Act-Checkin: binutils-gdb X-Git-Author: Kito Cheng X-Git-Refname: refs/heads/master X-Git-Oldrev: 341eba4f9d4f39c8bd08ff59120662e86a3de305 X-Git-Newrev: c2f60ac565f1d369fde98146a16f1d3ef79e1000 Message-Id: <20230418034152.505703858D28@sourceware.org> Date: Tue, 18 Apr 2023 03:41:52 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Apr 2023 03:41:52 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc2f60ac565f1= d369fde98146a16f1d3ef79e1000 commit c2f60ac565f1d369fde98146a16f1d3ef79e1000 Author: Kito Cheng Date: Mon Apr 17 20:16:33 2023 +0800 RISC-V: Cache the latest mapping symbol and its boundary. =20 This issue was reported from https://github.com/riscv-collab/riscv-gnu-= toolchain/issues/1188 =20 Current flow: 1) Scan any mapping symbol less than this instruciton. 2) If not found, did a backward search. =20 The flow seems not big issue, let run an example here: =20 $x: 0x0 a <--- Found at step 1 0x4 b <--- Not found in step 1, but found at step 2 0x8 c <--- Not found in step 1, but found at step 2 $d 0x12 .word 1234 <-- Found at step 1 =20 The instruciton didn't have the same address with mapping symbol will still did backward search again and again. =20 So the new flow is: 1) Use the last mapping symbol status if the address is still within th= e range of the current mapping symbol. 2) Scan any mapping symbol less than this instruciton. 3) If not found, did a backward search. 4) If a proper mapping symbol is found in either step 2 or 3, find its = boundary, and cache that. =20 Use the same example to run the new flow again: =20 $x: 0x0 a <--- Found at step 2, the boundary is 0x12 0x4 b <--- Cache hit at step 1, within the boundary. 0x8 c <--- Cache hit at step 1, within the boundary. $d 0x12 .word 1234 <-- Found at step 2, the boundary is the end of section. =20 The disassemble time of the test cases has been reduced from ~20 minute= s to ~4 seconds. =20 opcode/ChangeLog PR 30282 * riscv-dis.c (last_map_symbol_boundary): New. (last_map_state): New. (last_map_section): New. (riscv_search_mapping_symbol): Cache the result of latest mapping symbol. Diff: --- opcodes/riscv-dis.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index 3aaa45f419c..f25993d1e45 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -64,6 +64,9 @@ struct riscv_private_data /* Used for mapping symbols. */ static int last_map_symbol =3D -1; static bfd_vma last_stop_offset =3D 0; +static bfd_vma last_map_symbol_boundary =3D 0; +static enum riscv_seg_mstate last_map_state =3D MAP_NONE; +static asection *last_map_section =3D NULL; =20 /* Register names as used by the disassembler. */ static const char * const *riscv_gpr_names; @@ -868,6 +871,14 @@ riscv_search_mapping_symbol (bfd_vma memaddr, int symbol =3D -1; int n; =20 + /* Return the last map state if the address is still within the range of= the + last mapping symbol. */ + if (last_map_section =3D=3D info->section + && (memaddr < last_map_symbol_boundary)) + return last_map_state; + + last_map_section =3D info->section; + /* Decide whether to print the data or instruction by default, in case we can not find the corresponding mapping symbols. */ mstate =3D MAP_DATA; @@ -939,6 +950,36 @@ riscv_search_mapping_symbol (bfd_vma memaddr, } } =20 + if (found) + { + /* Find the next mapping symbol to determine the boundary of this ma= pping + symbol. */ + + bool found_next =3D false; + /* Try to found next mapping symbol. */ + for (n =3D symbol + 1; n < info->symtab_size; n++) + { + if (info->symtab[symbol]->section !=3D info->symtab[n]->section) + continue; + + bfd_vma addr =3D bfd_asymbol_value (info->symtab[n]); + const char *sym_name =3D bfd_asymbol_name(info->symtab[n]); + if (sym_name[0] =3D=3D '$' && (sym_name[1] =3D=3D 'x' || sym_name[1] = =3D=3D 'd')) + { + /* The next mapping symbol has been found, and it represents the + boundary of this mapping symbol. */ + found_next =3D true; + last_map_symbol_boundary =3D addr; + break; + } + } + + /* No further mapping symbol has been found, indicating that the bou= ndary + of the current mapping symbol is the end of this section. */ + if (!found_next) + last_map_symbol_boundary =3D info->section->vma + info->section->size; + } + /* Save the information for next use. */ last_map_symbol =3D symbol; last_stop_offset =3D info->stop_offset; @@ -1059,6 +1100,8 @@ print_insn_riscv (bfd_vma memaddr, struct disassemble= _info *info) set_default_riscv_dis_options (); =20 mstate =3D riscv_search_mapping_symbol (memaddr, info); + /* Save the last mapping state. */ + last_map_state =3D mstate; =20 /* Set the size to dump. */ if (mstate =3D=3D MAP_DATA