Skip to content

Commit 724a75a

Browse files
JamieCunliffectmarinas
authored andcommitted
arm64: rust: Enable Rust support for AArch64
This commit provides the build flags for Rust for AArch64. The core Rust support already in the kernel does the rest. This enables the PAC ret and BTI options in the Rust build flags to match the options that are used when building C. The Rust samples have been tested with this commit. Signed-off-by: Jamie Cunliffe <[email protected]> Acked-by: Will Deacon <[email protected]> Tested-by: Dirk Behme <[email protected]> Tested-by: Boqun Feng <[email protected]> Acked-by: Miguel Ojeda <[email protected]> Acked-by: Catalin Marinas <[email protected]> Tested-by: Alice Ryhl <[email protected]> Tested-by: Fabien Parent <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent f82811e commit 724a75a

File tree

5 files changed

+10
-1
lines changed

5 files changed

+10
-1
lines changed

Documentation/rust/arch-support.rst

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file.
1515
============= ================ ==============================================
1616
Architecture Level of support Constraints
1717
============= ================ ==============================================
18+
``arm64`` Maintained Little Endian only.
1819
``loongarch`` Maintained -
1920
``um`` Maintained ``x86_64`` only.
2021
``x86`` Maintained ``x86_64`` only.

arch/arm64/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ config ARM64
229229
select HAVE_FUNCTION_ARG_ACCESS_API
230230
select MMU_GATHER_RCU_TABLE_FREE
231231
select HAVE_RSEQ
232+
select HAVE_RUST if CPU_LITTLE_ENDIAN
232233
select HAVE_STACKPROTECTOR
233234
select HAVE_SYSCALL_TRACEPOINTS
234235
select HAVE_KPROBES

arch/arm64/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ KBUILD_CFLAGS += -mgeneral-regs-only \
4141
KBUILD_CFLAGS += $(call cc-disable-warning, psabi)
4242
KBUILD_AFLAGS += $(compat_vdso)
4343

44+
KBUILD_RUSTFLAGS += --target=aarch64-unknown-none -Ctarget-feature="-neon"
45+
4446
KBUILD_CFLAGS += $(call cc-option,-mabi=lp64)
4547
KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)
4648

@@ -65,7 +67,9 @@ endif
6567

6668
ifeq ($(CONFIG_ARM64_BTI_KERNEL),y)
6769
KBUILD_CFLAGS += -mbranch-protection=pac-ret+bti
70+
KBUILD_RUSTFLAGS += -Zbranch-protection=bti,pac-ret
6871
else ifeq ($(CONFIG_ARM64_PTR_AUTH_KERNEL),y)
72+
KBUILD_RUSTFLAGS += -Zbranch-protection=pac-ret
6973
ifeq ($(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET),y)
7074
KBUILD_CFLAGS += -mbranch-protection=pac-ret
7175
else

rust/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
297297

298298
# Derived from `scripts/Makefile.clang`.
299299
BINDGEN_TARGET_x86 := x86_64-linux-gnu
300+
BINDGEN_TARGET_arm64 := aarch64-linux-gnu
300301
BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
301302

302303
# All warnings are inhibited since GCC builds are very experimental,

scripts/generate_rust_target.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ fn main() {
148148
let mut ts = TargetSpec::new();
149149

150150
// `llvm-target`s are taken from `scripts/Makefile.clang`.
151-
if cfg.has("X86_64") {
151+
if cfg.has("ARM64") {
152+
panic!("arm64 uses the builtin rustc aarch64-unknown-none target");
153+
} else if cfg.has("X86_64") {
152154
ts.push("arch", "x86_64");
153155
ts.push(
154156
"data-layout",

0 commit comments

Comments
 (0)