From f99fc4a134f59e114e2fff087472be4f71d1ebdd Mon Sep 17 00:00:00 2001 From: spinline Date: Sat, 7 Feb 2026 00:40:39 +0300 Subject: [PATCH] fix: use pure MIPS asm for __atomic_is_lock_free, remove unsupported --defsym --- .gitea/workflows/build-mips.yml | 3 +-- docker/runner/Dockerfile | 27 ++++++--------------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/.gitea/workflows/build-mips.yml b/.gitea/workflows/build-mips.yml index b8c427a..38589e4 100644 --- a/.gitea/workflows/build-mips.yml +++ b/.gitea/workflows/build-mips.yml @@ -34,8 +34,7 @@ jobs: env: # Ensure we are building a fully static binary # -C link-self-contained=no: Let Zig (the linker) handle CRT objects (crt1.o, etc.) - # --defsym=__atomic_is_lock_free=... Maps the missing symbol to our shim - RUSTFLAGS: "-C target-feature=+crt-static -C link-self-contained=no -C link-arg=-msoft-float -C link-arg=-Wl,--defsym=__atomic_is_lock_free=__atomic_is_lock_free_shim" + RUSTFLAGS: "-C target-feature=+crt-static -C link-self-contained=no -C link-arg=-msoft-float" CFLAGS_mips_unknown_linux_musl: "-msoft-float" run: | cd backend diff --git a/docker/runner/Dockerfile b/docker/runner/Dockerfile index 7272259..bb24c0d 100644 --- a/docker/runner/Dockerfile +++ b/docker/runner/Dockerfile @@ -46,20 +46,18 @@ RUN ARCH=$(dpkg --print-architecture) && \ mv "zig-linux-$ZIG_ARCH-$ZIG_VER" /root/zig && \ rm zig.tar.xz -# 5. Fix: Create libatomic.a shim for MIPS -# MIPS musl static build often misses __atomic_is_lock_free. -# We create a minimal implementation to satisfy the linker. -# We rename the function to avoid builtin conflict and alias it via linker flags later. +# 5. Fix: Create libatomic.a with __atomic_is_lock_free for MIPS +# MIPS musl static build misses __atomic_is_lock_free. +# We provide it via pure assembly to avoid Clang builtin conflicts. RUN . "$HOME/.cargo/env" && \ - echo '#include ' > atomic.c && \ - echo 'bool __atomic_is_lock_free_shim(unsigned int size, const volatile void *ptr) { return size <= 4; }' >> atomic.c && \ - /root/zig/zig cc -target mips-linux-musl -msoft-float -c -o atomic.o atomic.c && \ + printf '.text\n.globl __atomic_is_lock_free\n.type __atomic_is_lock_free, @function\n__atomic_is_lock_free:\n sltiu $v0, $a0, 5\n jr $ra\n nop\n.size __atomic_is_lock_free, .-__atomic_is_lock_free\n' > atomic.s && \ + /root/zig/zig cc -target mips-linux-musl -msoft-float -c -o atomic.o atomic.s && \ /root/zig/zig ar rcs libatomic.a atomic.o && \ RUST_SYSROOT=$(rustc --print sysroot) && \ TARGET_LIB_DIR="$RUST_SYSROOT/lib/rustlib/mips-unknown-linux-musl/lib" && \ mkdir -p "$TARGET_LIB_DIR" && \ cp libatomic.a "$TARGET_LIB_DIR/" && \ - rm atomic.c atomic.o libatomic.a + rm atomic.s atomic.o libatomic.a # 6. Install Tools (Trunk, cargo-zigbuild, wasm-bindgen protocol aligned) # We install trunk binary to save time, others via cargo @@ -75,19 +73,6 @@ RUN . "$HOME/.cargo/env" && \ # Install wasm-bindgen-cli (Compiling from source to avoid glibc issues, doing it ONCE here) cargo install wasm-bindgen-cli --version 0.2.108 -# 6. Fix: Create dummy libatomic.a for MIPS -# openssl-sys demands -latomic, but Zig provides the symbols in compiler-rt. -# We create an empty archive to satisfy the linker. -RUN . "$HOME/.cargo/env" && \ - echo '' > atomic.c && \ - /root/zig/zig cc -target mips-linux-musl -c -o atomic.o atomic.c && \ - /root/zig/zig ar rcs libatomic.a atomic.o && \ - RUST_SYSROOT=$(rustc --print sysroot) && \ - TARGET_LIB_DIR="$RUST_SYSROOT/lib/rustlib/mips-unknown-linux-musl/lib" && \ - mkdir -p "$TARGET_LIB_DIR" && \ - cp libatomic.a "$TARGET_LIB_DIR/" && \ - rm atomic.c atomic.o libatomic.a - # 7. Install Gitea Act Runner Binary # We fetch the binary directly to run as the entrypoint RUN ARCH=$(dpkg --print-architecture) && \