Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8faffe9

Browse files
committedMar 5, 2024
rust: add flags for shadow call stack sanitizer
Add flags to support the shadow call stack sanitizer, both in the dynamic and non-dynamic modes. Right now, the compiler will emit the warning "unknown feature specified for `-Ctarget-feature`: `reserve-x18`". However, the compiler still passes it to the codegen backend, so the flag will work just fine. Once rustc starts recognizing the flag (or provides another way to enable the feature), it will stop emitting this warning. See [1] for the relevant issue. Currently, the compiler thinks that the aarch64-unknown-none target doesn't support -Zsanitizer=shadow-call-stack, so the build will fail if you enable shadow call stack in non-dynamic mode. However, I still think it is reasonable to add the flag now, as it will at least fail the build when using an invalid configuration, until the Rust compiler is fixed to list -Zsanitizer=shadow-call-stack as supported for the target. See [2] for the feature request to add this. I have tested this change with Rust Binder on an Android device using CONFIG_DYNAMIC_SCS. Without the -Ctarget-feature=+reserve-x18 flag, the phone crashes immediately on boot, and with the flag, the phone appears to work normally. This contains a TODO to add the -Zuse-sync-unwind=n flag. The flag defaults to n, so it isn't a problem today, but the flag is unstable, so the default could change in a future compiler release. Link: rust-lang/rust#121970 [1] Link: rust-lang/rust#121972 [2] Signed-off-by: Alice Ryhl <aliceryhl@google.com>
1 parent 90d35da commit 8faffe9

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed
 

‎Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ ifdef CONFIG_SHADOW_CALL_STACK
936936
ifndef CONFIG_DYNAMIC_SCS
937937
CC_FLAGS_SCS := -fsanitize=shadow-call-stack
938938
KBUILD_CFLAGS += $(CC_FLAGS_SCS)
939+
KBUILD_RUSTFLAGS += -Zsanitizer=shadow-call-stack
939940
endif
940941
export CC_FLAGS_SCS
941942
endif

‎arch/arm64/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)
4848
ifneq ($(CONFIG_UNWIND_TABLES),y)
4949
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
5050
KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
51+
KBUILD_RUSTFLAGS += -Cforce-unwind-tables=n
5152
else
5253
KBUILD_CFLAGS += -fasynchronous-unwind-tables
5354
KBUILD_AFLAGS += -fasynchronous-unwind-tables
55+
# TODO: Pass -Zuse-sync-unwind=n once we upgrade to Rust 1.77.0
56+
KBUILD_RUSTFLAGS += -Cforce-unwind-tables=y
5457
endif
5558

5659
ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
@@ -103,6 +106,7 @@ endif
103106

104107
ifeq ($(CONFIG_SHADOW_CALL_STACK), y)
105108
KBUILD_CFLAGS += -ffixed-x18
109+
KBUILD_RUSTFLAGS += -Ctarget-feature=+reserve-x18
106110
endif
107111

108112
ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)

0 commit comments

Comments
 (0)
Failed to load comments.