rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Rust enablement for AArch64
@ 2023-06-06 14:56 Jamie Cunliffe
  2023-06-06 14:56 ` [PATCH v2 1/3] arm64: rust: Enable Rust support " Jamie Cunliffe
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Jamie Cunliffe @ 2023-06-06 14:56 UTC (permalink / raw)
  To: linux-arm-kernel, rust-for-linux
  Cc: Miguel Ojeda, Catalin Marinas, Will Deacon, steve.capper,
	Asahi Lina

Enable Rust support for the AArch64 architecture.

The first patch enables the basic building of Rust for AArch64. Since
v1 this has been rewritten to avoid the use of a target.json file for
AArch64 and use the upstream rustc target definition. x86-64 still
uses the target.json approach though.

The second patch enables the PAC ret and BTI options in the Rust build
flags to match the options that are used when building C.

The third patch disables Rust support when building for big
endian. Currently there is no `aarch64_be-unknown-none` target which
would allow this. Support for this can come at a later time either by
using the target.json approach, or upstreaming a new target definition
to rustc (preferred). We also might be able to use the
`aarch64_be-unknown-linux-gnu` target, however, this can be done at a
later time.  It's worth noting that in Makefile.clang, it's
recommended for arch/{arch}/Makefile to set the endianness based on
arguments rather than the target triple. It's currently not possible
to do this with rustc, a different target triple has to be used.


Jamie Cunliffe (3):
  arm64: rust: Enable Rust support for AArch64
  arm64: rust: Enable PAC support for Rust.
  arm64: Restrict Rust support to little endian only.

 Documentation/rust/arch-support.rst | 1 +
 Makefile                            | 1 -
 arch/arm64/Kconfig                  | 1 +
 arch/arm64/Makefile                 | 4 ++++
 arch/x86/Makefile                   | 1 +
 rust/Makefile                       | 6 +++++-
 scripts/Makefile                    | 5 +++--
 scripts/generate_rust_target.rs     | 4 +++-
 8 files changed, 18 insertions(+), 5 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/3] arm64: rust: Enable Rust support for AArch64
  2023-06-06 14:56 [PATCH v2 0/3] Rust enablement for AArch64 Jamie Cunliffe
@ 2023-06-06 14:56 ` Jamie Cunliffe
  2023-06-09 17:47   ` Boqun Feng
  2023-06-06 14:56 ` [PATCH v2 2/3] arm64: rust: Enable PAC support for Rust Jamie Cunliffe
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Jamie Cunliffe @ 2023-06-06 14:56 UTC (permalink / raw)
  To: linux-arm-kernel, rust-for-linux
  Cc: Miguel Ojeda, Catalin Marinas, Will Deacon, steve.capper,
	Asahi Lina

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>
---
 Documentation/rust/arch-support.rst | 1 +
 Makefile                            | 1 -
 arch/arm64/Kconfig                  | 1 +
 arch/arm64/Makefile                 | 2 ++
 arch/x86/Makefile                   | 1 +
 rust/Makefile                       | 6 +++++-
 scripts/Makefile                    | 5 +++--
 scripts/generate_rust_target.rs     | 4 +++-
 8 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst
index b91e9ef4d0c2..9b022af2f649 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        None.
 ``um``        Maintained        ``x86_64`` only.
 ``x86``       Maintained        ``x86_64`` only.
 ============  ================  ==============================================
diff --git a/Makefile b/Makefile
index 9d765ebcccf1..16b1e4de70e3 100644
--- a/Makefile
+++ b/Makefile
@@ -561,7 +561,6 @@ KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
 		   -std=gnu11
 KBUILD_CPPFLAGS := -D__KERNEL__
 KBUILD_RUSTFLAGS := $(rust_common_flags) \
-		    --target=$(objtree)/scripts/target.json \
 		    -Cpanic=abort -Cembed-bitcode=n -Clto=n \
 		    -Cforce-unwind-tables=n -Ccodegen-units=1 \
 		    -Csymbol-mangling-version=v0 \
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index b1201d25a8a4..10e9399e8e2f 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -217,6 +217,7 @@ config ARM64
 	select HAVE_FUNCTION_ARG_ACCESS_API
 	select MMU_GATHER_RCU_TABLE_FREE
 	select HAVE_RSEQ
