Skip to content
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

"PHP is compiled or limited to using 32-bit integers" #44

Open
mglaman opened this issue Jun 28, 2024 · 7 comments
Open

"PHP is compiled or limited to using 32-bit integers" #44

mglaman opened this issue Jun 28, 2024 · 7 comments

Comments

@mglaman
Copy link

mglaman commented Jun 28, 2024

Running Drupal 10.3, I get the following warning

You are running on a system where PHP is compiled or limited to using 32-bit integers. This will limit the range of dates and timestamps to the years 1901-2038. Read about the limitations of 32-bit PHP.

@mglaman
Copy link
Author

mglaman commented Jul 18, 2024

Looks like it has nothing to do with php-wasm: emscripten-core/emscripten#12087

But there is an experimental flag: emscripten-core/emscripten#17708

https://emscripten.org/docs/tools_reference/settings_reference.html?highlight=memory64#memory64

-sMEMORY64

It's tied to the larger WebAssembly spec: https://github.com/WebAssembly/memory64

@mglaman
Copy link
Author

mglaman commented Jul 18, 2024

In Makefile we can do something like:

MEMORY64       ?=0

This way it defaults to 32bit, but someone can pass 1 for 64bit or 2 for the mix.

		-s MODULARIZE=1                          \
		-s ASYNCIFY=1                            \
		-s MEMORY64=${MEMORY64}                  \

@mglaman
Copy link
Author

mglaman commented Jul 18, 2024

Announcement of support as well: https://v8.dev/features/wasm-bigint

@mglaman
Copy link
Author

mglaman commented Jul 18, 2024

Actually this shows Memory64 support: https://webassembly.org/features/. It looks like it's all behind feature flags.

I wonder if the -sWASM_BIGINT flag would be enough? That has wide spread support.

@mglaman
Copy link
Author

mglaman commented Jul 25, 2024

I tried a build with -sWASM_BIGINT and it crashed: Cannot convert 0 to a BigInt.

500: Internal Server Error.
================================================================================

Stacktrace:
TypeError: Cannot convert 0 to a BigInt
    at ret.<computed> (http://localhost/php-cgi-worker.mjs:9:380235)
    at wasm://wasm/0058e82e:wasm-function[1787]:0x150853
    at wasm://wasm/0058e82e:wasm-function[175]:0x19ff0
    at wasm://wasm/0058e82e:wasm-function[924]:0xad5ea
    at wasm://wasm/0058e82e:wasm-function[387]:0x39bdc
    at wasm://wasm/0058e82e:wasm-function[463]:0x4e5b1
    at ret.<computed> (http://localhost/php-cgi-worker.mjs:9:380235)
    at wasm://wasm/d3b27a3e:wasm-function[117]:0x1faf
    at http://localhost/php-cgi-worker.mjs.wasm:wasm-function[1739]:0x2cf170
    at http://localhost/php-cgi-worker.mjs.wasm:wasm-function[6296]:0x825491
================================================================================

STDERR:

================================================================================

STDOUT:

================================================================================

Looking at the stack trace: d3b27a3e:0x1faf was a call to call $env.sqlite3_open_v2

@mglaman
Copy link
Author

mglaman commented Jul 25, 2024

Also, even with the flag this test failed:

test('PHP_INT_SIZE', async () => {
	const php = new PhpNode();

	let stdOut = '', stdErr = '';

	php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line)));
	php.addEventListener('error',  (event) => event.detail.forEach(line => void (stdErr += line)));

	await php.binary;

	const exitCode = await php.run(`<?php var_dump(PHP_INT_SIZE);`);

	assert.equal(exitCode, 0);
	assert.equal(stdOut, `int(4)\n`);
	assert.equal(stdErr, '');
})

@mglaman
Copy link
Author

mglaman commented Jul 25, 2024

-s MEMORY64 assumes -sWASM_BIGINT which was crashing. Maybe this cannot be done quite yet

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