Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/programs/_build_cfi_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ build cfi_lpad_unlabeled_failed.S cfi_lpad_unlabeled_failed
build cfi_lpad_func_sig.S cfi_lpad_func_sig
build cfi_lpad_func_sig_zero.S cfi_lpad_func_sig_zero
build cfi_lpad_func_sig_failed.S cfi_lpad_func_sig_failed
build cfi_ss_only_pop.S cfi_ss_only_pop
build cfi_ss_popchk_failed.S cfi_ss_popchk_failed

Binary file modified tests/programs/cfi_lpad_func_sig
Binary file not shown.
21 changes: 2 additions & 19 deletions tests/programs/cfi_lpad_func_sig.S
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
.include "cfi_macro.h"

.section ".note.gnu.property", "a"
.balign 8
.4byte 4
.4byte (ndesc_end - ndesc_begin)
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
.asciz "GNU"
ndesc_begin:
.balign 8
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
.4byte 4
.4byte 4 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG
.balign 8
ndesc_end:

.macro exit_imm val
li a0, \val
li a7, 93
ecall
.endm
gnu_property_cfi_ss 4

.text
.global _start
Expand Down
21 changes: 2 additions & 19 deletions tests/programs/cfi_lpad_func_sig_failed.S
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
.include "cfi_macro.h"

.section ".note.gnu.property", "a"
.balign 8
.4byte 4
.4byte (ndesc_end - ndesc_begin)
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
.asciz "GNU"
ndesc_begin:
.balign 8
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
.4byte 4
.4byte 4 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG
.balign 8
ndesc_end:

.macro exit_imm val
li a0, \val
li a7, 93
ecall
.endm
gnu_property_cfi_ss 4

.text
.global _start
Expand Down
21 changes: 2 additions & 19 deletions tests/programs/cfi_lpad_func_sig_zero.S
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
.include "cfi_macro.h"

.section ".note.gnu.property", "a"
.balign 8
.4byte 4
.4byte (ndesc_end - ndesc_begin)
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
.asciz "GNU"
ndesc_begin:
.balign 8
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
.4byte 4
.4byte 4 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG
.balign 8
ndesc_end:

.macro exit_imm val
li a0, \val
li a7, 93
ecall
.endm
gnu_property_cfi_ss 4

.text
.global _start
Expand Down
21 changes: 2 additions & 19 deletions tests/programs/cfi_lpad_not_active.S
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
.include "cfi_macro.h"

.section ".note.gnu.property", "a"
.balign 8
.4byte 4
.4byte (ndesc_end - ndesc_begin)
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
.asciz "GNU"
ndesc_begin:
.balign 8
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
.4byte 4
.4byte 0 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED not active
.balign 8
ndesc_end:

.macro exit_imm val
li a0, \val
li a7, 93
ecall
.endm
gnu_property_cfi_ss 0

.text
.global _start
Expand Down
Binary file modified tests/programs/cfi_lpad_unlabeled
Binary file not shown.
40 changes: 20 additions & 20 deletions tests/programs/cfi_lpad_unlabeled.S
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
.include "cfi_macro.h"

.section ".note.gnu.property", "a"
.balign 8
.4byte 4
.4byte (ndesc_end - ndesc_begin)
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
.asciz "GNU"
ndesc_begin:
.balign 8
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
.4byte 4
.4byte 1 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED
.balign 8
ndesc_end:

.macro exit_imm val
li a0, \val
li a7, 93
ecall
.endm
gnu_property_cfi_ss 1

.text
.global _start
_start:
la t1, func
jalr ra, t1, 0
exit_imm 0

la t1, func
c.jalr t1

la t1, exit
c.jr t1

exit_imm 1

.globl func
.type func,@function
# lpad checks alignment with 4
.balign 4
func:
lpad 0
ret

.global exit
.type func,@function
# lpad checks alignment with 4
.balign 4
exit:
lpad 0
exit_imm 0
21 changes: 2 additions & 19 deletions tests/programs/cfi_lpad_unlabeled_failed.S
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
.include "cfi_macro.h"

.section ".note.gnu.property", "a"
.balign 8
.4byte 4
.4byte (ndesc_end - ndesc_begin)
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
.asciz "GNU"
ndesc_begin:
.balign 8
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
.4byte 4
.4byte 1 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED
.balign 8
ndesc_end:

.macro exit_imm val
li a0, \val
li a7, 93
ecall
.endm
gnu_property_cfi_ss 1

.text
.global _start
Expand Down
22 changes: 22 additions & 0 deletions tests/programs/cfi_macro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.macro gnu_property_cfi_ss flags
.section ".note.gnu.property", "a"
.balign 8
.4byte 4
.4byte (ndesc_end - ndesc_begin)
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
.asciz "GNU"
ndesc_begin:
.balign 8
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
.4byte 4
.4byte \flags
.balign 8
ndesc_end:
.endm

.macro exit_imm val
li a0, \val
li a7, 93
ecall
.endm

21 changes: 2 additions & 19 deletions tests/programs/cfi_ss_not_active.S
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
.include "cfi_macro.h"

.section ".note.gnu.property", "a"
.balign 8
.4byte 4
.4byte (ndesc_end - ndesc_begin)
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
.asciz "GNU"
ndesc_begin:
.balign 8
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
.4byte 4
.4byte 0 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS not active
.balign 8
ndesc_end:

.macro exit_imm val
li a0, \val
li a7, 93
ecall
.endm
gnu_property_cfi_ss 0

.text
.global _start
Expand Down
Binary file added tests/programs/cfi_ss_only_pop
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/programs/cfi_ss_only_pop.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.include "cfi_macro.h"

gnu_property_cfi_ss 2


.text
.global _start
_start:
li ra, 0
sspopchk ra
Binary file added tests/programs/cfi_ss_popchk_failed
Binary file not shown.
14 changes: 14 additions & 0 deletions tests/programs/cfi_ss_popchk_failed.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.include "cfi_macro.h"

gnu_property_cfi_ss 2


.text
.global _start
_start:
li ra, 42
sspush ra
li ra, 41
sspopchk ra
exit_imm 0

Binary file modified tests/programs/cfi_ss_stack_downto_zero
Binary file not shown.
21 changes: 2 additions & 19 deletions tests/programs/cfi_ss_stack_downto_zero.S
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
.include "cfi_macro.h"

.section ".note.gnu.property", "a"
.balign 8
.4byte 4
.4byte (ndesc_end - ndesc_begin)
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
.asciz "GNU"
ndesc_begin:
.balign 8
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
.4byte 4
.4byte 2 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS
.balign 8
ndesc_end:

.macro exit_imm val
li a0, \val
li a7, 93
ecall
.endm
gnu_property_cfi_ss 2

.text
.global _start
Expand Down
Binary file modified tests/programs/cfi_ss_stack_full
Binary file not shown.
21 changes: 2 additions & 19 deletions tests/programs/cfi_ss_stack_full.S
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
.include "cfi_macro.h"

.section ".note.gnu.property", "a"
.balign 8
.4byte 4
.4byte (ndesc_end - ndesc_begin)
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
.asciz "GNU"
ndesc_begin:
.balign 8
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
.4byte 4
.4byte 2 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS
.balign 8
ndesc_end:

.macro exit_imm val
li a0, \val
li a7, 93
ecall
.endm
gnu_property_cfi_ss 2

.text
.global _start
Expand Down
Binary file modified tests/programs/cfi_ss_success
Binary file not shown.
35 changes: 16 additions & 19 deletions tests/programs/cfi_ss_success.S
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
.include "cfi_macro.h"

.section ".note.gnu.property", "a"
.balign 8
.4byte 4
.4byte (ndesc_end - ndesc_begin)
.4byte 0x5 // NT_GNU_PROPERTY_TYPE_0
.asciz "GNU"
ndesc_begin:
.balign 8
.4byte 0xc0000000 // GNU_PROPERTY_RISCV_FEATURE_1_AND
.4byte 4
.4byte 2 // GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS
.balign 8
ndesc_end:

.macro exit_imm val
li a0, \val
li a7, 93
ecall
.endm
gnu_property_cfi_ss 2

.text
.global _start
Expand All @@ -39,6 +22,9 @@ _start:
sspush ra
sspopchk ra

sspush t0
sspopchk t0

li t0, 42
beq ra, t0, 1f
exit_imm 2
Expand Down Expand Up @@ -80,5 +66,16 @@ _start:
beq t0, t1, 1f
exit_imm 6

1:
# test ssamoswap.w version
li t0, 100
sspush t0
ssrdp t3
li t4, 200
ssamoswap.w t5, t4, (t3)
li t6, 100
beq t5, t6, 1f
exit_imm 7

1:
exit_imm 0
24 changes: 24 additions & 0 deletions tests/test_cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,27 @@ pub fn test_cfi_lpad_func_sig_failed() {
assert!(ret_asm.is_err());
}
}

#[test]
pub fn test_cfi_ss_only_pop() {
let ret = run_int("tests/programs/cfi_ss_only_pop");
assert!(ret.is_err());

#[cfg(has_asm)]
{
let ret_asm = run_asm("tests/programs/cfi_ss_only_pop");
assert!(ret_asm.is_err());
}
}

#[test]
pub fn test_cfi_ss_popchk_failed() {
let ret = run_int("tests/programs/cfi_ss_popchk_failed");
assert!(ret.is_err());

#[cfg(has_asm)]
{
let ret_asm = run_asm("tests/programs/cfi_ss_popchk_failed");
assert!(ret_asm.is_err());
}
}
Loading