+	select HAVE_RUST
 	select HAVE_STACKPROTECTOR
 	select HAVE_SYSCALL_TRACEPOINTS
 	select HAVE_KPROBES
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 2d49aea0ff67..2ce1555e9fc5 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 -C target-feature="-neon,-fp-armv8"
+
 KBUILD_CFLAGS	+= $(call cc-option,-mabi=lp64)
 KBUILD_AFLAGS	+= $(call cc-option,-mabi=lp64)
 
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index b39975977c03..79cffe92c916 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -68,6 +68,7 @@ export BITS
 #    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
 #
 KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
+KBUILD_RUSTFLAGS += --target=$(objtree)/scripts/target.json
 KBUILD_RUSTFLAGS += -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2
 
 ifeq ($(CONFIG_X86_KERNEL_IBT),y)
diff --git a/rust/Makefile b/rust/Makefile
index 7c9d9f11aec5..18d6fdb73fa9 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -262,6 +262,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,
@@ -393,8 +394,11 @@ $(obj)/core.o: private skip_clippy = 1
 $(obj)/core.o: private skip_flags = -Dunreachable_pub
 $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
 $(obj)/core.o: private rustc_target_flags = $(core-cfgs)
-$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs scripts/target.json FORCE
+$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
 	$(call if_changed_dep,rustc_library)
+ifeq ($(ARCH),x86_64)
+$(obj)/core.o: scripts/target.json
+endif
 
 $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
 $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
diff --git a/scripts/Makefile b/scripts/Makefile
index 32b6ba722728..633479d02e33 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -9,12 +9,13 @@ hostprogs-always-$(CONFIG_BUILDTIME_TABLE_SORT)		+= sorttable
 hostprogs-always-$(CONFIG_ASN1)				+= asn1_compiler
 hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT)		+= sign-file
 hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE)	+= insert-sys-cert
-always-$(CONFIG_RUST)					+= target.json
 
+ifeq ($(ARCH),x86_64)
+always-$(CONFIG_RUST)					+= target.json
 filechk_rust_target = $< < include/config/auto.conf
-
 $(obj)/target.json: scripts/generate_rust_target include/config/auto.conf FORCE
 	$(call filechk,rust_target)
+endif
 
 hostprogs += generate_rust_target
 generate_rust_target-rust := y
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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/3] arm64: rust: Enable PAC support for Rust.
  2023-06-06 14:56 [PATCH v2 0/3] Rust enablement for AArch64 Jamie Cunliffe
  2023-06-06 14:56 ` [PATCH v2 1/3] arm64: rust: Enable Rust support " Jamie Cunliffe
@ 2023-06-06 14:56 ` Jamie Cunliffe
  2023-06-06 14:56 ` [PATCH v2 3/3] arm64: Restrict Rust support to little endian only Jamie Cunliffe
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Jamie Cunliffe @ 2023-06-06 14:56 UTC (permalink / raw)
  To: linux-arm-kernel, rust-for-linux
  Cc: Miguel Ojeda, Catalin Marinas, Will Deacon, steve.capper,
	Asahi Lina

Enable the PAC ret and BTI options in the Rust build flags to match
the options that are used when building C.

Signed-off-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
---
 arch/arm64/Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 2ce1555e9fc5..4a2c807d65db 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -67,7 +67,9 @@ endif
 
 ifeq ($(CONFIG_ARM64_BTI_KERNEL),y)
   KBUILD_CFLAGS += -mbranch-protection=pac-ret+bti
+  KBUILD_RUSTFLAGS += -Z branch-protection=bti,pac-ret
 else ifeq ($(CONFIG_ARM64_PTR_AUTH_KERNEL),y)
+  KBUILD_RUSTFLAGS += -Z branch-protection=pac-ret
   ifeq ($(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET),y)
     KBUILD_CFLAGS += -mbranch-protection=pac-ret
   else
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 3/3] arm64: Restrict Rust support to little endian only.
  2023-06-06 14:56 [PATCH v2 0/3] Rust enablement for AArch64 Jamie Cunliffe
  2023-06-06 14:56 ` [PATCH v2 1/3] arm64: rust: Enable Rust support " Jamie Cunliffe
  2023-06-06 14:56 ` [PATCH v2 2/3] arm64: rust: Enable PAC support for Rust Jamie Cunliffe
@ 2023-06-06 14:56 ` Jamie Cunliffe
  2023-06-06 15:25 ` [PATCH v2 0/3] Rust enablement for AArch64 Miguel Ojeda
  2023-06-09 18:34 ` Boqun Feng
  4 siblings, 0 replies; 10+ messages in thread
From: Jamie Cunliffe @ 2023-06-06 14:56 UTC (permalink / raw)
  To: linux-arm-kernel, rust-for-linux
  Cc: Miguel Ojeda, Catalin Marinas, Will Deacon, steve.capper,
	Asahi Lina

Signed-off-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
---
 Documentation/rust/arch-support.rst | 2 +-
 arch/arm64/Kconfig                  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst
index 9b022af2f649..6bcb3b97c5b6 100644
--- a/Documentation/rust/arch-support.rst
+++ b/Documentation/rust/arch-support.rst
@@ -15,7 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file.
 ============  ================  ==============================================
 Architecture  Level of support  Constraints
 ============  ================  ==============================================
-``arm64``     Maintained        None.
+``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 10e9399e8e2f..02187dd3b839 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -217,7 +217,7 @@ config ARM64
 	select HAVE_FUNCTION_ARG_ACCESS_API
 	select MMU_GATHER_RCU_TABLE_FREE
 	select HAVE_RSEQ
-	select HAVE_RUST
+	select HAVE_RUST if CPU_LITTLE_ENDIAN
 	select HAVE_STACKPROTECTOR
 	select HAVE_SYSCALL_TRACEPOINTS
 	select HAVE_KPROBES
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/3] Rust enablement for AArch64
  2023-06-06 14:56 [PATCH v2 0/3] Rust enablement for AArch64 Jamie Cunliffe
                   ` (2 preceding siblings ...)
  2023-06-06 14:56 ` [PATCH v2 3/3] arm64: Restrict Rust support to little endian only Jamie Cunliffe
@ 2023-06-06 15:25 ` Miguel Ojeda
  2023-06-09 18:34 ` Boqun Feng
  4 siblings, 0 replies; 10+ messages in thread
From: Miguel Ojeda @ 2023-06-06 15:25 UTC (permalink / raw)
  To: Jamie Cunliffe
  Cc: linux-arm-kernel, rust-for-linux, Miguel Ojeda, Catalin Marinas,
	Will Deacon, steve.capper, Asahi Lina

On Tue, Jun 6, 2023 at 4:56 PM Jamie Cunliffe <Jamie.Cunliffe@arm.com> wrote:
>
> The third patch disables Rust support when building for big
> endian. Currently there is no `aarch64_be-unknown-none` target which
> would allow this. Support for this can come at a later time either by
> using the target.json approach, or upstreaming a new target definition
> to rustc (preferred). We also might be able to use the
> `aarch64_be-unknown-linux-gnu` target, however, this can be done at a
> later time.  It's worth noting that in Makefile.clang, it's
> recommended for arch/{arch}/Makefile to set the endianness based on
> arguments rather than the target triple. It's currently not possible
> to do this with rustc, a different target triple has to be used.

Thanks Jamie for this!

It sounds like upstream `rustc` should support setting the endianness,
but if they are OK with maintaining another target, so that we can
start to get rid of `target.json`, that would be great.

By the way, should the patches be merged into one? i.e. the first
patch applied alone would be "wrong" in that BE is not supported
anyway, right? So why not put the constraint directly in the first
patch? Or am I missing something?

Similarly, for the second patch, I think it would be better to squash
it into the first, especially if the build is not correct if those
flags are not set.

But maybe I am missing something, or perhaps the arm64 maintainers
prefer otherwise.

Lina's `Tested-by` for Asahi would be great here.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/3] arm64: rust: Enable Rust support for AArch64
  2023-06-06 14:56 ` [PATCH v2 1/3] arm64: rust: Enable Rust support " Jamie Cunliffe
@ 2023-06-09 17:47   ` Boqun Feng
  2023-06-12 15:26     ` Jamie Cunliffe
  0 siblings, 1 reply; 10+ messages in thread
From: Boqun Feng @ 2023-06-09 17:47 UTC (permalink / raw)
  To: Jamie Cunliffe
  Cc: linux-arm-kernel, rust-for-linux, Miguel Ojeda, Catalin Marinas,
	Will Deacon, steve.capper, Asahi Lina

On Tue, Jun 06, 2023 at 03:56:04PM +0100, Jamie Cunliffe wrote:
> 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>
> ---
>  Documentation/rust/arch-support.rst | 1 +
>  Makefile                            | 1 -
>  arch/arm64/Kconfig                  | 1 +
>  arch/arm64/Makefile                 | 2 ++
>  arch/x86/Makefile                   | 1 +
>  rust/Makefile                       | 6 +++++-
>  scripts/Makefile                    | 5 +++--
>  scripts/generate_rust_target.rs     | 4 +++-
>  8 files changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst
> index b91e9ef4d0c2..9b022af2f649 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        None.
>  ``um``        Maintained        ``x86_64`` only.
>  ``x86``       Maintained        ``x86_64`` only.
>  ============  ================  ==============================================
> diff --git a/Makefile b/Makefile
> index 9d765ebcccf1..16b1e4de70e3 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -561,7 +561,6 @@ KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
>  		   -std=gnu11
>  KBUILD_CPPFLAGS := -D__KERNEL__
>  KBUILD_RUSTFLAGS := $(rust_common_flags) \
> -		    --target=$(objtree)/scripts/target.json \
>  		    -Cpanic=abort -Cembed-bitcode=n -Clto=n \
>  		    -Cforce-unwind-tables=n -Ccodegen-units=1 \
>  		    -Csymbol-mangling-version=v0 \
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index b1201d25a8a4..10e9399e8e2f 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -217,6 +217,7 @@ config ARM64
>  	select HAVE_FUNCTION_ARG_ACCESS_API
>  	select MMU_GATHER_RCU_TABLE_FREE
>  	select HAVE_RSEQ
> +	select HAVE_RUST
>  	select HAVE_STACKPROTECTOR
>  	select HAVE_SYSCALL_TRACEPOINTS
>  	select HAVE_KPROBES
> diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
> index 2d49aea0ff67..2ce1555e9fc5 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 -C target-feature="-neon,-fp-armv8"

I don't think you need "-fp-armv8" here, because "aarch64-unknown-none"
target doesn't have the target-feature "fp-arm64":

	rustc +1.68.2 --print cfg --target aarch64-unknown-none | grep target_feature

	target_feature="neon"

, and having the "-fp-armv8" gave me a warning at compile time:

	  RUSTC L rust/core.o warning: unknown feature specified for `-Ctarget-feature`: `fp-armv8`
	  |
	  = note: it is still passed through to the codegen backend
	  = help: consider filing a feature request

Regards,
Boqun

> +
>  KBUILD_CFLAGS	+= $(call cc-option,-mabi=lp64)
>  KBUILD_AFLAGS	+= $(call cc-option,-mabi=lp64)
>  
> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
> index b39975977c03..79cffe92c916 100644
> --- a/arch/x86/Makefile
> +++ b/arch/x86/Makefile
> @@ -68,6 +68,7 @@ export BITS
>  #    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
>  #
>  KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
> +KBUILD_RUSTFLAGS += --target=$(objtree)/scripts/target.json
>  KBUILD_RUSTFLAGS += -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2
>  
>  ifeq ($(CONFIG_X86_KERNEL_IBT),y)
> diff --git a/rust/Makefile b/rust/Makefile
> index 7c9d9f11aec5..18d6fdb73fa9 100644
> --- a/rust/Makefile
> +++ b/rust/Makefile
> @@ -262,6 +262,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,
> @@ -393,8 +394,11 @@ $(obj)/core.o: private skip_clippy = 1
>  $(obj)/core.o: private skip_flags = -Dunreachable_pub
>  $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
>  $(obj)/core.o: private rustc_target_flags = $(core-cfgs)
> -$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs scripts/target.json FORCE
> +$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
>  	$(call if_changed_dep,rustc_library)
> +ifeq ($(ARCH),x86_64)
> +$(obj)/core.o: scripts/target.json
> +endif
>  
>  $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
>  $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
> diff --git a/scripts/Makefile b/scripts/Makefile
> index 32b6ba722728..633479d02e33 100644
> --- a/scripts/Makefile
> +++ b/scripts/Makefile
> @@ -9,12 +9,13 @@ hostprogs-always-$(CONFIG_BUILDTIME_TABLE_SORT)		+= sorttable
>  hostprogs-always-$(CONFIG_ASN1)				+= asn1_compiler
>  hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT)		+= sign-file
>  hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE)	+= insert-sys-cert
> -always-$(CONFIG_RUST)					+= target.json
>  
> +ifeq ($(ARCH),x86_64)
> +always-$(CONFIG_RUST)					+= target.json
>  filechk_rust_target = $< < include/config/auto.conf
> -
>  $(obj)/target.json: scripts/generate_rust_target include/config/auto.conf FORCE
>  	$(call filechk,rust_target)
> +endif
>  
>  hostprogs += generate_rust_target
>  generate_rust_target-rust := y
> 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
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/3] Rust enablement for AArch64
  2023-06-06 14:56 [PATCH v2 0/3] Rust enablement for AArch64 Jamie Cunliffe
                   ` (3 preceding siblings ...)
  2023-06-06 15:25 ` [PATCH v2 0/3] Rust enablement for AArch64 Miguel Ojeda
@ 2023-06-09 18:34 ` Boqun Feng
  4 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2023-06-09 18:34 UTC (permalink / raw)
  To: Jamie Cunliffe
  Cc: linux-arm-kernel, rust-for-linux, Miguel Ojeda, Catalin Marinas,
	Will Deacon, steve.capper, Asahi Lina

On Tue, Jun 06, 2023 at 03:56:03PM +0100, Jamie Cunliffe wrote:
> Enable Rust support for the AArch64 architecture.
> 

With the following diff on the whole series:

	diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
	index 4a2c807d65db..4562a8173e90 100644
	--- a/arch/arm64/Makefile
	+++ b/arch/arm64/Makefile
	@@ -41,7 +41,7 @@ KBUILD_CFLAGS += -mgeneral-regs-only  \
	 KBUILD_CFLAGS  += $(call cc-disable-warning, psabi)
	 KBUILD_AFLAGS  += $(compat_vdso)

	-KBUILD_RUSTFLAGS += --target aarch64-unknown-none -C target-feature="-neon,-fp-armv8"
	+KBUILD_RUSTFLAGS += --target aarch64-unknown-none -C target-feature="-neon"

	 KBUILD_CFLAGS  += $(call cc-option,-mabi=lp64)
	 KBUILD_AFLAGS  += $(call cc-option,-mabi=lp64)

I've built with RUST=y and boot it in one ARM64 Hyper-V VM. Also I tried
load/unload rust_minimal and rust_print modules, they all worked.

Tested-by: Boqun Feng <boqun.feng@gmail.com>

Regards,
Boqun
	

> The first patch enables the basic building of Rust for AArch64. Since
> v1 this has been rewritten to avoid the use of a target.json file for
> AArch64 and use the upstream rustc target definition. x86-64 still
> uses the target.json approach though.
> 
> The second patch enables the PAC ret and BTI options in the Rust build
> flags to match the options that are used when building C.
> 
> The third patch disables Rust support when building for big
> endian. Currently there is no `aarch64_be-unknown-none` target which
> would allow this. Support for this can come at a later time either by
> using the target.json approach, or upstreaming a new target definition
> to rustc (preferred). We also might be able to use the
> `aarch64_be-unknown-linux-gnu` target, however, this can be done at a
> later time.  It's worth noting that in Makefile.clang, it's
> recommended for arch/{arch}/Makefile to set the endianness based on
> arguments rather than the target triple. It's currently not possible
> to do this with rustc, a different target triple has to be used.
> 
> 
> Jamie Cunliffe (3):
>   arm64: rust: Enable Rust support for AArch64
>   arm64: rust: Enable PAC support for Rust.
>   arm64: Restrict Rust support to little endian only.
> 
>  Documentation/rust/arch-support.rst | 1 +
>  Makefile                            | 1 -
>  arch/arm64/Kconfig                  | 1 +
>  arch/arm64/Makefile                 | 4 ++++
>  arch/x86/Makefile                   | 1 +
>  rust/Makefile                       | 6 +++++-
>  scripts/Makefile                    | 5 +++--
>  scripts/generate_rust_target.rs     | 4 +++-
>  8 files changed, 18 insertions(+), 5 deletions(-)
> 
> -- 
> 2.30.2
> 
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/3] arm64: rust: Enable Rust support for AArch64
  2023-06-09 17:47   ` Boqun Feng
@ 2023-06-12 15:26     ` Jamie Cunliffe
  2023-06-29 19:46       ` Boqun Feng
  0 siblings, 1 reply; 10+ messages in thread
From: Jamie Cunliffe @ 2023-06-12 15:26 UTC (permalink / raw)
  To: boqun.feng
  Cc: Jamie.Cunliffe, catalin.marinas, lina, linux-arm-kernel, ojeda,
	rust-for-linux, steve.capper, will

> I don't think you need "-fp-armv8" here, because "aarch64-unknown-none"
> target doesn't have the target-feature "fp-arm64":
> 
> 	rustc +1.68.2 --print cfg --target aarch64-unknown-none | grep target_feature
> 
> 	target_feature="neon"
> 
> , and having the "-fp-armv8" gave me a warning at compile time:
> 
> 	  RUSTC L rust/core.o warning: unknown feature specified for `-Ctarget-feature`: `fp-armv8`
> 	  |
> 	  = note: it is still passed through to the codegen backend
> 	  = help: consider filing a feature request

Rust removed the fp feature for arm64 and tied it with Neon. However
this initially had a bug that meant it couldn't be disabled. This has
now been fixed in https://github.com/rust-lang/rust/pull/107294 so
once we can update rustc we can fix that warning by removing the
`-fp-armv8`. Until we do that we still need the `-fp-armv8` otherwise
we will get some floating point usage. This can be seen by doing an
objdump of core.o if you build after removing the `-fp-armv8`.


You can also see that fp-armv8 is enabled in the aarch64-unknown-none target
here: https://raw.githubusercontent.com/rust-lang/rust/master/compiler/rustc_target/src/spec/aarch64_unknown_none.rs


Thanks,
Jamie.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/3] arm64: rust: Enable Rust support for AArch64
  2023-06-12 15:26     ` Jamie Cunliffe
