Skip to content

Support PHP 8.1 #92

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

Closed
adamziel opened this issue Dec 16, 2022 · 8 comments
Closed

Support PHP 8.1 #92

adamziel opened this issue Dec 16, 2022 · 8 comments

Comments

@adamziel
Copy link
Collaborator

PHP patches no longer cleanly apply to PHP 8.1. Adjusting the patches leads to the following error in the emmake make -j8 step:

> PHP_VERSION=8.1.13 npm run build:php
...
#21 205.5 /bin/bash /root/php-src/libtool --silent --preserve-dup-deps --tag CC --mode=compile /emsdk/upstream/emscripten/emcc -Imain/ -I/root/php-src/main/ -I/root/php-src/include -I/root/php-src/main -I/root/php-src -I/root/php-src/ext/date/lib -I/root/php-src/TSRM -I/root/php-src/Zend    -fno-common -Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare -g -O2 -fvisibility=hidden -DZEND_SIGNALS   -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -c /root/php-src/main/fopen_wrappers.c -o main/fopen_wrappers.lo  -MMD -MF main/fopen_wrappers.dep -MT main/fopen_wrappers.lo
#21 206.4 /root/php-src/Zend/asm/make_x86_64_sysv_elf_gas.S:40:10: error: Unexpected token in operand: %
#21 206.4     movq %rdi, %rax
#21 206.4          ^
#21 206.4 /root/php-src/Zend/asm/make_x86_64_sysv_elf_gas.S:43:10: error: Unexpected token in operand: $
#21 206.4     andq $-16, %rax

...

#21 206.6 make: *** [Makefile:863: Zend/asm/make_x86_64_sysv_elf_gas.lo] Error 1
#21 206.6 make: *** Waiting for unfinished jobs....
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:39:15: error: Expected ,, instead got: (
#21 207.3     leaq -0x38(%rsp), %rsp
#21 207.3               ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:42:13: error: Unexpected token in operand: (
#21 207.3     stmxcsr (%rsp)
#21 207.3             ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:43:15: error: Expected ,, instead got: (
#21 207.3     fnstcw 0x4(%rsp)
#21 207.3               ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:46:10: error: Unexpected token in operand: %
#21 207.3     movq %r12, 0x8(%rsp)
#21 207.3          ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:47:10: error: Unexpected token in operand: %
#21 207.3     movq %r13, 0x10(%rsp)
#21 207.3          ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:48:10: error: Unexpected token in operand: %
#21 207.3     movq %r14, 0x18(%rsp)
#21 207.3          ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:49:10: error: Unexpected token in operand: %
#21 207.3     movq %r15, 0x20(%rsp)
#21 207.3          ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:50:10: error: Unexpected token in operand: %
#21 207.3     movq %rbx, 0x28(%rsp)
#21 207.3          ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:51:10: error: Unexpected token in operand: %
#21 207.3     movq %rbp, 0x30(%rsp)
#21 207.3          ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:54:10: error: Unexpected token in operand: %
#21 207.3     movq %rsp, %rax
#21 207.3          ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:57:10: error: Unexpected token in operand: %
#21 207.3     movq %rdi, %rsp
#21 207.3          ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:59:14: error: Expected ,, instead got: (
#21 207.3     movq 0x38(%rsp), %r8
#21 207.3              ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:62:13: error: Unexpected token in operand: (
#21 207.3     ldmxcsr (%rsp)
#21 207.3             ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:63:14: error: Expected ,, instead got: (
#21 207.3     fldcw 0x4(%rsp)
#21 207.3              ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:66:13: error: Expected ,, instead got: (
#21 207.3     movq 0x8(%rsp), %r12
#21 207.3             ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:67:14: error: Expected ,, instead got: (
#21 207.3     movq 0x10(%rsp), %r13
#21 207.3              ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:68:14: error: Expected ,, instead got: (
#21 207.3     movq 0x18(%rsp), %r14
#21 207.3              ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:69:14: error: Expected ,, instead got: (
#21 207.3     movq 0x20(%rsp), %r15
#21 207.3              ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:70:14: error: Expected ,, instead got: (
#21 207.3     movq 0x28(%rsp), %rbx
#21 207.3              ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:71:14: error: Expected ,, instead got: (
#21 207.3     movq 0x30(%rsp), %rbp
#21 207.3              ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:73:14: error: Expected ,, instead got: (
#21 207.3     leaq 0x40(%rsp), %rsp
#21 207.3              ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:81:10: error: Unexpected token in operand: $
#21 207.3     salq $32, %rsi
#21 207.3          ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:82:9: error: Unexpected token in operand: %
#21 207.3     orq %rsi, %rax
#21 207.3         ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:90:10: error: Unexpected token in operand: %
#21 207.3     movq %rax, %rdi
#21 207.3          ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:93:9: error: Unexpected token in operand: *
#21 207.3     jmp *%r8
#21 207.3         ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:94:1: warning: .size directive ignored for function symbols
#21 207.3 .size jump_fcontext,.-jump_fcontext
#21 207.3 ^
#21 207.3 /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S:97:19: error: Expected ,, instead got: -
#21 207.3 .section .note.GNU-stack,"",%progbits
#21 207.3                   ^
#21 207.4 emcc: error: '/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN -I/emsdk/upstream/emscripten/cache/sysroot/include/SDL --sysroot=/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -IZend/asm/ -I/root/php-src/Zend/asm/ -I/root/php-src/include -I/root/php-src/main -I/root/php-src -I/root/php-src/ext/date/lib -I/root/php-src/TSRM -I/root/php-src/Zend -fno-common -Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare -g3 -O2 -fvisibility=hidden -DZEND_SIGNALS -c -MMD -MF Zend/asm/jump_x86_64_sysv_elf_gas.dep -MT Zend/asm/jump_x86_64_sysv_elf_gas.lo /root/php-src/Zend/asm/jump_x86_64_sysv_elf_gas.S -o Zend/asm/jump_x86_64_sysv_elf_gas.o' failed (returned 1)

This resembles a gist I found that's labeled Compiling error of PHP 8.1.0 on 32 bit architecture. WASM is inherently 32-bit, and yet make tries to use the 640bit jump_x86_64_sysv_elf_gas – perhaps some flag that must be set to enforce using 32 files.

@adamziel
Copy link
Collaborator Author

adamziel commented Dec 16, 2022

These files seem related to PHP 8.1 fibers feature – PHP's configure.ac says:

PHP_ADD_SOURCES(Zend/asm, make_${fiber_asm_file}.S jump_${fiber_asm_file}.S)

$fiber_asm_file is derived from $fiber_cpu which is derived from $host_cpu.

Autoconf docs says:

The variables ‘build_alias’, ‘host_alias’, and ‘target_alias’ are always exactly the arguments of --build, --host, and --target;
If --host was specified, then host is the canonicalization of host_alias by config.sub, otherwise it defaults to build.

Perhaps this is as easy as specifying the --host option

@adamziel
Copy link
Collaborator Author

Adding --build i386-linux-gnu to ./configure looks promising!

Before:

#20 6.005 checking build system type... x86_64-pc-linux-gnu
#20 6.753 checking host system type... x86_64-pc-linux-gnu
#20 6.754 checking target system type... x86_64-pc-linux-gnu

After:

#20 6.263 checking build system type... i386-pc-linux-gnu
#20 6.360 checking host system type... i386-pc-linux-gnu
#20 6.361 checking target system type... i386-pc-linux-gnu

@adamziel
Copy link
Collaborator Author

adamziel commented Dec 16, 2022

Oh, it wasn't about that at all.

The elf files in question (./Zend/asm/jump_i386_sysv_elf_gas.S) are built asm files unsupported by emscripten. They'd need to be ported to some emscripten-compatible format:

  • ./Zend/asm/jump_i386_sysv_elf_gas.S
  • ./Zend/asm/jump_i386_ms_pe_masm.asm
  • ./Zend/asm/jump_i386_sysv_macho_gas.S

They look as follows:

.file "jump_mips64_n64_elf_gas.S"
.text
.globl jump_fcontext
.align 3
.type jump_fcontext,@function
.ent jump_fcontext
jump_fcontext:
    # reserve space on stack
    daddiu $sp, $sp, -160

    sd  $s0, 64($sp)  # save S0
    sd  $s1, 72($sp)  # save S1
    sd  $s2, 80($sp)  # save S2
    sd  $s3, 88($sp)  # save S3

@adamziel
Copy link
Collaborator Author

adamziel commented Dec 17, 2022

The --disable-fiber-asm option for ./configure might solve this 🤞

If not, then perhaps more hacky RUN sed -i 's/if test "$fiber_asm" = 'yes'; then/if test "$fiber_asm" = 'no'; then/g' php-src/configure.ac

@adamziel
Copy link
Collaborator Author

--disable-fiber-asm worked!

@adamziel
Copy link
Collaborator Author

#94 adds support for PHP 8.1 and 8.2

@adamziel
Copy link
Collaborator Author

PHP 7.4 worked at 2403d0f

@adamziel
Copy link
Collaborator Author

bgrgicak pushed a commit that referenced this issue May 7, 2025
## Motivation for the change, related issues

When running Playground CLI and php-wasm CLI with the built-script
executor, I've wanted to add extra Node.js flags like
`--experimental-wasm-jspi`.

Prior to this PR, the only way was to hack the executor.ts file, but
these changes show up in `git status` and are easy to misplace and lose
when switching between branches and pushing and popping from the stash.

## Implementation details

This PR adds a `nodeArg` option to our custom `built-script` executor.
It is an array and can be specified multiple times to add multiple args.

## Testing Instructions (or ideally a Blueprint)

The built-script executor is only used by Playground CLI and php-wasm
CLI. Let's test both.

Run the following command:
```
npx nx start php-wasm-cli --nodeArg='--cpu-prof' --nodeArg='--trace-promises' -r 'phpinfo();'
```

- Confirm you see promise tracing in the output
- Confirm the command created a file ending in `.cpuprofile`

Run `npx nx start playground-cli server` to confirm it is still working.
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

No branches or pull requests

1 participant