Skip to content

[RFC][PoC] Allow opcache to be built statically #18660

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 8 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 0 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ jobs:
--prefix=/usr \
--enable-phpdbg \
--enable-fpm \
--enable-opcache \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pgsql \
Expand Down Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion .github/actions/freebsd/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,3 @@ runs:
--show-diff \
--show-slow 1000 \
--set-timeout 120 \
-d zend_extension=opcache.so
1 change: 0 additions & 1 deletion .github/scripts/windows/test_task.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ jobs:
jitType: tracing
runTestsParameters: >-
--asan -x
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Notify Slack
if: failure()
Expand Down Expand Up @@ -240,14 +239,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
Expand All @@ -258,7 +255,6 @@ jobs:
jitType: function
runTestsParameters: >-
${{ matrix.run_tests_parameters }}
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Verify generated files are up to date
uses: ./.github/actions/verify-generated-files
Expand Down Expand Up @@ -332,22 +328,19 @@ 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
with:
jitType: function
runTestsParameters: >-
${{ matrix.run_tests_parameters }}
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- name: Notify Slack
if: failure()
Expand Down Expand Up @@ -392,21 +385,18 @@ 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
uses: ./.github/actions/test-macos
with:
jitType: function
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
Expand Down Expand Up @@ -468,7 +458,6 @@ jobs:
with:
jitType: tracing
runTestsParameters: >-
-d zend_extension=opcache.so
-d opcache.enable_cli=1
- uses: codecov/codecov-action@v4
if: ${{ !cancelled() }}
Expand Down Expand Up @@ -522,7 +511,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
Expand Down Expand Up @@ -713,37 +701,32 @@ 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
- name: Test File Cache Only (prime)
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
- name: Test File Cache Only (use)
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
Expand Down Expand Up @@ -837,7 +820,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
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ jobs:
with:
jitType: tracing
runTestsParameters: >-
-d zend_extension=opcache.so
Copy link
Contributor

Choose a reason for hiding this comment

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

On my Windows the php.exe has size of 128 KB but the php_opcache.dll has size of 463 KB. This is 3.6x binary size increase which might be an issue for embedded devices running php.

-d opcache.enable_cli=1
${{ matrix.asan && '--asan -x' || '' }}
- name: Verify generated files are up to date
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -299,7 +296,6 @@ jobs:
./configure \
--disable-debug \
--enable-mbstring \
--enable-opcache \
--enable-option-checking=fatal \
--enable-sockets \
--enable-werror \
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions docs/release-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ 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

# 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
Expand Down Expand Up @@ -528,15 +528,15 @@ 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

# 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
Expand Down
32 changes: 31 additions & 1 deletion ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -100,7 +101,13 @@ typedef int gid_t;

#include "zend_simd.h"

#ifdef COMPILE_DL_OPCACHE
ZEND_EXTENSION();
ZEND_EXT_API zend_extension zend_extension_entry;
#define opcache_extension_entry zend_extension_entry
#else
zend_extension opcache_extension_entry;
#endif

#ifndef ZTS
zend_accel_globals accel_globals;
Expand All @@ -118,6 +125,7 @@ zend_accel_shared_globals *accel_shared_globals = NULL;
#ifdef ZEND_WIN32
char accel_uname_id[32];
#endif
bool accel_starting = false;
bool accel_startup_ok = false;
static const char *zps_failure_reason = NULL;
const char *zps_api_failure_reason = NULL;
Expand Down Expand Up @@ -3154,8 +3162,21 @@ 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)
{
if (accel_starting) {
return;
}

accel_starting = true;

zend_register_extension(&opcache_extension_entry, NULL);
}

static int accel_startup(zend_extension *extension)
{
accel_starting = true;

#ifdef ZTS
accel_globals_id = ts_allocate_id(&accel_globals_id, sizeof(zend_accel_globals), (ts_allocate_ctor) accel_globals_ctor, (ts_allocate_dtor) accel_globals_dtor);
#else
Expand All @@ -3172,12 +3193,15 @@ static int accel_startup(zend_extension *extension)
# endif
#endif

if (start_accel_module() == FAILURE) {
zend_module_entry *module = start_accel_module();
if (module == NULL) {
accel_startup_ok = false;
zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME ": module registration failed!");
return FAILURE;
}

accel_register_ini_entries(module);

#ifdef ZEND_WIN32
if (UNEXPECTED(accel_gen_uname_id() == FAILURE)) {
zps_startup_failure("Unable to get user name", NULL, accelerator_remove_cb);
Expand Down Expand Up @@ -3461,6 +3485,8 @@ void accel_shutdown(void)
zend_ini_entry *ini_entry;
bool _file_cache_only = false;

accel_starting = false;

#ifdef HAVE_JIT
zend_jit_shutdown();
#endif
Expand Down Expand Up @@ -5037,7 +5063,11 @@ static void accel_activate(void) {
}
}

#ifdef COMPILE_DL_OPCACHE
ZEND_EXT_API zend_extension zend_extension_entry = {
#else
zend_extension opcache_extension_entry = {
#endif
ACCELERATOR_PRODUCT_NAME, /* name */
PHP_VERSION, /* version */
"Zend Technologies", /* author */
Expand Down
5 changes: 5 additions & 0 deletions ext/opcache/ZendAccelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,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);
Expand All @@ -336,6 +337,10 @@ zend_string* ZEND_FASTCALL accel_new_interned_string(zend_string *str);

uint32_t zend_accel_get_class_name_map_ptr(zend_string *type_name);

#ifndef COMPILE_DL_OPCACHE
extern zend_extension opcache_extension_entry;
#endif

END_EXTERN_C()

/* memory write protection */
Expand Down
Loading