-
- Downloads
aarch64: Add compiler support for Shadow Call Stack
Shadow Call Stack can be used to protect the return address of a function at runtime, and clang already supports this feature[1]. To enable SCS in user mode, in addition to compiler, other support is also required (as discussed in [2]). This patch only adds basic support for SCS from the compiler side, and provides convenience for users to enable SCS. For linux kernel, only the support of the compiler is required. [1] https://clang.llvm.org/docs/ShadowCallStack.html [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102768 Signed-off-by:Dan Li <ashimida@linux.alibaba.com> gcc/ChangeLog: * config/aarch64/aarch64.cc (SLOT_REQUIRED): Change wb_candidate[12] to wb_push_candidate[12]. (aarch64_layout_frame): Likewise, and change callee_adjust when scs is enabled. (aarch64_save_callee_saves): Change wb_candidate[12] to wb_push_candidate[12]. (aarch64_restore_callee_saves): Change wb_candidate[12] to wb_pop_candidate[12]. (aarch64_get_separate_components): Change wb_candidate[12] to wb_push_candidate[12]. (aarch64_expand_prologue): Push x30 onto SCS before it's pushed onto stack. (aarch64_expand_epilogue): Pop x30 frome SCS, while preventing it from being popped from the regular stack again. (aarch64_override_options_internal): Add SCS compile option check. (TARGET_HAVE_SHADOW_CALL_STACK): New hook. * config/aarch64/aarch64.h (struct GTY): Add is_scs_enabled, wb_pop_candidate[12], and rename wb_candidate[12] to wb_push_candidate[12]. * config/aarch64/aarch64.md (scs_push): New template. (scs_pop): Likewise. * doc/invoke.texi: Document -fsanitize=shadow-call-stack. * doc/tm.texi: Regenerate. * doc/tm.texi.in: Add hook have_shadow_call_stack. * flag-types.h (enum sanitize_code): Add SANITIZE_SHADOW_CALL_STACK. * opts.cc (parse_sanitizer_options): Add shadow-call-stack and exclude SANITIZE_SHADOW_CALL_STACK. * target.def: New hook. * toplev.cc (process_options): Add SCS compile option check. * ubsan.cc (ubsan_expand_null_ifn): Enum type conversion. gcc/testsuite/ChangeLog: * gcc.target/aarch64/shadow_call_stack_1.c: New test. * gcc.target/aarch64/shadow_call_stack_2.c: New test. * gcc.target/aarch64/shadow_call_stack_3.c: New test. * gcc.target/aarch64/shadow_call_stack_4.c: New test. * gcc.target/aarch64/shadow_call_stack_5.c: New test. * gcc.target/aarch64/shadow_call_stack_6.c: New test. * gcc.target/aarch64/shadow_call_stack_7.c: New test. * gcc.target/aarch64/shadow_call_stack_8.c: New test.
Showing
- gcc/config/aarch64/aarch64.cc 85 additions, 28 deletionsgcc/config/aarch64/aarch64.cc
- gcc/config/aarch64/aarch64.h 18 additions, 3 deletionsgcc/config/aarch64/aarch64.h
- gcc/config/aarch64/aarch64.md 10 additions, 0 deletionsgcc/config/aarch64/aarch64.md
- gcc/doc/invoke.texi 30 additions, 0 deletionsgcc/doc/invoke.texi
- gcc/doc/tm.texi 5 additions, 0 deletionsgcc/doc/tm.texi
- gcc/doc/tm.texi.in 2 additions, 0 deletionsgcc/doc/tm.texi.in
- gcc/flag-types.h 2 additions, 0 deletionsgcc/flag-types.h
- gcc/opts.cc 3 additions, 1 deletiongcc/opts.cc
- gcc/target.def 8 additions, 0 deletionsgcc/target.def
- gcc/testsuite/gcc.target/aarch64/shadow_call_stack_1.c 6 additions, 0 deletionsgcc/testsuite/gcc.target/aarch64/shadow_call_stack_1.c
- gcc/testsuite/gcc.target/aarch64/shadow_call_stack_2.c 6 additions, 0 deletionsgcc/testsuite/gcc.target/aarch64/shadow_call_stack_2.c
- gcc/testsuite/gcc.target/aarch64/shadow_call_stack_3.c 45 additions, 0 deletionsgcc/testsuite/gcc.target/aarch64/shadow_call_stack_3.c
- gcc/testsuite/gcc.target/aarch64/shadow_call_stack_4.c 20 additions, 0 deletionsgcc/testsuite/gcc.target/aarch64/shadow_call_stack_4.c
- gcc/testsuite/gcc.target/aarch64/shadow_call_stack_5.c 18 additions, 0 deletionsgcc/testsuite/gcc.target/aarch64/shadow_call_stack_5.c
- gcc/testsuite/gcc.target/aarch64/shadow_call_stack_6.c 18 additions, 0 deletionsgcc/testsuite/gcc.target/aarch64/shadow_call_stack_6.c
- gcc/testsuite/gcc.target/aarch64/shadow_call_stack_7.c 18 additions, 0 deletionsgcc/testsuite/gcc.target/aarch64/shadow_call_stack_7.c
- gcc/testsuite/gcc.target/aarch64/shadow_call_stack_8.c 24 additions, 0 deletionsgcc/testsuite/gcc.target/aarch64/shadow_call_stack_8.c
- gcc/toplev.cc 10 additions, 0 deletionsgcc/toplev.cc
- gcc/ubsan.cc 2 additions, 2 deletionsgcc/ubsan.cc
Loading
Please register or sign in to comment