Skip to content

Commit 19a9099

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 <Jamie.Cunliffe@arm.com> Link: https://lore.kernel.org/r/20230606145606.1153715-2-Jamie.Cunliffe@arm.com [boqun: resolve the conflicts with kunit test enablement]
1 parent 846c1cf commit 19a9099

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
@@ -575,7 +575,6 @@ KBUILD_CFLAGS += -Wno-trigraphs
575575

576576
KBUILD_CPPFLAGS := -D__KERNEL__
577577
KBUILD_RUSTFLAGS := $(rust_common_flags) \
578-
--target=$(objtree)/scripts/target.json \
579578
-Cpanic=abort -Cembed-bitcode=n -Clto=n \
580579
-Cforce-unwind-tables=n -Ccodegen-units=1 \
581580
-Csymbol-mangling-version=v0 \

arch/arm64/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ config ARM64
225225
select HAVE_FUNCTION_ARG_ACCESS_API
226226
select MMU_GATHER_RCU_TABLE_FREE
227227
select HAVE_RSEQ
228+
select HAVE_RUST
228229
select HAVE_STACKPROTECTOR
229230
select HAVE_SYSCALL_TRACEPOINTS
230231
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
@@ -291,6 +291,7 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
291291

292292
# Derived from `scripts/Makefile.clang`.
293293
BINDGEN_TARGET_x86 := x86_64-linux-gnu
294+
BINDGEN_TARGET_arm64 := aarch64-linux-gnu
294295
BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
295296

296297
# All warnings are inhibited since GCC builds are very experimental,
@@ -425,8 +426,11 @@ $(obj)/core.o: private skip_clippy = 1
425426
$(obj)/core.o: private skip_flags = -Dunreachable_pub
426427
$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
427428
$(obj)/core.o: private rustc_target_flags = $(core-cfgs)
428-
$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs scripts/target.json FORCE
429+
$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
429430
$(call if_changed_dep,rustc_library)
431+
ifeq ($(ARCH),x86_64)
432+
$(obj)/core.o: scripts/target.json
433+
endif
430434

431435
$(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
432436
$(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)