Skip to content

[PHP.wasm] Export Zend symbols for compiling PHP extensions - #3584

Merged
adamziel merged 4 commits into
trunkfrom
adamziel/php84-a1
May 1, 2026
Merged

[PHP.wasm] Export Zend symbols for compiling PHP extensions#3584
adamziel merged 4 commits into
trunkfrom
adamziel/php84-a1

Conversation

@adamziel

@adamziel adamziel commented May 1, 2026

Copy link
Copy Markdown
Collaborator

What it does

Exports the Zend symbols that PHP extension side modules need from the JSPI
PHP.wasm main modules.

This covers the committed JSPI artifacts for web and Node across PHP 5.2,
7.4, and 8.0-8.5. It does not add asyncify support for these side
module exports.

Rationale

MAIN_MODULE=2 only exposes explicitly requested symbols. PHP internals and
statically linked extensions can still work without these exports, but dynamic
WASM side modules need the main module to expose the Zend class entries,
globals, handlers, and function addresses they import through the WASM ABI.

Implementation

Adds JSPI-only .WASM_ABI_EXPORTS entries guarded by PHP version. PHP
7.4-8.5 also compile a small zend-side-module-exports.c helper into the
main module so the linker keeps the referenced Zend symbols visible.

Symbols added for PHP 5.2 JSPI:

zend_ce_traversable
zend_ce_iterator
zend_ce_aggregate
zend_ce_arrayaccess
zend_ce_serializable
std_object_handlers
executor_globals
compiler_globals
sapi_globals
file_globals
sapi_module
compile_string
execute
_zval_ptr_dtor
destroy_op_array
_efree
_zend_bailout

Symbols added for PHP 7.4-8.5 JSPI:

zend_ce_exception
zend_ce_traversable
zend_ce_iterator
zend_ce_aggregate
zend_ce_arrayaccess
zend_ce_countable
zend_ce_throwable
zend_ce_serializable
zend_string_init_interned
zend_empty_string
zend_one_char_string
std_object_handlers
executor_globals
compiler_globals
sapi_globals
file_globals
sapi_module
zend_compile_string
zend_get_executed_scope
zend_execute
zval_ptr_dtor
destroy_op_array
_efree
_zend_bailout

Additional PHP 8.0-8.5 JSPI symbols:

zend_ce_stringable
zend_ce_unhandled_match_error
zend_ce_division_by_zero_error

Additional PHP 8.1-8.5 JSPI symbols:

zend_ce_unit_enum
zend_ce_backed_enum
zend_destroy_static_vars

The PHP 5.2 build also switches the config.guess and config.sub download
URLs to Savannah gitweb blob_plain endpoints to avoid the failing cgit
plain-file endpoint during rebuilds.

Testing instructions

Rebuilt JSPI PHP artifacts for web and Node:

npm exec nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=5.2
npm exec nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=7.4
npm exec nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.0
npm exec nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.1
npm exec nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.2
npm exec nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.3
npm exec nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.4
npm exec nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.5
npm exec nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=5.2
npm exec nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=7.4
npm exec nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.0
npm exec nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.1
npm exec nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.2
npm exec nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.3
npm exec nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.4
npm exec nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.5

Also verified the rebuilt JSPI WASM files export the expected symbols with
wasm-objdump, and ran git diff --check.

CI currently passes except for test-legacy-wp-version-boot, which fails on
trunk with the same WP 6.2 (PHP 7.4) Vite worker-load timeout.

@adamziel
adamziel force-pushed the adamziel/php84-a1 branch from d6e9afe to d85a9e7 Compare May 1, 2026 19:48
adamziel added 2 commits May 1, 2026 22:11
5.2 doesn't have zend_ce_exception, zend_ce_throwable, zend_string_init_interned,
zend_empty_string, zend_one_char_string, zend_get_executed_scope, or
zval_ptr_dtor (it has _zval_ptr_dtor instead). Guard the side-module export
list both in the Dockerfile and zend-side-module-exports.c by PHP version.

Also switch the 5.2 Dockerfile's config.guess/config.sub fetches from the
broken cgit/plain endpoint to a working gitweb URL, and only inject the
zend-side-module-exports.c source when building with JSPI.
@adamziel
adamziel marked this pull request as ready for review May 1, 2026 23:11
@adamziel
adamziel requested review from a team, brandonpayton and Copilot May 1, 2026 23:11
@adamziel adamziel added the [Type] Enhancement New feature or request label May 1, 2026
@adamziel adamziel changed the title [codex] Export Zend symbols for PHP side modules May 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@adamziel
adamziel merged commit 7d2b901 into trunk May 1, 2026
97 of 99 checks passed
@adamziel
adamziel deleted the adamziel/php84-a1 branch May 1, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment