Skip to content

Enable 64bit integer support on 32bit arch --enable-zend-int64 #19079

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

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

marc-mabe
Copy link
Contributor

@marc-mabe marc-mabe commented Jul 9, 2025

This PR allows to use 64bit integers on 32bit platforms if compiled with --enable-zend-int64

  • allow to enable 64bit integers on 32bit platforms (--enable-zend-int64)
  • add const for system architecture (currently PHP_SYS_SIZE = [4|8])
  • fix all errors in Zend/tests/ and tests/
  • fix all errors in ext/
  • Support 64 bit timestamps
  • Support large files

The main part is that ZEND_ENABLE_ZVAL_LONG64 1 gets defined.

@iluuu1994
Copy link
Member

iluuu1994 commented Jul 9, 2025

I think this should go through the RFC process. There have been suggestions to drop 32-bit support, so I'm sure at least some people would object to expanding support further. I could see this as an alternative to dropping 32-bit support iff we also dropped 4-byte zend_long support, as that would align 32 and 64-bit.

Comment on lines +112 to +145
void gmp_set_zlong(mpz_t z, zend_long zlong) {
if (zlong <= GMP_SI_MAX && zlong >= GMP_SI_MIN) {
mpz_set_si(z, zlong);
} else if (zlong >= 0) {
mpz_import(z, 1, 1, sizeof(zend_long), 0, 0, &zlong);
} else {
mpz_import(z, 1, 1, sizeof(zend_long), 0, 0, &zlong);
mpz_neg(z, z);
}
}

int gmp_fits_zlong_p(mpz_t z) {
int result = 1;
mpz_t z_min_max;
zend_long min_max;

if (mpz_cmp_si(z, GMP_SI_MAX) > 0) {
min_max = ZEND_LONG_MAX;
mpz_init(z_min_max);
mpz_import(z_min_max, 1, 1, sizeof(zend_long), 0, 0, &min_max);
result = mpz_cmp(z, z_min_max) <= 0;
mpz_clear(z_min_max);
} else if (mpz_cmp_si(z, GMP_SI_MIN) < 0) {
min_max = ZEND_LONG_MIN;
mpz_init(z_min_max);
mpz_import(z_min_max, 1, 1, sizeof(zend_long), 0, 0, &min_max);
mpz_neg(z_min_max, z_min_max);
result = mpz_cmp(z, z_min_max) >= 0;
mpz_clear(z_min_max);
}

return result;
}

Copy link
Member

Choose a reason for hiding this comment

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

Can these functions be static?

@marc-mabe
Copy link
Contributor Author

marc-mabe commented Jul 9, 2025

I have fixed some cases which failed due to SIZEOF_SIZE_T != SIZEOF_ZEND_LONG, but there are probably more.
But there is something off with closure handling and static variables I'm not able to find :(

Currently, the test state is as follows:

$ sapi/cli/php run-tests.php Zend/tests/ tests/
<snip>
Number of tests :  5929              5791
Tests skipped   :   138 (  2.3%) --------
Tests warned    :     0 (  0.0%) (  0.0%)
Tests failed    :    44 (  0.7%) (  0.8%)
Expected fail   :     2 (  0.0%) (  0.0%)
Tests passed    :  5745 ( 96.9%) ( 99.2%)
---------------------------------------------------------------------
Time taken      : 158.811 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
php://input is empty when enable_post_data_reading=Off [tests/basic/bug67198.phpt]
Static variables in functions [tests/func/002.phpt]
Bug #23384 (use of class constants in statics) [tests/lang/bug23384.phpt]
Static keyword - basic tests [tests/lang/static_basic_001.phpt]
Bug #78502: Incorrect stack size calculation for indirectly recursive function call [Zend/tests/bug78502.phpt]
Bug #54358 (Closure, use and reference) [Zend/tests/closures/bug54358.phpt]
Closure 009: Using static vars inside lambda [Zend/tests/closures/closure_009.phpt]
Closure 047: Use in preg_replace_callback() using variables by reference [Zend/tests/closures/closure_047.phpt]
Closure 048: Use in preg_replace_callback() using variables by reference [Zend/tests/closures/closure_048.phpt]
Closures in const expressions support static variables. [Zend/tests/closures/closure_const_expr/static_variable.phpt]
Closure use list can have trailing commas [Zend/tests/closures/closure_use_trailing_comma.phpt]
Bug #79836 (Segfault in concat_function) [Zend/tests/concat/bug79836.phpt]
new in constant expressions [Zend/tests/constexpr/new.phpt]
Named params in new in const expr [Zend/tests/constexpr/new_named_params.phpt]
GH-13446: Exception handler attempting to free itself [Zend/tests/exceptions/gh13446_2.phpt]
Fiber::getReturn() after bailout [Zend/tests/fibers/get-return-after-bailout.phpt]
GH-15108 003: Segfault with delegated generator in suspended fiber [Zend/tests/fibers/gh15108-003.phpt]
GH-15108 004: Segfault with delegated generator in suspended fiber [Zend/tests/fibers/gh15108-004.phpt]
GH-15108 007: Segfault with delegated generator in suspended fiber [Zend/tests/fibers/gh15108-007.phpt]
Bug GH-9916 001 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) [Zend/tests/fibers/gh9916-001.phpt]
Bug GH-9916 002 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) [Zend/tests/fibers/gh9916-002.phpt]
Bug GH-9916 003 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) [Zend/tests/fibers/gh9916-003.phpt]
Bug GH-9916 004 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) [Zend/tests/fibers/gh9916-004.phpt]
Bug GH-9916 005 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) [Zend/tests/fibers/gh9916-005.phpt]
Bug GH-9916 006 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) [Zend/tests/fibers/gh9916-006.phpt]
Bug GH-9916 007 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) [Zend/tests/fibers/gh9916-007.phpt]
Bug GH-9916 008 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) [Zend/tests/fibers/gh9916-008.phpt]
Bug GH-9916 009 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) [Zend/tests/fibers/gh9916-009.phpt]
Bug GH-9916 010 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) [Zend/tests/fibers/gh9916-010.phpt]
Bug GH-9916 011 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) [Zend/tests/fibers/gh9916-011.phpt]
GC 049: Objects created during GC do not participate in the same collection [Zend/tests/gc/gc_049.phpt]
GH-15330 003: Do not scan generator frames more than once [Zend/tests/generators/gh15330-003.phpt]
GH-15330 004: Do not scan generator frames more than once [Zend/tests/generators/gh15330-004.phpt]
GH-15330 005: Do not scan generator frames more than once [Zend/tests/generators/gh15330-005.phpt]
GH-15330 006: Do not scan generator frames more than once [Zend/tests/generators/gh15330-006.phpt]
GH-16408: Array to string conversion warning emitted in optimizer [Zend/tests/gh16408.phpt]
Lazy objects: Initializer effects are reverted after exception (nested) [Zend/tests/lazy_objects/init_exception_reverts_initializer_changes_nested.phpt]
Lazy objects: RFC example 011 [Zend/tests/lazy_objects/rfc/rfc_example_011.phpt]
Test nullsafe in binary op [Zend/tests/nullsafe_operator/014.phpt]
Allow fetching properties in static initializer [Zend/tests/prop_const_expr/static_initalizer.phpt]
Hooks containing static variables [Zend/tests/property_hooks/static_variables.phpt]
Test binary operands exposing the same behavior at compile as at run time [Zend/tests/runtime_compile_time_binary_operands.phpt]
Static Variable Expressions [Zend/tests/static_variables/static_variable.phpt]
Zend signed multiply 64-bit, variation 2 [Zend/tests/zend_signed_multiply-64bit-2.phpt]

@marc-mabe
Copy link
Contributor Author

I think this should go through the RFC process. There have been suggestions to drop 32-bit support, so I'm sure at least some people would object to expanding support further. I could see this as an alternative to dropping 32-bit support iff we also dropped 4-byte zend_long support, as that would align 32 and 64-bit.

Yes, of course. At the current state I want to get to know the work needed to be done and do some benchmarks.

For dropping 32-bit support entirely it seems to be to early at least for WebAssembly + there might be people hoping for supporting older (in some cases not that old) systems - so I don't thing it would go through currently.

@iluuu1994 iluuu1994 added the RFC label Jul 9, 2025
@marc-mabe marc-mabe force-pushed the int64 branch 4 times, most recently from 3c8a5ac to 97bb3dd Compare July 9, 2025 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants