Skip to content

fix(build): re-enable x86 hardware intrinsics (SHA-NI, PCLMUL, AVX2)#36

Merged
luthermonson merged 1 commit into
mainfrom
fix/hash-intrinsics
Jul 10, 2026
Merged

fix(build): re-enable x86 hardware intrinsics (SHA-NI, PCLMUL, AVX2)#36
luthermonson merged 1 commit into
mainfrom
fix/hash-intrinsics

Conversation

@luthermonson

Copy link
Copy Markdown
Contributor

Summary

  • Every Linux SDK shipped to date has had all x86 intrinsic resolvers compiled out: a C++-only flag (-fvisibility-inlines-hidden) in the spc fork's PHP_MAKE_EXTRA_CFLAGS makes GCC warn on every C compile, and php-src's AX_GCC_FUNC_ATTRIBUTE treats any stderr as "attribute unsupported" -- HAVE_FUNC_ATTRIBUTE_TARGET/IFUNC come back undefined, so SHA-NI sha256 (measured 2.7x slow), PCLMUL crc32c (2.2x), and the SSSE3/AVX2 ZEND_INTRIN paths (incl. base64) never build.
  • Fix: override SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS via env in the Linux build script (env beats env.ini) with the identical flag set minus the poison token, pre-expanded. No fork change needed -- upstream spc already fixed the placement on their main; the fork inherits it whenever it rebases.
  • Guard: x86_64 builds now fail unless HAVE_FUNC_ATTRIBUTE_TARGET is defined and SHA256_Transform_shani is present in libphp.a.

Evidence

  • nm on shipped 8.4.22 linux-x86_64{,-gnu} tarballs: no SHA256_Transform_shani, php_config.h has /* #undef HAVE_FUNC_ATTRIBUTE_TARGET */
  • autoconf repro on the almalinux8/gcc-toolset-13 builder: 236 bytes of conftest stderr with the flag, 0 without
  • algo matrix vs FrankenPHP: exactly the two attribute-gated algorithms run 2-3x slow; sha1/md5/sha512/xxh128 all sit at ratio ~1.0

Test plan

  • Dispatch linux-x86_64-gnu + linux-x86_64 builds for 8.4 from this branch
  • Guard passes (shani symbol + config define present)
  • Rebuild ephpm image against the new tarball, rerun the hash matrix: sha256 ~200ns/op (from 540), crc32c at parity

The spc fork env.ini places -fvisibility-inlines-hidden (C++-only) in
PHP_MAKE_EXTRA_CFLAGS. GCC warns on every C compile, php-src's
AX_GCC_FUNC_ATTRIBUTE macro treats any stderr as "unsupported", and
HAVE_FUNC_ATTRIBUTE_TARGET/IFUNC come back undefined -- so every Linux
SDK ever shipped had ALL x86 intrinsic resolvers compiled out:

- SHA-NI sha256: measured 2.7x slower than FrankenPHP/docker builds
  (540ns vs 200ns per 64-byte digest)
- PCLMUL crc32c: 2.2x slower
- every ZEND_INTRIN_* resolver (SSSE3/SSE4.2/AVX2/AVX512 incl. base64)

Verified via nm on shipped tarballs (no SHA256_Transform_shani symbol),
an autoconf repro on the almalinux8/gcc-13 builder (236 bytes of stderr
with the flag, 0 without), and an algo matrix where exactly the two
algorithms with attribute-gated hardware paths run 2-3x slow while all
others sit at ratio ~1.0.

Upstream static-php-cli fixed the flag placement on main in May 2026;
until the fork rebases onto that, override PHP_MAKE_EXTRA_CFLAGS via
env (real env vars win over env.ini) with the identical value minus
the one poison token, ${SPC_DEFAULT_CFLAGS} pre-expanded.

Adds a hard guard after staging: x86_64 builds fail unless
HAVE_FUNC_ATTRIBUTE_TARGET is defined in php_config.h AND
SHA256_Transform_shani is present in libphp.a -- a soft-sha256 SDK can
never ship silently again.
@luthermonson luthermonson merged commit 43267a7 into main Jul 10, 2026
5 checks passed
@luthermonson luthermonson deleted the fix/hash-intrinsics branch July 10, 2026 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant