Skip to content

php-in-php: hash_crypto_jit_runtime.c — delete ~800 lines from AOT link bundle, lower hash via VmHashNative (#5989 phase 2) #7437

Description

@PurHur

Category

php-in-PHP

Problem

lib/AOT/Linker.php still compiles and links lib/JIT/Builtin/hash_crypto_jit_runtime.c (~800 lines of hand-written SHA/MD5 C) on every AOT binary. VM hash builtins already live in ext/hash/ + ext/standard/VmHashNative.php; JIT lowering should reuse that PHP path instead of maintaining a parallel C crypto table.

This blocks M5 self-host honesty (shrink C runtime) and duplicates semantics already tracked in #5989 / #5227.

php-src reference

Behavior reference only — implementation belongs in PHP (ext/hash/, lib/JIT/Builtin/).

Repro (bundle audit)

./script/docker-exec.sh -- bash -lc '
wc -l lib/JIT/Builtin/hash_crypto_jit_runtime.c
grep hash_crypto lib/AOT/Linker.php
php -r "
\$s = file_get_contents(\"lib/AOT/Linker.php\");
echo str_contains(\$s, \"hash_crypto_jit_runtime.c\") ? \"still linked\n\" : \"removed\n\";
"
'

Today: file present (~800 lines) and listed in Linker::RUNTIME_C_SOURCES.

After a minimal hash(\"sha256\", \"x\") AOT fixture, native binary must still print the same digest as Zend without linking hash_crypto_jit_runtime.c.

Scope

Layer Path
Delete C lib/JIT/Builtin/hash_crypto_jit_runtime.c (after parity)
Linker lib/AOT/Linker.php — remove from RUNTIME_C_SOURCES
JIT/AOT ext/standard/JitHash.php, ext/hash/JitHashAlgos.php — route to VmHashNative / existing LLVM helpers
VM ext/standard/VmHashNative.php, ext/hash/ — SSOT for algorithms
Tests existing test/compliance/cases/stdlib/hash*.phpt; AOT fixture hash_sha256.phpt

php-src-strict: enum-case operands must still TypeError (#5780).

Done when

  • hash_crypto_jit_runtime.c removed from repo or ≤50-line thin ABI stub with proof no algorithm logic remains
  • Linker::RUNTIME_C_SOURCES no longer references the file
  • AOT hash('sha256', 'x') / md5('x') fixtures match Zend
  • ./script/ci-fast.sh --filter Hash green; full ./script/ci-local.sh llvm phases when JIT hash touched

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./script/ci-local.sh --filter hash_sha256'

Related

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 7, 2026
  2. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#7437: migrate hash_crypto_jit_runtime.c LLVM lowering to PHP StringHashCryptoJit, delete ~762 C lines from AOT link bundle).

  3. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    Unclaiming #7437 this run: phase 2 requires porting ~762 lines of sha256/sha1/md5/HMAC/PBKDF2 from VmHashNative into PHPLLVM Builder (HashCryptoNativeJit.php) — same scope as #7078 json_decode. Phase 1 (#7480) already removed hash_equals/hmac_algos from C. Next run should implement HashCryptoNativeJit mirroring VmHashNative, then delete hash_crypto_jit_runtime.c from Linker.

  4. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#7437: HashCryptoNativeJit + delete hash_crypto_jit_runtime.c from AOT link bundle).

  5. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    Merged via #7538

    C shrink: deleted lib/JIT/Builtin/hash_crypto_jit_runtime.c (762 lines) and removed from Linker::RUNTIME_C_SOURCES.

    PHP path: lib/JIT/Builtin/StringHashCryptoNativeJit.php lowers __compiler_hash / __compiler_hash_hmac / __compiler_hash_pbkdf2 in PHPLLVM Builder (mirrors VmHashNative). StringHashCryptoJit.php no longer compiles C bitcode or skips standalone mode.

    Verification (Docker):

    • StringHashCryptoRuntimeStandaloneTest + VmHashNativeTest — OK
    • stdlib hash compliance (digest cases) — OK
    • AOT fixtures hash_hmac, hash_raw_output, hash_equals, hash_pbkdf2 — OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions