]> git.ipfire.org Git - thirdparty/gcc.git/commit
RISC-V: Add Zicfiss ISA extension.
authorMonk Chiang <monk.chiang@sifive.com>
Fri, 15 Nov 2024 05:38:48 +0000 (13:38 +0800)
committerMonk Chiang <monk.chiang@sifive.com>
Fri, 17 Jan 2025 02:49:16 +0000 (10:49 +0800)
commitdc76aa0e4d5398104b6b26f08b46524b97de5100
tree7210fc03f9544ca682238548dd4768490651e16e
parent29da6a642402ac64002f5edeab268606b4637103
RISC-V: Add Zicfiss ISA extension.

This patch is implemented according to the RISC-V CFI specification.
It supports the generation of shadow stack instructions in the prologue,
epilogue, non-local gotos, and unwinding.

RISC-V CFI SPEC: https://github.com/riscv/riscv-cfi

gcc/ChangeLog:
* common/config/riscv/riscv-common.cc: Add ZICFISS ISA string.
* config/riscv/predicates.md: New predicate x1x5_operand.
* config/riscv/riscv.cc
(riscv_expand_prologue): Insert shadow stack instructions.
(riscv_expand_epilogue): Likewise.
(riscv_for_each_saved_reg): Assign t0 or ra register for
sspopchk instruction.
(need_shadow_stack_push_pop_p): New function. Omit shadow
stack operation on leaf function.
* config/riscv/riscv.h
(need_shadow_stack_push_pop_p): Define.
* config/riscv/riscv.md: Add shadow stack patterns.
(save_stack_nonlocal): Add shadow stack instructions for setjump.
(restore_stack_nonlocal): Add shadow stack instructions for longjump.
* config/riscv/riscv.opt (TARGET_ZICFISS): Define.

libgcc/ChangeLog:
* config/riscv/linux-unwind.h: Include shadow-stack-unwind.h.
* config/riscv/shadow-stack-unwind.h
(_Unwind_Frames_Extra): Define.
(_Unwind_Frames_Increment): Define.

gcc/testsuite/ChangeLog:
* gcc.target/riscv/ssp-1.c: New test.
* gcc.target/riscv/ssp-2.c: New test.

Co-Developed-by: Greg McGary <gkm@rivosinc.com>,
Kito Cheng <kito.cheng@gmail.com>
gcc/common/config/riscv/riscv-common.cc
gcc/config/riscv/predicates.md
gcc/config/riscv/riscv.cc
gcc/config/riscv/riscv.h
gcc/config/riscv/riscv.md
gcc/config/riscv/riscv.opt
gcc/testsuite/gcc.target/riscv/ssp-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/ssp-2.c [new file with mode: 0644]
libgcc/config/riscv/linux-unwind.h
libgcc/config/riscv/shadow-stack-unwind.h [new file with mode: 0644]