Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ PHP NEWS
. Added the pipe (|>) operator. (crell)
. Added support for `final` with constructor property promotion.
(DanielEScherzer)
. Do not use RTLD_DEEPBIND if dlmopen is available. (Daniil Gentili)

- Curl:
. Added curl_multi_get_handles(). (timwolla)
Expand Down
14 changes: 13 additions & 1 deletion UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ PHP 8.5 INTERNALS UPGRADE NOTES
- Core
. PG(arg_separator).input and PG(arg_separator).output are now `zend_string*`
instead of `char*`.
. DL_LOAD now doesn't use RTLD_DEEPBIND deepbind anymore on platforms
where dlmopen with LM_ID_NEWLM is available:
this means shared library symbol isolation (if needed) must be enabled on
the user side when requiring libphp.so, by using dlmopen with LM_ID_NEWLM
instead of dlopen.
RTLD_DEEPBIND is still enabled when the Apache SAPI is in use.

- Zend
. Added zend_safe_assign_to_variable_noref() function to safely assign
Expand Down Expand Up @@ -49,12 +55,18 @@ PHP 8.5 INTERNALS UPGRADE NOTES
without duplicate build rules. It is up to the SAPI maintainers to ensure
that appropriate build rules are created.

- Linux build system changes
- Unix build system changes
. libdir is properly set when --libdir (ex: /usr/lib64) and --with-libdir (ex lib64)
configure options are used to ${libdir}/php (ex: /usr/lib64/php)
. PHP_ODBC_CFLAGS, PHP_ODBC_LFLAGS, PHP_ODBC_LIBS, PHP_ODBC_TYPE preprocessor
macros defined by ext/odbc are now defined in php_config.h instead of the
build-defs.h header.
. Autoconf macro PHP_AP_EXTRACT_VERSION has been removed.
. Autoconf macro PHP_BUILD_THREAD_SAFE has been removed (set enable_zts
manually).
. Autoconf macro PHP_DEF_HAVE has been removed (use AC_DEFINE).
. Autoconf macro PHP_OUTPUT has been removed (use AC_CONFIG_FILES).
. Autoconf macro PHP_TEST_BUILD has been removed (use AC_* macros).

========================
3. Module changes
Expand Down
7 changes: 7 additions & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@
/* these variables are true statics/globals, and have to be mutex'ed on every access */
ZEND_API HashTable module_registry;

ZEND_API bool zend_dl_use_deepbind = false;

static zend_module_entry **module_request_startup_handlers;
static zend_module_entry **module_request_shutdown_handlers;
static zend_module_entry **module_post_deactivate_handlers;
static zend_module_entry **modules_dl_loaded;

static zend_class_entry **class_cleanup_handlers;

ZEND_API void zend_set_dl_use_deepbind(bool use_deepbind)
{
zend_dl_use_deepbind = use_deepbind;
}

