-
Notifications
You must be signed in to change notification settings - Fork 2
Disassembler: Core Optimization 1-2 (Mapping symbols) #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
a4lg
wants to merge
3
commits into
riscv-dis-opt1-1-hashtable-and-caching
Choose a base branch
from
riscv-dis-opt1-2-mapping
base: riscv-dis-opt1-1-hashtable-and-caching
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Disassembler: Core Optimization 1-2 (Mapping symbols) #89
a4lg
wants to merge
3
commits into
riscv-dis-opt1-1-hashtable-and-caching
from
riscv-dis-opt1-2-mapping
Conversation
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
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
4d1b2e2 to
89d9259
Compare
e1a793e to
97be487
Compare
89d9259 to
0503ae0
Compare
97be487 to
5da6585
Compare
19b5c6a to
fba1e6e
Compare
f8d4788 to
d08c88a
Compare
556828e to
b8f7218
Compare
6921cd1 to
ebdb18b
Compare
33a5cee to
f298147
Compare
491c911 to
f1b6d8a
Compare
6de3f96 to
846b59c
Compare
37af5cd to
84734db
Compare
846b59c to
6643949
Compare
84734db to
30b8505
Compare
6643949 to
057a7fc
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 <[email protected]>
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.
057a7fc to
c77bc7e
Compare
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