Rust-for-linux archive mirror
 help / color / mirror / Atom feed
From: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
To: linux-arm-kernel@lists.infradead.org, rust-for-linux@vger.kernel.org
Cc: Miguel Ojeda <ojeda@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	steve.capper@arm.com, Asahi Lina <lina@asahilina.net>,
	boqun.feng@gmail.com, andrew@lunn.ch
Subject: [PATCH v4 2/2] arm64: rust: Enable Rust support for AArch64
Date: Fri, 20 Oct 2023 16:50:56 +0100	[thread overview]
Message-ID: <20231020155056.3495121-3-Jamie.Cunliffe@arm.com> (raw)
In-Reply-To: <20231020155056.3495121-1-Jamie.Cunliffe@arm.com>

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 <Jamie.Cunliffe@arm.com>
Acked-by: Will Deacon <will@kernel.org>
---
 Documentation/rust/arch-support.rst | 1 +
 arch/arm64/Kconfig                  | 1 +
 arch/arm64/Makefile                 | 4 ++++
 rust/Makefile                       | 1 +
 scripts/generate_rust_target.rs     | 4 +++-
 5 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst
index b91e9ef4d0c2..6bcb3b97c5b6 100644
--- a/Documentation/rust/arch-support.rst
+++ b/Documentation/rust/arch-support.rst
@@ -15,6 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file.
 ============  ================  ==============================================
 Architecture  Level of support  Constraints
 ============  ================  ==============================================
+``arm64``     Maintained        Little Endian only.
 ``um``        Maintained        ``x86_64`` only.
 ``x86``       Maintained        ``x86_64`` only.
 ============  ================  ==============================================
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 78f20e632712..d72618433521 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -227,6 +227,7 @@ config ARM64
 	select HAVE_FUNCTION_ARG_ACCESS_API
 	select MMU_GATHER_RCU_TABLE_FREE
 	select HAVE_RSEQ
+	select HAVE_RUST if CPU_LITTLE_ENDIAN
 	select HAVE_STACKPROTECTOR
 	select HAVE_SYSCALL_TRACEPOINTS
 	select HAVE_KPROBES
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 2d49aea0ff67..52d75c9483a9 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -41,6 +41,8 @@ KBUILD_CFLAGS	+= -mgeneral-regs-only	\
 KBUILD_CFLAGS	+= $(call cc-disable-warning, psabi)
 KBUILD_AFLAGS	+= $(compat_vdso)
 
+KBUILD_RUSTFLAGS += --target=aarch64-unknown-none -Ctarget-feature="-neon"
+
 KBUILD_CFLAGS	+= $(call cc-option,-mabi=lp64)
 KBUILD_AFLAGS	+= $(call cc-option,-mabi=lp64)
 
@@ -65,7 +67,9 @@ endif
 
 ifeq ($(CONFIG_ARM64_BTI_KERNEL),y)
   KBUILD_CFLAGS += -mbranch-protection=pac-ret+bti
+  KBUILD_RUSTFLAGS += -Zbranch-protection=bti,pac-ret
 else ifeq ($(CONFIG_ARM64_PTR_AUTH_KERNEL),y)
+  KBUILD_RUSTFLAGS += -Zbranch-protection=pac-ret
   ifeq ($(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET),y)
     KBUILD_CFLAGS += -mbranch-protection=pac-ret
   else
diff --git a/rust/Makefile b/rust/Makefile
index 8d75a6ffe951..8ced65c9b905 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -294,6 +294,7 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
 
 # Derived from `scripts/Makefile.clang`.
 BINDGEN_TARGET_x86	:= x86_64-linux-gnu
+BINDGEN_TARGET_arm64	:= aarch64-linux-gnu
 BINDGEN_TARGET		:= $(BINDGEN_TARGET_$(SRCARCH))
 
 # All warnings are inhibited since GCC builds are very experimental,
diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs
index 3c6cbe2b278d..ec5ef35dbe52 100644
--- a/scripts/generate_rust_target.rs
+++ b/scripts/generate_rust_target.rs
@@ -148,7 +148,9 @@ fn main() {
     let mut ts = TargetSpec::new();
 
     // `llvm-target`s are taken from `scripts/Makefile.clang`.
-    if cfg.has("X86_64") {
+    if cfg.has("ARM64") {
+        panic!("arm64 uses the builtin rustc aarch64-unknown-none target");
+    } else if cfg.has("X86_64") {
         ts.push("arch", "x86_64");
         ts.push(
             "data-layout",
-- 
2.30.2


  parent reply	other threads:[~2023-10-20 15:53 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-20 15:50 [PATCH v4 0/2] Rust enablement for AArch64 Jamie Cunliffe
2023-10-20 15:50 ` [PATCH v4 1/2] rust: Refactor the build target to allow the use of builtin targets Jamie Cunliffe
2023-10-22 10:55   ` Catalin Marinas
2023-10-22 11:07     ` Ingo Molnar
2023-10-31  0:24       ` Trevor Gross
2023-10-31 11:58         ` Catalin Marinas
2023-10-31 19:01           ` Trevor Gross
2023-12-12 16:47           ` Will Deacon
2024-01-22  9:17   ` Trevor Gross
2024-01-25  3:19     ` WANG Rui
2024-01-26 19:37       ` Masahiro Yamada
2024-01-27  5:08         ` WANG Rui
2024-01-27 17:31           ` Miguel Ojeda
2024-01-22  9:29   ` Alice Ryhl
2024-01-24  9:12   ` Masahiro Yamada
2023-10-20 15:50 ` Jamie Cunliffe [this message]
2023-10-20 16:45   ` [PATCH v4 2/2] arm64: rust: Enable Rust support for AArch64 Catalin Marinas
2023-10-21 13:40     ` Miguel Ojeda
2023-10-22 10:48       ` Catalin Marinas
2023-10-22 12:14         ` Miguel Ojeda
2023-10-20 17:21   ` Andrew Lunn
2023-10-20 18:33     ` Boqun Feng
2023-10-20 18:47       ` Andrew Lunn
2023-10-21 12:50       ` Alice Ryhl
2023-10-21 13:41       ` Miguel Ojeda
2023-10-21 16:03         ` Andrew Lunn
2023-10-22 12:57           ` Miguel Ojeda
2023-10-24  0:57       ` Stephen Boyd
2023-10-25 23:55         ` Boqun Feng
2023-11-01 15:04       ` Linus Walleij
2023-10-31 18:31   ` Matthew Maurer
2023-11-28 18:29     ` Boqun Feng
2023-12-13 19:00     ` Miguel Ojeda
2024-01-22  2:01   ` Fabien Parent
2024-01-22  5:27   ` Behme Dirk (CM/ESO2)
2024-01-22  9:30   ` Alice Ryhl
2024-02-09 17:38 ` [PATCH v4 0/2] Rust enablement " Catalin Marinas
2024-02-09 21:41   ` Miguel Ojeda
  -- strict thread matches above, loose matches on Subject: below --
2023-10-24 14:17 [PATCH v4 2/2] arm64: rust: Enable Rust support " Pratham Patel
2023-10-24 15:19 ` Miguel Ojeda
2023-10-25  2:01   ` Pratham Patel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231020155056.3495121-3-Jamie.Cunliffe@arm.com \
    --to=jamie.cunliffe@arm.com \
    --cc=andrew@lunn.ch \
    --cc=boqun.feng@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=lina@asahilina.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=steve.capper@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).