ZEND_API zend_result zend_get_parameters_array_ex(uint32_t param_count, zval *argument_array) /* {{{ */
{
zval *param_ptr;
Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ typedef struct _zend_fcall_info_cache {
ZEND_API int zend_next_free_module(void);

BEGIN_EXTERN_C()
ZEND_API void zend_set_dl_use_deepbind(bool use_deepbind);

ZEND_API zend_result zend_get_parameters_array_ex(uint32_t param_count, zval *argument_array);

/* internal function to efficiently copy parameters when executing __call() */
Expand Down
7 changes: 6 additions & 1 deletion Zend/zend_portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@
# if defined(RTLD_GROUP) && defined(RTLD_WORLD) && defined(RTLD_PARENT)
# define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL | RTLD_GROUP | RTLD_WORLD | RTLD_PARENT)
# elif defined(RTLD_DEEPBIND) && !defined(__SANITIZE_ADDRESS__) && !__has_feature(memory_sanitizer)
# define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL | RTLD_DEEPBIND)
# if defined(LM_ID_NEWLM)
ZEND_API extern bool zend_dl_use_deepbind;
# define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL | (zend_dl_use_deepbind ? RTLD_DEEPBIND : 0))
# else
# define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL | RTLD_DEEPBIND)
# endif
# else
# define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL)
# endif
Expand Down
71 changes: 0 additions & 71 deletions build/php.m4
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ dnl ----------------------------------------------------------------------------
dnl Build system helper macros.
dnl ----------------------------------------------------------------------------

dnl
dnl PHP_DEF_HAVE(what)
dnl
dnl Generates 'AC_DEFINE(HAVE_WHAT, 1, [ ])'.
dnl
AC_DEFUN([PHP_DEF_HAVE], [m4_warn([obsolete],
[The macro 'PHP_DEF_HAVE' is obsolete. Use AC_DEFINE.])
AC_DEFINE([HAVE_]translit($1,a-z_.-,A-Z___), 1, [ ])])

dnl
dnl PHP_RUN_ONCE(namespace, variable, code)
dnl
Expand Down Expand Up @@ -89,17 +80,6 @@ AC_DEFUN([PHP_SUBST_OLD],[
PHP_SUBST([$1])
])

dnl
dnl PHP_OUTPUT(file)
dnl
dnl Adds "file" to the list of files generated by AC_OUTPUT. This macro can be
dnl used several times. This macro is obsolete as of PHP 8.4 in favor of the
dnl default AC_CONFIG_FILES.
dnl
AC_DEFUN([PHP_OUTPUT],
[m4_warn([obsolete], [The macro 'PHP_OUTPUT' is obsolete. Use AC_CONFIG_FILES.])
AC_CONFIG_FILES([$1])])

dnl ----------------------------------------------------------------------------
dnl Build system base macros.
dnl ----------------------------------------------------------------------------
Expand Down Expand Up @@ -743,13 +723,6 @@ dnl ----------------------------------------------------------------------------
dnl Build macros
dnl ----------------------------------------------------------------------------

dnl
dnl PHP_BUILD_THREAD_SAFE
dnl
AC_DEFUN([PHP_BUILD_THREAD_SAFE], [m4_warn([obsolete],
[The macro 'PHP_BUILD_THREAD_SAFE' is obsolete. Set 'enable_zts' manually.])
enable_zts=yes])

dnl
dnl PHP_REQUIRE_CXX
dnl
Expand Down Expand Up @@ -1518,31 +1491,6 @@ AC_DEFUN([PHP_CHECK_FUNC],[
esac
])

dnl
dnl PHP_TEST_BUILD(function, action-if-ok, action-if-not-ok [, extra-libs [, extra-source]])
dnl
dnl This macro checks whether build works and given function exists.
dnl
AC_DEFUN([PHP_TEST_BUILD], [m4_warn([obsolete],
[The macro 'PHP_TEST_BUILD' is obsolete. Use AC_* macros.])
old_LIBS=$LIBS
LIBS="$4 $LIBS"
AC_LINK_IFELSE([AC_LANG_SOURCE([
$5
char $1(void);
int main(void) {
$1();
return 0;
}
])],[
LIBS=$old_LIBS
$2
],[
LIBS=$old_LIBS
$3
])
])

dnl ----------------------------------------------------------------------------
dnl Platform characteristics checks.
dnl ----------------------------------------------------------------------------
Expand Down Expand Up @@ -2039,25 +1987,6 @@ AC_DEFUN([PHP_INSTALL_HEADERS],
])
])

dnl
dnl PHP_AP_EXTRACT_VERSION(/path/httpd)
dnl
dnl This macro is used to get a comparable version for Apache.
dnl
AC_DEFUN([PHP_AP_EXTRACT_VERSION], [m4_warn([obsolete],
[The macro 'PHP_AP_EXTRACT_VERSION' is obsolete. Use 'apxs -q HTTPD_VERSION'])
AS_IF([test -x "$1"], [
ac_output=$($1 -v 2>&1 | grep version | $SED -e 's/Oracle-HTTP-//')
ac_IFS=$IFS
IFS="- /.
"
set $ac_output
IFS=$ac_IFS

APACHE_VERSION=$(expr [$]4 \* 1000000 + [$]5 \* 1000 + [$]6)
])
])

dnl
dnl PHP_CONFIG_NICE(filename)
dnl
Expand Down
47 changes: 47 additions & 0 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@

#ifdef HAVE_JIT
# include "jit/zend_jit.h"
# include "Optimizer/zend_func_info.h"
# include "Optimizer/zend_call_graph.h"
#endif

#ifndef ZEND_WIN32
Expand Down Expand Up @@ -4537,6 +4539,39 @@ static void preload_load(size_t orig_map_ptr_static_last)
}
}

#if HAVE_JIT
static void zend_accel_clear_call_graph_ptrs(zend_op_array *op_array)
{
ZEND_ASSERT(ZEND_USER_CODE(op_array->type));
zend_func_info *info = ZEND_FUNC_INFO(op_array);
if (info) {
info->caller_info = NULL;
info->callee_info = NULL;
}
}

static void accel_reset_arena_info(zend_persistent_script *script)
{
zend_op_array *op_array;
zend_class_entry *ce;

zend_accel_clear_call_graph_ptrs(&script->script.main_op_array);
ZEND_HASH_MAP_FOREACH_PTR(&script->script.function_table, op_array) {
zend_accel_clear_call_graph_ptrs(op_array);
} ZEND_HASH_FOREACH_END();
ZEND_HASH_MAP_FOREACH_PTR(&script->script.class_table, ce) {
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) {
if (op_array->scope == ce
&& op_array->type == ZEND_USER_FUNCTION
&& !(op_array->fn_flags & ZEND_ACC_ABSTRACT)
&& !(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) {
zend_accel_clear_call_graph_ptrs(op_array);
}
} ZEND_HASH_FOREACH_END();
} ZEND_HASH_FOREACH_END();
}
#endif

static zend_result accel_preload(const char *config, bool in_child)
{
zend_file_handle file_handle;
Expand Down Expand Up @@ -4749,6 +4784,18 @@ static zend_result accel_preload(const char *config, bool in_child)
} ZEND_HASH_FOREACH_END();
ZCSG(saved_scripts)[i] = NULL;

#if HAVE_JIT
/* During persisting, the JIT may trigger and fill in the call graph.
* The call graph info is allocated on the arena which will be gone after preloading.
* To prevent invalid accesses during normal requests, the arena data should be cleared.
* This has to be done after all scripts have been persisted because shared op arrays between
* scripts can change the call graph. */
accel_reset_arena_info(ZCSG(preload_script));
for (zend_persistent_script **scripts = ZCSG(saved_scripts); *scripts; scripts++) {
accel_reset_arena_info(*scripts);
}
#endif

zend_shared_alloc_save_state();
accel_interned_strings_save_state();

Expand Down
10 changes: 9 additions & 1 deletion ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3449,8 +3449,16 @@ int zend_jit_script(zend_script *script)
|| JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) {
zend_class_entry *ce;
zend_op_array *op_array;
zval *zv;

ZEND_HASH_MAP_FOREACH_VAL(&script->class_table, zv) {
if (Z_TYPE_P(zv) == IS_ALIAS_PTR) {
continue;
}

ce = Z_PTR_P(zv);
ZEND_ASSERT(ce->type == ZEND_USER_CLASS);

ZEND_HASH_MAP_FOREACH_PTR(&script->class_table, ce) {
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) {
if (!ZEND_FUNC_INFO(op_array)) {
void *jit_extension = zend_shared_alloc_get_xlat_entry(op_array->opcodes);
Expand Down
2 changes: 2 additions & 0 deletions ext/opcache/jit/zend_jit_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -5944,6 +5944,7 @@ static int zend_jit_long_math_helper(zend_jit_ctx *jit,
ir_IF_FALSE_cold(if_def);

// zend_error_unchecked(E_WARNING, "Undefined variable $%S", CV_DEF_OF(EX_VAR_TO_NUM(opline->op1.var)));
jit_SET_EX_OPLINE(jit, opline);
ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(opline->op1.var));

ref2 = jit_EG(uninitialized_zval);
Expand All @@ -5960,6 +5961,7 @@ static int zend_jit_long_math_helper(zend_jit_ctx *jit,
ir_IF_FALSE_cold(if_def);

// zend_error_unchecked(E_WARNING, "Undefined variable $%S", CV_DEF_OF(EX_VAR_TO_NUM(opline->op2.var)));
jit_SET_EX_OPLINE(jit, opline);
ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(opline->op2.var));

ref2 = jit_EG(uninitialized_zval);
Expand Down
20 changes: 20 additions & 0 deletions ext/opcache/tests/gh18639.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
GH-18639 (Internal class aliases can break preloading + JIT)
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.jit=1255
opcache.jit_buffer_size=16M
opcache.preload={PWD}/preload_gh18567.inc
--EXTENSIONS--
opcache
--SKIPIF--
<?php
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
?>
--FILE--
<?php
echo "ok\n";
?>
--EXPECT--
ok
23 changes: 23 additions & 0 deletions ext/opcache/tests/jit/gh14082.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
GH-14082 (Segmentation fault on unknown address 0x600000000018 in ext/opcache/jit/zend_jit.c)
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.jit=1235
opcache.jit_buffer_size=16M
opcache.preload={PWD}/preload_gh14082.inc
--EXTENSIONS--
opcache
--SKIPIF--
<?php
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
?>
--FILE--
<?php
Foo::test();
echo "ok\n";
?>
--EXPECT--
int(1)
int(1)
ok
21 changes: 21 additions & 0 deletions ext/opcache/tests/jit/gh18899.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
GH-18899 (JIT function crash when emitting undefined variable warning and opline is not set yet)
--EXTENSIONS--
opcache
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.jit=1205
opcache.jit_buffer_size=8M
--FILE--
<?php
function ptr2str()
{
for ($i=0; $i<8; $i++) {
$ptr >>= 8;
}
}
str_repeat("A",232).ptr2str();
?>
--EXPECTF--
Warning: Undefined variable $ptr in %s on line %d
9 changes: 9 additions & 0 deletions ext/opcache/tests/jit/preload_gh14082.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
class Foo {
public static function test() {
static $i = 0;
var_dump(++$i);
}
}

Foo::test();
1 change: 0 additions & 1 deletion ext/phar/tests/zip/notphar.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Phar: a non-executable zip with no stub named .phar.zip
phar
--INI--
phar.readonly=1
detect_unicode=0
zend.multibyte=0
--FILE--
<?php
Expand Down
Loading