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.
Unified · Split
| @@ -15,6 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file. · 14 unmodified lines | |||
| 15 | ============= ================ ============================================== | 15 | ============= ================ ============================================== |
| 16 | Architecture Level of support Constraints | 16 | Architecture Level of support Constraints |
| 17 | ============= ================ ============================================== | 17 | ============= ================ ============================================== |
| 18 | ``arm64`` Maintained Little Endian only. | ||
| 18 | ``loongarch`` Maintained - | 19 | ``loongarch`` Maintained - |
| 19 | ``um`` Maintained ``x86_64`` only. | 20 | ``um`` Maintained ``x86_64`` only. |
| 20 | ``x86`` Maintained ``x86_64`` only. | 21 | ``x86`` Maintained ``x86_64`` only. |
| @@ -229,6 +229,7 @@ config ARM64 · 228 unmodified lines | |||
| 229 | select HAVE_FUNCTION_ARG_ACCESS_API | 229 | select HAVE_FUNCTION_ARG_ACCESS_API |
| 230 | select MMU_GATHER_RCU_TABLE_FREE | 230 | select MMU_GATHER_RCU_TABLE_FREE |
| 231 | select HAVE_RSEQ | 231 | select HAVE_RSEQ |
| 232 | select HAVE_RUST if CPU_LITTLE_ENDIAN | ||
| 232 | select HAVE_STACKPROTECTOR | 233 | select HAVE_STACKPROTECTOR |
| 233 | select HAVE_SYSCALL_TRACEPOINTS | 234 | select HAVE_SYSCALL_TRACEPOINTS |
| 234 | select HAVE_KPROBES | 235 | select HAVE_KPROBES |
| @@ -41,6 +41,8 @@ KBUILD_CFLAGS += -mgeneral-regs-only \ · 40 unmodified lines | |||
| 41 | KBUILD_CFLAGS += $(call cc-disable-warning, psabi) | 41 | KBUILD_CFLAGS += $(call cc-disable-warning, psabi) |
| 42 | KBUILD_AFLAGS += $(compat_vdso) | 42 | KBUILD_AFLAGS += $(compat_vdso) |
| 43 | 43 | ||
| 44 | KBUILD_RUSTFLAGS += --target=aarch64-unknown-none -Ctarget-feature="-neon" | ||
| 45 | |||
| 44 | KBUILD_CFLAGS += $(call cc-option,-mabi=lp64) | 46 | KBUILD_CFLAGS += $(call cc-option,-mabi=lp64) |
| 45 | KBUILD_AFLAGS += $(call cc-option,-mabi=lp64) | 47 | KBUILD_AFLAGS += $(call cc-option,-mabi=lp64) |
| 46 | 48 | ||
| @@ -65,7 +67,9 @@ endif · 18 unmodified lines | |||
| 65 | 67 | ||
| 66 | ifeq ($(CONFIG_ARM64_BTI_KERNEL),y) | 68 | ifeq ($(CONFIG_ARM64_BTI_KERNEL),y) |
| 67 | KBUILD_CFLAGS += -mbranch-protection=pac-ret+bti | 69 | KBUILD_CFLAGS += -mbranch-protection=pac-ret+bti |
| 70 | KBUILD_RUSTFLAGS += -Zbranch-protection=bti,pac-ret | ||
| 68 | else ifeq ($(CONFIG_ARM64_PTR_AUTH_KERNEL),y) | 71 | else ifeq ($(CONFIG_ARM64_PTR_AUTH_KERNEL),y) |
| 72 | KBUILD_RUSTFLAGS += -Zbranch-protection=pac-ret | ||
| 69 | ifeq ($(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET),y) | 73 | ifeq ($(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET),y) |
| 70 | KBUILD_CFLAGS += -mbranch-protection=pac-ret | 74 | KBUILD_CFLAGS += -mbranch-protection=pac-ret |
| 71 | else | 75 | else |
| @@ -297,6 +297,7 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \ · 296 unmodified lines | |||
| 297 | 297 | ||
| 298 | # Derived from `scripts/Makefile.clang`. | 298 | # Derived from `scripts/Makefile.clang`. |
| 299 | BINDGEN_TARGET_x86 := x86_64-linux-gnu | 299 | BINDGEN_TARGET_x86 := x86_64-linux-gnu |
| 300 | BINDGEN_TARGET_arm64 := aarch64-linux-gnu | ||
| 300 | BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH)) | 301 | BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH)) |
| 301 | 302 | ||
| 302 | # All warnings are inhibited since GCC builds are very experimental, | 303 | # All warnings are inhibited since GCC builds are very experimental, |
| @@ -148,7 +148,9 @@ fn main() { · 147 unmodified lines | |||
| 148 | let mut ts = TargetSpec::new(); | 148 | let mut ts = TargetSpec::new(); |
| 149 | 149 | ||
| 150 | // `llvm-target`s are taken from `scripts/Makefile.clang`. | 150 | // `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") { | ||
| 152 | ts.push("arch", "x86_64"); | 154 | ts.push("arch", "x86_64"); |
| 153 | ts.push( | 155 | ts.push( |
| 154 | "data-layout", | 156 | "data-layout", |