Skip to content
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

Improve Jump Table Symbolization Algorithm #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

witbring
Copy link

I observed that RetroWrite missed some jump table entries when they refers to
the function boundary. The following assembly code that gcc-9 compiler emitted
represents the error case. Since the second jump table entry refers to label
.LBB38_624, which was defined at the function boundary, RetroWrite misses 6
jump table entries.

get_machine_flags:
    # ...
    leaq    .LJTI38_6(%rip), %rax
    movslq  (%rax,%r15,4), %rcx
    addq    %rax, %rcx
    jmpq    *%rcx
    # ...
    jmp .LBB38_535        #end of get_machine_flags
.LBB38_624:
    .cfi_endproc

.LJTI38_6:
    .long   .LBB38_47-.LJTI38_6
    .long   .LBB38_624-.LJTI38_6  # Miss
    .long   .LBB38_355-.LJTI38_6  # Miss
    .long   .LBB38_624-.LJTI38_6  # Miss
    .long   .LBB38_360-.LJTI38_6  # Miss
    .long   .LBB38_624-.LJTI38_6  # Miss
    .long   .LBB38_353-.LJTI38_6  # Miss

I added is_located_at_the_end_of_function() method to check function boundary
and define additional label to symbolize jump table entry. Also, I revised
symbolize_switch_tables() method to resolve the error.

I observed that RetroWrite missed some jump table entries when they refers to
the function boundary. The following assembly code that gcc-9 compiler emitted
represents the error case. Since the second jump table entry refers to label
.LBB38_624, which was defined at the function boundary, RetroWrite misses 6
jump table entries.

I added is_located_at_the_end_of_function() method to check function boundary
and define additional label to symbolize jump table entry. Also, I revised
symbolize_switch_tables() method to resolve the error.

```
get_machine_flags:
    # ...
    leaq    .LJTI38_6(%rip), %rax
    movslq  (%rax,%r15,4), %rcx
    addq    %rax, %rcx
    jmpq    *%rcx
    # ...
    jmp .LBB38_535        #end of get_machine_flags
.LBB38_624:
    .cfi_endproc

.LJTI38_6:
    .long   .LBB38_47-.LJTI38_6
    .long   .LBB38_624-.LJTI38_6  # Miss
    .long   .LBB38_355-.LJTI38_6  # Miss
    .long   .LBB38_624-.LJTI38_6  # Miss
    .long   .LBB38_360-.LJTI38_6  # Miss
    .long   .LBB38_624-.LJTI38_6  # Miss
    .long   .LBB38_353-.LJTI38_6  # Miss

```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant