Make OPcache non-optional

This removes the --enable-opcache/--disable-opcache configure switch. OPcache
is now always builtin. The default value of opcache.enable and
opcache.enable_cli is unchanged.

RFC: https://wiki.php.net/rfc/make_opcache_required

Closes GH-18961.

Co-authored-by: Tim Düsterhus <tim@tideways-gmbh.com>
This commit is contained in:
Arnaud Le Blanc 2025-05-20 11:27:26 +02:00
parent 6f3bc59950
commit 7b4c14dc10
No known key found for this signature in database
21 changed files with 239 additions and 264 deletions

View file

@ -90,7 +90,6 @@ jobs:
--prefix=/usr \
--enable-phpdbg \
--enable-fpm \
--enable-opcache \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pgsql \
@ -168,7 +167,6 @@ jobs:
no_output_timeout: 30m
command: |
sapi/cli/php run-tests.php \
-d zend_extension=opcache.so \
-d opcache.enable_cli=1 \
-d opcache.jit_buffer_size=64M \
-d opcache.jit=tracing \

View file

@ -113,8 +113,7 @@ runs:
--offline \
--show-diff \
--show-slow 1000 \
--set-timeout 120 \
-d zend_extension=opcache.so
--set-timeout 120
if test "${{ inputs.runExtraTests }}" = "true"; then
sapi/cli/php run-extra-tests.php

View file

@ -128,7 +128,6 @@ mkdir %PHP_BUILD_DIR%\test_file_cache
rem generate php.ini
echo extension_dir=%PHP_BUILD_DIR% > %PHP_BUILD_DIR%\php.ini
echo opcache.file_cache=%PHP_BUILD_DIR%\test_file_cache >> %PHP_BUILD_DIR%\php.ini
if "%OPCACHE%" equ "1" echo zend_extension=php_opcache.dll >> %PHP_BUILD_DIR%\php.ini
rem work-around for some spawned PHP processes requiring OpenSSL and sockets
echo extension=php_openssl.dll >> %PHP_BUILD_DIR%\php.ini
echo extension=php_sockets.dll >> %PHP_BUILD_DIR%\php.ini

View file

@ -134,7 +134,6 @@ jobs:
jitType: tracing
runTestsParameters: >-
--asan -x
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Extra tests
uses: ./.github/actions/extra-tests
@ -250,14 +249,12 @@ jobs:
jitType: tracing
runTestsParameters: >-
${{ matrix.run_tests_parameters }}
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Test OpCache
uses: ./.github/actions/test-linux
with:
runTestsParameters: >-
${{ matrix.run_tests_parameters }}
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Test Function JIT
# ASAN frequently timeouts. Each test run takes ~90 minutes, we can
@ -268,7 +265,6 @@ jobs:
jitType: function
runTestsParameters: >-
${{ matrix.run_tests_parameters }}
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Extra tests
uses: ./.github/actions/extra-tests
@ -344,14 +340,12 @@ jobs:
jitType: tracing
runTestsParameters: >-
${{ matrix.run_tests_parameters }}
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Test OpCache
uses: ./.github/actions/test-linux
with:
runTestsParameters: >-
${{ matrix.run_tests_parameters }}
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Test Function JIT
uses: ./.github/actions/test-linux
@ -359,7 +353,6 @@ jobs:
jitType: function
runTestsParameters: >-
${{ matrix.run_tests_parameters }}
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Extra tests
uses: ./.github/actions/extra-tests
@ -406,13 +399,11 @@ jobs:
with:
jitType: tracing
runTestsParameters: >-
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Test OpCache
uses: ./.github/actions/test-macos
with:
runTestsParameters: >-
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Test Function JIT
if: matrix.os != '14' || !matrix.zts
@ -420,7 +411,6 @@ jobs:
with:
jitType: function
runTestsParameters: >-
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Extra tests
uses: ./.github/actions/extra-tests
@ -484,7 +474,6 @@ jobs:
with:
jitType: tracing
runTestsParameters: >-
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- uses: codecov/codecov-action@v4
if: ${{ !cancelled() }}
@ -538,7 +527,6 @@ jobs:
- name: Enable Opcache
run: |
echo memory_limit=-1 >> /etc/php.d/opcache.ini
echo zend_extension=opcache.so > /etc/php.d/opcache.ini
echo opcache.enable_cli=1 >> /etc/php.d/opcache.ini
echo opcache.enable=1 >> /etc/php.d/opcache.ini
echo opcache.protect_memory=1 >> /etc/php.d/opcache.ini
@ -729,21 +717,18 @@ jobs:
uses: ./.github/actions/test-linux
with:
runTestsParameters: >-
-d zend_extension=opcache.so
-d opcache.enable_cli=1
--file-cache-prime
- name: Test File Cache (prime shm, use shm)
uses: ./.github/actions/test-linux
with:
runTestsParameters: >-
-d zend_extension=opcache.so
-d opcache.enable_cli=1
--file-cache-use
- name: Test File Cache (prime shm, use file)
uses: ./.github/actions/test-linux
with:
runTestsParameters: >-
-d zend_extension=opcache.so
-d opcache.enable_cli=1
--file-cache-use
-d opcache.file_cache_only=1
@ -751,7 +736,6 @@ jobs:
uses: ./.github/actions/test-linux
with:
runTestsParameters: >-
-d zend_extension=opcache.so
-d opcache.enable_cli=1
--file-cache-prime
-d opcache.file_cache_only=1
@ -759,7 +743,6 @@ jobs:
uses: ./.github/actions/test-linux
with:
runTestsParameters: >-
-d zend_extension=opcache.so
-d opcache.enable_cli=1
--file-cache-use
-d opcache.file_cache_only=1
@ -853,7 +836,6 @@ jobs:
with:
runTestsParameters: >-
--msan
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Verify generated files are up to date
uses: ./.github/actions/verify-generated-files

View file

@ -130,7 +130,6 @@ jobs:
with:
jitType: tracing
runTestsParameters: >-
-d zend_extension=opcache.so
-d opcache.enable_cli=1
${{ matrix.asan && '--asan -x' || '' }}
- name: Verify generated files are up to date
@ -190,7 +189,6 @@ jobs:
with:
jitType: tracing
runTestsParameters: >-
-d zend_extension=opcache.so
-d opcache.enable_cli=1
MACOS_DEBUG_NTS:
if: github.repository == 'php/php-src' || github.event_name == 'pull_request'
@ -229,7 +227,6 @@ jobs:
with:
jitType: tracing
runTestsParameters: >-
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Verify generated files are up to date
uses: ./.github/actions/verify-generated-files
@ -299,7 +296,6 @@ jobs:
./configure \
--disable-debug \
--enable-mbstring \
--enable-opcache \
--enable-option-checking=fatal \
--enable-sockets \
--enable-werror \
@ -319,7 +315,6 @@ jobs:
sudo mkdir -p /etc/php.d
sudo chmod 777 /etc/php.d
echo mysqli.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/mysqli.ini
echo zend_extension=opcache.so >> /etc/php.d/opcache.ini
echo opcache.enable=1 >> /etc/php.d/opcache.ini
echo opcache.enable_cli=1 >> /etc/php.d/opcache.ini
- name: Setup

2
NEWS
View file

@ -15,6 +15,8 @@ PHP NEWS
- OPcache:
. Disallow changing opcache.memory_consumption when SHM is already set up.
(timwolla)
. Fixed GH-15074 (Compiling opcache statically into ZTS PHP fails). (Arnaud)
. Make OPcache non-optional (Arnaud, timwolla)
- OpenSSL:
. Add $digest_algo parameter to openssl_public_encrypt() and

View file

@ -71,6 +71,16 @@ PHP 8.5 UPGRADE NOTES
. Calling the mysqli constructor on an already-constructed object
is now no longer possible and throws an Error.
- Opcache:
. The Opcache extension is now always built into the PHP binary and is always
loaded. The INI directives opcache.enable and opcache.enable_cli are still
honored.
The --enable-opcache/--disable-opcache configure flags have been removed,
and the build does not produce opcache.so or php_opcache.dll objects
anymore.
Using zend_extension=opcache.so or zend_extension=php_opcache.dll INI
directives will emit a warning.
- PCNTL:
. pcntl_exec() now throws ValueErrors when entries of the $args parameter
contain null bytes.
@ -522,6 +532,11 @@ PHP 8.5 UPGRADE NOTES
library that was separated from ext/dom for being reused among other
extensions. The new extension is not directly exposed to userland.
- Opcache:
. The Opcache extension is now always built into the PHP binary and is always
loaded. The INI directives opcache.enable and opcache.enable_cli are still
honored.
- URI:
. An always enabled uri extension is added that can be used for handling
URIs and URLs according to RFC 3986 and WHATWG URL.
@ -693,6 +708,10 @@ PHP 8.5 UPGRADE NOTES
. The parts of the code that used SSE2 have been adapted to use SIMD
with ARM NEON as well.
- Opcache:
. Improved performance of fetching TLS variables in JIT'ed code in non-Glibc
builds.
- ReflectionProperty:
. Improved performance of the following methods: getValue(), getRawValue(),
isInitialized(), setValue(), setRawValue().

View file

@ -219,7 +219,7 @@ slightly different steps. We'll call attention where the steps differ.
# With ZTS
make distclean || \
./buildconf --force \
&& ./configure --enable-zts --disable-all --enable-debug --enable-opcache --enable-opcache-jit \
&& ./configure --enable-zts --disable-all --enable-debug --enable-opcache-jit \
&& make -j$(nproc) \
&& make test TEST_PHP_ARGS="-q -j$(nproc)" \
|| ./sapi/cli/php -v
@ -227,7 +227,7 @@ slightly different steps. We'll call attention where the steps differ.
# Without ZTS
make distclean || \
./buildconf --force \
&& ./configure --disable-all --enable-debug --enable-opcache --enable-opcache-jit \
&& ./configure --disable-all --enable-debug --enable-opcache-jit \
&& make -j$(nproc) \
&& make test TEST_PHP_ARGS="-q -j$(nproc)" \
|| ./sapi/cli/php -v
@ -571,7 +571,7 @@ slightly different steps. We'll call attention where the steps differ.
# With ZTS
make distclean || \
./buildconf --force \
&& ./configure --enable-zts --disable-all --enable-debug --enable-opcache --enable-opcache-jit \
&& ./configure --enable-zts --disable-all --enable-debug --enable-opcache-jit \
&& make -j$(nproc) \
&& make test TEST_PHP_ARGS="-q -j$(nproc)" \
|| ./sapi/cli/php -v
@ -579,7 +579,7 @@ slightly different steps. We'll call attention where the steps differ.
# Without ZTS
make distclean || \
./buildconf --force \
&& ./configure --disable-all --enable-debug --enable-opcache --enable-opcache-jit \
&& ./configure --disable-all --enable-debug --enable-opcache-jit \
&& make -j$(nproc) \
&& make test TEST_PHP_ARGS="-q -j$(nproc)" \
|| ./sapi/cli/php -v

View file

@ -25,6 +25,7 @@
#include "zend_extensions.h"
#include "zend_compile.h"
#include "ZendAccelerator.h"
#include "zend_modules.h"
#include "zend_persist.h"
#include "zend_shared_alloc.h"
#include "zend_accelerator_module.h"
@ -102,15 +103,12 @@ typedef int gid_t;
#include "zend_simd.h"
ZEND_EXTENSION();
static zend_extension opcache_extension_entry;
#ifndef ZTS
zend_accel_globals accel_globals;
#else
int accel_globals_id;
#if defined(COMPILE_DL_OPCACHE)
ZEND_TSRMLS_CACHE_DEFINE()
#endif
#endif
/* Points to the structure shared across all PHP processes */
@ -2969,9 +2967,6 @@ static zend_result zend_accel_init_shm(void)
static void accel_globals_ctor(zend_accel_globals *accel_globals)
{
#if defined(COMPILE_DL_OPCACHE) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
memset(accel_globals, 0, sizeof(zend_accel_globals));
accel_globals->key = zend_string_alloc(ZCG_KEY_LEN, true);
GC_MAKE_PERSISTENT_LOCAL(accel_globals->key);
@ -3156,6 +3151,11 @@ static void accel_move_code_to_huge_pages(void)
# endif /* defined(MAP_HUGETLB) || defined(MADV_HUGEPAGE) */
#endif /* HAVE_HUGE_CODE_PAGES */
void start_accel_extension(void)
{
zend_register_extension(&opcache_extension_entry, NULL);
}
static int accel_startup(zend_extension *extension)
{
#ifdef ZTS
@ -3174,11 +3174,7 @@ static int accel_startup(zend_extension *extension)
# endif
#endif
if (start_accel_module() == FAILURE) {
accel_startup_ok = false;
zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME ": module registration failed!");
return FAILURE;
}
zend_accel_register_ini_entries();
#ifdef ZEND_WIN32
if (UNEXPECTED(accel_gen_uname_id() == FAILURE)) {
@ -5086,7 +5082,7 @@ static void accel_activate(void) {
}
}
ZEND_EXT_API zend_extension zend_extension_entry = {
static zend_extension opcache_extension_entry = {
ACCELERATOR_PRODUCT_NAME, /* name */
PHP_VERSION, /* version */
"Zend Technologies", /* author */

View file

@ -302,9 +302,6 @@ extern zend_accel_shared_globals *accel_shared_globals;
#ifdef ZTS
# define ZCG(v) ZEND_TSRMG(accel_globals_id, zend_accel_globals *, v)
extern int accel_globals_id;
# ifdef COMPILE_DL_OPCACHE
ZEND_TSRMLS_CACHE_EXTERN()
# endif
#else
# define ZCG(v) (accel_globals.v)
extern zend_accel_globals accel_globals;
@ -314,6 +311,7 @@ extern const char *zps_api_failure_reason;
BEGIN_EXTERN_C()
void start_accel_extension(void);
void accel_shutdown(void);
ZEND_RINIT_FUNCTION(zend_accelerator);
zend_result accel_post_deactivate(void);

View file

@ -1,9 +1,3 @@
PHP_ARG_ENABLE([opcache],
[whether to enable Zend OPcache support],
[AS_HELP_STRING([--disable-opcache],
[Disable Zend OPcache support])],
[yes])
PHP_ARG_ENABLE([huge-code-pages],
[whether to enable copying PHP CODE pages into HUGE PAGES],
[AS_HELP_STRING([--disable-huge-code-pages],
@ -25,97 +19,93 @@ PHP_ARG_WITH([capstone],
[no],
[no])
if test "$PHP_OPCACHE" != "no"; then
dnl Always build as shared extension.
ext_shared=yes
AS_VAR_IF([PHP_HUGE_CODE_PAGES], [yes],
[AC_DEFINE([HAVE_HUGE_CODE_PAGES], [1],
[Define to 1 to enable copying PHP CODE pages into HUGE PAGES.])])
AS_VAR_IF([PHP_HUGE_CODE_PAGES], [yes],
[AC_DEFINE([HAVE_HUGE_CODE_PAGES], [1],
[Define to 1 to enable copying PHP CODE pages into HUGE PAGES.])])
AS_VAR_IF([PHP_OPCACHE_JIT], [yes], [
AS_CASE([$host_cpu],
[[i[34567]86*|x86*|aarch64|amd64]], [],
[
AC_MSG_WARN([JIT not supported by host architecture])
PHP_OPCACHE_JIT=no
])
if test "$host_vendor" = "apple" && test "$host_cpu" = "aarch64" && test "$PHP_THREAD_SAFETY" = "yes"; then
AC_MSG_WARN([JIT not supported on Apple Silicon with ZTS])
AS_VAR_IF([PHP_OPCACHE_JIT], [yes], [
AS_CASE([$host_cpu],
[[i[34567]86*|x86*|aarch64|amd64]], [],
[
AC_MSG_WARN([JIT not supported by host architecture])
PHP_OPCACHE_JIT=no
fi
])
AS_VAR_IF([PHP_OPCACHE_JIT], [yes], [
AC_DEFINE([HAVE_JIT], [1], [Define to 1 to enable JIT.])
ZEND_JIT_SRC=m4_normalize(["
jit/ir/ir_cfg.c
jit/ir/ir_check.c
jit/ir/ir_dump.c
jit/ir/ir_emit.c
jit/ir/ir_gcm.c
jit/ir/ir_gdb.c
jit/ir/ir_patch.c
jit/ir/ir_perf.c
jit/ir/ir_ra.c
jit/ir/ir_save.c
jit/ir/ir_sccp.c
jit/ir/ir_strtab.c
jit/ir/ir.c
jit/zend_jit_vm_helpers.c
jit/zend_jit.c
"])
dnl Find out which ABI we are using.
AS_CASE([$host_alias],
[x86_64-*-darwin*], [
IR_TARGET=IR_TARGET_X64
DASM_FLAGS="-D X64APPLE=1 -D X64=1"
DASM_ARCH="x86"
TLS_TARGET="darwin"
],
[*x86_64*|amd64-*-freebsd*], [
IR_TARGET=IR_TARGET_X64
DASM_FLAGS="-D X64=1"
DASM_ARCH="x86"
TLS_TARGET="x86_64"
],
[[i[34567]86*|x86*]], [
IR_TARGET=IR_TARGET_X86
DASM_ARCH="x86"
TLS_TARGET="x86"
],
[aarch64*], [
IR_TARGET=IR_TARGET_AARCH64
DASM_ARCH="aarch64"
TLS_TARGET="aarch64"
])
AS_VAR_IF([PHP_CAPSTONE], [yes],
[PKG_CHECK_MODULES([CAPSTONE], [capstone >= 3.0.0], [
AC_DEFINE([HAVE_CAPSTONE], [1], [Define to 1 if Capstone is available.])
PHP_EVAL_LIBLINE([$CAPSTONE_LIBS], [OPCACHE_SHARED_LIBADD])
PHP_EVAL_INCLINE([$CAPSTONE_CFLAGS])
ZEND_JIT_SRC="$ZEND_JIT_SRC jit/ir/ir_disasm.c"
])])
PHP_SUBST([IR_TARGET])
PHP_SUBST([DASM_FLAGS])
PHP_SUBST([DASM_ARCH])
JIT_CFLAGS="-I@ext_builddir@/jit/ir -D$IR_TARGET -DIR_PHP"
AS_VAR_IF([ZEND_DEBUG], [yes], [JIT_CFLAGS="$JIT_CFLAGS -DIR_DEBUG"])
AS_VAR_IF([PHP_THREAD_SAFETY], [yes], [
ZEND_JIT_SRC="$ZEND_JIT_SRC jit/tls/zend_jit_tls_$TLS_TARGET.c"
])
if test "$host_vendor" = "apple" && test "$host_cpu" = "aarch64" && test "$PHP_THREAD_SAFETY" = "yes"; then
AC_MSG_WARN([JIT not supported on Apple Silicon with ZTS])
PHP_OPCACHE_JIT=no
fi
])
AS_VAR_IF([PHP_OPCACHE_JIT], [yes], [
AC_DEFINE([HAVE_JIT], [1], [Define to 1 to enable JIT.])
ZEND_JIT_SRC=m4_normalize(["
jit/ir/ir_cfg.c
jit/ir/ir_check.c
jit/ir/ir_dump.c
jit/ir/ir_emit.c
jit/ir/ir_gcm.c
jit/ir/ir_gdb.c
jit/ir/ir_patch.c
jit/ir/ir_perf.c
jit/ir/ir_ra.c
jit/ir/ir_save.c
jit/ir/ir_sccp.c
jit/ir/ir_strtab.c
jit/ir/ir.c
jit/zend_jit_vm_helpers.c
jit/zend_jit.c
"])
dnl Find out which ABI we are using.
AS_CASE([$host_alias],
[x86_64-*-darwin*], [
IR_TARGET=IR_TARGET_X64
DASM_FLAGS="-D X64APPLE=1 -D X64=1"
DASM_ARCH="x86"
TLS_TARGET="darwin"
],
[*x86_64*|amd64-*-freebsd*], [
IR_TARGET=IR_TARGET_X64
DASM_FLAGS="-D X64=1"
DASM_ARCH="x86"
TLS_TARGET="x86_64"
],
[[i[34567]86*|x86*]], [
IR_TARGET=IR_TARGET_X86
DASM_ARCH="x86"
TLS_TARGET="x86"
],
[aarch64*], [
IR_TARGET=IR_TARGET_AARCH64
DASM_ARCH="aarch64"
TLS_TARGET="aarch64"
])
AS_VAR_IF([PHP_CAPSTONE], [yes],
[PKG_CHECK_MODULES([CAPSTONE], [capstone >= 3.0.0], [
AC_DEFINE([HAVE_CAPSTONE], [1], [Define to 1 if Capstone is available.])
PHP_EVAL_LIBLINE([$CAPSTONE_LIBS], [OPCACHE_SHARED_LIBADD])
PHP_EVAL_INCLINE([$CAPSTONE_CFLAGS])
ZEND_JIT_SRC="$ZEND_JIT_SRC jit/ir/ir_disasm.c"
])])
PHP_SUBST([IR_TARGET])
PHP_SUBST([DASM_FLAGS])
PHP_SUBST([DASM_ARCH])
JIT_CFLAGS="-I@ext_builddir@/jit/ir -D$IR_TARGET -DIR_PHP"
AS_VAR_IF([ZEND_DEBUG], [yes], [JIT_CFLAGS="$JIT_CFLAGS -DIR_DEBUG"])
AS_VAR_IF([PHP_THREAD_SAFETY], [yes], [
ZEND_JIT_SRC="$ZEND_JIT_SRC jit/tls/zend_jit_tls_$TLS_TARGET.c"
])
])
AC_CHECK_FUNCS([mprotect shm_create_largepage])
AC_CHECK_FUNCS([mprotect shm_create_largepage])
AC_CACHE_CHECK([for sysvipc shared memory support], [php_cv_shm_ipc],
[AC_RUN_IFELSE([AC_LANG_SOURCE([
AC_CACHE_CHECK([for sysvipc shared memory support], [php_cv_shm_ipc],
[AC_RUN_IFELSE([AC_LANG_SOURCE([
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/ipc.h>
@ -317,56 +307,55 @@ int main(void) {
}
return 0;
}]])],
[php_cv_shm_mmap_posix=yes],
[php_cv_shm_mmap_posix=no],
[php_cv_shm_mmap_posix=no])
])
[php_cv_shm_mmap_posix=yes],
[php_cv_shm_mmap_posix=no],
[php_cv_shm_mmap_posix=no])
])
LIBS=$LIBS_save
])
LIBS=$LIBS_save
AS_VAR_IF([php_cv_shm_mmap_posix], [yes], [
AC_DEFINE([HAVE_SHM_MMAP_POSIX], [1],
[Define to 1 if you have the POSIX mmap() SHM support.])
AS_CASE([$ac_cv_search_shm_open], ["none required"|no], [],
[PHP_EVAL_LIBLINE([$ac_cv_search_shm_open], [OPCACHE_SHARED_LIBADD])])
])
AS_VAR_IF([php_cv_shm_mmap_posix], [yes], [
AC_DEFINE([HAVE_SHM_MMAP_POSIX], [1],
[Define to 1 if you have the POSIX mmap() SHM support.])
AS_CASE([$ac_cv_search_shm_open], ["none required"|no], [],
[PHP_EVAL_LIBLINE([$ac_cv_search_shm_open], [OPCACHE_SHARED_LIBADD])])
])
PHP_NEW_EXTENSION([opcache], m4_normalize([
shared_alloc_mmap.c
shared_alloc_posix.c
shared_alloc_shm.c
zend_accelerator_blacklist.c
zend_accelerator_debug.c
zend_accelerator_hash.c
zend_accelerator_module.c
zend_accelerator_util_funcs.c
zend_file_cache.c
zend_persist_calc.c
zend_persist.c
zend_shared_alloc.c
ZendAccelerator.c
$ZEND_JIT_SRC
]),
[$ext_shared],,
[-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 $JIT_CFLAGS],,
[yes])
PHP_NEW_EXTENSION([opcache], m4_normalize([
shared_alloc_mmap.c
shared_alloc_posix.c
shared_alloc_shm.c
zend_accelerator_blacklist.c
zend_accelerator_debug.c
zend_accelerator_hash.c
zend_accelerator_module.c
zend_accelerator_util_funcs.c
zend_file_cache.c
zend_persist_calc.c
zend_persist.c
zend_shared_alloc.c
ZendAccelerator.c
$ZEND_JIT_SRC
]),
[no],,
[-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 $JIT_CFLAGS],,
[yes])
PHP_ADD_EXTENSION_DEP(opcache, date)
PHP_ADD_EXTENSION_DEP(opcache, pcre)
PHP_ADD_EXTENSION_DEP(opcache, date)
PHP_ADD_EXTENSION_DEP(opcache, pcre)
if test "$php_cv_shm_ipc" != "yes" && test "$php_cv_shm_mmap_posix" != "yes" && test "$php_cv_shm_mmap_anon" != "yes"; then
AC_MSG_FAILURE(m4_text_wrap([
No supported shared memory caching support was found when configuring
opcache.
]))
fi
AS_VAR_IF([PHP_OPCACHE_JIT], [yes], [
PHP_ADD_BUILD_DIR([
$ext_builddir/jit
$ext_builddir/jit/ir
])
PHP_ADD_MAKEFILE_FRAGMENT([$ext_srcdir/jit/Makefile.frag])
])
PHP_SUBST([OPCACHE_SHARED_LIBADD])
if test "$php_cv_shm_ipc" != "yes" && test "$php_cv_shm_mmap_posix" != "yes" && test "$php_cv_shm_mmap_anon" != "yes"; then
AC_MSG_FAILURE(m4_text_wrap([
No supported shared memory caching support was found when configuring
opcache.
]))
fi
AS_VAR_IF([PHP_OPCACHE_JIT], [yes], [
PHP_ADD_BUILD_DIR([
$ext_builddir/jit
$ext_builddir/jit/ir
])
PHP_ADD_MAKEFILE_FRAGMENT([$ext_srcdir/jit/Makefile.frag])
])
PHP_SUBST([OPCACHE_SHARED_LIBADD])

View file

@ -1,75 +1,70 @@
ARG_ENABLE("opcache", "whether to enable Zend OPcache support", "yes");
ARG_ENABLE("opcache-jit", "whether to enable JIT (not supported for ARM64)", "yes");
PHP_OPCACHE="yes";
if (PHP_OPCACHE != "no") {
ZEND_EXTENSION('opcache', "\
ZendAccelerator.c \
zend_accelerator_blacklist.c \
zend_accelerator_debug.c \
zend_accelerator_hash.c \
zend_accelerator_module.c \
zend_accelerator_util_funcs.c \
zend_persist.c \
zend_persist_calc.c \
zend_file_cache.c \
zend_shared_alloc.c \
shared_alloc_win32.c", false, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
ZEND_EXTENSION('opcache', "\
ZendAccelerator.c \
zend_accelerator_blacklist.c \
zend_accelerator_debug.c \
zend_accelerator_hash.c \
zend_accelerator_module.c \
zend_accelerator_util_funcs.c \
zend_persist.c \
zend_persist_calc.c \
zend_file_cache.c \
zend_shared_alloc.c \
shared_alloc_win32.c", true, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
ADD_EXTENSION_DEP('opcache', 'date');
ADD_EXTENSION_DEP('opcache', 'hash');
ADD_EXTENSION_DEP('opcache', 'pcre');
ADD_EXTENSION_DEP('opcache', 'date');
ADD_EXTENSION_DEP('opcache', 'hash');
ADD_EXTENSION_DEP('opcache', 'pcre');
if (PHP_OPCACHE_JIT == "yes") {
if (TARGET_ARCH == 'arm64') {
WARNING("JIT not enabled; not yet supported for ARM64");
} else if (CHECK_HEADER_ADD_INCLUDE("ir/ir.h", "CFLAGS_OPCACHE", PHP_OPCACHE + ";ext\\opcache\\jit")) {
var dasm_flags = (X64 ? "-D X64=1" : "") + (X64 ? " -D X64WIN=1" : "") + " -D WIN=1";
var ir_target = (X64 ? "IR_TARGET_X64" : "IR_TARGET_X86");
var ir_src = "ir_strtab.c ir_cfg.c ir_sccp.c ir_gcm.c ir_ra.c ir_save.c \
ir_dump.c ir_check.c ir_patch.c";
if (PHP_OPCACHE_JIT == "yes") {
if (TARGET_ARCH == 'arm64') {
WARNING("JIT not enabled; not yet supported for ARM64");
} else if (CHECK_HEADER_ADD_INCLUDE("ir/ir.h", "CFLAGS_OPCACHE", PHP_OPCACHE + ";ext\\opcache\\jit")) {
var dasm_flags = (X64 ? "-D X64=1" : "") + (X64 ? " -D X64WIN=1" : "") + " -D WIN=1";
var ir_target = (X64 ? "IR_TARGET_X64" : "IR_TARGET_X86");
var ir_src = "ir_strtab.c ir_cfg.c ir_sccp.c ir_gcm.c ir_ra.c ir_save.c \
ir_dump.c ir_check.c ir_patch.c";
DEFINE("IR_TARGET", ir_target);
DEFINE("DASM_FLAGS", dasm_flags);
DEFINE("DASM_ARCH", "x86");
DEFINE("TLS_TARGET", "win");
DEFINE("IR_TARGET", ir_target);
DEFINE("DASM_FLAGS", dasm_flags);
DEFINE("DASM_ARCH", "x86");
DEFINE("TLS_TARGET", "win");
AC_DEFINE('HAVE_JIT', 1, 'Define to 1 to enable JIT.');
AC_DEFINE('HAVE_JIT', 1, 'Define to 1 to enable JIT.');
ADD_FLAG("CFLAGS_OPCACHE", "/I \"ext\\opcache\\jit\\ir\" /D "+ir_target+" /D IR_PHP");
if (PHP_DEBUG == "yes") {
ADD_FLAG("CFLAGS_OPCACHE", "/D IR_DEBUG");
}
ADD_FLAG("CFLAGS_OPCACHE", "/I \"ext\\opcache\\jit\\ir\" /D "+ir_target+" /D IR_PHP");
if (PHP_DEBUG == "yes") {
ADD_FLAG("CFLAGS_OPCACHE", "/D IR_DEBUG");
}
if (CHECK_HEADER_ADD_INCLUDE("capstone\\capstone.h", "CFLAGS_OPCACHE", PHP_OPCACHE+ ";" + PHP_PHP_BUILD + "\\include") &&
CHECK_LIB("capstone.lib", "opcache", PHP_OPCACHE)) {
AC_DEFINE('HAVE_CAPSTONE', 1, 'Define to 1 if Capstone is available.');
ir_src += " ir_disasm.c";
}
if (CHECK_HEADER_ADD_INCLUDE("capstone\\capstone.h", "CFLAGS_OPCACHE", PHP_OPCACHE+ ";" + PHP_PHP_BUILD + "\\include") &&
CHECK_LIB("capstone.lib", "opcache", PHP_OPCACHE)) {
AC_DEFINE('HAVE_CAPSTONE', 1, 'Define to 1 if Capstone is available.');
ir_src += " ir_disasm.c";
}
ADD_MAKEFILE_FRAGMENT(configure_module_dirname + "\\jit\\Makefile.frag.w32");
ADD_MAKEFILE_FRAGMENT(configure_module_dirname + "\\jit\\Makefile.frag.w32");
ADD_SOURCES(configure_module_dirname + "\\jit",
"zend_jit.c zend_jit_vm_helpers.c",
"opcache", "ext\\opcache\\jit");
if (PHP_ZTS == "yes") {
ADD_SOURCES(configure_module_dirname + "\\jit\\tls",
ADD_SOURCES(configure_module_dirname + "\\jit",
"zend_jit.c zend_jit_vm_helpers.c",
"opcache", "ext\\opcache\\jit");
if (PHP_ZTS == "yes") {
ADD_SOURCES(configure_module_dirname + "\\jit\\tls",
"zend_jit_tls_win.c",
"opcache", "ext\\opcache\\jit\\tls");
}
ADD_SOURCES(configure_module_dirname + "\\jit\\ir",
"ir.c", "opcache", "ext\\opcache\\jit\\ir");
ADD_SOURCES(configure_module_dirname + "\\jit\\ir",
"ir_emit.c", "opcache", "ext\\opcache\\jit\\ir");
ADD_SOURCES(configure_module_dirname + "\\jit\\ir",
ir_src, "opcache", "ext\\opcache\\jit\\ir");
} else {
WARNING("JIT not enabled, headers not found");
}
ADD_SOURCES(configure_module_dirname + "\\jit\\ir",
"ir.c", "opcache", "ext\\opcache\\jit\\ir");
ADD_SOURCES(configure_module_dirname + "\\jit\\ir",
"ir_emit.c", "opcache", "ext\\opcache\\jit\\ir");
ADD_SOURCES(configure_module_dirname + "\\jit\\ir",
ir_src, "opcache", "ext\\opcache\\jit\\ir");
} else {
WARNING("JIT not enabled, headers not found");
}
ADD_FLAG('CFLAGS_OPCACHE', "/I " + configure_module_dirname);
}
ADD_FLAG('CFLAGS_OPCACHE', "/I " + configure_module_dirname);

View file

@ -12,4 +12,4 @@ ADD . /php-src/
WORKDIR /php-src
RUN ./buildconf
# Compile a minimal debug build. --enable-debug adds runtime assertions and is slower than regular builds.
RUN ./configure --enable-debug --disable-all --enable-opcache && make clean && make -j$(nproc)
RUN ./configure --enable-debug --disable-all && make clean && make -j$(nproc)

View file

@ -76,7 +76,7 @@ export LDFLAGS=-L/usr/lib/i386-linux-gnu
export CFLAGS='-m32'
export CXXFLAGS='-m32'
export PKG_CONFIG=/usr/bin/i686-linux-gnu-pkg-config
./configure --disable-all --enable-opcache --build=i686-pc-linux-gnu
./configure --disable-all --build=i686-pc-linux-gnu
make -j$(nproc)
```

View file

@ -23,7 +23,6 @@ $proc = proc_open([
PHP_BINARY,
"-n",
"-d", "extension_dir=$extension_dir",
"-d", "zend_extension=opcache",
"-d", "opcache.memory_consumption=$new_memory_consumption",
"-d", "opcache.enable=1",
"-d", "opcache.enable_cli=1",

View file

@ -25,6 +25,8 @@
#include "ZendAccelerator.h"
#include "zend_API.h"
#include "zend_closures.h"
#include "zend_extensions.h"
#include "zend_modules.h"
#include "zend_shared_alloc.h"
#include "zend_accelerator_blacklist.h"
#include "zend_file_cache.h"
@ -432,13 +434,19 @@ static ZEND_NAMED_FUNCTION(accel_is_readable)
static ZEND_MINIT_FUNCTION(zend_accelerator)
{
(void)type; /* keep the compiler happy */
REGISTER_INI_ENTRIES();
start_accel_extension();
return SUCCESS;
}
void zend_accel_register_ini_entries(void)
{
zend_module_entry *module = zend_hash_str_find_ptr_lc(&module_registry,
ACCELERATOR_PRODUCT_NAME, strlen(ACCELERATOR_PRODUCT_NAME));
zend_register_ini_entries_ex(ini_entries, module->module_number, module->type);
}
void zend_accel_override_file_functions(void)
{
zend_function *old_function;
@ -469,6 +477,7 @@ static ZEND_MSHUTDOWN_FUNCTION(zend_accelerator)
UNREGISTER_INI_ENTRIES();
accel_shutdown();
return SUCCESS;
}
@ -581,7 +590,7 @@ void zend_accel_info(ZEND_MODULE_INFO_FUNC_ARGS)
DISPLAY_INI_ENTRIES();
}
static zend_module_entry accel_module_entry = {
zend_module_entry opcache_module_entry = {
STANDARD_MODULE_HEADER,
ACCELERATOR_PRODUCT_NAME,
ext_functions,
@ -596,11 +605,6 @@ static zend_module_entry accel_module_entry = {
STANDARD_MODULE_PROPERTIES_EX
};
int start_accel_module(void)
{
return zend_startup_module(&accel_module_entry);
}
/* {{{ Get the scripts which are accelerated by ZendAccelerator */
static int accelerator_get_scripts(zval *return_value)
{

View file

@ -22,7 +22,12 @@
#ifndef ZEND_ACCELERATOR_MODULE_H
#define ZEND_ACCELERATOR_MODULE_H
int start_accel_module(void);
#include "Zend/zend_modules.h"
#define phpext_opcache_ptr &opcache_module_entry
extern zend_module_entry opcache_module_entry;
void zend_accel_register_ini_entries(void);
void zend_accel_override_file_functions(void);

View file

@ -965,8 +965,6 @@ default_socket_timeout = 60
;extension=xsl
;extension=zip
;zend_extension=opcache
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

View file

@ -967,8 +967,6 @@ default_socket_timeout = 60
;extension=xsl
;extension=zip
;zend_extension=opcache
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

View file

@ -17,7 +17,6 @@ if (!file_exists($extDir . '/opcache.so')) {
$cmd = [
PHP_BINARY,
'-dextension_dir=' . ini_get('extension_dir'),
'-dzend_extension=opcache.so',
'-dopcache.enable=1',
'-dopcache.enable_cli=1',
'-dopcache.preload=' . __DIR__ . '/preload.inc',

View file

@ -31,8 +31,8 @@ When running `make` it creates these binaries in `sapi/fuzzer/`:
* `php-fuzz-mbstring`: Fuzzing `mb_convert_encoding()` (requires `--enable-mbstring`)
* `php-fuzz-mbregex`: Fuzzing `mb_ereg[i]()` (requires --enable-mbstring)
* `php-fuzz-execute`: Fuzzing the executor
* `php-fuzz-function-jit`: Fuzzing the function JIT (requires --enable-opcache)
* `php-fuzz-tracing-jit`: Fuzzing the tracing JIT (requires --enable-opcache)
* `php-fuzz-function-jit`: Fuzzing the function JIT
* `php-fuzz-tracing-jit`: Fuzzing the tracing JIT
Some fuzzers have a seed corpus in `sapi/fuzzer/corpus`. You can use it as follows: