Skip to content

Commit

Permalink
gas: aarch64: testsuite: add new tests for SCFI
Browse files Browse the repository at this point in the history
[Changes in V5]
 - Rename the previously added testcase scfi-diag-3 for SVE memory op to
   scfi-unsupported-2.  This will help keep track of the work to be done
   in near future.
 - Add new testcase scfi-diag-3 where the insn " b symbol+1" leads to an
   error:
      "Error: SCFI: 0x14000000 op with non-zero addend to sym not supported"
 - Add "stg sp, [sp, 32]!" and "ldpsw x8, x15, [sp, -256]" to ginsn-ldst-1.
 - Add prfm, irg, addg ops to ginsn-misc-1.
 - Add ldrsw, ldpsw ops to ginsn-misc-1.
 - Adjust ginsn-ldst-1 as now S and W register loads and stores are
   skipped.
 - Added a new testcase scfi-ldstnap-1 which includes some insns from
   iclass ldstnapair_offs.
[End of changes in V5]

[Changes in V4]
 - New testcases for FP callee-saved registers.
   scfi-callee-saved-fp-1.s uses D registers, scfi-callee-saved-fp-2.s
   uses Q registers and is run with -mbig-endian.
 - Added new ops (movk, prfm) to ginsn-misc-1. These ops are not
   relevant for SCFI correctness; this testcase merely
   ensures graceful handling of ginsn creation for such insns.
 - Fixed ginsn-ldst-1 as it included some load / store ops with D
   registers, which we now handle.  Also added some insns using W and S
   registers.
 - Added a new test scfi-diag-3 where SCFI machinery reports the
   following error when it sees an SVE memory op with callee-saved
   register:
    "Error: SCFI: unhandled op 0xe5e0e000 may cause incorrect CFI"
[End of changes in V4]

[No changes in V3]

[Changes in V2]
 - new testcase scfi-cfg-4.s for the changes in cmp_scfi_state.
 - new testcase ginsn-arith-1.s for ginsn creation for various add sub insns.
 - removed redundant insns from ginsn-misc-1.s, some of those insns are
   now in ginsn-arith-1.s.
 - added more ld st opts in ginsn-ldst-1.s testcase.
[End of changes in V2]

Similar to the x86_64 testcases, some .s files contain the corresponding
CFI directives.  This helps in validating the synthesized CFI by running
those tests with and without the --scfi=experimental command line
option.

