Skip to content

Commit 668750c

Browse files
committed
rust: add flags for shadow call stack sanitizer
As of rustc 1.80.0, the Rust compiler supports the -Zfixed-x18 flag, so we can now use Rust with the shadow call stack sanitizer. On older versions of Rust, it is possible to use shadow call stack by passing -Ctarget-feature=+reserve-x18 instead of -Zfixed-x18. However, this flag emits a warning, so this patch does not add support for that. 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. See [2] for the feature request to add this. Kconfig is not configured to reject this configuration because that leads to cyclic Kconfig rules. Link: rust-lang/rust#121972 [1] Signed-off-by: Alice Ryhl <aliceryhl@google.com>
1 parent fc71eed commit 668750c

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,7 @@ ifdef CONFIG_SHADOW_CALL_STACK
945945
ifndef CONFIG_DYNAMIC_SCS
946946
CC_FLAGS_SCS := -fsanitize=shadow-call-stack
947947
KBUILD_CFLAGS += $(CC_FLAGS_SCS)
948+
KBUILD_RUSTFLAGS += -Zsanitizer=shadow-call-stack
948949
endif
949950
export CC_FLAGS_SCS
950951
endif

arch/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ config SHADOW_CALL_STACK
690690
bool "Shadow Call Stack"
691691
depends on ARCH_SUPPORTS_SHADOW_CALL_STACK
692692
depends on DYNAMIC_FTRACE_WITH_ARGS || DYNAMIC_FTRACE_WITH_REGS || !FUNCTION_GRAPH_TRACER
693-
depends on !RUST
693+
depends on !RUST || RUSTC_VERSION >= 108000
694694
depends on MMU
695695
help
696696
This option enables the compiler's Shadow Call Stack, which

arch/arm64/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)
5757
ifneq ($(CONFIG_UNWIND_TABLES),y)
5858
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
5959
KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
60+
KBUILD_RUSTFLAGS += -Cforce-unwind-tables=n
6061
else
6162
KBUILD_CFLAGS += -fasynchronous-unwind-tables
6263
KBUILD_AFLAGS += -fasynchronous-unwind-tables
64+
KBUILD_RUSTFLAGS += -Cforce-unwind-tables=y -Zuse-sync-unwind=n
6365
endif
6466

6567
ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
@@ -114,6 +116,7 @@ endif
114116

115117
ifeq ($(CONFIG_SHADOW_CALL_STACK), y)
116118
KBUILD_CFLAGS += -ffixed-x18
119+
KBUILD_RUSTFLAGS += -Zfixed-x18
117120
endif
118121

119122
ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)

0 commit comments

Comments
 (0)