]> git.99rst.org Git - openwrt-packages.git/commitdiff
rust: build soft-float on soft-float PowerPC subtargets
authorJosef Schlehofer <redacted>
Fri, 7 Aug 2026 22:21:50 +0000 (00:21 +0200)
committerJosef Schlehofer <redacted>
Sun, 16 Aug 2026 06:15:03 +0000 (08:15 +0200)
RUSTC_TARGET_ARCH comes from the GNU triple, so every 32-bit PowerPC
subtarget gets powerpc-unknown-linux-musl. That triple is hard-float and
mpc85xx is not: its e500v2 has no floating-point unit, and the toolchain
reports _SOFT_FLOAT and calls __divdf3 for a division.

So rustc emits lfd, stfd and fdiv for a core with no floating-point
registers, and passes doubles in a way nothing else in the image does. It
does not fail outright — a speed test reported negative throughput, and
formatting one of those values tripped an assertion inside core.

Pass -Ctarget-feature=-hard-float where CONFIG_SOFT_FLOAT says so. The same
flag has to reach the std that rust/host builds, or std and the packages
linked against it disagree about how a double is passed.

Signed-off-by: Josef Schlehofer <redacted>
lang/rust/Makefile
lang/rust/rust-values.mk

index 08adae63ca6e54d8a095b39ed2a5eef55610b0dd..2a01fb65562ce9a14bed28a2d2989a15e82730a5 100644 (file)
@@ -89,6 +89,7 @@ define Host/Compile
        $(RUST_SCCACHE_VARS) \
        CARGO_HOME=$(CARGO_HOME) \
        TARGET_CFLAGS="$(TARGET_CFLAGS)" \
+       $(if $(RUSTC_TARGET_RUSTFLAGS),$(RUSTC_TARGET_CARGO_RUSTFLAGS)="$(RUSTC_TARGET_RUSTFLAGS)") \
        $(PYTHON) $(HOST_BUILD_DIR)/x.py \
                --build-dir $(HOST_BUILD_DIR)/build \
                dist build-manifest rustc rust-std cargo llvm-tools rust-src
index 8e49409ff64f32226b16ca0b6b5ce50544f4b755..de3de92c52dd329e2068e7f828e1fe1a3f9683dc 100644 (file)
@@ -52,6 +52,24 @@ else ifeq ($(ARCH),riscv64)
   RUSTC_TARGET_ARCH:=$(subst riscv64,riscv64gc,$(RUSTC_TARGET_ARCH))
 endif
 
+# 32-bit PowerPC has both soft-float and hard-float subtargets: mpc85xx is an
+# e500v2 with no floating-point unit at all, while apm821xx (powerpc_464fp)
+# has one. They share the powerpc-unknown-linux-musl triple, which is the
+# hard-float one, so on the soft-float subtarget rustc emits lfd, stfd and
+# fdiv for a core with no floating-point registers, and passes doubles in
+# registers nothing else in the image uses.
+#
+# CONFIG_SOFT_FLOAT already carries this: it defaults to y when the target has
+# no fpu feature, and it is what puts --with-float=soft into the toolchain and
+# -msoft-float into TARGET_CFLAGS.
+ifeq ($(ARCH),powerpc)
+  ifeq ($(CONFIG_SOFT_FLOAT),y)
+    RUSTC_TARGET_RUSTFLAGS+=-Ctarget-feature=-hard-float
+  endif
+endif
+
+CARGO_RUSTFLAGS+=$(RUSTC_TARGET_RUSTFLAGS)
+
 # ARM Logic
 ifeq ($(ARCH),arm)
   ifeq ($(CONFIG_arm_v6)$(CONFIG_arm_v7),)
@@ -70,6 +88,16 @@ ifeq ($(ARCH),aarch64)
     RUSTC_CFLAGS:=-mno-outline-atomics
 endif
 
+# The same flags have to reach the std that rust/host builds for the target,
+# or std and the packages linked against it disagree about how a double is
+# passed. Bootstrap sets RUSTFLAGS itself on the cargo invocations it spawns,
+# so setting that would be overwritten; it does however read
+# CARGO_TARGET_<TRIPLE>_RUSTFLAGS and fold it in, scoped to that triple, which
+# leaves the host artifacts built in the same run untouched.
+# Deferred, because the blocks above still rewrite RUSTC_TARGET_ARCH.
+RUSTC_TARGET_UPPER = $(subst -,_,$(call toupper,$(RUSTC_TARGET_ARCH)))
+RUSTC_TARGET_CARGO_RUSTFLAGS = CARGO_TARGET_$(RUSTC_TARGET_UPPER)_RUSTFLAGS
+
 # Support only a subset for now.
 RUST_ARCH_DEPENDS:=@(aarch64||arm||i386||loongarch64||mips||mips64||mips64el||mipsel||powerpc||powerpc64||riscv64||x86_64)
 
@@ -100,7 +128,7 @@ CARGO_PKG_CONFIG_VARS= \
        CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS=true \
        CARGO_PROFILE_RELEASE_PANIC=unwind \
        CARGO_PROFILE_RELEASE_RPATH=false \
-       CARGO_TARGET_$(subst -,_,$(call toupper,$(RUSTC_TARGET_ARCH)))_LINKER=$(TARGET_CC_NOCACHE) \
+       CARGO_TARGET_$(RUSTC_TARGET_UPPER)_LINKER=$(TARGET_CC_NOCACHE) \
        RUSTFLAGS="$(CARGO_RUSTFLAGS)" \
        TARGET_CC=$(TARGET_CC_NOCACHE) \
        TARGET_CFLAGS="$(TARGET_CFLAGS) $(RUSTC_CFLAGS)"
git clone https://git.99rst.org/PROJECT