@ 2023-06-29 19:46       ` Boqun Feng
  2023-08-15 18:00         ` Boqun Feng
  0 siblings, 1 reply; 10+ messages in thread
From: Boqun Feng @ 2023-06-29 19:46 UTC (permalink / raw)
  To: Jamie Cunliffe
  Cc: catalin.marinas, lina, linux-arm-kernel, ojeda, rust-for-linux,
	steve.capper, will

On Mon, Jun 12, 2023 at 04:26:39PM +0100, Jamie Cunliffe wrote:
> > I don't think you need "-fp-armv8" here, because "aarch64-unknown-none"
> > target doesn't have the target-feature "fp-arm64":
> > 
> > 	rustc +1.68.2 --print cfg --target aarch64-unknown-none | grep target_feature
> > 
> > 	target_feature="neon"
> > 
> > , and having the "-fp-armv8" gave me a warning at compile time:
> > 
> > 	  RUSTC L rust/core.o warning: unknown feature specified for `-Ctarget-feature`: `fp-armv8`
> > 	  |
> > 	  = note: it is still passed through to the codegen backend
> > 	  = help: consider filing a feature request
> 
> Rust removed the fp feature for arm64 and tied it with Neon. However
> this initially had a bug that meant it couldn't be disabled. This has
> now been fixed in https://github.com/rust-lang/rust/pull/107294 so
> once we can update rustc we can fix that warning by removing the
> `-fp-armv8`. Until we do that we still need the `-fp-armv8` otherwise
> we will get some floating point usage. This can be seen by doing an
> objdump of core.o if you build after removing the `-fp-armv8`.
> 

Thanks for the information (and the fix)! That's good to know. Looks
like the fix will be in 1.71, then agree, we should keep `-fp-armv8`
until we update to 1.71 or later.

