Skip to content

Commit fa55696

Browse files
committed
Force function-pointer CPU dispatch for zig builds to fix silent lld crash
Root cause of the intermittent 'Aborted (core dumped) zig-cc' at the sapi/cli/php LTO link, proven by byte-exact local replay of the CI link (lld --reproduce) and single-file bisection: PHP's configure probes __builtin_cpu_supports/__builtin_cpu_init with a link test that runs under -flto. Whether zig resolves compiler-rt's __cpu_model in that probe varies by machine, so the result is a per-VM lottery. When it says yes, zend_portability.h enables ZEND_INTRIN_*_FUNC_PROTO and mbstring/standard compile __attribute__((ifunc)) AVX2 resolvers. An ifunc in full-LTO bitcode crashes zig 0.16's lld (LLVM 21.1.0): during LTO prevailing-symbol resolution it dereferences a null summary for the local symbol mb_cut_utf16le (GUID 0x151eb2c1758fcd09 = md5_64 of '<mbfilter_utf16.c>;mb_cut_utf16le'), and the zig driver swallows the child's SIGSEGV, leaving no output. Verified both directions: compiling mbfilter_utf16.o with the cpu builtins defined produces the ifunc object and the link crashes; compiling with them off produces the function-pointer object and the same link succeeds. Forcing the configure cache vars to no (like the existing avx512 overrides) makes every build take the safe, deterministic function-pointer dispatch path. Runtime cost is a pointer call instead of an ifunc-resolved call for a handful of mb/crc32 functions.
1 parent 6b998b2 commit fa55696

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

config/templates/craft.yml.twig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,13 @@ extra-env:
9797
SPC_MUSL_DYNAMIC: 'true'
9898
{% else -%}
9999
SPC_TARGET: '{{ target }}'
100-
SPC_EXTRA_PHP_VARS: 'php_cv_preserve_none=yes'
100+
# __builtin_cpu_supports=yes makes PHP emit __attribute__((ifunc)) AVX2 resolvers
101+
# (mbstring, standard), and ifuncs in full-LTO bitcode crash zig 0.16's lld
102+
# (LLVM 21.1.0) with a silent SIGSEGV during LTO symbol resolution. The configure
103+
# probe itself is an -flto link test whose result varies per machine (zig
104+
# compiler_rt __cpu_model resolution), which made the crash look random per VM.
105+
# Force the safe function-pointer dispatch path instead.
106+
SPC_EXTRA_PHP_VARS: 'php_cv_preserve_none=yes php_cv_have___builtin_cpu_supports=no php_cv_have___builtin_cpu_init=no'
101107
# zig cc without -O keeps Debug UB traps; bare-built minilua aborts on Lua's 2^32 double->int cast
102108
SPC_COMPILER_EXTRA: '-fno-sanitize=undefined'
103109
{% endif -%}

0 commit comments

Comments
 (0)