Browse Source
PR gas/31326
SCFI must handle non QWORD ALU with imm and MOV ops correctly
As per the x86 ISA manual:
- 32-bit operands generate a 32-bit result, zero-extended to a 64-bit
result in the destination general-purpose register.
- 8-bit and 16-bit operands generate an 8-bit or 16-bit result. The
upper 56 bits or 48 bits (respectively) of the destination
general-purpose register are not modified by the operation.
Unlike previously thought, sub-QWORD ALU/imm and MOV ops do have
implications on SCFI. SCFI/ginsn machinery does not track operation size
in the ginsn representation. But given that these sub-QWORD ops update
only a portion of a 64-bit destination register, for SCFI purposes, this
needs to be deemed as an untraceable update (when the destination is
REG_SP / REG_FP). Although in most cases, sub-QWORD ops are not expected
for stack management, but the SCFI machinery must behave correctly, when
such ops are indeed present.
As mentioned earlier, ginsn representation does not carry operation size
information. To resolve the issue raised in PR gas/31326, an option is
to force the generation of GINSN_TYPE_OTHER for all cases when there is
a 8/16/32 bit op. But this may dilute the utility of ginsn for other
use-cases, when they pop up in future.
The current approach is less disruptive than above in that it generates
GINSN_TYPE_OTHER for all cases only when:
- there is a 8/16/32 bit op, and
- the 64-bit op is otherwise traceable.
In other words this means:
- For add/sub ops where dest is reg and src is reg/mem: these always
make dest reg untraceable; So, the current handling is unchanged. We
simply skip detecting 8/16/32-bit ops.
- An x86 pop instruction is translated to a load ginsn followed by a stack
increment add op. A load op always makes dest reg untraceable.
Hence, if the pop instruction is sub-QWORD, we continue to (skip
detecting 8/16/32-bit op, and) generate the load instruction as usual.
This means that if input asm does have save and restore of unequal sized
registers, gas/SCFI will not detect nor warn.
- For ALU imm or MOV reg,reg, however, a GINSN_TYPE_OTHER is generated
when a 8/16/32-bit op is seen.
gas/
PR gas/31326
* config/tc-i386.c (x86_ginsn_addsub_reg_mem): Add a code
comment.
(x86_ginsn_addsub_mem_reg): Likewise.
(x86_ginsn_alu_imm): Detect sub-QWORD opsize and exit early.
(x86_ginsn_move): Likewise.
(x86_ginsn_new): Add comment for 8-bit add/sub opcodes (in
opcode_space SPACE_BASE) about skipped handling.
gas/testsuite/:
PR gas/31326
* gas/scfi/x86_64/ginsn-add-1.l: Update.
* gas/scfi/x86_64/ginsn-add-1.s: Add some sub-QWORD add ops.
* gas/scfi/x86_64/ginsn-dw2-regnum-1.l: Update.
* gas/scfi/x86_64/ginsn-dw2-regnum-1.s: Use mov ops instead of
add to invoke and test the ginsn_dw2_regnum code path.
master
5 changed files with 149 additions and 96 deletions
@ -1,69 +1,85 @@ |
|||
GAS LISTING .* |
|||
|
|||
|
|||
.*# Testcase for DWARF regnum ginsn API |
|||
1 # Testcase for DWARF regnum ginsn API |
|||
2 .text |
|||
3 .globl foo |
|||
4 .type foo, @function |
|||
4 ginsn: SYM FUNC_BEGIN |
|||
5 foo: |
|||
5 ginsn: SYM foo |
|||
6 0000 0408 add \$8, %al |
|||
7 0002 80C108 add \$8, %cl |
|||
7 ginsn: ADD %r2, 8, %r2 |
|||
8 0005 80C208 add \$8, %dl |
|||
8 ginsn: ADD %r1, 8, %r1 |
|||
9 0008 80C408 add \$8, %ah |
|||
9 ginsn: ADD %r0, 8, %r0 |
|||
10 000b 80C508 add \$8, %ch |
|||
10 ginsn: ADD %r2, 8, %r2 |
|||
11 000e 80C608 add \$8, %dh |
|||
11 ginsn: ADD %r1, 8, %r1 |
|||
12 0011 80C708 add \$8, %bh |
|||
12 ginsn: ADD %r3, 8, %r3 |
|||
13 |
|||
14 0014 4080C008 add \$8, %axl |
|||
14 ginsn: ADD %r0, 8, %r0 |
|||
15 0018 4080C408 add \$8, %spl |
|||
15 ginsn: ADD %r7, 8, %r7 |
|||
6 0000 55 push %rbp |
|||
6 ginsn: SUB %r7, 8, %r7 |
|||
6 ginsn: STORE %r6, \[%r7\+0\] |
|||
7 0001 4889E5 mov %rsp, %rbp |
|||
7 ginsn: MOV %r7, %r6 |
|||
8 |
|||
9 0004 8A40FE mov -0x2\(%rax\), %al |
|||
9 ginsn: MOV \[%r0\+-2\], %r0 |
|||
10 0007 8A58FE mov -0x2\(%rax\), %bl |
|||
10 ginsn: MOV \[%r0\+-2\], %r3 |
|||
11 000a 8A50FE mov -0x2\(%rax\), %dl |
|||
11 ginsn: MOV \[%r0\+-2\], %r1 |
|||
12 000d 8A60FE mov -0x2\(%rax\), %ah |
|||
12 ginsn: MOV \[%r0\+-2\], %r0 |
|||
13 0010 8A68FE mov -0x2\(%rax\), %ch |
|||
13 ginsn: MOV \[%r0\+-2\], %r2 |
|||
14 0013 8A70FE mov -0x2\(%rax\), %dh |
|||
14 ginsn: MOV \[%r0\+-2\], %r1 |
|||
15 0016 8A78FE mov -0x2\(%rax\), %bh |
|||
15 ginsn: MOV \[%r0\+-2\], %r3 |
|||
16 |
|||
17 001c 6683C008 add \$8, %ax |
|||
17 ginsn: ADD %r0, 8, %r0 |
|||
18 0020 664183C0 add \$8, %r8w |
|||
18 08 |
|||
18 ginsn: ADD %r8, 8, %r8 |
|||
19 0025 6683C408 add \$8, %sp |
|||
19 ginsn: ADD %r7, 8, %r7 |
|||
20 |
|||
21 0029 83C008 add \$8, %eax |
|||
21 ginsn: ADD %r0, 8, %r0 |
|||
22 002c 4183C008 add \$8, %r8d |
|||
22 ginsn: ADD %r8, 8, %r8 |
|||
23 0030 81C40040 add \$16384, %esp |
|||
23 0000 |
|||
23 ginsn: ADD %r7, 16384, %r7 |
|||
24 |
|||
25 0036 4883C508 add \$8, %rbp |
|||
25 ginsn: ADD %r6, 8, %r6 |
|||
26 |
|||
27 003a 488D05FE lea -0x2\(%rip\), %rax |
|||
27 FFFFFF |
|||
27 ginsn: ADD %r4, -2, %r0 |
|||
28 0041 67488905 mov %rax, 0x2\(%eip\) |
|||
28 02000000 |
|||
28 ginsn: MOV %r0, \[%r4\+2\] |
|||
29 0049 67488B05 mov -0x2\(%eip\), %rax |
|||
29 FEFFFFFF |
|||
29 ginsn: MOV \[%r4\+-2\], %r0 |
|||
17 0019 408A40FE mov -0x2\(%rax\), %axl |
|||
17 ginsn: MOV \[%r0\+-2\], %r0 |
|||
18 001d 408A60FE mov -0x2\(%rax\), %spl |
|||
18 ginsn: MOV \[%r0\+-2\], %r7 |
|||
19 |
|||
20 0021 668B40FE mov -0x2\(%rax\), %ax |
|||
20 ginsn: MOV \[%r0\+-2\], %r0 |
|||
21 0025 66448B40 mov -0x2\(%rax\), %r8w |
|||
21 FE |
|||
21 ginsn: MOV \[%r0\+-2\], %r8 |
|||
22 002a 668B60FE mov -0x2\(%rax\), %sp |
|||
22 ginsn: MOV \[%r0\+-2\], %r7 |
|||
23 |
|||
24 002e 4080C408 add \$8, %spl |
|||
24 ginsn: OTH 0, 0, %r7 |
|||
25 |
|||
26 0032 8B40FE mov -0x2\(%rax\), %eax |
|||
26 ginsn: MOV \[%r0\+-2\], %r0 |
|||
27 0035 448B40FE mov -0x2\(%rax\), %r8d |
|||
27 ginsn: MOV \[%r0\+-2\], %r8 |
|||
28 |
|||
29 0039 81C40040 add \$16384, %esp |
|||
29 0000 |
|||
29 ginsn: OTH 0, 0, %r7 |
|||
30 |
|||
31 0051 C3 ret |
|||
31 ginsn: RET |
|||
31 003f 4883C508 add \$8, %rbp |
|||
31 ginsn: ADD %r6, 8, %r6 |
|||
32 |
|||
33 0043 488D05FE lea -0x2\(%rip\), %rax |
|||
GAS LISTING .* |
|||
|
|||
|
|||
32 .LFE0: |
|||
32 ginsn: SYM .LFE0 |
|||
33 .size foo, .-foo |
|||
33 ginsn: SYM FUNC_END |
|||
33 FFFFFF |
|||
33 ginsn: ADD %r4, -2, %r0 |
|||
34 004a 67488905 mov %rax, 0x2\(%eip\) |
|||
34 02000000 |
|||
34 ginsn: MOV %r0, \[%r4\+2\] |
|||
35 0052 67488B05 mov -0x2\(%eip\), %rax |
|||
35 FEFFFFFF |
|||
35 ginsn: MOV \[%r4\+-2\], %r0 |
|||
36 |
|||
37 005a 4889EC mov %rbp, %rsp |
|||
37 ginsn: MOV %r6, %r7 |
|||
38 005d 5D pop %rbp |
|||
38 ginsn: LOAD \[%r7\+0\], %r6 |
|||
38 ginsn: ADD %r7, 8, %r7 |
|||
39 005e C3 ret |
|||
39 ginsn: RET |
|||
40 .LFE0: |
|||
40 ginsn: SYM .LFE0 |
|||
41 .size foo, .-foo |
|||
41 ginsn: SYM FUNC_END |
|||
|
|||
#pass |
|||
|
|||
Loading…
Reference in new issue