Browse Source
A GCFG (ginsn control flow graph) is created for SCFI purposes in GAS. The existing GCFG creation process was ignoring some paths. add_bb_at_ginsn () is a recursive function which should return the root of the added basic blocks. This property was being violated in some traversals, e.g., where a taken path involving a sequence of a few basic blocks eventually culminated in a GINSN_TYPE_RETURN instruction. This patch fixes the issue by keeping an explicit variable root_bb to memorize the bb to be returned. Next, find_or_make_bb () must either create or find the bb with the first ginsn as the provided ginsn. Add a few assertions to ensure health of the cfg creation process. Note that the testcase, in its current shape, is not fit for catching regressions for the issue at hand. Although the testcase does exercise the updated code path, the testcase passes even without the current fix, because the added edge in this specific testcase does not alter the synthesized CFI. (The missing edge is the fallthrough edge of the conditional branch "jne .L13" in the testcase.) Using a manual gcfg_print (), one can see the missing edge without the fix. Lets keep the testcase for now, until there is a better way to test the GCFG for this issue (e.g., either by dumping the GCFG in textual format, or a case when the missing edge does cause wrong synthesized CFI). gas/ * ginsn.c (bb_add_edge): Fix a code comment. (find_bb): Likewise. (find_or_make_bb): Add new assertions to ensure health of cfg creation process. (add_bb_at_ginsn): Keep reference to the root_bb and return it. gas/testsuite/ * gas/scfi/x86_64/scfi-x86-64.exp: Add new test. * gas/scfi/x86_64/scfi-cfg-4.d: New test. * gas/scfi/x86_64/scfi-cfg-4.l: New test. * gas/scfi/x86_64/scfi-cfg-4.s: New test.master
5 changed files with 164 additions and 26 deletions
@ -0,0 +1,43 @@ |
|||
#as: --scfi=experimental -W |
|||
#as: |
|||
#objdump: -Wf |
|||
#name: Synthesize CFI in presence of control flow 4 |
|||
#... |
|||
Contents of the .eh_frame section: |
|||
|
|||
00000000 0+0014 0+0000 CIE |
|||
Version: 1 |
|||
Augmentation: "zR" |
|||
Code alignment factor: 1 |
|||
Data alignment factor: -8 |
|||
Return address column: 16 |
|||
Augmentation data: 1b |
|||
DW_CFA_def_cfa: r7 \(rsp\) ofs 8 |
|||
DW_CFA_offset: r16 \(rip\) at cfa-8 |
|||
DW_CFA_nop |
|||
DW_CFA_nop |
|||
|
|||
0+0018 0+002c 0+001c FDE cie=00000000 pc=0000000000000000..0000000000000045 |
|||
DW_CFA_advance_loc: 1 to 0000000000000001 |
|||
DW_CFA_def_cfa_offset: 16 |
|||
DW_CFA_offset: r3 \(rbx\) at cfa-16 |
|||
DW_CFA_advance_loc: 6 to 0000000000000007 |
|||
DW_CFA_def_cfa_offset: 32 |
|||
DW_CFA_advance_loc: 15 to 0000000000000016 |
|||
DW_CFA_remember_state |
|||
DW_CFA_advance_loc: 4 to 000000000000001a |
|||
DW_CFA_def_cfa_offset: 16 |
|||
DW_CFA_advance_loc: 1 to 000000000000001b |
|||
DW_CFA_restore: r3 \(rbx\) |
|||
DW_CFA_def_cfa_offset: 8 |
|||
DW_CFA_advance_loc: 1 to 000000000000001c |
|||
DW_CFA_restore_state |
|||
DW_CFA_advance_loc: 35 to 000000000000003f |
|||
DW_CFA_def_cfa_offset: 16 |
|||
DW_CFA_advance_loc: 1 to 0000000000000040 |
|||
DW_CFA_restore: r3 \(rbx\) |
|||
DW_CFA_def_cfa_offset: 8 |
|||
DW_CFA_nop |
|||
#... |
|||
|
|||
#pass |
|||
@ -0,0 +1,2 @@ |
|||
.*Assembler messages: |
|||
.*5: Warning: SCFI ignores most user-specified CFI directives |
|||
@ -0,0 +1,42 @@ |
|||
.text |
|||
.globl foo_handler |
|||
.type foo_handler, @function |
|||
foo_handler: |
|||
.cfi_startproc |
|||
pushq %rbx |
|||
.cfi_def_cfa_offset 16 |
|||
.cfi_offset %rbx, -16 |
|||
movl %esi, %ebx |
|||
subq $16, %rsp |
|||
.cfi_def_cfa_offset 32 |
|||
movl current_style(%rip), %eax |
|||
cmpl $-1, %eax |
|||
je .L12 |
|||
testb $4, %al |
|||
jne .L13 |
|||
.L1: |
|||
.cfi_remember_state |
|||
addq $16, %rsp |
|||
.cfi_def_cfa_offset 16 |
|||
popq %rbx |
|||
.cfi_restore %rbx |
|||
.cfi_def_cfa_offset 8 |
|||
ret |
|||
.L13: |
|||
.cfi_restore_state |
|||
movq %rdi, 8(%rsp) |
|||
call foo_handler_v2 |
|||
testq %rax, %rax |
|||
jne .L1 |
|||
movl current_style(%rip), %eax |
|||
movq 8(%rsp), %rdi |
|||
jmp .L3 |
|||
.L12: |
|||
addq $16, %rsp |
|||
.cfi_def_cfa_offset 16 |
|||
popq %rbx |
|||
.cfi_restore %rbx |
|||
.cfi_def_cfa_offset 8 |
|||
jmp xstrdup |
|||
.cfi_endproc |
|||
.size foo_handler, .-foo_handler |
|||
Loading…
Reference in new issue