Disassembler: Core Optimization 1-2 (Mapping symbols)#89
Open
a4lg wants to merge 3 commits intoriscv-dis-opt1-1-hashtable-and-cachingfrom
Open
Disassembler: Core Optimization 1-2 (Mapping symbols)#89a4lg wants to merge 3 commits intoriscv-dis-opt1-1-hashtable-and-cachingfrom
a4lg wants to merge 3 commits intoriscv-dis-opt1-1-hashtable-and-cachingfrom
Conversation
27bf225 to
fa6aaa9
Compare
444fbaa to
b83e54a
Compare
fa6aaa9 to
90cbce7
Compare
b83e54a to
9fdf0f8
Compare
ff6d0c3 to
8f73fe2
Compare
8f73fe2 to
d41edfb
Compare
844db36 to
f3378df
Compare
3af33e2 to
a7983af
Compare
a452e06 to
515d02e
Compare
33a34e5 to
31e4c81
Compare
29236db to
3ddff53
Compare
176ede7 to
e887d6f
Compare
29c84f1 to
e6a6657
Compare
e1402d5 to
a9eeb46
Compare
521e646 to
8c9fc20
Compare
f1b6ec2 to
412f6fb
Compare
0e92186 to
e679d61
Compare
8b63344 to
afff826
Compare
5a6b1a0 to
524c00d
Compare
6609896 to
c4c251b
Compare
b9ae787 to
bdbf711
Compare
c4c251b to
2369d8a
Compare
bdbf711 to
fa9d1ca
Compare
2369d8a to
ee69c33
Compare
fa9d1ca to
fb9a584
Compare
7a2f076 to
ef6b719
Compare
c543f8c to
fd27a9a
Compare
ec4d7f8 to
f247a24
Compare
9430407 to
ec66303
Compare
f247a24 to
aadd5c6
Compare
ec66303 to
3c2d155
Compare
aadd5c6 to
0dd2ee6
Compare
3c2d155 to
bb3e2d1
Compare
0dd2ee6 to
277d4db
Compare
bb3e2d1 to
f352220
Compare
a4f2841 to
3a6ca13
Compare
0117f25 to
b91bca0
Compare
3a6ca13 to
0cf4707
Compare
b91bca0 to
c1cf9dc
Compare
Before further optimization, we can optimize the function riscv_search_mapping_symbol a bit for clarity. opcodes/ChangeLog: * riscv-dis.c (riscv_search_mapping_symbol): Make MAP_INSN default considering major usecases. Remove setting found here as no one uses the value after setting this. memaddr cannot be negative so simplify and change comment. Idea-by: Nelson Chu <nelson@rivosinc.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.
For ELF files with many symbols and/or sections (static libraries, partially
linked files [e.g. vmlinux.o] or large object files), the disassembler is
drastically slowed down by looking up the suitable mapping symbol.
This is caused by the fact that:
- It used an inefficient linear search to find the suitable mapping symbol
- symtab_pos is not always a good hint for forward linear search and
- The symbol table accessible by the disassembler is sorted by address and
then section (not section, then address).
They sometimes force O(n^2) mapping symbol search time while searching for
the suitable mapping symbol for given address.
This commit implements:
- A binary search to look up suitable mapping symbol (O(log(n)) time per
a lookup call, O(m + n*log(n)) time on initialization where n < m),
- Separate mapping symbol table, sorted by section and then address
(unless the section to disassemble is NULL),
- A very short linear search, even faster than binary search,
when disassembling consecutive addresses (usually traverses only 1 or 2
symbols, O(n) on the worst case but this is only expected on adversarial
samples) and
- Efficient tracking of mapping symbols with ISA string
(by propagating arch field of "$x+(arch)" to succeeding "$x" symbols).
It also changes when the disassembler reuses the last mapping symbol. This
commit only uses the last disassembled address to determine whether the last
mapping symbol should be reused.
This commit doesn't improve the disassembler performance much on regular
programs in general. However, it expects >50% disassembler performance
improvements on some files that "RISC-V: Use faster hash table on
disassembling" was not effective enough.
opcodes/ChangeLog:
* disassemble.c (disassemble_free_target): Call new
disassemble_free_riscv function to free the memory.
* disassemble.h (disassemble_free_riscv): Declare.
* riscv-dis.c (struct riscv_mapping_sym): Separate structure to
represent a mapping symbol and ISA string corresponding to it.
(struct riscv_private_data): Add mapping symbol-related fields.
Add is_elf_with_mapsyms.
(last_map_symbol, last_stop_offset): Remove. The role is replaced
by riscv_private_data.{last_mapping_sym,expected_next_addr}.
(from_last_map_symbol): Remove as this is no longer required with
the new design.
(init_riscv_dis_private_data): Initialize new fields. Filter
mapping symbols and make a separate mapping symbol table.
(compare_mapping_syms_without_section): New function to sort
mapping symbols when the current section is NULL.
(compare_mapping_syms_with_section): New function to sort mapping
symbols when the current section is not NULL.
(riscv_propagate_prev_arch_for_mapping_syms): New function to
propagate arch field to succeeding mapping "$x" symbols.
(init_riscv_dis_private_data_for_section): Reset last_mapping_sym.
Sort the mapping symbol table depending on the current section and
propagate arch field.
(riscv_get_map_state): Remove.
(riscv_search_mapping_sym): Do a binary search to update the
mapping state but without reinitializing the architecture here.
(riscv_search_mapping_symbol): Use riscv_search_mapping_sym to
do a optimized lookup. Reuse the last mapping symbol if able.
Use is_elf_with_mapsyms to determine whether the object is an ELF
one with mapping symbols.
(riscv_data_length): Use last_mapping_sym instead of
last_map_symbol.
(print_insn_riscv): Add a comment. Update the architecture if the
suitable mapping symbol in the table has a non-default one.
Update expected_next_addr here.
(disassemble_free_riscv): Free the mapping symbol table.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wiki Page (details): https://github.com/a4lg/binutils-gdb/wiki/riscv_dis_opt1_2_mapping