Skip to content

Commit bf7703a

Browse files
authored
test: add CFI tests for stack operations
1 parent 260d7aa commit bf7703a

22 files changed

+125
-191
lines changed

tests/programs/_build_cfi_native.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ build cfi_lpad_unlabeled_failed.S cfi_lpad_unlabeled_failed
2323
build cfi_lpad_func_sig.S cfi_lpad_func_sig
2424
build cfi_lpad_func_sig_zero.S cfi_lpad_func_sig_zero
2525
build cfi_lpad_func_sig_failed.S cfi_lpad_func_sig_failed
26+
build cfi_ss_only_pop.S cfi_ss_only_pop
27+
build cfi_ss_popchk_failed.S cfi_ss_popchk_failed
28+

tests/programs/cfi_lpad_func_sig

0 Bytes
Binary file not shown.

tests/programs/cfi_lpad_func_sig.S

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1+
.include "cfi_macro.h"
12

2-
.section ".note.gnu.property", "a"
3-
.balign 8
4-
.4byte 4
5-
.4byte (ndesc_end - ndesc_begin)
6-
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
7-
.asciz "GNU"
8-
ndesc_begin:
9-
.balign 8
10-
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
11-
.4byte 4
12-
.4byte 4 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG
13-
.balign 8
14-
ndesc_end:
15-
16-
.macro exit_imm val
17-
li a0, \val
18-
li a7, 93
19-
ecall
20-
.endm
3+
gnu_property_cfi_ss 4
214

225
.text
236
.global _start

tests/programs/cfi_lpad_func_sig_failed.S

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1+
.include "cfi_macro.h"
12

2-
.section ".note.gnu.property", "a"
3-
.balign 8
4-
.4byte 4
5-
.4byte (ndesc_end - ndesc_begin)
6-
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
7-
.asciz "GNU"
8-
ndesc_begin:
9-
.balign 8
10-
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
11-
.4byte 4
12-
.4byte 4 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG
13-
.balign 8
14-
ndesc_end:
15-
16-
.macro exit_imm val
17-
li a0, \val
18-
li a7, 93
19-
ecall
20-
.endm
3+
gnu_property_cfi_ss 4
214

225
.text
236
.global _start

tests/programs/cfi_lpad_func_sig_zero.S

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1+
.include "cfi_macro.h"
12

2-
.section ".note.gnu.property", "a"
3-
.balign 8
4-
.4byte 4
5-
.4byte (ndesc_end - ndesc_begin)
6-
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
7-
.asciz "GNU"
8-
ndesc_begin:
9-
.balign 8
10-
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
11-
.4byte 4
12-
.4byte 4 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG
13-
.balign 8
14-
ndesc_end:
15-
16-
.macro exit_imm val
17-
li a0, \val
18-
li a7, 93
19-
ecall
20-
.endm
3+
gnu_property_cfi_ss 4
214

225
.text
236
.global _start

tests/programs/cfi_lpad_not_active.S

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1+
.include "cfi_macro.h"
12

2-
.section ".note.gnu.property", "a"
3-
.balign 8
4-
.4byte 4
5-
.4byte (ndesc_end - ndesc_begin)
6-
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
7-
.asciz "GNU"
8-
ndesc_begin:
9-
.balign 8
10-
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
11-
.4byte 4
12-
.4byte 0 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED not active
13-
.balign 8
14-
ndesc_end:
15-
16-
.macro exit_imm val
17-
li a0, \val
18-
li a7, 93
19-
ecall
20-
.endm
3+
gnu_property_cfi_ss 0
214

225
.text
236
.global _start

tests/programs/cfi_lpad_unlabeled

128 Bytes
Binary file not shown.
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1+
.include "cfi_macro.h"
12

2-
.section ".note.gnu.property", "a"
3-
.balign 8
4-
.4byte 4
5-
.4byte (ndesc_end - ndesc_begin)
6-
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
7-
.asciz "GNU"
8-
ndesc_begin:
9-
.balign 8
10-
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
11-
.4byte 4
12-
.4byte 1 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED
13-
.balign 8
14-
ndesc_end:
15-
16-
.macro exit_imm val
17-
li a0, \val
18-
li a7, 93
19-
ecall
20-
.endm
3+
gnu_property_cfi_ss 1
214

225
.text
236
.global _start
247
_start:
258
la t1, func
269
jalr ra, t1, 0
27-
exit_imm 0
10+
11+
la t1, func
12+
c.jalr t1
13+
14+
la t1, exit
15+
c.jr t1
16+
17+
exit_imm 1
2818

2919
.globl func
3020
.type func,@function
21+
# lpad checks alignment with 4
22+
.balign 4
3123
func:
3224
lpad 0
3325
ret
26+
27+
.global exit
28+
.type func,@function
29+
# lpad checks alignment with 4
30+
.balign 4
31+
exit:
32+
lpad 0
33+
exit_imm 0

tests/programs/cfi_lpad_unlabeled_failed.S

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1+
.include "cfi_macro.h"
12

2-
.section ".note.gnu.property", "a"
3-
.balign 8
4-
.4byte 4
5-
.4byte (ndesc_end - ndesc_begin)
6-
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
7-
.asciz "GNU"
8-
ndesc_begin:
9-
.balign 8
10-
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
11-
.4byte 4
12-
.4byte 1 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED
13-
.balign 8
14-
ndesc_end:
15-
16-
.macro exit_imm val
17-
li a0, \val
18-
li a7, 93
19-
ecall
20-
.endm
3+
gnu_property_cfi_ss 1
214

225
.text
236
.global _start

tests/programs/cfi_macro.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.macro gnu_property_cfi_ss flags
2+
.section ".note.gnu.property", "a"
3+
.balign 8
4+
.4byte 4
5+
.4byte (ndesc_end - ndesc_begin)
6+
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
7+
.asciz "GNU"
8+
ndesc_begin:
9+
.balign 8
10+
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
11+
.4byte 4
12+
.4byte \flags
13+
.balign 8
14+
ndesc_end:
15+
.endm
16+
17+
.macro exit_imm val
18+
li a0, \val
19+
li a7, 93
20+
ecall
21+
.endm
22+

0 commit comments

Comments
 (0)