Regards,
Boqun

> 
> You can also see that fp-armv8 is enabled in the aarch64-unknown-none target
> here: https://raw.githubusercontent.com/rust-lang/rust/master/compiler/rustc_target/src/spec/aarch64_unknown_none.rs
> 
> 
> Thanks,
> Jamie.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/3] arm64: rust: Enable Rust support for AArch64
  2023-06-29 19:46       ` Boqun Feng
@ 2023-08-15 18:00         ` Boqun Feng
  0 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2023-08-15 18:00 UTC (permalink / raw)
  To: Jamie Cunliffe
  Cc: catalin.marinas, lina, linux-arm-kernel, ojeda, rust-for-linux,
	steve.capper, will

On Thu, Jun 29, 2023 at 12:46:13PM -0700, Boqun Feng wrote:
> On Mon, Jun 12, 2023 at 04:26:39PM +0100, Jamie Cunliffe wrote:
> > > I don't think you need "-fp-armv8" here, because "aarch64-unknown-none"
> > > target doesn't have the target-feature "fp-arm64":
> > > 
> > > 	rustc +1.68.2 --print cfg --target aarch64-unknown-none | grep target_feature
> > > 
> > > 	target_feature="neon"
> > > 
> > > , and having the "-fp-armv8" gave me a warning at compile time:
> > > 
> > > 	  RUSTC L rust/core.o warning: unknown feature specified for `-Ctarget-feature`: `fp-armv8`
> > > 	  |
> > > 	  = note: it is still passed through to the codegen backend
> > > 	  = help: consider filing a feature request
> > 
> > Rust removed the fp feature for arm64 and tied it with Neon. However
> > this initially had a bug that meant it couldn't be disabled. This has
> > now been fixed in https://github.com/rust-lang/rust/pull/107294 so
> > once we can update rustc we can fix that warning by removing the
> > `-fp-armv8`. Until we do that we still need the `-fp-armv8` otherwise
> > we will get some floating point usage. This can be seen by doing an
> > objdump of core.o if you build after removing the `-fp-armv8`.
> > 
> 
> Thanks for the information (and the fix)! That's good to know. Looks
> like the fix will be in 1.71, then agree, we should keep `-fp-armv8`
> until we update to 1.71 or later.
> 

Just FYI, rustc has been bumped to 1.71:

	https://lore.kernel.org/rust-for-linux/CANiq72mrzALO3J2VvDntscXwt7Z9KzT4+S8sc_HGc8u8izjyLw@mail.gmail.com/

BTW, recently I learned that ARCH is set as "x86" by default even on
x86_64 host, so things like:

	+ifeq ($(ARCH),x86_64)
	+$(obj)/core.o: scripts/target.json
	+endif

"ifeq .." will return false if compiled with "make LLVM=1" even on a
x86_64 host. Maybe use

	ifdef CONFIG_X86_64

?

Regards,
Boqun

> Regards,
> Boqun
> 
> > 
> > You can also see that fp-armv8 is enabled in the aarch64-unknown-none target
> > here: https://raw.githubusercontent.com/rust-lang/rust/master/compiler/rustc_target/src/spec/aarch64_unknown_none.rs
> > 
> > 
> > Thanks,
> > Jamie.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-08-15 18:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-06 14:56 [PATCH v2 0/3] Rust enablement for AArch64 Jamie Cunliffe
2023-06-06 14:56 ` [PATCH v2 1/3] arm64: rust: Enable Rust support " Jamie Cunliffe
2023-06-09 17:47   ` Boqun Feng
2023-06-12 15:26     ` Jamie Cunliffe
2023-06-29 19:46       ` Boqun Feng
2023-08-15 18:00         ` Boqun Feng
2023-06-06 14:56 ` [PATCH v2 2/3] arm64: rust: Enable PAC support for Rust Jamie Cunliffe
2023-06-06 14:56 ` [PATCH v2 3/3] arm64: Restrict Rust support to little endian only Jamie Cunliffe
2023-06-06 15:25 ` [PATCH v2 0/3] Rust enablement for AArch64 Miguel Ojeda
2023-06-09 18:34 ` Boqun Feng

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 NNTP newsgroup(s).