fix: force LLVM backend for x86_64 app executables to avoid .sframe linker crash#93
fix: force LLVM backend for x86_64 app executables to avoid .sframe linker crash#93mvanhorn wants to merge 2 commits into
Conversation
|
@mvanhorn is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
Scoped follow-up to bot review on build.zig/app.zig; zig build verified locally.
|
Addressed in b8899df; zig build passes locally on x86_64 and aarch64 hosts. |
|
Tested on Ubuntu 24.04.4 LTS x86_64, Zig 0.16.0. |
|
Good catch — yes. The 11 examples that call |
Summary
The repo already contains the exact remedy:
useLlvmWorkaround(target)inbuild/app.zig(returnstrueon x86_64) is applied to the mobile static lib, the test compile, and the model-contract exe - but NOT to the main app executable created inaddAppArtifacts(b.addExecutable(.{ .name = app_options.name, .root_module = app_mod }), ~line 244). Add.use_llvm = useLlvmWorkaround(target)there so Debug app builds on x86_64 use LLVM+LLD and never hit the self-hosted linker's .sframe limitation; verify whether.use_lldmust also be set explicitly on this Zig version (the upstream workaround sets both). Extend theuseLlvmWorkarounddoc comment to record this second justification (the .sframe R_X86_64_PC64 linker crash with GCC 15 crt1.o, issue #37) alongside the existing SysV f32 miscompile rationale.Why this matters
On Linux x86_64 hosts with GCC 15+, Debug builds of Native SDK apps fail at link time with
fatal linker error: unhandled relocation type R_X86_64_PC64 ... crt1.o:.sframe. GCC 15 emits.sframesections into crt1.o, and Zig 0.15/0.16's self-hosted x86_64 linker (used for Debug builds) cannot process their R_X86_64_PC64 relocations - this is upstream Zig issue codeberg.org/ziglang/zig#31272, where the confirmed workaround is forcing the LLVM backend (.use_llvm = true), which links via LLD. Multiple users are affected (any Arch/Manjaro/CachyOS system with GCC 15), and a commenter on the issue linked the upstream fix/workaround.See #37.
Testing
zig build -Doptimize=Debug(andzig build run) for an app usingaddAppcompiles and links successfully - the emitted compile uses the LLVM backend instead of the self-hosted x86_64 backend, so noR_X86_64_PC64error. - Edge case: non-x86_64 targets (aarch64 macOS/Linux) are unaffected -useLlvmWorkaroundreturnsnullthere, preserving current backend selection. - Edge case: Release builds are unchanged (they already default to LLVM); the flag only alters Debug-mode backend choice. - Regression guard: repozig build teststill passes; the existing file-contains checker step in rootbuild.zigcan gain a pattern assertingbuild/app.zigappliesuseLlvmWorkaroundto the app exe so the workaround is not silently dropped.Fixes #37