Skip to content

Commit c670ecb

Browse files
committed
x86/rust: support MITIGATION_RETHUNK
The Rust compiler added support for `-Zfunction-return=thunk-extern` [1] in 1.76.0 [2], i.e. the equivalent of `-mfunction-return=thunk-extern`. Thus add support for `MITIGATION_RETHUNK`. Without this, `objtool` would warn if enabled for Rust and already warns under IBT builds, e.g.: samples/rust/rust_print.o: warning: objtool: _R...init+0xa5c: 'naked' return found in RETHUNK build Link: rust-lang/rust#116853 [1] Link: rust-lang/rust#116892 [2] Reviewed-by: Gary Guo <gary@garyguo.net> Tested-by: Alice Ryhl <aliceryhl@google.com> Tested-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Link: #945 Link: https://lore.kernel.org/r/20240725183325.122827-4-ojeda@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent b9cfa87 commit c670ecb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

arch/x86/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ RETPOLINE_CFLAGS += $(call cc-option,-mindirect-branch-cs-prefix)
2424

2525
ifdef CONFIG_MITIGATION_RETHUNK
2626
RETHUNK_CFLAGS := -mfunction-return=thunk-extern
27+
RETHUNK_RUSTFLAGS := -Zfunction-return=thunk-extern
2728
RETPOLINE_CFLAGS += $(RETHUNK_CFLAGS)
29+
RETPOLINE_RUSTFLAGS += $(RETHUNK_RUSTFLAGS)
2830
endif
2931

3032
export RETHUNK_CFLAGS
33+
export RETHUNK_RUSTFLAGS
3134
export RETPOLINE_CFLAGS
35+
export RETPOLINE_RUSTFLAGS
3236
export RETPOLINE_VDSO_CFLAGS
3337

3438
# For gcc stack alignment is specified with -mpreferred-stack-boundary,
@@ -218,6 +222,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
218222
# Avoid indirect branches in kernel to deal with Spectre
219223
ifdef CONFIG_MITIGATION_RETPOLINE
220224
KBUILD_CFLAGS += $(RETPOLINE_CFLAGS)
225+
KBUILD_RUSTFLAGS += $(RETPOLINE_RUSTFLAGS)
221226
# Additionally, avoid generating expensive indirect jumps which
222227
# are subject to retpolines for small number of switch cases.
223228
# LLVM turns off jump table generation by default when under

0 commit comments

Comments
 (0)