GAS issues some diagnostics, enabled by default, with
--scfi=experimental.  The diagnostics have been added with an intent to
help user correct inadvertent errors in their hand-written asm.  An
error is issued when GAS finds that input asm is not amenable to
accurate CFI synthesis.  The existing scfi-diag-*.s tests in the
gas/testsuite/gas/scfi/x86_64 directory test some SCFI diagnostics
already:

      - (#1) "Warning: SCFI: Asymetrical register restore"
      - (#2) "Error: SCFI: usage of REG_FP as scratch not supported"
      - (#3) "Error: SCFI: unsupported stack manipulation pattern"
      - (#4) "Error: untraceable control flow for func 'XXX'"

In the newly added aarch64 testsuite, further tests for additional
diagnostics have been added:
 - scfi-diag-1.s in this patch highlights an aarch64-specific diagnostic:
   (#5) "Warning: SCFI: ignored probable save/restore op with reg offset"

Additionally, some testcases are added to showcase the (currently)
unsupported patterns, e.g., scfi-unsupported-1.s
        mov     x16, 4384
        sub     sp, sp, x16

gas/testsuite/:
	* gas/scfi/README: Update comment to include aarch64.
	* gas/scfi/aarch64/scfi-aarch64.exp: New file.
	* gas/scfi/aarch64/ginsn-arith-1.l: New test.
	* gas/scfi/aarch64/ginsn-arith-1.s: New test.
	* gas/scfi/aarch64/ginsn-cofi-1.l: New test.
	* gas/scfi/aarch64/ginsn-cofi-1.s: New test.
	* gas/scfi/aarch64/ginsn-ldst-1.l: New test.
	* gas/scfi/aarch64/ginsn-ldst-1.s: New test.
	* gas/scfi/aarch64/scfi-callee-saved-fp-1.d: New test.
	* gas/scfi/aarch64/scfi-callee-saved-fp-1.l: New test.
	* gas/scfi/aarch64/scfi-callee-saved-fp-1.s: New test.
	* gas/scfi/aarch64/scfi-callee-saved-fp-2.d: New test.
	* gas/scfi/aarch64/scfi-callee-saved-fp-2.l: New test.
	* gas/scfi/aarch64/scfi-callee-saved-fp-2.s: New test.
	* gas/scfi/aarch64/scfi-cb-1.d: New test.
	* gas/scfi/aarch64/scfi-cb-1.l: New test.
	* gas/scfi/aarch64/scfi-cb-1.s: New test.
	* gas/scfi/aarch64/scfi-cfg-1.d: New test.
	* gas/scfi/aarch64/scfi-cfg-1.l: New test.
	* gas/scfi/aarch64/scfi-cfg-1.s: New test.
	* gas/scfi/aarch64/scfi-cfg-2.d: New test.
	* gas/scfi/aarch64/scfi-cfg-2.l: New test.
	* gas/scfi/aarch64/scfi-cfg-2.s: New test.
	* gas/scfi/aarch64/scfi-cfg-3.d: New test.
	* gas/scfi/aarch64/scfi-cfg-3.l: New test.
	* gas/scfi/aarch64/scfi-cfg-3.s: New test.
	* gas/scfi/aarch64/scfi-cfg-4.l: New test.
	* gas/scfi/aarch64/scfi-cfg-4.s: New test.
	* gas/scfi/aarch64/scfi-cond-br-1.d: New test.
	* gas/scfi/aarch64/scfi-cond-br-1.l: New test.
	* gas/scfi/aarch64/scfi-cond-br-1.s: New test.
	* gas/scfi/aarch64/scfi-diag-1.l: New test.
	* gas/scfi/aarch64/scfi-diag-1.s: New test.
	* gas/scfi/aarch64/scfi-diag-2.l: New test.
	* gas/scfi/aarch64/scfi-diag-2.s: New test.
	* gas/scfi/aarch64/scfi-diag-3.l: New test.
	* gas/scfi/aarch64/scfi-diag-3.s: New test.
	* gas/scfi/aarch64/scfi-ldrp-1.d: New test.
	* gas/scfi/aarch64/scfi-ldrp-1.l: New test.
	* gas/scfi/aarch64/scfi-ldrp-1.s: New test.
	* gas/scfi/aarch64/scfi-ldrp-2.d: New test.
	* gas/scfi/aarch64/scfi-ldrp-2.l: New test.
	* gas/scfi/aarch64/scfi-ldrp-2.s: New test.
	* gas/scfi/aarch64/scfi-ldstnap-1.d: New test.
	* gas/scfi/aarch64/scfi-ldstnap-1.l: New test.
	* gas/scfi/aarch64/scfi-ldstnap-1.s: New test.
	* gas/scfi/aarch64/scfi-strp-1.d: New test.
	* gas/scfi/aarch64/scfi-strp-1.l: New test.
	* gas/scfi/aarch64/scfi-strp-1.s: New test.
	* gas/scfi/aarch64/scfi-strp-2.d: New test.
	* gas/scfi/aarch64/scfi-strp-2.l: New test.
	* gas/scfi/aarch64/scfi-strp-2.s: New test.
	* gas/scfi/aarch64/scfi-unsupported-1.l: New test.
	* gas/scfi/aarch64/scfi-unsupported-1.s: New test.
	* gas/scfi/aarch64/scfi-unsupported-2.l: New test.
	* gas/scfi/aarch64/scfi-unsupported-2.s: New test.
  • Loading branch information
ibhagatgnu committed Jul 13, 2024
1 parent e66ee71 commit 566a29d
Show file tree
Hide file tree
Showing 59 changed files with 1,435 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gas/testsuite/gas/scfi/README
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Notes on the SCFI testsuite in GAS:

* At this time, SCFI machinery is only supported for x86_64.
* At this time, SCFI machinery is only supported for x86_64 and aarch64.

* When adding more tests, please keep CFI annotations updated in the .s files.
Ideally the test should be run with and without --scfi (as is done currently
Expand Down
35 changes: 35 additions & 0 deletions gas/testsuite/gas/scfi/aarch64/ginsn-arith-1.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.*: Assembler messages:
.*:13: Error: SCFI: unsupported stack manipulation pattern
.*:16: Error: SCFI: forward pass failed for func 'foo'

AARCH64 GAS .*


1 # Testcase for a variety of arith instructions
2 .text
3 .align 2
4 .global foo
5 .type foo, %function
5 ginsn: SYM FUNC_BEGIN
6 foo:
6 ginsn: SYM foo
7 \?\?\?\? FF830091 add sp, sp, 32
7 ginsn: ADD %r31, 32, %r31
8 \?\?\?\? FD5B21B1 adds x29, sp, 2134
8 ginsn: ADD %r31, 2134, %r29
9 \?\?\?\? FF8300D1 sub sp, sp, 32
9 ginsn: SUB %r31, 32, %r31
10 \?\?\?\? FD5B21F1 subs x29, sp, 2134
10 ginsn: SUB %r31, 2134, %r29
11 \?\?\?\? FD63228B add x29, sp, x2
11 ginsn: ADD %r31, %r2, %r29
12 \?\?\?\? FD6323CB sub x29, sp, x3
12 ginsn: SUB %r31, %r3, %r29
13 \?\?\?\? BF63238B add sp, x29, x3
13 ginsn: ADD %r29, %r3, %r31
14 \?\?\?\? BF6322CB sub sp, x29, x2
14 ginsn: SUB %r29, %r2, %r31
15 \?\?\?\? C0035FD6 ret
15 ginsn: RET
16 .size foo, .-foo
16 ginsn: SYM FUNC_END
16 changes: 16 additions & 0 deletions gas/testsuite/gas/scfi/aarch64/ginsn-arith-1.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Testcase for a variety of arith instructions
.text
.align 2
.global foo
.type foo, %function
foo:
add sp, sp, 32
adds x29, sp, 2134
sub sp, sp, 32
subs x29, sp, 2134
add x29, sp, x2
sub x29, sp, x3
add sp, x29, x3
sub sp, x29, x2
ret
.size foo, .-foo
30 changes: 30 additions & 0 deletions gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.*: Assembler messages:
.*:16: Error: untraceable control flow for func 'foo'

AARCH64 GAS .*

1 # Testcase for a variety of change of flow instructions
2 # Because some of these are indirect branches, SCFI will bail out
3 # with an error. This test merely checks that the ginsn creation
4 # process can handle these insns gracefully.
5 .text
6 .align 2
7 .global foo
8 .type foo, %function
8 ginsn: SYM FUNC_BEGIN
9 foo:
9 ginsn: SYM foo
10 \?\?\?\? 00000094 bl dump_bt
10 ginsn: CALL
11 \?\?\?\? 02000014 b .L3
11 ginsn: JMP
12 \?\?\?\? 20021FD6 br x17
12 ginsn: JMP %r17,
13 .L3:
13 ginsn: SYM .L3
14 \?\?\?\? 60003FD6 blr x3
14 ginsn: CALL
15 \?\?\?\? C0035FD6 ret
15 ginsn: RET
16 .size foo, .-foo
16 ginsn: SYM FUNC_END
16 changes: 16 additions & 0 deletions gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Testcase for a variety of change of flow instructions
# Because some of these are indirect branches, SCFI will bail out
# with an error. This test merely checks that the ginsn creation
# process can handle these insns gracefully.
.text
.align 2
.global foo
.type foo, %function
foo:
bl dump_bt
b .L3
br x17
.L3:
blr x3
ret
.size foo, .-foo
77 changes: 77 additions & 0 deletions gas/testsuite/gas/scfi/aarch64/ginsn-ldst-1.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
AARCH64 GAS .*

1 # Testcase for a variety of ld st instructions.
2 # stg ops must generate the sp update arithmetic insn, when applicable
3 # due to writeback.
4 .text
5 .align 2
6 .global foo
7 .type foo, %function
7 ginsn: SYM FUNC_BEGIN
8 foo:
8 ginsn: SYM foo
9 # ldstpair_indexed
10 0000 FF7F8629 stp wzr, wzr, \[sp, 48\]!
10 ginsn: ADD %r31, 48, %r31
11 0004 E00782A9 stp x0, x1, \[sp, 32\]!
11 ginsn: ADD %r31, 32, %r31
11 ginsn: STORE %r0, \[%r31\+0\]
11 ginsn: STORE %r1, \[%r31\+8\]
12 0008 E827BC6D stp d8, d9, \[sp, -64\]!
12 ginsn: ADD %r31, -64, %r31
12 ginsn: STORE %r72, \[%r31\+0\]
12 ginsn: STORE %r73, \[%r31\+8\]
13 000c E827C46C ldp d8, d9, \[sp\], 64
13 ginsn: LOAD \[%r31\+0\], %r72
13 ginsn: LOAD \[%r31\+8\], %r73
13 ginsn: ADD %r31, 64, %r31
14 # 32-bit FP regs
15 0010 E51BB42D stp s5, s6, \[sp, -96\]!
15 ginsn: ADD %r31, -96, %r31
16 0014 E51BCC2C ldp s5, s6, \[sp\], 96
16 ginsn: ADD %r31, 96, %r31
17 # 32-bit INT regs
18 0018 E10BB029 stp w1, w2, \[sp, -128\]!
18 ginsn: ADD %r31, -128, %r31
19 001c E10BD028 ldp w1, w2, \[sp\], 128
19 ginsn: ADD %r31, 128, %r31
20 # ldstpair_off
21 0020 E00702AD stp q0, q1, \[sp, 64\]
21 ginsn: STORE %r64, \[%r31\+64\]
21 ginsn: STORE %r65, \[%r31\+80\]
22 0024 FF7F0629 stp wzr, wzr, \[sp, 48\]
23 0028 1F7840AD ldp q31, q30, \[x0\]
23 ginsn: LOAD \[%r0\+0\], %r95
23 ginsn: LOAD \[%r0\+16\], %r94
24 # ldst_imm9
25 002c E78F4F38 ldrb w7, \[sp, 248\]!
25 ginsn: ADD %r31, 248, %r31
26 0030 FD0FC33C ldr q29, \[sp, 48\]!
26 ginsn: ADD %r31, 48, %r31
26 ginsn: LOAD \[%r31\+0\], %r93
27 0034 FF0F42B8 ldr wzr, \[sp, 32\]!
27 ginsn: ADD %r31, 32, %r31
28 0038 E30742F8 ldr x3, \[sp\], 32
28 ginsn: LOAD \[%r31\+0\], %r3
28 ginsn: ADD %r31, 32, %r31
29 # 32-bit ldr
30 003c E10744BC ldr s1, \[sp\], 64
30 ginsn: ADD %r31, 64, %r31
AARCH64 GAS .*


31 # ldst_pos
32 0040 FF3340B9 ldr wzr, \[sp, 48\]
33 0044 FD1300F9 str x29, \[sp, 32\]
33 ginsn: STORE %r29, \[%r31\+32\]
34 0048 FD1340F9 ldr x29, \[sp, 32\]
34 ginsn: LOAD \[%r31\+32\], %r29
35 # store tag
36 004c FF2F20D9 stg sp, \[sp, 32\]!
36 ginsn: ADD %r31, 32, %r31
37 # ldpsw
38 0050 E83F6069 ldpsw x8, x15, \[sp, -256\]
39 0054 C0035FD6 ret
39 ginsn: RET
40 .size foo, .-foo
40 ginsn: SYM FUNC_END
40 changes: 40 additions & 0 deletions gas/testsuite/gas/scfi/aarch64/ginsn-ldst-1.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Testcase for a variety of ld st instructions.
# stg ops must generate the sp update arithmetic insn, when applicable
# due to writeback.
.text
.align 2
.global foo
.type foo, %function
foo:
# ldstpair_indexed
stp wzr, wzr, [sp, 48]!
stp x0, x1, [sp, 32]!
stp d8, d9, [sp, -64]!
ldp d8, d9, [sp], 64
# 32-bit FP regs
stp s5, s6, [sp, -96]!
ldp s5, s6, [sp], 96
# 32-bit INT regs
stp w1, w2, [sp, -128]!
ldp w1, w2, [sp], 128
# ldstpair_off
stp q0, q1, [sp, 64]
stp wzr, wzr, [sp, 48]
ldp q31, q30, [x0]
# ldst_imm9
ldrb w7, [sp, 248]!
ldr q29, [sp, 48]!
ldr wzr, [sp, 32]!
ldr x3, [sp], 32
# 32-bit ldr
ldr s1, [sp], 64
# ldst_pos
ldr wzr, [sp, 48]
str x29, [sp, 32]
ldr x29, [sp, 32]
# store tag
stg sp, [sp, 32]!
# ldpsw
ldpsw x8, x15, [sp, -256]
ret
.size foo, .-foo
37 changes: 37 additions & 0 deletions gas/testsuite/gas/scfi/aarch64/ginsn-misc-1.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.*: Assembler messages:
.*:13: Error: SCFI: unsupported stack manipulation pattern
.*:23: Error: SCFI: forward pass failed for func 'foo'

AARCH64 GAS .*


1 # Testcase for a variety of misc instructions.
2 # Ensure graceful handling, irrespective of ginsn generation.
3 # - ldrsw, ldpsw ops need a mention: they are 32-bit loads from memory
4 # and cannot be used for reg restore. For CFI purposes, the width has to be
5 # 8 bytes or more. Expect no memory ginsn ever as ginsn do not track width
6 # of memory accesses yet.
7 symbol:
8 \?\?\?\? 7700 .string "w"
9
10 .type foo, %function
10 ginsn: SYM FUNC_BEGIN
11 foo:
11 ginsn: SYM foo
12 \?\?\?\? 00000000 adrp x0, symbol
12 0090
13 \?\?\?\? 1F000091 add sp, x0, :lo12:symbol
13 ginsn: OTH 0, 0, %r31
14 \?\?\?\? 2000A0F2 movk x0, 0x1, lsl 16
15 \?\?\?\? E10380F9 prfm PLDL1STRM, \[sp\]
16 \?\?\?\? E013DF9A irg x0, sp
17 \?\?\?\? 000820D9 stg x0, \[x0\]
18 \?\?\?\? E03FBF91 addg x0, sp, #0x3f0, #0xf
19 \?\?\?\? 1F3CAA91 addg sp, x0, #0x2a0, #0xf
19 ginsn: OTH 0, 0, %r31
20 \?\?\?\? F3534069 ldpsw x19, x20, \[sp\]
21 \?\?\?\? 9B0080B9 ldrsw x27, \[x4\]
22 \?\?\?\? C0035FD6 ret
22 ginsn: RET
23 .size foo,.-foo
23 ginsn: SYM FUNC_END
23 changes: 23 additions & 0 deletions gas/testsuite/gas/scfi/aarch64/ginsn-misc-1.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Testcase for a variety of misc instructions.
# Ensure graceful handling, irrespective of ginsn generation.
# - ldrsw, ldpsw ops need a mention: they are 32-bit loads from memory
# and cannot be used for reg restore. For CFI purposes, the width has to be
# 8 bytes or more. Expect no memory ginsn ever as ginsn do not track width
# of memory accesses yet.
symbol:
.string "w"

.type foo, %function
foo:
adrp x0, symbol
add sp, x0, :lo12:symbol
movk x0, 0x1, lsl 16
prfm PLDL1STRM, [sp]
irg x0, sp
stg x0, [x0]
addg x0, sp, #0x3f0, #0xf
addg sp, x0, #0x2a0, #0xf
ldpsw x19, x20, [sp]
ldrsw x27, [x4]
ret
.size foo,.-foo
74 changes: 74 additions & 0 deletions gas/testsuite/gas/scfi/aarch64/scfi-aarch64.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright (C) 2022-2023 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.

if { ![is_elf_format] } then {
return
}

# common tests
if { ([istarget "aarch64-*-*"]) } then {

global ASFLAGS
set old_ASFLAGS "$ASFLAGS"

run_list_test "ginsn-arith-1" "--scfi=experimental -ali --warn"
run_list_test "ginsn-cofi-1" "--scfi=experimental -ali --warn"
run_list_test "ginsn-ldst-1" "--scfi=experimental -march=armv8-a+memtag -ali --warn"
run_list_test "ginsn-misc-1" "--scfi=experimental -march=armv8-a+memtag -ali --warn"

run_list_test "scfi-diag-1" "--scfi=experimental"
run_list_test "scfi-diag-2" "--scfi=experimental"
run_list_test "scfi-diag-3" "--scfi=experimental"

run_list_test "scfi-unsupported-1" "--scfi=experimental"
run_list_test "scfi-unsupported-2" "--scfi=experimental"

run_dump_test "scfi-callee-saved-fp-1"
run_list_test "scfi-callee-saved-fp-1" "--scfi=experimental --warn"
run_dump_test "scfi-callee-saved-fp-2"
run_list_test "scfi-callee-saved-fp-2" "--scfi=experimental --warn"

run_dump_test "scfi-ldrp-1"
run_list_test "scfi-ldrp-1" "--scfi=experimental --warn"
run_dump_test "scfi-ldrp-2"
run_list_test "scfi-ldrp-2" "--scfi=experimental --warn"

run_dump_test "scfi-strp-1"
run_list_test "scfi-strp-1" "--scfi=experimental --warn"
run_dump_test "scfi-strp-2"
run_list_test "scfi-strp-2" "--scfi=experimental --warn"

run_dump_test "scfi-ldstnap-1"
run_list_test "scfi-ldstnap-1" "--scfi=experimental --warn"

run_dump_test "scfi-cb-1"
run_list_test "scfi-cb-1" "--scfi=experimental --warn"
run_dump_test "scfi-cond-br-1"
run_list_test "scfi-cond-br-1" "--scfi=experimental --warn"

run_dump_test "scfi-cfg-1"
run_list_test "scfi-cfg-1" "--scfi=experimental --warn"

run_dump_test "scfi-cfg-2"
run_list_test "scfi-cfg-2" "--scfi=experimental --warn"

run_dump_test "scfi-cfg-3"
run_list_test "scfi-cfg-3" "--scfi=experimental --warn"

run_dump_test "scfi-cfg-4"
run_list_test "scfi-cfg-4" "--scfi=experimental --warn"

}
Loading

0 comments on commit 566a29d

Please sign in to comment.