-
Notifications
You must be signed in to change notification settings - Fork 448
Fix external PHP extension ABI exports #4108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chubes4
wants to merge
13
commits into
WordPress:trunk
Choose a base branch
from
chubes4:fix/4107-external-extension-abi
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8dfaff7
Fix external PHP extension ABI exports
chubes4 5bef6ca
Filter archive labels from PHP ABI exports
chubes4 ba600e9
Account for local extension ABI exports
chubes4 a0f218f
Harden external extension ABI generation
chubes4 a2345f9
Complete external extension libc ABI
chubes4 48f1b6f
Distinguish local side-module symbols
chubes4 566511c
Keep extension PHP versions aligned with runtime builds
chubes4 744d41c
Allow canonical PHP version metadata import
chubes4 202bc37
Harden external ABI build determinism
chubes4 b6fbb05
Test external extension ABI at runtime
chubes4 e549261
Validate PHP extension module exports
chubes4 4147a18
Explain stable allocator entry point
chubes4 f0c4a9d
Export strncasecmp for side modules
chubes4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| // eslint-disable-next-line @nx/enforce-module-boundaries | ||
| import { phpVersions } from '../../supported-php-versions.mjs'; | ||
| import { resolvePHPRelease, SupportedExtensionPHPVersions } from './compile'; | ||
|
|
||
| describe('resolvePHPRelease', () => { | ||
| it('uses the canonical release for every supported extension PHP minor version', () => { | ||
| const canonicalReleases = new Map( | ||
| phpVersions.map(({ version, lastRelease }) => [ | ||
| version, | ||
| lastRelease, | ||
| ]) | ||
| ); | ||
|
|
||
| for (const phpVersion of SupportedExtensionPHPVersions) { | ||
| expect(resolvePHPRelease(phpVersion)).toBe( | ||
| canonicalReleases.get(phpVersion) | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| it('resolves PHP 8.4 to the canonical release', () => { | ||
| expect(resolvePHPRelease('8.4')).toBe('8.4.23'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/php-wasm/compile-extension/tests/fixtures/external-abi/config.m4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| PHP_ARG_ENABLE([external_abi], [whether to enable external_abi], [--enable-external_abi]) | ||
|
|
||
| if test "$PHP_EXTERNAL_ABI" != "no"; then | ||
| PHP_NEW_EXTENSION([external_abi], [external_abi.c], [$ext_shared]) | ||
| fi | ||
|
chubes4 marked this conversation as resolved.
|
||
59 changes: 59 additions & 0 deletions
59
packages/php-wasm/compile-extension/tests/fixtures/external-abi/external_abi.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #ifdef HAVE_CONFIG_H | ||
| #include "config.h" | ||
| #endif | ||
|
|
||
| #include "php.h" | ||
| #include "ext/standard/php_password.h" | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include <strings.h> | ||
|
|
||
| PHP_FUNCTION(external_abi_probe) | ||
| { | ||
| zval value; | ||
| char cleared[4] = {1, 1, 1, 1}; | ||
| int parsed = 0; | ||
| void *first = emalloc(160); | ||
| void *second = emalloc(448); | ||
| zend_string *algorithm = zend_string_init("bcrypt", sizeof("bcrypt") - 1, 0); | ||
| zend_string *mixed_case = zend_string_init("Zstd", sizeof("Zstd") - 1, 0); | ||
| int compared; | ||
|
|
||
| ZVAL_LONG(&value, 1); | ||
| convert_to_null(&value); | ||
| php_password_algo_find(algorithm); | ||
| php_password_algo_register("external_abi", &php_password_algo_bcrypt); | ||
| explicit_bzero(cleared, sizeof(cleared)); | ||
| sscanf("42", "%d", &parsed); | ||
| compared = strncasecmp(ZSTR_VAL(mixed_case), "zstd", 4); | ||
| zend_string_release(algorithm); | ||
| zend_string_release(mixed_case); | ||
| efree(first); | ||
| efree(second); | ||
| RETURN_BOOL(cleared[0] == 0 && parsed == 42 && compared == 0); | ||
| } | ||
|
|
||
| static const zend_function_entry external_abi_functions[] = { | ||
| PHP_FE(external_abi_probe, NULL) | ||
| PHP_FE_END | ||
| }; | ||
|
|
||
| zend_module_entry external_abi_module_entry = { | ||
| STANDARD_MODULE_HEADER, | ||
| "external_abi", | ||
| external_abi_functions, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| "0.1.0", | ||
| STANDARD_MODULE_PROPERTIES, | ||
| }; | ||
|
|
||
| #ifdef COMPILE_DL_EXTERNAL_ABI | ||
| #ifdef ZTS | ||
| ZEND_TSRMLS_CACHE_DEFINE() | ||
| #endif | ||
| ZEND_GET_MODULE(external_abi) | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/php-wasm/compile-extension/tests/test-external-extension-abi.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env bash | ||
|
brandonpayton marked this conversation as resolved.
|
||
| set -euo pipefail | ||
|
|
||
| ROOT_DIR="$(git rev-parse --show-toplevel)" | ||
| PHP_VERSION="${PHP_VERSION:-8.5}" | ||
|
|
||
| if ! command -v docker >/dev/null 2>&1; then | ||
| echo "Docker is required for external extension ABI tests." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| mkdir -p "${ROOT_DIR}/tmp" | ||
| WORK_DIR="$(mktemp -d "${ROOT_DIR}/tmp/external-extension-abi.XXXXXX")" | ||
| trap 'rm -rf "$WORK_DIR"' EXIT | ||
|
|
||
| node "$ROOT_DIR/packages/php-wasm/compile/build.js" \ | ||
| --PLATFORM=node \ | ||
| --PHP_VERSION="$PHP_VERSION" \ | ||
| --WITH_JSPI=yes \ | ||
| --output-dir="$WORK_DIR/runtime" | ||
|
|
||
| node \ | ||
| --experimental-wasm-jspi \ | ||
| --experimental-strip-types \ | ||
| --experimental-transform-types \ | ||
| --disable-warning=ExperimentalWarning \ | ||
| --import "$ROOT_DIR/packages/meta/src/node-es-module-loader/register.mts" \ | ||
| "$ROOT_DIR/packages/php-wasm/compile-extension/src/cli.ts" \ | ||
| --source "$ROOT_DIR/packages/php-wasm/compile-extension/tests/fixtures/external-abi" \ | ||
| --name external_abi \ | ||
| --php-versions "$PHP_VERSION" \ | ||
| --jobs 1 \ | ||
| --out "$WORK_DIR/extension" | ||
|
|
||
| node \ | ||
| --experimental-wasm-jspi \ | ||
| --experimental-strip-types \ | ||
| --experimental-transform-types \ | ||
| --disable-warning=ExperimentalWarning \ | ||
| --import "$ROOT_DIR/packages/meta/src/node-es-module-loader/register.mts" \ | ||
| "$ROOT_DIR/packages/php-wasm/compile-extension/tests/load-built-extension.mjs" \ | ||
| "$WORK_DIR/extension/manifest.json" \ | ||
| "$PHP_VERSION" \ | ||
| "<?php echo external_abi_probe() ? 'external ABI loaded' : 'probe failed';" \ | ||
| "external ABI loaded" \ | ||
| "$WORK_DIR/runtime/php_${PHP_VERSION//./_}.js" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense.