Skip to content

Commit 34fbe1d

Browse files
JamieCunliffefbq
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. When disabling the neon and fp target features to avoid fp & simd registers. The use of fp-armv8 will cause a warning from rustc about an unknown feature that is specified. The target feature is still passed through to LLVM, this behaviour is documented as part of the warning. This will be fixed in a future version of the rustc toolchain. The Rust samples have been tested with this commit. Signed-off-by: Jamie Cunliffe <[email protected]> Link: https://lore.kernel.org/r/[email protected] [boqun: resolve the conflicts with kunit test enablement]
1 parent 24c8041 commit 34fbe1d

File tree

8 files changed

+16
-5
lines changed

8 files changed

+16
-5
lines changed

Documentation/rust/arch-support.rst

Lines changed: 1 addition & 0 deletions
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 None.
1819
``um`` Maintained ``x86_64`` only.
1920
``x86`` Maintained ``x86_64`` only.
2021
============ ================ ==============================================

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ KBUILD_CFLAGS += -fno-strict-aliasing
566566

567567
KBUILD_CPPFLAGS := -D__KERNEL__
568568
KBUILD_RUSTFLAGS := $(rust_common_flags) \
569-
--target=$(objtree)/scripts/target.json \
570569
-Cpanic=abort -Cembed-bitcode=n -Clto=n \
571570
-Cforce-unwind-tables=n -Ccodegen-units=1 \
572571
-Csymbol-mangling-version=v0 \

arch/arm64/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ config ARM64
227227
select HAVE_FUNCTION_ARG_ACCESS_API
228228
select MMU_GATHER_RCU_TABLE_FREE
229229
select HAVE_RSEQ
230+
select HAVE_RUST
230231
select HAVE_STACKPROTECTOR
231232
select HAVE_SYSCALL_TRACEPOINTS
232233
select HAVE_KPROBES

arch/arm64/Makefile

Lines changed: 2 additions & 0 deletions
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 -C target-feature="-neon,-fp-armv8"
45+
4446
KBUILD_CFLAGS += $(call cc-option,-mabi=lp64)
4547
KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)
4648

arch/x86/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export BITS
6868
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
6969
#
7070
KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
71+
KBUILD_RUSTFLAGS += --target=$(objtree)/scripts/target.json
7172
KBUILD_RUSTFLAGS += -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2
7273

7374
ifeq ($(CONFIG_X86_KERNEL_IBT),y)

rust/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
294294

295295
# Derived from `scripts/Makefile.clang`.
296296
BINDGEN_TARGET_x86 := x86_64-linux-gnu
297+
BINDGEN_TARGET_arm64 := aarch64-linux-gnu
297298
BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
298299

299300
# All warnings are inhibited since GCC builds are very experimental,
@@ -428,8 +429,11 @@ $(obj)/core.o: private skip_clippy = 1
428429
$(obj)/core.o: private skip_flags = -Dunreachable_pub
429430
$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
430431
$(obj)/core.o: private rustc_target_flags = $(core-cfgs)
431-
$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs scripts/target.json FORCE
432+
$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
432433
$(call if_changed_dep,rustc_library)
434+
ifeq ($(ARCH),x86_64)
435+
$(obj)/core.o: scripts/target.json
436+
endif
433437

434438
$(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
435439
$(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE

scripts/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file
1111
hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert
1212
hostprogs-always-$(CONFIG_RUST_KERNEL_DOCTESTS) += rustdoc_test_builder
1313
hostprogs-always-$(CONFIG_RUST_KERNEL_DOCTESTS) += rustdoc_test_gen
14-
always-$(CONFIG_RUST) += target.json
1514

15+
ifeq ($(ARCH),x86_64)
16+
always-$(CONFIG_RUST) += target.json
1617
filechk_rust_target = $< < include/config/auto.conf
17-
1818
$(obj)/target.json: scripts/generate_rust_target include/config/auto.conf FORCE
1919
$(call filechk,rust_target)
20+
endif
2021

2122
hostprogs += generate_rust_target
2223
generate_rust_target-rust := y

scripts/generate_rust_target.rs

Lines changed: 3 additions & 1 deletion
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)