From 73e9db0fa1f6360a31a8a996aaf437ca940dae69 Mon Sep 17 00:00:00 2001 From: Florian Engelhardt Date: Wed, 30 Oct 2024 11:06:50 +0100 Subject: [PATCH] PHP 8.4 support (#2758) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add PHP 8.4 * PHP 8.4 interceptor compatibility Signed-off-by: Bob Weinand * Add missing dependencies in CircleCI jobs * pecl php 8.4 * make appsec compile with PHP 8.4 * Add PHP 8.4 windows support * run verify php 8.4 only on alpine * update prof correctness to new closure frames * Reduce visual studio parts needing to be installed * fix prof correctness * fix PHP 8.4 closure tests * update PHP 8.4 to beta3 * fix xdebug * fix circleci * fix appsec * Fix warning: Warning: JIT on AArch64 doesn't support opcache.jit_buffer_size above 128M. in Unknown on line 0 Signed-off-by: Bob Weinand * Fix closures on PHP 8.4 (#2812) * update to RC1 * Fix cross-compile Signed-off-by: Bob Weinand * update to RC1 * fix tests * fix xdebug * fix comment * set xdebug for loader test * Adapt to PHP 8.4 stuff Signed-off-by: Bob Weinand * fix build extension * update to llvm 17 * cmake * add libltdl-dev for php 7 * add libltdl-dev for php 7 * asdf * fix warning `as` vs `AS` * use new asan * bump llvm to 17 * fix xdebug php 8.3Ä * Add missing libclang-rt-17-dev * Include frameless functions in stack walk Signed-off-by: Bob Weinand * fix php < 8.4 compile * fix: warning about unused variable * perf: PHP 8.4+ doesn't need zend_execute_internal * add zts to buster php 7 * add tar * Add clang ASAN handling Signed-off-by: Bob Weinand * stuff * Fix asan stuff Signed-off-by: Bob Weinand * updates * Use cc instead of gcc in CI Signed-off-by: Bob Weinand * fix 8.1 * fix * upadte 8.3 in other OS as well * Fix compile issues Signed-off-by: Bob Weinand * update 8.4 to rc3 * Try fix more compile issues Signed-off-by: Bob Weinand * fix llvm vs gcc flags * fix dns_check_record() * Fix sidecar asan Signed-off-by: Bob Weinand * Update php 8.4 windows version * Fix everything Signed-off-by: Bob Weinand Signed-off-by: Bob Weinand * Make coverage jobs independent Signed-off-by: Bob Weinand * Skip ubsan tea tests for PHP 7.0-7.3 Signed-off-by: Bob Weinand * Exclude some tests from running Signed-off-by: Bob Weinand * fix cmake asan * disable code coverage * Fix tea tests Signed-off-by: Bob Weinand * It's forbidden to use EG(uninitialized_zval) in ZTS in startup Signed-off-by: Bob Weinand * Fix stacktarget handling in zai_hook_safe_finish Signed-off-by: Bob Weinand --------- Signed-off-by: Bob Weinand Co-authored-by: Bob Weinand Co-authored-by: Alejandro Estringana Ruiz Co-authored-by: Levi Morrison --- .circleci/continue_config.yml | 226 +++++++++++++++--- .github/workflows/prof_asan.yml | 6 +- .github/workflows/prof_correctness.yml | 8 +- .gitlab/ci-images.yml | 4 + Makefile | 11 +- appsec/cmake/run_tests.cmake | 2 +- appsec/src/extension/backtrace.c | 10 +- appsec/src/extension/commands_ctx.h | 2 +- appsec/src/extension/commands_helpers.h | 2 +- appsec/src/extension/compatibility.h | 11 + appsec/src/extension/configuration.c | 6 +- appsec/src/extension/ddappsec.c | 15 +- appsec/src/extension/ddappsec.h | 2 +- appsec/src/extension/ddtrace.c | 13 +- appsec/src/extension/ddtrace.h | 2 +- appsec/src/extension/entity_body.h | 2 +- appsec/src/extension/helper_process.c | 7 +- appsec/src/extension/ip_extraction.c | 3 +- appsec/src/extension/logging.c | 9 +- appsec/src/extension/logging.h | 2 +- appsec/src/extension/msgpack_helpers.c | 3 +- appsec/src/extension/msgpack_helpers.h | 2 +- appsec/src/extension/php_helpers.h | 2 +- appsec/src/extension/php_objects.c | 3 +- appsec/src/extension/request_abort.c | 6 +- appsec/src/extension/request_lifecycle.c | 6 +- appsec/src/extension/string_helpers.h | 2 +- appsec/src/extension/tags.c | 17 +- appsec/src/extension/tags.h | 2 + appsec/tests/integration/build.gradle | 2 +- cmake/asan.cmake | 11 +- compile_rust.sh | 5 +- config.m4 | 28 ++- datadog-setup.php | 2 +- docker-compose.yml | 2 + .../alpine_compile_extension/base.Dockerfile | 8 +- .../docker-compose.yml | 21 +- dockerfiles/ci/bookworm/.env | 4 +- dockerfiles/ci/bookworm/Dockerfile | 18 +- dockerfiles/ci/bookworm/build-extensions.sh | 15 +- dockerfiles/ci/bookworm/docker-compose.yml | 20 +- dockerfiles/ci/bookworm/php-7.0/Dockerfile | 10 +- dockerfiles/ci/bookworm/php-7.1/Dockerfile | 10 +- dockerfiles/ci/bookworm/php-7.2/Dockerfile | 10 +- dockerfiles/ci/bookworm/php-7.3/Dockerfile | 10 +- dockerfiles/ci/bookworm/php-7.4/Dockerfile | 12 +- dockerfiles/ci/bookworm/php-8.0/Dockerfile | 12 +- dockerfiles/ci/bookworm/php-8.1/Dockerfile | 12 +- dockerfiles/ci/bookworm/php-8.2/Dockerfile | 12 +- dockerfiles/ci/bookworm/php-8.3/Dockerfile | 14 +- dockerfiles/ci/bookworm/php-8.4/Dockerfile | 109 +++++++++ dockerfiles/ci/bookworm/php-8.4/suppr.txt | 1 + dockerfiles/ci/buster/Dockerfile | 68 ++++-- dockerfiles/ci/buster/build-extensions.sh | 60 +++-- dockerfiles/ci/buster/build-php.sh | 14 +- dockerfiles/ci/buster/docker-compose.yml | 21 +- ...m_cookie_seeker-signature-under-musl.patch | 37 +++ .../0001-fix-broken-sprintf-detection.patch | 11 + .../php-7.0/0001-fix-build-scripts.patch | 91 +++++++ dockerfiles/ci/buster/php-7.0/Dockerfile | 23 +- ...m_cookie_seeker-signature-under-musl.patch | 37 +++ .../0001-fix-broken-sprintf-detection.patch | 11 + .../php-7.1/0001-fix-build-scripts.patch | 100 ++++++++ dockerfiles/ci/buster/php-7.1/Dockerfile | 23 +- ...m_cookie_seeker-signature-under-musl.patch | 37 +++ .../0001-fix-broken-sprintf-detection.patch | 11 + .../php-7.2/0001-fix-build-scripts.patch | 100 ++++++++ dockerfiles/ci/buster/php-7.2/Dockerfile | 23 +- .../php-7.3/0001-fix-build-scripts.patch | 64 +++++ dockerfiles/ci/buster/php-7.3/Dockerfile | 19 +- .../php-7.4/0001-fix-build-scripts.patch | 37 +++ dockerfiles/ci/buster/php-7.4/Dockerfile | 14 +- dockerfiles/ci/buster/php-8.0/Dockerfile | 12 +- .../php-8.1/0002-fix-tsrm-jit-aarch64.patch | 131 ++++++++++ dockerfiles/ci/buster/php-8.1/Dockerfile | 14 +- dockerfiles/ci/buster/php-8.2/Dockerfile | 12 +- dockerfiles/ci/buster/php-8.3/Dockerfile | 12 +- dockerfiles/ci/buster/php-8.3/suppr.txt | 1 + dockerfiles/ci/buster/php-8.4/Dockerfile | 88 +++++++ dockerfiles/ci/buster/php-8.4/suppr.txt | 1 + dockerfiles/ci/centos/7/base.Dockerfile | 56 ++++- dockerfiles/ci/centos/7/docker-compose.yml | 19 +- dockerfiles/ci/centos/7/php-8.4/configure.sh | 51 ++++ dockerfiles/ci/centos/7/php.Dockerfile | 17 +- dockerfiles/ci/windows/Dockerfile | 4 +- dockerfiles/ci/windows/basetools.Dockerfile | 21 +- dockerfiles/ci/windows/docker-compose.yml | 31 +++ dockerfiles/ci/windows/vc15.Dockerfile | 2 +- dockerfiles/ci/windows/vs16.Dockerfile | 2 +- dockerfiles/ci/windows/vs17.Dockerfile | 4 + dockerfiles/ci/xfail_tests/7.0.list | 9 + dockerfiles/ci/xfail_tests/7.1.list | 9 + dockerfiles/ci/xfail_tests/7.2.list | 9 + dockerfiles/ci/xfail_tests/7.3.list | 9 + dockerfiles/ci/xfail_tests/7.4.list | 9 + dockerfiles/ci/xfail_tests/8.2.list | 1 + dockerfiles/ci/xfail_tests/8.3.list | 1 + dockerfiles/ci/xfail_tests/8.4.list | 192 +++++++++++++++ dockerfiles/ci/xfail_tests/README.md | 6 +- ext/collect_backtrace.c | 4 +- ext/coms.c | 28 ++- ext/coms.h | 1 + ext/handlers_exception.c | 6 +- ext/handlers_pcntl.c | 21 ++ libdatadog | 2 +- loader/dd_library_loader.c | 3 +- .../functional/test_incompatibility_jit.php | 4 +- .../functional/test_telemetry_complete.php | 4 +- package.xml | 2 +- profiling/build.rs | 3 + profiling/src/profiling/stack_walking.rs | 62 +++-- profiling/src/wall_time.rs | 133 ++++++----- .../tests/correctness/exceptions_zts.json | 2 +- .../tests/correctness/strange_frames.json | 2 +- tea/include/testing/catch2.hpp | 5 + ...ckground_sender_restores_capabilities.phpt | 1 + tests/ext/from_php_7_3_bug61728.phpt | 2 +- .../dd_trace_exception_span_event.phpt | 2 +- .../dd_trace_method_binds_called_object.phpt | 6 +- .../install_hook/override_argument_jit.phpt | 2 +- .../install_hook/remove_executing_hook.phpt | 8 +- .../install_hook/suppress_call_jit.phpt | 2 +- .../sandbox/install_hook/trace_closure.phpt | 10 +- .../install_hook/trace_closure_ge_php_84.phpt | 102 ++++++++ .../sandbox/install_hook/trace_generator.phpt | 11 +- .../trace_generator_ge_php_84.phpt | 45 ++++ .../install_hook/trace_generator_jit.phpt | 2 +- .../ext/sandbox/safe_to_string_metadata.phpt | 6 + .../safe_to_string_metadata_ge_php_84.phpt | 168 +++++++++++++ tests/ext/startup_logging_skipif.inc | 1 + tests/opcache/basic.phpt | 4 + tests/opcache/file_cache.phpt | 4 + tests/opcache/include.php | 2 + tests/opcache/preload.phpt | 6 +- tests/opcache/protect_memory.phpt | 4 + tests/opcache/resolver_cached.phpt | 4 + tooling/bin/generate-final-artifact.sh | 6 +- tooling/bin/generate-ssi-package.sh | 2 +- .../hook/tests/internal/request.cc | 13 +- .../hook/tests/internal/static.cc | 4 +- .../interceptor/php7/interceptor.c | 11 +- .../interceptor/php7/resolver.c | 3 +- .../interceptor/php8/interceptor.c | 63 +++-- .../jit_utils/jit_blacklist.c | 24 ++ .../sandbox/tests/error.cc | 4 +- zend_abstract_interface/symbols/call.c | 4 + 146 files changed, 2596 insertions(+), 470 deletions(-) create mode 100644 appsec/src/extension/compatibility.h create mode 100644 dockerfiles/ci/bookworm/php-8.4/Dockerfile create mode 100644 dockerfiles/ci/bookworm/php-8.4/suppr.txt create mode 100644 dockerfiles/ci/buster/php-7.0/0001-Fix-stream_cookie_seeker-signature-under-musl.patch create mode 100644 dockerfiles/ci/buster/php-7.0/0001-fix-broken-sprintf-detection.patch create mode 100644 dockerfiles/ci/buster/php-7.0/0001-fix-build-scripts.patch create mode 100644 dockerfiles/ci/buster/php-7.1/0001-Fix-stream_cookie_seeker-signature-under-musl.patch create mode 100644 dockerfiles/ci/buster/php-7.1/0001-fix-broken-sprintf-detection.patch create mode 100644 dockerfiles/ci/buster/php-7.1/0001-fix-build-scripts.patch create mode 100644 dockerfiles/ci/buster/php-7.2/0001-Fix-stream_cookie_seeker-signature-under-musl.patch create mode 100644 dockerfiles/ci/buster/php-7.2/0001-fix-broken-sprintf-detection.patch create mode 100644 dockerfiles/ci/buster/php-7.2/0001-fix-build-scripts.patch create mode 100644 dockerfiles/ci/buster/php-7.3/0001-fix-build-scripts.patch create mode 100644 dockerfiles/ci/buster/php-7.4/0001-fix-build-scripts.patch create mode 100644 dockerfiles/ci/buster/php-8.1/0002-fix-tsrm-jit-aarch64.patch create mode 100644 dockerfiles/ci/buster/php-8.4/Dockerfile create mode 100644 dockerfiles/ci/buster/php-8.4/suppr.txt create mode 100755 dockerfiles/ci/centos/7/php-8.4/configure.sh create mode 100644 dockerfiles/ci/windows/vs17.Dockerfile create mode 100644 dockerfiles/ci/xfail_tests/8.4.list create mode 100644 tests/ext/sandbox/install_hook/trace_closure_ge_php_84.phpt create mode 100644 tests/ext/sandbox/install_hook/trace_generator_ge_php_84.phpt create mode 100644 tests/ext/sandbox/safe_to_string_metadata_ge_php_84.phpt diff --git a/.circleci/continue_config.yml b/.circleci/continue_config.yml index 0802359e3b..23d0c3e548 100644 --- a/.circleci/continue_config.yml +++ b/.circleci/continue_config.yml @@ -253,7 +253,7 @@ aliases: # If it's missing, we're building in the job if [ -f ddtrace.a ]; then sed -i 's/-export-symbols .*\/ddtrace\.sym/-Wl,--retain-symbols-file=ddtrace.sym/g' ddtrace.ldflags - gcc -shared -Wl,-whole-archive ddtrace.a -Wl,-no-whole-archive $(cat ddtrace.ldflags) libddtrace_php.a -Wl,-soname -Wl,ddtrace.so -o ddtrace.so + cc -shared -Wl,-whole-archive ddtrace.a -Wl,-no-whole-archive $(cat ddtrace.ldflags) libddtrace_php.a -Wl,-soname -Wl,ddtrace.so -o ddtrace.so mkdir -p tmp/build_extension/modules mv ddtrace.so tmp/build_extension/modules/ fi @@ -847,6 +847,9 @@ jobs: echo "3.0.0" fi } + if [[ "<>" == "3.4.0" ]]; then + ln -s $(php-config --extension-dir)/xdebug-3.4.0.so $(php-config --extension-dir)/xdebug-3.4.0alpha2-dev.so + fi php /usr/local/src/php/run-tests.php -g FAIL,XFAIL,BORK,WARN,LEAK,XLEAK,SKIP -p $(which php) --show-all -d zend_extension=xdebug-<< parameters.xdebug_version_one >>.so tests/xdebug/$(targetdir << parameters.xdebug_version_one >>) if [[ ! "<>" == "none" ]]; then php /usr/local/src/php/run-tests.php -g FAIL,XFAIL,BORK,WARN,LEAK,XLEAK,SKIP -p $(which php) --show-all -d zend_extension=xdebug-<< parameters.xdebug_version_two >>.so tests/xdebug/$(targetdir << parameters.xdebug_version_two >>) @@ -2881,23 +2884,32 @@ jobs: grep -e "=== Total [0-9]+ memory leaks detected ===" Testing/Temporary/LastTest.log && exit 1 || true done - - run: - name: Build and test Zend Abstract Interface (debug + UBSan) - command: | - switch-php debug - mkdir -p /tmp/build/zai-debug-ubsan - cd /tmp/build/zai-debug-ubsan - CMAKE_PREFIX_PATH=/opt/catch2 \ - Tea_ROOT=/opt/tea/debug \ - cmake \ - -DCMAKE_TOOLCHAIN_FILE=~/datadog/cmake/ubsan.cmake \ - -DCMAKE_BUILD_TYPE=Debug \ - -DBUILD_ZAI_TESTING=ON \ - -DPhpConfig_ROOT=$(php-config --prefix) \ - ~/datadog/zend_abstract_interface - make -j all - make test - grep -e "=== Total [0-9]+ memory leaks detected ===" Testing/Temporary/LastTest.log && exit 1 || true + - when: + condition: # PHP itself is only really ubsan compatible since 7.4 + not: + or: + - equal: [ "7.0", << parameters.php_version >> ] + - equal: [ "7.1", << parameters.php_version >> ] + - equal: [ "7.2", << parameters.php_version >> ] + - equal: [ "7.3", << parameters.php_version >> ] + steps: + - run: + name: Build and test Zend Abstract Interface (debug + UBSan) + command: | + switch-php debug + mkdir -p /tmp/build/zai-debug-ubsan + cd /tmp/build/zai-debug-ubsan + CMAKE_PREFIX_PATH=/opt/catch2 \ + Tea_ROOT=/opt/tea/debug \ + cmake \ + -DCMAKE_TOOLCHAIN_FILE=~/datadog/cmake/ubsan.cmake \ + -DCMAKE_BUILD_TYPE=Debug \ + -DBUILD_ZAI_TESTING=ON \ + -DPhpConfig_ROOT=$(php-config --prefix) \ + ~/datadog/zend_abstract_interface + make -j all + make test + grep -e "=== Total [0-9]+ memory leaks detected ===" Testing/Temporary/LastTest.log && exit 1 || true - run: name: Extension Tea Tests @@ -2913,7 +2925,7 @@ jobs: # build ddtrace.so cd ~/datadog - make clean + rm -rf tmp/build_extension make install # Build ext Tea tests @@ -3379,8 +3391,10 @@ jobs: command: | set -xeuo pipefail - if [[ "<< parameters.php_major_minor >>" == "8.3" ]]; then - export XDEBUG_SO_NAME=xdebug-3.3.0.so + if [[ "<< parameters.php_major_minor >>" == "8.4" ]]; then + export XDEBUG_SO_NAME=xdebug-3.4.0.so + elif [[ "<< parameters.php_major_minor >>" == "8.3" ]]; then + export XDEBUG_SO_NAME=xdebug-3.3.2.so elif [[ "<< parameters.php_major_minor >>" == "8.2" ]]; then export XDEBUG_SO_NAME=xdebug-3.2.2.so elif [[ "<< parameters.php_major_minor >>" == "8.1" ]]; then @@ -3563,7 +3577,7 @@ jobs: pids=() for archive in extensions_$(uname -m)/*.a; do ( - gcc -shared -Wl,-whole-archive $archive -Wl,-no-whole-archive $(cat ddtrace_$(uname -m)<< parameters.libddtrace_suffix >>.ldflags) libddtrace_php_$(uname -m)<< parameters.libddtrace_suffix >>.a -Wl,-soname -Wl,ddtrace.so -o ${archive%.a}.so + cc -shared -Wl,-whole-archive $archive -Wl,-no-whole-archive $(cat ddtrace_$(uname -m)<< parameters.libddtrace_suffix >>.ldflags) libddtrace_php_$(uname -m)<< parameters.libddtrace_suffix >>.a -Wl,-soname -Wl,ddtrace.so -o ${archive%.a}.so objcopy --compress-debug-sections ${archive%.a}.so ) & pids+=($!) @@ -3993,6 +4007,7 @@ workflows: - "8.1" - "8.2" - "8.3" + - "8.4" cmake_version: - "3.24.4" catch2_version: @@ -4117,6 +4132,17 @@ workflows: abi_no: "20230831" triplet: "aarch64-alpine-linux-musl" resource_class: "arm.medium" + - "cargo build --release": + name: "Profiler PHP v8.4 - x86_64-alpine-linux-musl" + docker_image: "datadog/dd-trace-ci:php-compile-extension-alpine-8.4" + abi_no: "20240924" + triplet: "x86_64-alpine-linux-musl" + - "cargo build --release": + name: "Profiler PHP v8.4 - aarch64-alpine-linux-musl" + docker_image: "datadog/dd-trace-ci:php-compile-extension-alpine-8.4" + abi_no: "20240924" + triplet: "aarch64-alpine-linux-musl" + resource_class: "arm.medium" - "cache cargo deps": name: "cache cargo deps - x86_64-unknown-linux-gnu" @@ -4215,6 +4241,17 @@ workflows: abi_no: "20230831" triplet: "aarch64-unknown-linux-gnu" resource_class: "arm.medium" + - "cargo build --release": + name: "Profiler PHP v8.4 - x86_64-unknown-linux-gnu" + docker_image: "datadog/dd-trace-ci:php-8.4_centos-7" + abi_no: "20240924" + triplet: "x86_64-unknown-linux-gnu" + - "cargo build --release": + name: "Profiler PHP v8.4 - aarch64-unknown-linux-gnu" + docker_image: "datadog/dd-trace-ci:php-8.4_centos-7" + abi_no: "20240924" + triplet: "aarch64-unknown-linux-gnu" + resource_class: "arm.medium" - compile_appsec_extension_centos: matrix: @@ -4229,6 +4266,7 @@ workflows: - '8.1' - '8.2' - '8.3' + - '8.4' resource_class: - "medium" - "arm.medium" @@ -4246,6 +4284,7 @@ workflows: - '8.1' - '8.2' - '8.3' + - '8.4' resource_class: - "medium" - "arm.medium" @@ -4270,6 +4309,7 @@ workflows: - '8.1' - '8.2' - '8.3' + - '8.4' resource_class: "medium" name: "Compile alpine x86_64 PHP << matrix.php_major_minor >>" - compile_alpine: @@ -4285,6 +4325,7 @@ workflows: - '8.1' - '8.2' - '8.3' + - '8.4' resource_class: "arm.medium" name: "Compile alpine aarch64 PHP << matrix.php_major_minor >>" - compile_rust_alpine: @@ -4307,6 +4348,7 @@ workflows: - "Compile alpine x86_64 PHP 8.1" - "Compile alpine x86_64 PHP 8.2" - "Compile alpine x86_64 PHP 8.3" + - "Compile alpine x86_64 PHP 8.4" libddtrace_suffix: "-alpine" resource_class: "large" name: "Link x86_64 alpine" @@ -4323,6 +4365,7 @@ workflows: - "Compile alpine aarch64 PHP 8.1" - "Compile alpine aarch64 PHP 8.2" - "Compile alpine aarch64 PHP 8.3" + - "Compile alpine aarch64 PHP 8.4" libddtrace_suffix: "-alpine" resource_class: "arm.large" name: "Link aarch64 alpine" @@ -4465,6 +4508,25 @@ workflows: docker_image: "datadog/dd-trace-ci:php-8.3_windows" php_version: "8.3" so_suffix: "20230831" + - compile_extension_centos: + requires: [ 'Prepare Code' ] + name: "Compile x86_64 PHP 84 nts + zts + debug" + docker_image: "datadog/dd-trace-ci:php-8.4_centos-7" + php_version: "8.4" + so_suffix: "20240924" + - compile_extension_centos: + requires: [ 'Prepare Code' ] + name: "Compile aarch64 PHP 84 nts + zts + debug" + docker_image: "datadog/dd-trace-ci:php-8.4_centos-7" + php_version: "8.4" + so_suffix: "20240924" + resource_class: "arm.medium" + - compile_extension_windows: + requires: [ 'Prepare Code' ] + name: "Compile Windows PHP 84 nts + zts" + docker_image: "datadog/dd-trace-ci:php-8.4_windows" + php_version: "8.4" + so_suffix: "20240924" - compile_rust_centos: name: "Compile x86_64 rust" @@ -4486,6 +4548,7 @@ workflows: - "Compile x86_64 PHP 81 nts + zts + debug" - "Compile x86_64 PHP 82 nts + zts + debug" - "Compile x86_64 PHP 83 nts + zts + debug" + - "Compile x86_64 PHP 84 nts + zts + debug" name: "Link x86_64 PHP" docker_image: "datadog/dd-trace-ci:centos-7" - link_extension: @@ -4500,6 +4563,7 @@ workflows: - "Compile aarch64 PHP 81 nts + zts + debug" - "Compile aarch64 PHP 82 nts + zts + debug" - "Compile aarch64 PHP 83 nts + zts + debug" + - "Compile aarch64 PHP 84 nts + zts + debug" name: "Link aarch64 PHP" docker_image: "datadog/dd-trace-ci:centos-7" resource_class: "arm.xlarge" @@ -4522,6 +4586,7 @@ workflows: - "Compile Windows PHP 81 nts + zts" - "Compile Windows PHP 82 nts + zts" - "Compile Windows PHP 83 nts + zts" + - "Compile Windows PHP 84 nts + zts" - "Build PECL" - "Profiler PHP v7.1 - x86_64-alpine-linux-musl" @@ -4532,6 +4597,7 @@ workflows: - "Profiler PHP v8.1 - x86_64-alpine-linux-musl" - "Profiler PHP v8.2 - x86_64-alpine-linux-musl" - "Profiler PHP v8.3 - x86_64-alpine-linux-musl" + - "Profiler PHP v8.4 - x86_64-alpine-linux-musl" - "Profiler PHP v7.1 - x86_64-unknown-linux-gnu" - "Profiler PHP v7.2 - x86_64-unknown-linux-gnu" @@ -4541,6 +4607,7 @@ workflows: - "Profiler PHP v8.1 - x86_64-unknown-linux-gnu" - "Profiler PHP v8.2 - x86_64-unknown-linux-gnu" - "Profiler PHP v8.3 - x86_64-unknown-linux-gnu" + - "Profiler PHP v8.4 - x86_64-unknown-linux-gnu" - "Profiler PHP v7.1 - aarch64-alpine-linux-musl" - "Profiler PHP v7.2 - aarch64-alpine-linux-musl" @@ -4550,6 +4617,7 @@ workflows: - "Profiler PHP v8.1 - aarch64-alpine-linux-musl" - "Profiler PHP v8.2 - aarch64-alpine-linux-musl" - "Profiler PHP v8.3 - aarch64-alpine-linux-musl" + - "Profiler PHP v8.4 - aarch64-alpine-linux-musl" - "Profiler PHP v7.1 - aarch64-unknown-linux-gnu" - "Profiler PHP v7.2 - aarch64-unknown-linux-gnu" @@ -4559,6 +4627,7 @@ workflows: - "Profiler PHP v8.1 - aarch64-unknown-linux-gnu" - "Profiler PHP v8.2 - aarch64-unknown-linux-gnu" - "Profiler PHP v8.3 - aarch64-unknown-linux-gnu" + - "Profiler PHP v8.4 - aarch64-unknown-linux-gnu" - "Compile Loader Linux x86_64" - "Compile Loader Linux aarch64" @@ -4614,6 +4683,17 @@ workflows: docker_image: "datadog/dd-trace-ci:php-8.3_buster" so_suffix: "20230831" resource_class: "arm.medium" + - compile_extension_asan: + requires: [ 'Prepare Code' ] + name: "Compile x86_64 PHP 84 debug-zts-asan" + docker_image: "datadog/dd-trace-ci:php-8.4_buster" + so_suffix: "20240924" + - compile_extension_asan: + requires: [ 'Prepare Code' ] + name: "Compile aarch64 PHP 84 debug-zts-asan" + docker_image: "datadog/dd-trace-ci:php-8.4_buster" + so_suffix: "20240924" + resource_class: "arm.medium" - "package extension": name: "package extension zts-debug-asan" @@ -4630,6 +4710,8 @@ workflows: - "Compile aarch64 PHP 82 debug-zts-asan" - "Compile x86_64 PHP 83 debug-zts-asan" - "Compile aarch64 PHP 83 debug-zts-asan" + - "Compile x86_64 PHP 84 debug-zts-asan" + - "Compile aarch64 PHP 84 debug-zts-asan" - "x-profiling phpt tests on Alpine": requires: [ 'package extension' ] @@ -4644,6 +4726,7 @@ workflows: - '8.1' - '8.2' - '8.3' + - '8.4' - randomized_tests: requires: [ 'package extension' ] @@ -4794,6 +4877,7 @@ workflows: - php:8.1-fpm-alpine - php:8.2-fpm-alpine - php:8.3-fpm-alpine + - php:8.4-rc-fpm-alpine - verify_centos: requires: [ "package extension" ] matrix: @@ -4813,6 +4897,7 @@ workflows: - PHP_MAJOR=8 PHP_MINOR=1 - PHP_MAJOR=8 PHP_MINOR=2 - PHP_MAJOR=8 PHP_MINOR=3 + # - PHP_MAJOR=8 PHP_MINOR=4 - verify_debian: requires: [ "package extension" ] matrix: @@ -4835,6 +4920,7 @@ workflows: - PHP_VERSION=8.1 - PHP_VERSION=8.2 - PHP_VERSION=8.3 + # - PHP_VERSION=8.4 - verify_tar_gz: requires: [ "package extension" ] @@ -4887,6 +4973,10 @@ workflows: requires: [ "Build PECL" ] name: "PHP 83 PECL tests" docker_image: "datadog/dd-trace-ci:php-8.3_buster" + - pecl_tests: + requires: [ "Build PECL" ] + name: "PHP 84 PECL tests" + docker_image: "datadog/dd-trace-ci:php-8.4_buster" - min_install_tests: requires: [ 'package extension' ] @@ -4911,13 +5001,11 @@ workflows: name: "System tests Integration Tests" build: | cd system-tests - git checkout conti/fix-php-errors ./build.sh php run: | export SYSTEM_TESTS_AWS_ACCESS_KEY_ID=$SYSTEM_TESTS_IDM_AWS_ACCESS_KEY_ID export SYSTEM_TESTS_AWS_SECRET_ACCESS_KEY=$SYSTEM_TESTS_IDM_AWS_SECRET_ACCESS_KEY cd system-tests - git checkout conti/fix-php-errors DD_API_KEY=$SYSTEM_TESTS_DD_API_KEY ./run.sh INTEGRATIONS - system_tests: @@ -4925,13 +5013,11 @@ workflows: name: "System tests Crossed Tracer Propagation Tests for Messaging" build: | cd system-tests - git checkout conti/fix-php-errors ./build.sh php run: | export SYSTEM_TESTS_AWS_ACCESS_KEY_ID=$SYSTEM_TESTS_IDM_AWS_ACCESS_KEY_ID export SYSTEM_TESTS_AWS_SECRET_ACCESS_KEY=$SYSTEM_TESTS_IDM_AWS_SECRET_ACCESS_KEY cd system-tests - git checkout conti/fix-php-errors DD_API_KEY=$SYSTEM_TESTS_DD_API_KEY ./run.sh CROSSED_TRACING_LIBRARIES - system_tests: @@ -5004,6 +5090,7 @@ workflows: - "8.1" - "8.2" - "8.3" + - "8.4" switch_php_version: - debug - zts @@ -5040,6 +5127,7 @@ workflows: - "8.1" - "8.2" - "8.3" + - "8.4" switch_php_version: - debug - zts @@ -5119,6 +5207,7 @@ workflows: - "8.1" - "8.2" - "8.3" + - "8.4" switch_php_version: - debug @@ -5132,6 +5221,7 @@ workflows: - "8.1" - "8.2" - "8.3" + - "8.4" switch_php_version: - debug-zts-asan resource_class: @@ -5152,8 +5242,9 @@ workflows: - "8.1" - "8.2" - "8.3" + - "8.4" make_target: - - test_coverage + # - test_coverage - test_unit - test_api_unit - test_c2php @@ -5161,6 +5252,24 @@ workflows: - test_internal_api_randomized - test_opcache + - test: + requires: [ 'Prepare Code' ] + matrix: + parameters: + php_major_minor: + - "7.0" + - "7.1" + - "7.2" + - "7.3" + - "7.4" + - "8.0" + - "8.1" + - "8.2" + - "8.3" + - "8.4" + make_target: + # - test_coverage + - test: requires: [ 'Prepare Code', 'Compile << matrix.php_major_minor >> extension for testing', 'Compile rust code for testing' ] coverage: true @@ -5197,6 +5306,7 @@ workflows: - "8.1" - "8.2" - "8.3" + - "8.4" make_target: - test_extension_ci @@ -5212,6 +5322,7 @@ workflows: - "datadog/dd-trace-ci:php-8.1_windows" - "datadog/dd-trace-ci:php-8.2_windows" - "datadog/dd-trace-ci:php-8.3_windows" + - "datadog/dd-trace-ci:php-8.4_windows" # sidecar is version independent - test_sidecar_sender: @@ -5229,11 +5340,12 @@ workflows: - "8.1" - "8.2" - "8.3" + - "8.4" switch_php_version: - debug-zts-asan - coverage: - requires: [ 'Prepare Code', 'Compile << matrix.php_major_minor >> extension for testing', 'Compile rust code for testing' ] + requires: [ 'Prepare Code' ] matrix: parameters: php_major_minor: @@ -5246,8 +5358,9 @@ workflows: - "8.1" - "8.2" - "8.3" + - "8.4" make_target: - - test_coverage + # - test_coverage - asan: requires: [ 'Prepare Code', '<< matrix.resource_class >>: Compile << matrix.php_major_minor >> ZTS asan extension for testing', '<< matrix.resource_class >>: Compile ASAN rust code for testing' ] matrix: @@ -5258,6 +5371,7 @@ workflows: - '8.1' - '8.2' - '8.3' + - '8.4' switch_php_version: - debug-zts-asan resource_class: @@ -5290,6 +5404,7 @@ workflows: - '8.1' - '8.2' - '8.3' + - '8.4' make_target: - test_auto_instrumentation - test_composer @@ -5326,6 +5441,7 @@ workflows: - '8.1' - '8.2' - '8.3' + - '8.4' make_target: - test_web - test_integrations @@ -5363,6 +5479,7 @@ workflows: - '8.1' - '8.2' - '8.3' + - '8.4' make_target: - test_distributed_tracing @@ -5454,6 +5571,22 @@ workflows: make_target: "test_web" docker_image: "datadog/dd-trace-ci:php-8.3_buster" php_major_minor: "8.3" + - integration_tests: + requires: [ 'Prepare Code', 'Compile 8.4 extension for testing', 'Compile rust code for testing' ] + name: "PHP 84 web tests with apache (+ opcache)" + resource_class: medium+ + sapi: apache2handler + make_target: "test_web" + docker_image: "datadog/dd-trace-ci:php-8.4_buster" + php_major_minor: "8.4" + - integration_tests: + requires: [ 'Prepare Code', 'Compile 8.4 extension for testing', 'Compile rust code for testing' ] + name: "PHP 84 web tests with nginx + FastCGI" + resource_class: medium+ + sapi: cgi-fcgi + make_target: "test_web" + docker_image: "datadog/dd-trace-ci:php-8.4_buster" + php_major_minor: "8.4" - integration_tests: requires: [ 'Prepare Code', 'Compile 7.4 extension for testing', 'Compile rust code for testing' ] name: "PHP 74 custom autoloaded web tests with nginx + PHP-FPM" @@ -5527,8 +5660,19 @@ workflows: requires: [ 'Prepare Code', 'Compile 8.3 extension for testing', 'Compile rust code for testing' ] name: "PHP 83 Xdebug tests" docker_image: "datadog/dd-trace-ci:php-8.3_buster" - xdebug_version_one: "3.3.0" + xdebug_version_one: "3.3.2" + - xdebug_tests: + requires: [ 'Prepare Code', 'Compile 8.4 extension for testing', 'Compile rust code for testing' ] + name: "PHP 84 Xdebug tests" + docker_image: "datadog/dd-trace-ci:php-8.4_buster" + xdebug_version_one: "3.4.0" + - php_language_tests: + requires: [ 'Compile rust code for testing', 'Compile 8.4 extension for testing' ] + name: "PHP 84 language tests" + xfail_list: dockerfiles/ci/xfail_tests/8.4.list + docker_image: "datadog/dd-trace-ci:php-8.4_buster" + parallel_workers: true - php_language_tests: requires: [ 'Compile rust code for testing', 'Compile 8.3 extension for testing' ] name: "PHP 83 language tests" @@ -5632,6 +5776,7 @@ workflows: - "8.1" - "8.2" - "8.3" + - "8.4" resource_class: - medium - arm.medium @@ -5663,6 +5808,7 @@ workflows: - "8.1" - "8.2" - "8.3" + - "8.4" resource_class: - medium - arm.medium @@ -5677,7 +5823,7 @@ workflows: targets: - test7.0-release test7.0-release-zts test7.1-release test7.1-release-zts test7.2-release test7.2-release-zts - test7.3-release test7.3-release-zts test7.4-release test7.4-release-zts test8.0-release test8.0-release-zts - - test8.1-release test8.1-release-zts test8.2-release test8.2-release-zts test8.3-release test8.3-release-zts + - test8.1-release test8.1-release-zts test8.2-release test8.2-release-zts test8.3-release test8.3-release-zts test8.4-release test8.4-release-zts - coverage_appsec: requires: [ hunter_cache_ubuntu ] @@ -5781,6 +5927,15 @@ workflows: docker_image: "datadog/dd-trace-ci:php-compile-extension-alpine-8.3" triplet: "aarch64-alpine-linux-musl" resource_class: "arm.medium" + - "profiling tests": + name: "Profiler test PHP v8.4 - x86_64-alpine-linux-musl" + docker_image: "datadog/dd-trace-ci:php-compile-extension-alpine-8.4" + triplet: "x86_64-alpine-linux-musl" + - "profiling tests": + name: "Profiler test PHP v8.4 - aarch64-alpine-linux-musl" + docker_image: "datadog/dd-trace-ci:php-compile-extension-alpine-8.4" + triplet: "aarch64-alpine-linux-musl" + resource_class: "arm.medium" - "profiling tests": name: "Profiler test PHP v7.1 - x86_64-unknown-linux-gnu" @@ -5854,3 +6009,12 @@ workflows: docker_image: "datadog/dd-trace-ci:php-8.3_centos-7" triplet: "aarch64-unknown-linux-gnu" resource_class: "arm.medium" + - "profiling tests": + name: "Profiler test PHP v8.4 - x86_64-unknown-linux-gnu" + docker_image: "datadog/dd-trace-ci:php-8.4_centos-7" + triplet: "x86_64-unknown-linux-gnu" + - "profiling tests": + name: "Profiler test PHP v8.4 - aarch64-unknown-linux-gnu" + docker_image: "datadog/dd-trace-ci:php-8.4_centos-7" + triplet: "aarch64-unknown-linux-gnu" + resource_class: "arm.medium" diff --git a/.github/workflows/prof_asan.yml b/.github/workflows/prof_asan.yml index 77e9ea4c7d..8d39889edb 100644 --- a/.github/workflows/prof_asan.yml +++ b/.github/workflows/prof_asan.yml @@ -7,7 +7,7 @@ jobs: prof-asan: runs-on: ubuntu-latest container: - image: datadog/dd-trace-ci:php-8.3_bookworm-3 + image: datadog/dd-trace-ci:php-8.3_bookworm-4 # https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions#user options: --user root --privileged @@ -35,10 +35,10 @@ jobs: switch-php nts-asan cd profiling export CARGO_TARGET_DIR=/tmp/build-cargo - export CC=clang-16 + export CC=clang-17 export CFLAGS='-fsanitize=address -fno-omit-frame-pointer' export LDFLAGS='-fsanitize=address' - export RUSTC_LINKER=lld-16 + export RUSTC_LINKER=lld-17 triplet=$(uname -m)-unknown-linux-gnu RUST_NIGHTLY_VERSION="-2024-02-27" RUSTFLAGS='-Zsanitizer=address' cargo +nightly${RUST_NIGHTLY_VERSION} build -Zbuild-std --target $triplet --release diff --git a/.github/workflows/prof_correctness.yml b/.github/workflows/prof_correctness.yml index 2cc777a570..5472383332 100644 --- a/.github/workflows/prof_correctness.yml +++ b/.github/workflows/prof_correctness.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: [8.0, 8.1, 8.2, 8.3] + php-version: [8.0, 8.1, 8.2, 8.3, 8.4] phpts: [nts, zts] include: - phpts: zts @@ -44,13 +44,13 @@ jobs: - name: Build profiler run: | - echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main" | sudo tee -a /etc/apt/sources.list - echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main" | sudo tee -a /etc/apt/sources.list + echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" | sudo tee -a /etc/apt/sources.list + echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" | sudo tee -a /etc/apt/sources.list curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc sudo apt remove -y clang-* sudo apt-get update - sudo apt install -y clang-16 + sudo apt install -y clang-17 cd profiling version_number=$(awk -F' = ' '$1 == "channel" { gsub(/"/, "", $2); print $2 }' rust-toolchain.toml) curl https://sh.rustup.rs -sSf | sh -s -- --profile minimal -y --default-toolchain "$version_number" diff --git a/.gitlab/ci-images.yml b/.gitlab/ci-images.yml index 706d1e9c3b..b2130f42ce 100644 --- a/.gitlab/ci-images.yml +++ b/.gitlab/ci-images.yml @@ -20,6 +20,7 @@ CentOS: matrix: - PHP_VERSION: - base + - php-8.4 - php-8.3 - php-8.2 - php-8.1 @@ -46,6 +47,7 @@ Alpine Compile Extension: matrix: - PHP_VERSION: - base-alpine + - 8.4-alpine - 8.3-alpine - 8.2-alpine - 8.1-alpine @@ -72,6 +74,7 @@ Ubuntu Bookworm: matrix: - PHP_VERSION: - base + - php-8.4 - php-8.3 - php-8.2 - php-8.1 @@ -100,6 +103,7 @@ Ubuntu Buster: matrix: - PHP_VERSION: - base + - php-8.4 - php-8.3 - php-8.2 - php-8.1 diff --git a/Makefile b/Makefile index 158f01ed60..954f0ef1bb 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ Q := @ , := , PROJECT_ROOT := ${PWD} TRACER_SOURCE_DIR := $(PROJECT_ROOT)/src/ -ASAN ?= $(shell ldd $(shell which php) 2>/dev/null | grep -q libasan && echo 1) +ASAN ?= $(shell ldd $(shell which php) 2>/dev/null | grep -q asan && echo 1) SHELL = /bin/bash APPSEC_SOURCE_DIR = $(PROJECT_ROOT)/appsec/ BUILD_SUFFIX = extension @@ -261,6 +261,9 @@ build_tea_coverage: -DCMAKE_BUILD_TYPE=Debug \ -DBUILD_TEA_TESTING=$(TEA_BUILD_TESTS) \ -DCMAKE_C_FLAGS="-O0 --coverage" \ + -DCMAKE_SHARED_LINKER_FLAGS="--coverage" \ + -DCMAKE_MODULE_LINKER_FLAGS="--coverage" \ + -DCMAKE_EXE_LINKER_FLAGS="--coverage" \ -DPhpConfig_ROOT=$(shell php-config --prefix) \ $(PROJECT_ROOT)/tea; \ $(MAKE) $(MAKEFLAGS) && touch $(TEA_BUILD_DIR)/.built.coverage; \ @@ -301,7 +304,7 @@ build_zai_coverage: install_tea_coverage cd $(ZAI_BUILD_DIR); \ CMAKE_PREFIX_PATH=/opt/catch2 \ Tea_ROOT=$(TEA_INSTALL_DIR) \ - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-O0 --coverage" -DBUILD_ZAI_TESTING=ON -DPhpConfig_ROOT=$(shell php-config --prefix) $(PROJECT_ROOT)/zend_abstract_interface; \ + cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-O0 --coverage" -DCMAKE_SHARED_LINKER_FLAGS="--coverage" -DCMAKE_MODULE_LINKER_FLAGS="--coverage" -DCMAKE_EXE_LINKER_FLAGS="--coverage" -DBUILD_ZAI_TESTING=ON -DPhpConfig_ROOT=$(shell php-config --prefix) $(PROJECT_ROOT)/zend_abstract_interface; \ $(MAKE) $(MAKEFLAGS); \ ) @@ -315,7 +318,7 @@ build_components_coverage: ( \ mkdir -p "$(COMPONENTS_BUILD_DIR)"; \ cd $(COMPONENTS_BUILD_DIR); \ - CMAKE_PREFIX_PATH=/opt/catch2 cmake -DCMAKE_BUILD_TYPE=Debug -DDATADOG_PHP_TESTING=ON -DCMAKE_C_FLAGS="-O0 --coverage" $(PROJECT_ROOT)/components; \ + CMAKE_PREFIX_PATH=/opt/catch2 cmake -DCMAKE_BUILD_TYPE=Debug -DDATADOG_PHP_TESTING=ON -DCMAKE_C_FLAGS="-O0 --coverage" -DCMAKE_SHARED_LINKER_FLAGS="--coverage" -DCMAKE_MODULE_LINKER_FLAGS="--coverage" -DCMAKE_EXE_LINKER_FLAGS="--coverage" $(PROJECT_ROOT)/components; \ $(MAKE) $(MAKEFLAGS); \ ) @@ -1262,7 +1265,9 @@ test_integrations_frankenphp: global_test_run_dependencies test_integrations_roadrunner: global_test_run_dependencies tests/Frameworks/Roadrunner/Version_2/composer.lock-php$(PHP_MAJOR_MINOR) $(call run_tests_debug,tests/Integrations/Roadrunner/V2) test_integrations_sqlsrv: global_test_run_dependencies + $(eval TEST_EXTRA_INI=-d extension=sqlsrv.so) $(call run_tests_debug,tests/Integrations/SQLSRV) + $(eval TEST_EXTRA_INI=) test_integrations_swoole_5: global_test_run_dependencies $(call run_tests_debug,--testsuite=swoole-test) test_web_cakephp_28: global_test_run_dependencies tests/Frameworks/CakePHP/Version_2_8/composer.lock-php$(PHP_MAJOR_MINOR) diff --git a/appsec/cmake/run_tests.cmake b/appsec/cmake/run_tests.cmake index 8719eb7536..96ba5ed9bc 100644 --- a/appsec/cmake/run_tests.cmake +++ b/appsec/cmake/run_tests.cmake @@ -14,7 +14,7 @@ add_custom_target(xtest-prepare COMMAND mkdir -p /tmp/appsec-ext-test) add_custom_target(xtest - COMMAND ${CMAKE_COMMAND} -E env "DD_TRACE_GIT_METADATA_ENABLED=0" + COMMAND ${CMAKE_COMMAND} -E env "DD_TRACE_GIT_METADATA_ENABLED=0" "LSAN_OPTIONS=fast_unwind_on_malloc=0" ${CMAKE_SOURCE_DIR}/cmake/run-tests-wrapper.sh "${CMAKE_BINARY_DIR}" "$" "${DD_APPSEC_TRACER_EXT_FILE}" "${PhpConfig_PHP_BINARY}" -n -d variables_order=EGPCS diff --git a/appsec/src/extension/backtrace.c b/appsec/src/extension/backtrace.c index 8d5e5c8e9f..9a94cf7103 100644 --- a/appsec/src/extension/backtrace.c +++ b/appsec/src/extension/backtrace.c @@ -4,6 +4,7 @@ // This product includes software developed at Datadog // (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. #include "backtrace.h" +#include "compatibility.h" #include "configuration.h" #include "ddtrace.h" #include "logging.h" @@ -64,7 +65,10 @@ php_backtrace_frame_to_datadog_backtrace_frame( // NOLINTNEXTLINE(bugprone-easil } // Remove tracer integration php code frames - if (strncmp(Z_STRVAL_P(function), "DDTrace", sizeof("DDTrace") - 1) == 0) { + if (STR_STARTS_WITH_CONS( + Z_STRVAL_P(function), Z_STRLEN_P(function), "DDTrace") || + STR_STARTS_WITH_CONS( + Z_STRVAL_P(function), Z_STRLEN_P(function), "{closure:DDTrace")) { return false; } @@ -306,8 +310,8 @@ ZEND_END_ARG_INFO() // clang-format off static const zend_function_entry testing_functions[] = { - ZEND_RAW_FENTRY(DD_TESTING_NS "generate_backtrace", PHP_FN(datadog_appsec_testing_generate_backtrace), void_ret_array_arginfo,0) - ZEND_RAW_FENTRY(DD_TESTING_NS "report_exploit_backtrace", PHP_FN(datadog_appsec_testing_report_exploit_backtrace), void_ret_bool_arginfo, 0) + ZEND_RAW_FENTRY(DD_TESTING_NS "generate_backtrace", PHP_FN(datadog_appsec_testing_generate_backtrace), void_ret_array_arginfo,0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "report_exploit_backtrace", PHP_FN(datadog_appsec_testing_report_exploit_backtrace), void_ret_bool_arginfo, 0, NULL, NULL) PHP_FE_END }; // clang-format on diff --git a/appsec/src/extension/commands_ctx.h b/appsec/src/extension/commands_ctx.h index ab185db9d2..fb3904451c 100644 --- a/appsec/src/extension/commands_ctx.h +++ b/appsec/src/extension/commands_ctx.h @@ -1,7 +1,7 @@ #pragma once -#include "attributes.h" #include +#include "attributes.h" struct req_info { const char *nullable command_name; // for logging diff --git a/appsec/src/extension/commands_helpers.h b/appsec/src/extension/commands_helpers.h index 45321bb0aa..459fa0ac1d 100644 --- a/appsec/src/extension/commands_helpers.h +++ b/appsec/src/extension/commands_helpers.h @@ -5,8 +5,8 @@ // (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. #pragma once -#include "attributes.h" #include "commands_ctx.h" +#include "attributes.h" #include "dddefs.h" #include "network.h" #include diff --git a/appsec/src/extension/compatibility.h b/appsec/src/extension/compatibility.h new file mode 100644 index 0000000000..b9e9ad7954 --- /dev/null +++ b/appsec/src/extension/compatibility.h @@ -0,0 +1,11 @@ +#ifndef DD_COMPATIBILITY_H +#define DD_COMPATIBILITY_H + +#include + +#if PHP_VERSION_ID < 80400 +#undef ZEND_RAW_FENTRY +#define ZEND_RAW_FENTRY(zend_name, name, arg_info, flags, ...) { zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_internal_arg_info)-1), flags }, +#endif + +#endif // DD_COMPATIBILITY_H diff --git a/appsec/src/extension/configuration.c b/appsec/src/extension/configuration.c index b6e4259368..c063ff9952 100644 --- a/appsec/src/extension/configuration.c +++ b/appsec/src/extension/configuration.c @@ -15,6 +15,8 @@ #include "user_tracking.h" #include "zai_string/string.h" +#include "compatibility.h" + #define DD_TO_DATADOG_INC 5 /* "DD" expanded to "datadog" */ #define APPLY_0(...) @@ -285,8 +287,8 @@ ZEND_END_ARG_INFO() // clang-format off static const zend_function_entry testing_functions[] = { - ZEND_RAW_FENTRY(DD_TESTING_NS "zai_config_get_value", PHP_FN(datadog_appsec_testing_zai_config_get_value), set_string_arginfo, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "zai_config_get_global_value", PHP_FN(datadog_appsec_testing_zai_config_get_global_value), set_string_arginfo, 0) + ZEND_RAW_FENTRY(DD_TESTING_NS "zai_config_get_value", PHP_FN(datadog_appsec_testing_zai_config_get_value), set_string_arginfo, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "zai_config_get_global_value", PHP_FN(datadog_appsec_testing_zai_config_get_global_value), set_string_arginfo, 0, NULL, NULL) PHP_FE_END }; // clang-format on diff --git a/appsec/src/extension/ddappsec.c b/appsec/src/extension/ddappsec.c index f886165ff8..d5857f990d 100644 --- a/appsec/src/extension/ddappsec.c +++ b/appsec/src/extension/ddappsec.c @@ -25,6 +25,7 @@ #include "commands/request_init.h" #include "commands/request_shutdown.h" #include "commands_ctx.h" +#include "compatibility.h" #include "configuration.h" #include "ddappsec.h" #include "dddefs.h" @@ -542,16 +543,16 @@ ZEND_END_ARG_INFO() // clang-format off static const zend_function_entry functions[] = { - ZEND_RAW_FENTRY(DD_APPSEC_NS "is_enabled", PHP_FN(datadog_appsec_is_enabled), void_ret_bool_arginfo, 0) - ZEND_RAW_FENTRY(DD_APPSEC_NS "push_address", PHP_FN(datadog_appsec_push_address), push_address_arginfo, 0) + ZEND_RAW_FENTRY(DD_APPSEC_NS "is_enabled", PHP_FN(datadog_appsec_is_enabled), void_ret_bool_arginfo, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_APPSEC_NS "push_address", PHP_FN(datadog_appsec_push_address), push_address_arginfo, 0, NULL, NULL) PHP_FE_END }; static const zend_function_entry testing_functions[] = { - ZEND_RAW_FENTRY(DD_TESTING_NS "rinit", PHP_FN(datadog_appsec_testing_rinit), void_ret_bool_arginfo, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "rshutdown", PHP_FN(datadog_appsec_testing_rshutdown), void_ret_bool_arginfo, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "helper_mgr_acquire_conn", PHP_FN(datadog_appsec_testing_helper_mgr_acquire_conn), void_ret_bool_arginfo, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "stop_for_debugger", PHP_FN(datadog_appsec_testing_stop_for_debugger), void_ret_bool_arginfo, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "request_exec", PHP_FN(datadog_appsec_testing_request_exec), request_exec_arginfo, 0) + ZEND_RAW_FENTRY(DD_TESTING_NS "rinit", PHP_FN(datadog_appsec_testing_rinit), void_ret_bool_arginfo, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "rshutdown", PHP_FN(datadog_appsec_testing_rshutdown), void_ret_bool_arginfo, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "helper_mgr_acquire_conn", PHP_FN(datadog_appsec_testing_helper_mgr_acquire_conn), void_ret_bool_arginfo, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "stop_for_debugger", PHP_FN(datadog_appsec_testing_stop_for_debugger), void_ret_bool_arginfo, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "request_exec", PHP_FN(datadog_appsec_testing_request_exec), request_exec_arginfo, 0, NULL, NULL) PHP_FE_END }; // clang-format on diff --git a/appsec/src/extension/ddappsec.h b/appsec/src/extension/ddappsec.h index 7983ca2d4b..b8af96c209 100644 --- a/appsec/src/extension/ddappsec.h +++ b/appsec/src/extension/ddappsec.h @@ -9,11 +9,11 @@ // This header MUST be included in files that use EG/PG/OG/... // See https://bugs.php.net/bug.php?id=81634 -#include "attributes.h" #include "logging.h" #include "version.h" #include #include +#include "attributes.h" typedef enum _enabled_configuration { APPSEC_ENABLED_VIA_REMCFG = 0, diff --git a/appsec/src/extension/ddtrace.c b/appsec/src/extension/ddtrace.c index 36fb0da7fd..f26927803b 100644 --- a/appsec/src/extension/ddtrace.c +++ b/appsec/src/extension/ddtrace.c @@ -7,6 +7,7 @@ #include #include +#include "compatibility.h" #include "configuration.h" #include "ddappsec.h" #include "logging.h" @@ -504,12 +505,12 @@ ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) ZEND_END_ARG_INFO() static const zend_function_entry functions[] = { - ZEND_RAW_FENTRY(DD_TESTING_NS "ddtrace_rshutdown", PHP_FN(datadog_appsec_testing_ddtrace_rshutdown), void_ret_bool_arginfo, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_add_tag", PHP_FN(datadog_appsec_testing_root_span_add_tag), arginfo_root_span_add_tag, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_get_meta", PHP_FN(datadog_appsec_testing_root_span_get_meta), void_ret_nullable_array, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_get_meta_struct", PHP_FN(datadog_appsec_testing_root_span_get_meta_struct), void_ret_nullable_array, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_get_metrics", PHP_FN(datadog_appsec_testing_root_span_get_metrics), void_ret_nullable_array, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "get_formatted_runtime_id", PHP_FN(datadog_appsec_testing_get_formatted_runtime_id), void_ret_nullable_string, 0) + ZEND_RAW_FENTRY(DD_TESTING_NS "ddtrace_rshutdown", PHP_FN(datadog_appsec_testing_ddtrace_rshutdown), void_ret_bool_arginfo, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_add_tag", PHP_FN(datadog_appsec_testing_root_span_add_tag), arginfo_root_span_add_tag, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_get_meta", PHP_FN(datadog_appsec_testing_root_span_get_meta), void_ret_nullable_array, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_get_meta_struct", PHP_FN(datadog_appsec_testing_root_span_get_meta_struct), void_ret_nullable_array, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_get_metrics", PHP_FN(datadog_appsec_testing_root_span_get_metrics), void_ret_nullable_array, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "get_formatted_runtime_id", PHP_FN(datadog_appsec_testing_get_formatted_runtime_id), void_ret_nullable_string, 0, NULL, NULL) PHP_FE_END }; // clang-format on diff --git a/appsec/src/extension/ddtrace.h b/appsec/src/extension/ddtrace.h index 4a8a6ca624..7615854df8 100644 --- a/appsec/src/extension/ddtrace.h +++ b/appsec/src/extension/ddtrace.h @@ -5,9 +5,9 @@ // (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. #pragma once -#include "attributes.h" #include #include +#include "attributes.h" static const int PRIORITY_SAMPLING_AUTO_KEEP = 1; static const int PRIORITY_SAMPLING_AUTO_REJECT = 0; diff --git a/appsec/src/extension/entity_body.h b/appsec/src/extension/entity_body.h index 13ed83fa15..ff2caa5efe 100644 --- a/appsec/src/extension/entity_body.h +++ b/appsec/src/extension/entity_body.h @@ -5,8 +5,8 @@ // Copyright 2021 Datadog, Inc. #pragma once -#include "attributes.h" #include +#include "attributes.h" #include void dd_entity_body_startup(void); diff --git a/appsec/src/extension/helper_process.c b/appsec/src/extension/helper_process.c index 8b15e64a2e..7c5f33d19b 100644 --- a/appsec/src/extension/helper_process.c +++ b/appsec/src/extension/helper_process.c @@ -10,6 +10,7 @@ #include #define HELPER_PROCESS_C_INCLUDES +#include "compatibility.h" #include "configuration.h" #include "ddappsec.h" #include "dddefs.h" @@ -325,9 +326,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(void_ret_array_arginfo, 0, 0, IS_ARRAY, ZEND_END_ARG_INFO() static const zend_function_entry functions[] = { - ZEND_RAW_FENTRY(DD_TESTING_NS "set_helper_path", PHP_FN(datadog_appsec_testing_set_helper_path), set_string_arginfo, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "is_connected_to_helper", PHP_FN(datadog_appsec_testing_is_connected_to_helper), void_ret_bool_arginfo, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "backoff_status", PHP_FN(datadog_appsec_testing_backoff_status), void_ret_array_arginfo, 0) + ZEND_RAW_FENTRY(DD_TESTING_NS "set_helper_path", PHP_FN(datadog_appsec_testing_set_helper_path), set_string_arginfo, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "is_connected_to_helper", PHP_FN(datadog_appsec_testing_is_connected_to_helper), void_ret_bool_arginfo, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "backoff_status", PHP_FN(datadog_appsec_testing_backoff_status), void_ret_array_arginfo, 0, NULL, NULL) PHP_FE_END }; // clang-format on diff --git a/appsec/src/extension/ip_extraction.c b/appsec/src/extension/ip_extraction.c index 88004f90ea..4b461a1621 100644 --- a/appsec/src/extension/ip_extraction.c +++ b/appsec/src/extension/ip_extraction.c @@ -5,6 +5,7 @@ // (https://www.datadoghq.com/). Copyright 2022 Datadog, Inc. #include "ip_extraction.h" +#include "compatibility.h" #include "configuration.h" #include "ddtrace.h" #include "logging.h" @@ -38,7 +39,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(extract_ip_addr, 0, 1, IS_STRING, 1) ZEND_END_ARG_INFO() static const zend_function_entry functions[] = { - ZEND_RAW_FENTRY(DD_TESTING_NS "extract_ip_addr", PHP_FN(datadog_appsec_testing_extract_ip_addr), extract_ip_addr, 0) + ZEND_RAW_FENTRY(DD_TESTING_NS "extract_ip_addr", PHP_FN(datadog_appsec_testing_extract_ip_addr), extract_ip_addr, 0, NULL, NULL) PHP_FE_END }; // clang-format on diff --git a/appsec/src/extension/logging.c b/appsec/src/extension/logging.c index fa3f395221..2e698028bf 100644 --- a/appsec/src/extension/logging.c +++ b/appsec/src/extension/logging.c @@ -4,7 +4,7 @@ // This product includes software developed at Datadog // (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. #include "logging.h" -#include "attributes.h" +#include "compatibility.h" #include "configuration.h" #include "ddappsec.h" #include "dddefs.h" @@ -18,6 +18,9 @@ #include #include #include + +#include "attributes.h" + #ifdef __linux__ # include #endif @@ -564,8 +567,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(fdclose, 0, 1, _IS_BOOL, 0) ZEND_END_ARG_INFO() static const zend_function_entry functions[] = { - ZEND_RAW_FENTRY(DD_TESTING_NS "mlog", PHP_FN(datadog_appsec_testing_mlog), mlog, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "fdclose", PHP_FN(datadog_appsec_testing_fdclose), fdclose, 0) + ZEND_RAW_FENTRY(DD_TESTING_NS "mlog", PHP_FN(datadog_appsec_testing_mlog), mlog, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "fdclose", PHP_FN(datadog_appsec_testing_fdclose), fdclose, 0, NULL, NULL) PHP_FE_END }; // clang-format on diff --git a/appsec/src/extension/logging.h b/appsec/src/extension/logging.h index 60bc1ed762..759810261f 100644 --- a/appsec/src/extension/logging.h +++ b/appsec/src/extension/logging.h @@ -5,10 +5,10 @@ // (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. #pragma once -#include "attributes.h" #include "configuration.h" #include "php_helpers.h" #include +#include "attributes.h" /* log levels - the first argument to the mlog helper * The lower the number, the higher the priority */ diff --git a/appsec/src/extension/msgpack_helpers.c b/appsec/src/extension/msgpack_helpers.c index 69d90c60f2..37f3215488 100644 --- a/appsec/src/extension/msgpack_helpers.c +++ b/appsec/src/extension/msgpack_helpers.c @@ -7,6 +7,7 @@ // NOLINTNEXTLINE(misc-header-include-cycle) #include +#include "compatibility.h" #include "logging.h" #include "msgpack_helpers.h" #include "php_compat.h" @@ -377,7 +378,7 @@ ZEND_END_ARG_INFO() // clang-format off static const zend_function_entry testing_functions[] = { - ZEND_RAW_FENTRY(DD_TESTING_NS "decode_msgpack", PHP_FN(datadog_appsec_testing_decode_msgpack), void_ret_array_arginfo, 0) + ZEND_RAW_FENTRY(DD_TESTING_NS "decode_msgpack", PHP_FN(datadog_appsec_testing_decode_msgpack), void_ret_array_arginfo, 0, NULL, NULL) PHP_FE_END }; // clang-format on diff --git a/appsec/src/extension/msgpack_helpers.h b/appsec/src/extension/msgpack_helpers.h index 9edcd314db..8a698dec84 100644 --- a/appsec/src/extension/msgpack_helpers.h +++ b/appsec/src/extension/msgpack_helpers.h @@ -6,10 +6,10 @@ #ifndef DD_MSGPACK_HELPERS_H #define DD_MSGPACK_HELPERS_H -#include "attributes.h" #include "string_helpers.h" #include #include +#include "attributes.h" // safe against null returning from mpack_node_str because length is checked 1st #define dd_mpack_node_lstr_eq(node, lstr) \ diff --git a/appsec/src/extension/php_helpers.h b/appsec/src/extension/php_helpers.h index d8f8e61ca3..4489abd987 100644 --- a/appsec/src/extension/php_helpers.h +++ b/appsec/src/extension/php_helpers.h @@ -5,8 +5,8 @@ // (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. #pragma once -#include "attributes.h" #include +#include "attributes.h" #ifdef ZTS # define THREAD_LOCAL_ON_ZTS __thread diff --git a/appsec/src/extension/php_objects.c b/appsec/src/extension/php_objects.c index 24eec623b3..e16c36bbed 100644 --- a/appsec/src/extension/php_objects.c +++ b/appsec/src/extension/php_objects.c @@ -7,12 +7,13 @@ #include #include -#include "attributes.h" #include "ddappsec.h" #include "dddefs.h" #include "php_compat.h" #include "php_objects.h" +#include "attributes.h" + static int _module_number; static zend_llist _function_entry_arrays; diff --git a/appsec/src/extension/request_abort.c b/appsec/src/extension/request_abort.c index 0f0ed71373..af1a876891 100644 --- a/appsec/src/extension/request_abort.c +++ b/appsec/src/extension/request_abort.c @@ -9,7 +9,7 @@ #include #include -#include "attributes.h" +#include "compatibility.h" #include "configuration.h" #include "ddappsec.h" #include "dddefs.h" @@ -21,6 +21,8 @@ #include "request_abort.h" #include "string_helpers.h" +#include "attributes.h" + #define HTML_CONTENT_TYPE "text/html" #define JSON_CONTENT_TYPE "application/json" @@ -563,7 +565,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(no_params_void_ret, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() static const zend_function_entry functions[] = { - ZEND_RAW_FENTRY(DD_TESTING_NS "abort_static_page", PHP_FN(datadog_appsec_testing_abort_static_page), no_params_void_ret, 0) + ZEND_RAW_FENTRY(DD_TESTING_NS "abort_static_page", PHP_FN(datadog_appsec_testing_abort_static_page), no_params_void_ret, 0, NULL, NULL) PHP_FE_END }; // clang-format on diff --git a/appsec/src/extension/request_lifecycle.c b/appsec/src/extension/request_lifecycle.c index 69a6be898d..662db69470 100644 --- a/appsec/src/extension/request_lifecycle.c +++ b/appsec/src/extension/request_lifecycle.c @@ -1,9 +1,9 @@ #include "request_lifecycle.h" -#include "attributes.h" #include "commands/client_init.h" #include "commands/config_sync.h" #include "commands/request_init.h" #include "commands/request_shutdown.h" +#include "compatibility.h" #include "configuration.h" #include "ddappsec.h" #include "dddefs.h" @@ -23,6 +23,8 @@ #include #include +#include "attributes.h" + static void _do_request_finish_php(bool ignore_verdict); static zend_array *nullable _do_request_begin( zval *nullable rbe_zv, bool user_req); @@ -858,7 +860,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(dump_arginfo, 0, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() static const zend_function_entry functions[] = { - ZEND_RAW_FENTRY(DD_TESTING_NS "dump_req_lifecycle_state", PHP_FN(datadog_appsec_testing_dump_req_lifecycle_state), dump_arginfo, 0) + ZEND_RAW_FENTRY(DD_TESTING_NS "dump_req_lifecycle_state", PHP_FN(datadog_appsec_testing_dump_req_lifecycle_state), dump_arginfo, 0, NULL, NULL) PHP_FE_END }; // clang-format on diff --git a/appsec/src/extension/string_helpers.h b/appsec/src/extension/string_helpers.h index de2e10c532..bff18152f5 100644 --- a/appsec/src/extension/string_helpers.h +++ b/appsec/src/extension/string_helpers.h @@ -5,9 +5,9 @@ // Copyright 2021 Datadog, Inc. #pragma once -#include "attributes.h" #include #include +#include "attributes.h" #define STR_FOR_FMT(a) ((a) != NULL ? (a) : "(null)") diff --git a/appsec/src/extension/tags.c b/appsec/src/extension/tags.c index 626900526c..77ebc1e43f 100644 --- a/appsec/src/extension/tags.c +++ b/appsec/src/extension/tags.c @@ -3,7 +3,8 @@ // // This product includes software developed at Datadog // (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. -#include "tags.h" + +#include "compatibility.h" #include "configuration.h" #include "ddappsec.h" #include "ddtrace.h" @@ -853,6 +854,8 @@ bool match_regex(zend_string *pattern, zend_string *subject) #if PHP_VERSION_ID < 70400 php_pcre_match_impl( pce, ZSTR_VAL(subject), ZSTR_LEN(subject), &ret, NULL, 0, 0, 0, 0); +#elif PHP_VERSION_ID >= 80400 + php_pcre_match_impl(pce, subject, &ret, NULL, 0, 0, 0); #else php_pcre_match_impl(pce, subject, &ret, NULL, 0, 0, 0, 0); #endif @@ -1273,16 +1276,16 @@ ZEND_ARG_INFO(0, metadata) ZEND_END_ARG_INFO() static const zend_function_entry functions[] = { - ZEND_RAW_FENTRY(DD_APPSEC_NS "track_user_signup_event", PHP_FN(datadog_appsec_track_user_signup_event), datadog_appsec_track_user_signup_event_arginfo, 0) - ZEND_RAW_FENTRY(DD_APPSEC_NS "track_user_login_success_event", PHP_FN(datadog_appsec_track_user_login_success_event), track_user_login_success_event_arginfo, 0) - ZEND_RAW_FENTRY(DD_APPSEC_NS "track_user_login_failure_event", PHP_FN(datadog_appsec_track_user_login_failure_event), track_user_login_failure_event_arginfo, 0) - ZEND_RAW_FENTRY(DD_APPSEC_NS "track_custom_event", PHP_FN(datadog_appsec_track_custom_event), track_custom_event_arginfo, 0) + ZEND_RAW_FENTRY(DD_APPSEC_NS "track_user_signup_event", PHP_FN(datadog_appsec_track_user_signup_event), datadog_appsec_track_user_signup_event_arginfo, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_APPSEC_NS "track_user_login_success_event", PHP_FN(datadog_appsec_track_user_login_success_event), track_user_login_success_event_arginfo, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_APPSEC_NS "track_user_login_failure_event", PHP_FN(datadog_appsec_track_user_login_failure_event), track_user_login_failure_event_arginfo, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_APPSEC_NS "track_custom_event", PHP_FN(datadog_appsec_track_custom_event), track_custom_event_arginfo, 0, NULL, NULL) PHP_FE_END }; static const zend_function_entry test_functions[] = { - ZEND_RAW_FENTRY(DD_TESTING_NS "add_all_ancillary_tags", PHP_FN(datadog_appsec_testing_add_all_ancillary_tags), add_ancillary_tags, 0) - ZEND_RAW_FENTRY(DD_TESTING_NS "add_basic_ancillary_tags", PHP_FN(datadog_appsec_testing_add_basic_ancillary_tags), add_ancillary_tags, 0) + ZEND_RAW_FENTRY(DD_TESTING_NS "add_all_ancillary_tags", PHP_FN(datadog_appsec_testing_add_all_ancillary_tags), add_ancillary_tags, 0, NULL, NULL) + ZEND_RAW_FENTRY(DD_TESTING_NS "add_basic_ancillary_tags", PHP_FN(datadog_appsec_testing_add_basic_ancillary_tags), add_ancillary_tags, 0, NULL, NULL) PHP_FE_END }; // clang-format on diff --git a/appsec/src/extension/tags.h b/appsec/src/extension/tags.h index 172677e435..79c9120db5 100644 --- a/appsec/src/extension/tags.h +++ b/appsec/src/extension/tags.h @@ -4,10 +4,12 @@ // This product includes software developed at Datadog // (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. #pragma once +#include "configuration.h" #include "attributes.h" #include #include #include +#include "attributes.h" #define DD_TAG_DATA_MAX_LEN (1024UL * 1024UL) diff --git a/appsec/tests/integration/build.gradle b/appsec/tests/integration/build.gradle index 2402f703be..95dde0a654 100644 --- a/appsec/tests/integration/build.gradle +++ b/appsec/tests/integration/build.gradle @@ -38,7 +38,7 @@ test { } tasks['test'].enabled(false) -ext.testMatrix = ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'].collectMany { +ext.testMatrix = ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'].collectMany { [[it, 'release'], [it, 'debug'], [it, 'release-zts']] } ext.uuid = "id -u".execute().text.trim() diff --git a/cmake/asan.cmake b/cmake/asan.cmake index fe99854ef4..37a28e3509 100644 --- a/cmake/asan.cmake +++ b/cmake/asan.cmake @@ -1,4 +1,7 @@ -set(CMAKE_EXE_LINKER_FLAGS_INIT "-fsanitize=address -fno-omit-frame-pointer") -set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fsanitize=address -fno-omit-frame-pointer") -set(CMAKE_C_FLAGS_INIT "-fsanitize=address -fno-omit-frame-pointer") -set(CMAKE_CXX_FLAGS_INIT "-fsanitize=address -fno-omit-frame-pointer") +set(CMAKE_EXE_LINKER_FLAGS_INIT "-fsanitize=address -fno-omit-frame-pointer -shared-libasan") +set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fsanitize=address -fno-omit-frame-pointer -shared-libasan") +set(CMAKE_C_FLAGS_INIT "-fsanitize=address -fno-omit-frame-pointer -shared-libasan") +set(CMAKE_CXX_FLAGS_INIT "-fsanitize=address -fno-omit-frame-pointer -shared-libasan") +set(CMAKE_SHARED_LINKER_FLAGS "--coverage") +set(CMAKE_MODULE_LINKER_FLAGS "--coverage") +set(CMAKE_EXE_LINKER_FLAGS "--coverage") diff --git a/compile_rust.sh b/compile_rust.sh index a073e85ca7..8e88267ea7 100755 --- a/compile_rust.sh +++ b/compile_rust.sh @@ -18,8 +18,9 @@ esac set -x if test -n "$COMPILE_ASAN"; then - export LDFLAGS="-fsanitize=address" - export CFLAGS="-fsanitize=address -fno-omit-frame-pointer" + # We need -lresolv due to https://github.com/llvm/llvm-project/issues/59007 + export LDFLAGS="-fsanitize=address $(if cc -v 2>&1 | grep -q clang; then echo "-shared-libsan -lresolv"; fi)" + export CFLAGS="$LDFLAGS -fno-omit-frame-pointer" # the cc buildtools will only pick up CFLAGS it seems fi SIDECAR_VERSION=$(cat ../VERSION) RUSTFLAGS="$RUSTFLAGS" RUSTC_BOOTSTRAP=1 "${DDTRACE_CARGO:-cargo}" build $(test "${PROFILE:-debug}" = "debug" || echo --profile "$PROFILE") "$@" diff --git a/config.m4 b/config.m4 index e8f1f1c652..21b6e597a0 100644 --- a/config.m4 +++ b/config.m4 @@ -65,13 +65,39 @@ if test "$PHP_DDTRACE" != "no"; then fi if test "$PHP_DDTRACE_SANITIZE" != "no"; then - EXTRA_LDFLAGS="-fsanitize=address -lasan" + dnl gcc needs -lasan, clang needs -shared-libsan + ac_cflags=$LDFLAGS + LDFLAGS=-shared-libsan + AC_RUN_IFELSE([AC_LANG_SOURCE([[int main(void) { return (0); }]])],[found=yes],[found=no],[found=yes]) + LDFLAGS=$ac_ldflags + + EXTRA_LDFLAGS="-fsanitize=address $(if test $found = "yes"; then echo "-shared-libsan -lclang_rt.asan-$(uname -m)"; else echo "-lasan"; fi)" EXTRA_CFLAGS="-fsanitize=address -fno-omit-frame-pointer" fi CFLAGS="$CFLAGS -fms-extensions" EXTRA_CFLAGS="$EXTRA_CFLAGS -fms-extensions" + AC_MSG_CHECKING([whether the compiler is LLVM]) + + + AC_RUN_IFELSE([AC_LANG_SOURCE([[int main(void) { +#ifdef __clang__ + return 0; +#else + return 1; +#endif +}]])],[llvm=yes],[llvm=no],[llvm=yes]) + + if test "$llvm" = "yes"; then + AC_MSG_RESULT([yes]) + CFLAGS="$CFLAGS -Wno-microsoft-anon-tag" + EXTRA_CFLAGS="$EXTRA_CFLAGS -Wno-microsoft-anon-tag" + LDFLAGS="$LDFLAGS -Wl,--undefined-version" + else + AC_MSG_RESULT([no]) + fi + DD_TRACE_VENDOR_SOURCES="\ ext/vendor/mpack/mpack.c \ ext/vendor/mt19937/mt19937-64.c \ diff --git a/datadog-setup.php b/datadog-setup.php index e1c89dda27..d5b661bff6 100644 --- a/datadog-setup.php +++ b/datadog-setup.php @@ -1159,7 +1159,7 @@ function get_architecture() /** * @return array|false */ -function parse_cli_arguments(array $argv = null) +function parse_cli_arguments($argv = null) { if (is_null($argv)) { $argv = $_SERVER['argv']; diff --git a/docker-compose.yml b/docker-compose.yml index 9375dcfb9e..877c9e4445 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -82,6 +82,7 @@ services: '8.1-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.1_buster' } '8.2-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.2_buster' } '8.3-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.3_buster' } + '8.4-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.4_buster' } 'php-master-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-master_buster' } # --- Bookworm --- '8.2-bookworm': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.2_bookworm-3' } @@ -105,6 +106,7 @@ services: '8.1-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-8.1_windows' } '8.2-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-8.2_windows' } '8.3-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-8.3_windows' } + '8.4-windows': { <<: *windows_php_service, image: 'datadog/dd-trace-ci:php-8.4_windows' } rabbitmq_integration: image: rabbitmq:3.8.9-alpine # 3.8.9 is the latest version that supports Erlang 20 diff --git a/dockerfiles/ci/alpine_compile_extension/base.Dockerfile b/dockerfiles/ci/alpine_compile_extension/base.Dockerfile index 612325e793..b67c1a88c3 100644 --- a/dockerfiles/ci/alpine_compile_extension/base.Dockerfile +++ b/dockerfiles/ci/alpine_compile_extension/base.Dockerfile @@ -23,16 +23,14 @@ RUN set -eux; \ libxml2-dev \ gnu-libiconv-dev \ oniguruma-dev \ - cmake + cmake \ + tar # Profiling deps # Minimum: libclang. Nice-to-have: full toolchain including linker to play # with cross-language link-time optimization. Needs to match rustc -Vv's llvm # version. -RUN apk add --no-cache llvm16-libs clang16-dev lld llvm16 -RUN apk add --no-cache rust-stdlib -RUN apk add --no-cache cargo -RUN apk add --no-cache clang git protoc unzip +RUN apk add --no-cache llvm17-libs clang17-dev lld llvm17 rust-stdlib cargo clang git protoc unzip RUN cargo install --force --locked bindgen-cli && mv /root/.cargo/bin/bindgen /usr/local/bin/ && rm -rf /root/.cargo diff --git a/dockerfiles/ci/alpine_compile_extension/docker-compose.yml b/dockerfiles/ci/alpine_compile_extension/docker-compose.yml index 31d034a400..026aedf606 100644 --- a/dockerfiles/ci/alpine_compile_extension/docker-compose.yml +++ b/dockerfiles/ci/alpine_compile_extension/docker-compose.yml @@ -104,8 +104,8 @@ services: context: . x-bake: *bake args: - php_version: 8.2.21 - php_sha: 0c6323699309a4d2e71057f01bc071b199f240973c349287b667a3ab36a496c6 + php_version: 8.2.25 + php_sha: 7fe7ba6e3e66cd0e61cfa95341e6aefc8790030a7867333f54aef5fb78aad18b php_api: 20220829 volumes: - ../../:/app @@ -116,8 +116,21 @@ services: context: . x-bake: *bake args: - php_version: 8.3.9 - php_sha: f484dec6ee005c83f899af02fc021e1bc3b1d7b3f143ca062ef66b0fcee96566 + php_version: 8.3.13 + php_sha: ffe34317d2688ed3161809c90ca4135c84ebfdfd12a46880a264d7d1e1d7739a php_api: 20230831 volumes: - ../../:/app + + 8.4-alpine: + image: datadog/dd-trace-ci:php-compile-extension-alpine-8.4 + build: + context: . + x-bake: *bake + args: + php_version: 8.4.0 + php_url: https://downloads.php.net/~saki/php-8.4.0RC1.tar.gz + php_sha: ff924ce24493cd546c7227c2cedf75c32d23815b0a6e5c1658d9b005837631ff + php_api: 20240924 + volumes: + - ../../:/app diff --git a/dockerfiles/ci/bookworm/.env b/dockerfiles/ci/bookworm/.env index 8f87f82ebe..ac7063806f 100644 --- a/dockerfiles/ci/bookworm/.env +++ b/dockerfiles/ci/bookworm/.env @@ -1,2 +1,2 @@ -BOOKWORM_CURRENT_VERSION=3 -BOOKWORM_NEXT_VERSION=4 +BOOKWORM_CURRENT_VERSION=4 +BOOKWORM_NEXT_VERSION=5 diff --git a/dockerfiles/ci/bookworm/Dockerfile b/dockerfiles/ci/bookworm/Dockerfile index 2b02b0fc41..5508d9fe81 100644 --- a/dockerfiles/ci/bookworm/Dockerfile +++ b/dockerfiles/ci/bookworm/Dockerfile @@ -9,15 +9,17 @@ ENV ACCEPT_EULA=Y # with cross-language link-time optimization. Needs to match rustc -Vv's llvm # version. ENV DEVLIBS \ - libclang-16-dev \ - llvm-16-dev \ - lld-16 \ + libclang-17-dev \ + libclang-rt-17-dev \ + llvm-17-dev \ + lld-17 \ libcurl4-openssl-dev \ libedit-dev \ libffi-dev \ libfreetype6-dev \ libicu-dev \ libjpeg-dev \ + libtool \ libmcrypt-dev \ libmemcached-dev \ libodbc1 \ @@ -63,7 +65,7 @@ ENV PHPIZE_DEPS \ autoconf \ bison \ catch2 \ - clang-16 \ + clang-17 \ cmake \ dpkg-dev \ g++ \ @@ -90,12 +92,12 @@ RUN set -eux; \ echo "deb http://deb.debian.org/debian-debug/ bookworm-debug main" | \ tee -a /etc/apt/sources.list; \ \ -# Use LLVM from orig vendor (also LLVM 16 is not shipped with bookworm) +# Use LLVM from orig vendor (also LLVM 17 is not shipped with bookworm) apt-get update; \ apt-get install -y curl gnupg software-properties-common; \ curl https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc; \ - add-apt-repository "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-16 main"; \ - add-apt-repository "deb-src http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-16 main"; \ + add-apt-repository "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-17 main"; \ + add-apt-repository "deb-src http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-17 main"; \ \ # prevent Debian's PHP packages from being installed # https://github.com/docker-library/php/pull/542 @@ -214,7 +216,7 @@ RUN set -eux; \ mkdir -p $PHP_INSTALL_DIR; \ chown -R circleci:circleci /opt; -ARG RUST_VERSION="1.71.1" +ARG RUST_VERSION="1.76.0" # Need a nightly that is at least 1.71.1 ARG RUST_NIGHTLY_VERSION="-2024-02-27" # Mount a cache into /rust/cargo if you want to pre-fetch packages or something diff --git a/dockerfiles/ci/bookworm/build-extensions.sh b/dockerfiles/ci/bookworm/build-extensions.sh index 670705aa8b..01328c10c5 100755 --- a/dockerfiles/ci/bookworm/build-extensions.sh +++ b/dockerfiles/ci/bookworm/build-extensions.sh @@ -17,8 +17,10 @@ elif [[ $PHP_VERSION_ID -le 81 ]]; then XDEBUG_VERSIONS=(-3.1.0) elif [[ $PHP_VERSION_ID -le 82 ]]; then XDEBUG_VERSIONS=(-3.2.2) +elif [[ $PHP_VERSION_ID -le 83 ]]; then + XDEBUG_VERSIONS=(-3.3.2) else - XDEBUG_VERSIONS=(-3.3.0) + XDEBUG_VERSIONS=(-3.4.0) fi MONGODB_VERSION= @@ -119,7 +121,16 @@ else pecl install sqlsrv$SQLSRV_VERSION; echo "extension=sqlsrv.so" >> ${iniDir}/sqlsrv.ini; # Xdebug is disabled by default for VERSION in "${XDEBUG_VERSIONS[@]}"; do - pecl install xdebug$VERSION; + if [[ "${VERSION}" == "-3.4.0" ]]; then + curl -LO https://github.com/xdebug/xdebug/archive/12adc6394adbf14f239429d72cf34faadddd19fb.tar.gz + tar -xvzf 12adc6394adbf14f239429d72cf34faadddd19fb.tar.gz; + cd xdebug-12adc6394adbf14f239429d72cf34faadddd19fb; + phpize; + ./configure; + make && make install; + else + pecl install xdebug$VERSION; + fi cd $(php-config --extension-dir); mv xdebug.so xdebug$VERSION.so; done diff --git a/dockerfiles/ci/bookworm/docker-compose.yml b/dockerfiles/ci/bookworm/docker-compose.yml index 7919c55546..1f3f3b1e60 100644 --- a/dockerfiles/ci/bookworm/docker-compose.yml +++ b/dockerfiles/ci/bookworm/docker-compose.yml @@ -13,6 +13,18 @@ services: args: &build-base BUILD_BASE: datadog/dd-trace-ci:bookworm-$BOOKWORM_NEXT_VERSION + php-8.4: + image: datadog/dd-trace-ci:php-8.4_bookworm-$BOOKWORM_NEXT_VERSION + build: + context: . + dockerfile: php-8.4/Dockerfile + x-bake: *bake + args: + <<: *build-base + phpVersion: "8.4" + phpTarGzUrl: https://downloads.php.net/~saki/php-8.4.0RC3.tar.gz + phpSha256Hash: "1937d125c9bb42bc4d8dcd3b8bb25d377814aea50be492bbc64b3554b73af371" + php-8.3: image: datadog/dd-trace-ci:php-8.3_bookworm-$BOOKWORM_NEXT_VERSION build: @@ -22,8 +34,8 @@ services: args: <<: *build-base phpVersion: "8.3" - phpTarGzUrl: https://www.php.net/distributions/php-8.3.9.tar.gz - phpSha256Hash: "f484dec6ee005c83f899af02fc021e1bc3b1d7b3f143ca062ef66b0fcee96566" + phpTarGzUrl: https://www.php.net/distributions/php-8.3.13.tar.gz + phpSha256Hash: "ffe34317d2688ed3161809c90ca4135c84ebfdfd12a46880a264d7d1e1d7739a" php-8.2: image: datadog/dd-trace-ci:php-8.2_bookworm-$BOOKWORM_NEXT_VERSION @@ -34,8 +46,8 @@ services: args: <<: *build-base phpVersion: "8.2" - phpTarGzUrl: https://www.php.net/distributions/php-8.2.21.tar.gz - phpSha256Hash: "0c6323699309a4d2e71057f01bc071b199f240973c349287b667a3ab36a496c6" + phpTarGzUrl: https://www.php.net/distributions/php-8.2.25.tar.gz + phpSha256Hash: "7fe7ba6e3e66cd0e61cfa95341e6aefc8790030a7867333f54aef5fb78aad18b" php-8.1: image: datadog/dd-trace-ci:php-8.1_bookworm-$BOOKWORM_NEXT_VERSION diff --git a/dockerfiles/ci/bookworm/php-7.0/Dockerfile b/dockerfiles/ci/bookworm/php-7.0/Dockerfile index 34f8dfd5ef..8b90ab2bfb 100644 --- a/dockerfiles/ci/bookworm/php-7.0/Dockerfile +++ b/dockerfiles/ci/bookworm/php-7.0/Dockerfile @@ -1,5 +1,5 @@ ARG BUILD_BASE -FROM --platform=$BUILDPLATFORM $BUILD_BASE as src +FROM --platform=$BUILDPLATFORM $BUILD_BASE AS src ARG phpTarGzUrl ARG phpSha256Hash COPY 0001-Fixed-incorrect-behavior-of-internal-memory-debugger.patch /home/circleci @@ -29,25 +29,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug-zts +FROM build AS php-debug-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM $BUILD_BASE as final +FROM $BUILD_BASE AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts $PHP_INSTALL_DIR/debug-zts $PHP_INSTALL_DIR/debug-zts COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug diff --git a/dockerfiles/ci/bookworm/php-7.1/Dockerfile b/dockerfiles/ci/bookworm/php-7.1/Dockerfile index a0096d6c38..4e5c4a5a85 100644 --- a/dockerfiles/ci/bookworm/php-7.1/Dockerfile +++ b/dockerfiles/ci/bookworm/php-7.1/Dockerfile @@ -1,5 +1,5 @@ ARG BUILD_BASE -FROM --platform=$BUILDPLATFORM $BUILD_BASE as src +FROM --platform=$BUILDPLATFORM $BUILD_BASE AS src ARG phpTarGzUrl ARG phpSha256Hash COPY 0001-Fixed-incorrect-behavior-of-internal-memory-debugger.patch /home/circleci @@ -30,25 +30,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug-zts +FROM build AS php-debug-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM $BUILD_BASE as final +FROM $BUILD_BASE AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts $PHP_INSTALL_DIR/debug-zts $PHP_INSTALL_DIR/debug-zts COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug diff --git a/dockerfiles/ci/bookworm/php-7.2/Dockerfile b/dockerfiles/ci/bookworm/php-7.2/Dockerfile index 9a4aa1afd3..8506c981e7 100644 --- a/dockerfiles/ci/bookworm/php-7.2/Dockerfile +++ b/dockerfiles/ci/bookworm/php-7.2/Dockerfile @@ -1,6 +1,6 @@ ARG BUILD_BASE ARG BUILD_BASE -FROM --platform=$BUILDPLATFORM $BUILD_BASE as src +FROM --platform=$BUILDPLATFORM $BUILD_BASE AS src ARG phpTarGzUrl ARG phpSha256Hash COPY 0001-Fixed-incorrect-behavior-of-internal-memory-debugger.patch /home/circleci @@ -30,25 +30,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug-zts +FROM build AS php-debug-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM $BUILD_BASE as final +FROM $BUILD_BASE AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts $PHP_INSTALL_DIR/debug-zts $PHP_INSTALL_DIR/debug-zts COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug diff --git a/dockerfiles/ci/bookworm/php-7.3/Dockerfile b/dockerfiles/ci/bookworm/php-7.3/Dockerfile index 44aadd97f7..55c502fd21 100644 --- a/dockerfiles/ci/bookworm/php-7.3/Dockerfile +++ b/dockerfiles/ci/bookworm/php-7.3/Dockerfile @@ -1,5 +1,5 @@ ARG BUILD_BASE -FROM --platform=$BUILDPLATFORM $BUILD_BASE as src +FROM --platform=$BUILDPLATFORM $BUILD_BASE AS src ARG phpTarGzUrl ARG phpSha256Hash COPY 0001-Fix-OpenSSL-3.patch /home/circleci @@ -27,25 +27,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug-zts +FROM build AS php-debug-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM $BUILD_BASE as final +FROM $BUILD_BASE AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts $PHP_INSTALL_DIR/debug-zts $PHP_INSTALL_DIR/debug-zts COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug diff --git a/dockerfiles/ci/bookworm/php-7.4/Dockerfile b/dockerfiles/ci/bookworm/php-7.4/Dockerfile index d9e89c7f9d..30254b3e9b 100644 --- a/dockerfiles/ci/bookworm/php-7.4/Dockerfile +++ b/dockerfiles/ci/bookworm/php-7.4/Dockerfile @@ -1,5 +1,5 @@ ARG BUILD_BASE -FROM --platform=$BUILDPLATFORM $BUILD_BASE as src +FROM --platform=$BUILDPLATFORM $BUILD_BASE AS src ARG phpTarGzUrl ARG phpSha256Hash COPY 0001-Fix-OpenSSL-3.patch /home/circleci @@ -29,25 +29,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION $SHARED_BUILD COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION $SHARED_BUILD COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-zts +FROM build AS php-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR zts $PHP_VERSION $SHARED_BUILD COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug-zts-asan +FROM build AS php-debug-zts-asan ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts-asan $PHP_VERSION $SHARED_BUILD \ && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan @@ -59,7 +59,7 @@ COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh RUN cp /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/debug-zts-asan/bin/php -FROM $BUILD_BASE as final +FROM $BUILD_BASE AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug diff --git a/dockerfiles/ci/bookworm/php-8.0/Dockerfile b/dockerfiles/ci/bookworm/php-8.0/Dockerfile index 01416a06f3..f2352a1a09 100644 --- a/dockerfiles/ci/bookworm/php-8.0/Dockerfile +++ b/dockerfiles/ci/bookworm/php-8.0/Dockerfile @@ -1,5 +1,5 @@ ARG BUILD_BASE -FROM --platform=$BUILDPLATFORM $BUILD_BASE as src +FROM --platform=$BUILDPLATFORM $BUILD_BASE AS src ARG phpTarGzUrl ARG phpSha256Hash COPY 0001-Better-support-for-cross-compilation.patch /home/circleci @@ -33,25 +33,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION $SHARED_BUILD COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION $SHARED_BUILD COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-zts +FROM build AS php-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR zts $PHP_VERSION $SHARED_BUILD COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug-zts-asan +FROM build AS php-debug-zts-asan ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts-asan $PHP_VERSION $SHARED_BUILD \ && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan @@ -63,7 +63,7 @@ COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh RUN cp /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/debug-zts-asan/bin/php -FROM $BUILD_BASE as final +FROM $BUILD_BASE AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug diff --git a/dockerfiles/ci/bookworm/php-8.1/Dockerfile b/dockerfiles/ci/bookworm/php-8.1/Dockerfile index 9ab8ba434b..a0d15097fe 100644 --- a/dockerfiles/ci/bookworm/php-8.1/Dockerfile +++ b/dockerfiles/ci/bookworm/php-8.1/Dockerfile @@ -4,7 +4,7 @@ FROM $BUILD_BASE AS base ARG phpVersion ENV PHP_VERSION=${phpVersion} -FROM --platform=$BUILDPLATFORM $BUILD_BASE as src +FROM --platform=$BUILDPLATFORM $BUILD_BASE AS src ARG phpTarGzUrl ARG phpSha256Hash RUN set -eux; \ @@ -30,25 +30,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-zts +FROM build AS php-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR zts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug-zts-asan +FROM build AS php-debug-zts-asan ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts-asan $PHP_VERSION \ && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan @@ -60,7 +60,7 @@ COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh RUN cp /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/debug-zts-asan/bin/php -FROM base as final +FROM base AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug diff --git a/dockerfiles/ci/bookworm/php-8.2/Dockerfile b/dockerfiles/ci/bookworm/php-8.2/Dockerfile index fb691e2f28..9a4f2e0b06 100644 --- a/dockerfiles/ci/bookworm/php-8.2/Dockerfile +++ b/dockerfiles/ci/bookworm/php-8.2/Dockerfile @@ -4,7 +4,7 @@ FROM $BUILD_BASE AS base ARG phpVersion ENV PHP_VERSION=${phpVersion} -FROM --platform=$BUILDPLATFORM $BUILD_BASE as src +FROM --platform=$BUILDPLATFORM $BUILD_BASE AS src ARG phpTarGzUrl ARG phpSha256Hash RUN set -eux; \ @@ -30,25 +30,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-zts +FROM build AS php-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR zts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug-zts-asan +FROM build AS php-debug-zts-asan ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts-asan $PHP_VERSION \ && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan @@ -60,7 +60,7 @@ COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh RUN cp /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/debug-zts-asan/bin/php -FROM base as final +FROM base AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug diff --git a/dockerfiles/ci/bookworm/php-8.3/Dockerfile b/dockerfiles/ci/bookworm/php-8.3/Dockerfile index a0b902ddd8..65b160e557 100644 --- a/dockerfiles/ci/bookworm/php-8.3/Dockerfile +++ b/dockerfiles/ci/bookworm/php-8.3/Dockerfile @@ -7,7 +7,7 @@ ENV LSAN_OPTIONS="suppressions=/home/circleci/suppr.txt,print_suppressions=0" COPY php-8.3/suppr.txt /home/circleci/suppr.txt -FROM --platform=$BUILDPLATFORM $BUILD_BASE as src +FROM --platform=$BUILDPLATFORM $BUILD_BASE AS src ARG phpTarGzUrl ARG phpSha256Hash RUN set -eux; \ @@ -33,25 +33,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-zts +FROM build AS php-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR zts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug-zts-asan +FROM build AS php-debug-zts-asan ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts-asan $PHP_VERSION \ && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan @@ -63,7 +63,7 @@ COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh RUN cp /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/debug-zts-asan/bin/php -FROM build as php-nts-asan +FROM build AS php-nts-asan ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts-asan $PHP_VERSION \ && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan @@ -82,7 +82,7 @@ FROM build as php-nts-asan RUN /home/circleci/build-extensions.sh RUN mv /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/nts-asan/bin/php -FROM base as final +FROM base AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan COPY --chown=circleci:circleci --from=php-nts-asan $PHP_INSTALL_DIR/nts-asan $PHP_INSTALL_DIR/nts-asan diff --git a/dockerfiles/ci/bookworm/php-8.4/Dockerfile b/dockerfiles/ci/bookworm/php-8.4/Dockerfile new file mode 100644 index 0000000000..4331185327 --- /dev/null +++ b/dockerfiles/ci/bookworm/php-8.4/Dockerfile @@ -0,0 +1,109 @@ +ARG BUILD_BASE +FROM $BUILD_BASE AS base + +ARG phpVersion +ENV PHP_VERSION=${phpVersion} +ENV LSAN_OPTIONS="suppressions=/home/circleci/suppr.txt,print_suppressions=0" + +COPY php-8.4/suppr.txt /home/circleci/suppr.txt + +FROM --platform=$BUILDPLATFORM $BUILD_BASE AS src +ARG phpTarGzUrl +ARG phpSha256Hash +RUN set -eux; \ + curl -fsSL -o /tmp/php.tar.gz "${phpTarGzUrl}"; \ + (echo "${phpSha256Hash} /tmp/php.tar.gz" | sha256sum -c -); \ + tar xf /tmp/php.tar.gz -C "${PHP_SRC_DIR}" --strip-components=1; \ + rm -f /tmp/php.tar.gz; \ + cd ${PHP_SRC_DIR}; \ + ./buildconf --force; + +FROM --platform=$BUILDPLATFORM $BUILD_BASE AS build +ARG phpVersion +ENV PHP_VERSION=${phpVersion} +ENV PHP_INSTALL_DIR=${PHP_INSTALL_DIR} +ARG TARGETPLATFORM +ARG BUILDPLATFORM +# install cross-compiling packages +RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ + sudo dpkg --add-architecture ${TARGETPLATFORM#linux/}; \ + sudo apt update; \ + sudo apt-get install -y --no-install-recommends valgrind:${TARGETPLATFORM#linux/} $(echo $DEVLIBS | sed "s/\(\s\|$\)/:${TARGETPLATFORM#linux/}\1/g"); \ + fi +COPY build-php.sh /home/circleci +COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR + +FROM build AS php-debug +ARG TARGETPLATFORM +RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION +COPY build-extensions.sh /home/circleci +RUN /home/circleci/build-extensions.sh + +FROM build AS php-nts +ARG TARGETPLATFORM +RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION +COPY build-extensions.sh /home/circleci +RUN /home/circleci/build-extensions.sh + +FROM build AS php-zts +ARG TARGETPLATFORM +RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR zts $PHP_VERSION +COPY build-extensions.sh /home/circleci +RUN /home/circleci/build-extensions.sh + +FROM build AS php-debug-zts-asan +ARG TARGETPLATFORM +RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts-asan $PHP_VERSION \ + && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan +# for reasons the asan build just ... crashes in qemu (or executed via bytecode interpreter). The binary itself however perfectly works on the target platform +# just put a working php binary there to continue installation and be happy, then copy back later. +COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug/bin/php /tmp/build-php/sapi/cli/php +RUN set -eux; ln -s $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug; cd /tmp/build-php; touch sapi/cli/php; make install; switch-php debug-zts-asan; +COPY build-extensions.sh /home/circleci +RUN /home/circleci/build-extensions.sh +RUN cp /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/debug-zts-asan/bin/php + +FROM build AS php-nts-asan + ARG TARGETPLATFORM + RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts-asan $PHP_VERSION \ + && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan + # For reasons the asan build just ... crashes in qemu (or executed via + # bytecode interpreter). The binary itself however perfectly works on the + # target platform. Put a working php binary there to continue installation + # and be happy, then copy back later. + COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug/bin/php /tmp/build-php/sapi/cli/php + RUN set -eux; \ + ln -s $PHP_INSTALL_DIR/nts-asan $PHP_INSTALL_DIR/debug; \ + cd /tmp/build-php; \ + touch sapi/cli/php; \ + make install; \ + switch-php nts-asan; + COPY build-extensions.sh /home/circleci + RUN /home/circleci/build-extensions.sh + RUN mv /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/nts-asan/bin/php + +FROM base AS final +COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR +COPY --chown=circleci:circleci --from=php-debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan +COPY --chown=circleci:circleci --from=php-nts-asan $PHP_INSTALL_DIR/nts-asan $PHP_INSTALL_DIR/nts-asan +COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug +COPY --chown=circleci:circleci --from=php-nts $PHP_INSTALL_DIR/nts $PHP_INSTALL_DIR/nts +COPY --chown=circleci:circleci --from=php-zts $PHP_INSTALL_DIR/zts $PHP_INSTALL_DIR/zts + +USER root + +RUN set -eux; \ + # Enable the apache config \ + echo "LoadModule php_module /usr/lib/apache2/modules/libphp.so" | tee /etc/apache2/mods-enabled/php.load; \ + # Set the default PHP version + switch-php debug; + +# Install Composer +COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer + +COPY welcome /etc/motd +RUN sudo sed -i "s/VERSIONS/$(ls $PHP_INSTALL_DIR | xargs)/" /etc/motd + +USER circleci + +CMD ["php-fpm", "-F"] diff --git a/dockerfiles/ci/bookworm/php-8.4/suppr.txt b/dockerfiles/ci/bookworm/php-8.4/suppr.txt new file mode 100644 index 0000000000..39c643abb5 --- /dev/null +++ b/dockerfiles/ci/bookworm/php-8.4/suppr.txt @@ -0,0 +1 @@ +leak:timer_create diff --git a/dockerfiles/ci/buster/Dockerfile b/dockerfiles/ci/buster/Dockerfile index ea2af3d9db..20139bc4df 100644 --- a/dockerfiles/ci/buster/Dockerfile +++ b/dockerfiles/ci/buster/Dockerfile @@ -9,10 +9,10 @@ ENV ACCEPT_EULA=Y # with cross-language link-time optimization. Needs to match rustc -Vv's llvm # version. ENV DEVLIBS \ - libclang-16-dev \ - libclang-rt-16-dev \ - llvm-16-dev \ - lld-16 \ + libclang-17-dev \ + libclang-rt-17-dev \ + llvm-17-dev \ + lld-17 \ libbrotli-dev \ libcurl4-openssl-dev \ libedit-dev \ @@ -33,9 +33,9 @@ ENV DEVLIBS \ libxml2-dev \ libxslt1-dev \ libzip-dev \ + libc6-dbg \ odbcinst1debian2 \ zlib1g-dev \ - libasan5 \ unixodbc-dev \ unixodbc @@ -47,7 +47,6 @@ ENV RUNTIME_DEPS \ clang-format \ curl \ debian-goodies \ - gdb \ git \ less \ lsof \ @@ -57,7 +56,6 @@ ENV RUNTIME_DEPS \ strace \ sudo \ unzip \ - valgrind \ vim \ xz-utils \ zip @@ -65,16 +63,13 @@ ENV RUNTIME_DEPS \ ENV PHPIZE_DEPS \ autoconf \ bison \ - clang-16 \ + clang-17 \ cmake \ dpkg-dev \ file \ - g++ \ - gcc \ gnupg \ gpg \ file \ - lcov \ libc-dev \ make \ pkg-config \ @@ -95,11 +90,11 @@ RUN set -eux; \ echo "deb http://deb.debian.org/debian-debug/ buster-debug main" | \ tee -a /etc/apt/sources.list; \ \ -# Use LLVM from orig vendor (also LLVM 16 is not shipped with buster) +# Use LLVM from orig vendor (also LLVM 17 is not shipped with buster) apt-get update; \ apt-get install -y curl gnupg; \ - echo "deb http://apt.llvm.org/buster/ llvm-toolchain-buster-16 main" >> /etc/apt/sources.list; \ - echo "deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-16 main" >> /etc/apt/sources.list; \ + echo "deb http://apt.llvm.org/buster/ llvm-toolchain-buster-17 main" >> /etc/apt/sources.list; \ + echo "deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-17 main" >> /etc/apt/sources.list; \ curl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -; \ curl https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc; \ \ @@ -114,18 +109,10 @@ RUN set -eux; \ # persistent / runtime deps apt-get update; \ apt-get install -y --no-install-recommends \ - gcc-$(if [ "$TARGETPLATFORM" != "linux/arm64" ]; then echo aarch64; else echo x86-64; fi)-linux-gnu \ - g++-$(if [ "$TARGETPLATFORM" != "linux/arm64" ]; then echo aarch64; else echo x86-64; fi)-linux-gnu \ - libc6-dev-$(if [ "$TARGETPLATFORM" != "linux/arm64" ]; then echo arm64; else echo amd64; fi)-cross \ $DEVLIBS \ $PHPIZE_DEPS \ $RUNTIME_DEPS; \ \ -# valgrind 3.14 has a fatal bug making it unusable with PHP on arm64, manually install valgrind from bullseye \ - curl -O http://ftp.de.debian.org/debian/pool/main/v/valgrind/valgrind_3.16.1-1_${TARGETPLATFORM#linux/}.deb; \ - dpkg -i valgrind*.deb; \ - rm valgrind*.deb; \ - \ # Disable DST ROOT X3 certificate explicitly to fix conflicts with older openssl versions \ sed -ri 's/(mozilla\/DST_Root_CA_X3.crt)/!\1/' /etc/ca-certificates.conf; \ update-ca-certificates; \ @@ -137,7 +124,17 @@ RUN set -eux; \ echo 'Defaults env_keep += "DEBIAN_FRONTEND"' >> /etc/sudoers.d/env_keep; \ \ # Allow nginx to be run as non-root for tests - chown -R circleci:circleci /var/log/nginx/ /var/lib/nginx/; + chown -R circleci:circleci /var/log/nginx/ /var/lib/nginx/; \ + \ +# Make clang the default compiler + update-alternatives --install /usr/bin/cc cc /usr/bin/clang-17 100; \ + update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-17 100; \ + update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 100; \ + update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 100; \ + update-alternatives --install /usr/bin/ld ld /usr/bin/ld.lld-17 100; \ + echo "-L /usr/lib/llvm-17/lib/clang/17/lib/linux" > /usr/lib/llvm-17/bin/clang.cfg; \ +# Include libasan library path + echo /usr/lib/llvm-17/lib/clang/17/lib/linux > /etc/ld.so.conf.d/libasan.conf && ldconfig ENV CMAKE_VERSION="3.24.4" @@ -180,6 +177,31 @@ RUN set -eux; \ lcov --version; \ rm -rfv /tmp/* +# Install gdb +RUN set -eux; \ + apt install -y libmpfr-dev libgmp-dev; \ + GDB_VERSION="15.2"; \ + GDB_SHA256="9d16bc2539a2a20dc3ef99b48b8414d51c51305c8577eb7a1da00996f6dea223";\ + cd /tmp && curl -OL https://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.gz; \ + (echo "${GDB_SHA256} gdb-${GDB_VERSION}.tar.gz" | sha256sum -c -); \ + mkdir gdb && cd gdb; \ + tar -xf ../gdb-${GDB_VERSION}.tar.gz --strip 1;\ + ./configure; \ + make -j "$((`nproc`+1))"; \ + make install + +# Install valgrind +RUN set -eux; \ + VALGRIND_VERSION="3.23.0"; \ + VALGRIND_SHA1="ec410c75d3920d4f9249a5cfa2cac31e1bf6d586"; \ + cd /tmp && curl -OL https://sourceware.org/pub/valgrind/valgrind-${VALGRIND_VERSION}.tar.bz2; \ + (echo "${VALGRIND_SHA1}" valgrind-${VALGRIND_VERSION}.tar.bz2 | sha1sum -c -); \ + mkdir valgrind && cd valgrind; \ + tar -xjf ../valgrind-${VALGRIND_VERSION}.tar.bz2 --strip 1;\ + ./configure; \ + make -j "$((`nproc`+1))"; \ + make install + # Install SqlServer PHP Driver # https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server RUN set -eux; \ diff --git a/dockerfiles/ci/buster/build-extensions.sh b/dockerfiles/ci/buster/build-extensions.sh index 3fe52c7961..710df2930e 100755 --- a/dockerfiles/ci/buster/build-extensions.sh +++ b/dockerfiles/ci/buster/build-extensions.sh @@ -7,6 +7,9 @@ PHP_VERSION_ID=$(php -r 'echo PHP_MAJOR_VERSION . PHP_MINOR_VERSION;') PHP_ZTS=$(php -r 'echo PHP_ZTS;') EXTENSION_DIR=$(php-config --extension-dir) +# This make `pecl install` use all available cores +export MAKEFLAGS="-j $(nproc)" + XDEBUG_VERSIONS=(-3.1.2) if [[ $PHP_VERSION_ID -le 70 ]]; then XDEBUG_VERSIONS=(-2.7.2) @@ -18,8 +21,10 @@ elif [[ $PHP_VERSION_ID -le 81 ]]; then XDEBUG_VERSIONS=(-3.1.0) elif [[ $PHP_VERSION_ID -le 82 ]]; then XDEBUG_VERSIONS=(-3.2.2) +elif [[ $PHP_VERSION_ID -le 83 ]]; then + XDEBUG_VERSIONS=(-3.3.2) else - XDEBUG_VERSIONS=(-3.3.0) + XDEBUG_VERSIONS=(-3.4.0) fi MONGODB_VERSION= @@ -55,8 +60,8 @@ fi HOST_ARCH=$(if [[ $(file $(readlink -f $(which php))) == *aarch64* ]]; then echo "aarch64"; else echo "x86_64"; fi) export PKG_CONFIG=/usr/bin/$HOST_ARCH-linux-gnu-pkg-config -export CC=$HOST_ARCH-linux-gnu-gcc -export CXX=$HOST_ARCH-linux-gnu-g++ +# export CC=$HOST_ARCH-linux-gnu-gcc +# export CXX=$HOST_ARCH-linux-gnu-g++ iniDir=$(php -i | awk -F"=> " '/Scan this dir for additional .ini files/ {print $2}'); @@ -70,7 +75,7 @@ if [[ $SHARED_BUILD -ne 0 ]]; then tar -xf curl.tar.gz && rm curl.tar.gz cd curl-${curlVer} ./configure --with-openssl --prefix=/opt/curl/${curlVer} - make + make -j "$((`nproc`+1))" make install done @@ -81,14 +86,14 @@ if [[ $SHARED_BUILD -ne 0 ]]; then cd ${PHP_SRC_DIR}/ext/curl phpize ./configure - make + make -j "$((`nproc`+1))" mv ./modules/*.so $EXTENSION_DIR make clean for curlVer in ${CURL_VERSIONS}; do PKG_CONFIG_PATH=/opt/curl/${curlVer}/lib/pkgconfig/ ./configure - make + make -j "$((`nproc`+1))" mv ./modules/curl.so $EXTENSION_DIR/curl-${curlVer}.so make clean done @@ -98,7 +103,7 @@ if [[ $SHARED_BUILD -ne 0 ]]; then cd ${PHP_SRC_DIR}/ext/pdo phpize ./configure - make + make -j "$((`nproc`+1))" mv ./modules/*.so $(php-config --extension-dir) make clean; phpize --clean @@ -110,15 +115,25 @@ else yes '' | pecl install apcu; echo "extension=apcu.so" >> ${iniDir}/apcu.ini; pecl install ast$AST_VERSION; echo "extension=ast.so" >> ${iniDir}/ast.ini; if [[ $PHP_VERSION_ID -ge 71 && $PHP_VERSION_ID -le 80 ]]; then - yes '' | pecl install mcrypt$(if [[ $PHP_VERSION_ID -le 71 ]]; then echo -1.0.0; fi); echo "extension=mcrypt.so" >> ${iniDir}/mcrypt.ini; + yes '' | CFLAGS="-Wno-incompatible-function-pointer-types" pecl install mcrypt$(if [[ $PHP_VERSION_ID -le 71 ]]; then echo -1.0.0; fi); echo "extension=mcrypt.so" >> ${iniDir}/mcrypt.ini; fi yes 'no' | pecl install memcached; echo "extension=memcached.so" >> ${iniDir}/memcached.ini; yes '' | pecl install memcache$MEMCACHE_VERSION; echo "extension=memcache.so" >> ${iniDir}/memcache.ini; pecl install mongodb$MONGODB_VERSION; echo "extension=mongodb.so" >> ${iniDir}/mongodb.ini; - pecl install sqlsrv$SQLSRV_VERSION; echo "extension=sqlsrv.so" >> ${iniDir}/sqlsrv.ini; + pecl install sqlsrv$SQLSRV_VERSION; # Xdebug is disabled by default for VERSION in "${XDEBUG_VERSIONS[@]}"; do - pecl install xdebug$VERSION; + if [[ "${VERSION}" == "-3.4.0" ]]; then + curl -LO https://github.com/xdebug/xdebug/archive/12adc6394adbf14f239429d72cf34faadddd19fb.tar.gz + tar -xvzf 12adc6394adbf14f239429d72cf34faadddd19fb.tar.gz; + cd xdebug-12adc6394adbf14f239429d72cf34faadddd19fb; + phpize; + ./configure; + make -j "$((`nproc`+1))"; + make install; + else + pecl install xdebug$VERSION; + fi cd $(php-config --extension-dir); mv xdebug.so xdebug$VERSION.so; done @@ -131,13 +146,15 @@ else fi # ext-swoole needs PHP 8 - if [[ $PHP_VERSION_ID -ge 80 ]]; then + # currently no swoole for PHP 8.4, see https://github.com/swoole/swoole-src/issues/5451 + if [[ $PHP_VERSION_ID -ge 80 && $PHP_VERSION_ID -lt 84 ]]; then pushd /tmp pecl download swoole-5.1.2; # we don't install swoole here tar xzf swoole-5.1.2.tgz cd swoole-5.1.2 phpize ./configure --host=$HOST_ARCH-linux-gnu + make -j "$((`nproc`+1))" make install popd fi @@ -149,13 +166,18 @@ else pecl install redis-4.3.0 mv $EXTENSION_DIR/redis.so $EXTENSION_DIR/redis-4.3.0.so fi - pecl install redis-5.3.7 - - # Redis 6.0.0 dropped support for PHP 7.1 and below - if [[ $PHP_VERSION_ID -gt 71 ]]; then - mv $EXTENSION_DIR/redis.so $EXTENSION_DIR/redis-5.3.7.so - pecl install redis - else - ln -s $EXTENSION_DIR/redis.so $EXTENSION_DIR/redis-5.3.7.so + if [[ $PHP_VERSION_ID -le 83 ]]; then + pecl install redis-5.3.7 + # Redis 6.0.0 dropped support for PHP 7.1 and below + if [[ $PHP_VERSION_ID -gt 71 ]]; then + mv $EXTENSION_DIR/redis.so $EXTENSION_DIR/redis-5.3.7.so + pecl install redis-6.0.2 + else + ln -s $EXTENSION_DIR/redis.so $EXTENSION_DIR/redis-5.3.7.so + fi + fi + if [[ $PHP_VERSION_ID -ge 84 ]]; then + pecl install redis-6.1.0 fi + fi diff --git a/dockerfiles/ci/buster/build-php.sh b/dockerfiles/ci/buster/build-php.sh index c2d173572e..aacea377c4 100755 --- a/dockerfiles/ci/buster/build-php.sh +++ b/dockerfiles/ci/buster/build-php.sh @@ -13,7 +13,16 @@ INSTALL_DIR=$BASE_INSTALL_DIR/$INSTALL_VERSION if [[ ${INSTALL_VERSION} == *asan* ]]; then export CFLAGS='-fsanitize=address -DZEND_TRACK_ARENA_ALLOC' - export LDFLAGS='-fsanitize=address' + # GCC has `-shared-libasan` default, clang has '-static-libasan' default + export LDFLAGS='-fsanitize=address -shared-libasan' +fi + +if [[ ${PHP_VERSION_ID} -le 73 ]]; then + if [[ -z "${CFLAGS:-}" ]]; then + export CFLAGS="-Wno-implicit-function-declaration -DHAVE_POSIX_READDIR_R=1 -DHAVE_OLD_READDIR_R=0" + else + export CFLAGS="${CFLAGS} -Wno-implicit-function-declaration -DHAVE_POSIX_READDIR_R=1 -DHAVE_OLD_READDIR_R=0" + fi fi mkdir -p /tmp/build-php && cd /tmp/build-php @@ -23,7 +32,7 @@ mkdir -p ${INSTALL_DIR}/conf.d HOST_ARCH=$(if [[ $TARGETPLATFORM == "linux/arm64" ]]; then echo "aarch64"; else echo "x86_64"; fi) PKG_CONFIG=/usr/bin/$HOST_ARCH-linux-gnu-pkg-config \ -CC=$HOST_ARCH-linux-gnu-gcc \ +# CC=$HOST_ARCH-linux-gnu-gcc \ LIBS=-ldl \ ${PHP_SRC_DIR}/configure \ $(if [[ $SHARED_BUILD -ne 0 ]]; then echo \ @@ -80,6 +89,7 @@ ${PHP_SRC_DIR}/configure \ `# https://externals.io/message/118859` \ $(if [[ $INSTALL_VERSION == *zts* ]]; then echo --disable-zend-signals; fi) \ $(if [[ $INSTALL_VERSION == *zts* && ${PHP_VERSION_ID} -ge 82 ]]; then echo --enable-zend-max-execution-timers; fi) \ + $(if [[ $INSTALL_VERSION == *asan* ]]; then echo --without-pcre-jit; fi) \ --prefix=${INSTALL_DIR} \ --with-config-file-path=${INSTALL_DIR} \ --with-config-file-scan-dir=${INSTALL_DIR}/conf.d diff --git a/dockerfiles/ci/buster/docker-compose.yml b/dockerfiles/ci/buster/docker-compose.yml index 9ca7767fa5..8a553367e5 100644 --- a/dockerfiles/ci/buster/docker-compose.yml +++ b/dockerfiles/ci/buster/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.7' - services: base: @@ -11,6 +9,17 @@ services: - linux/arm64 - linux/amd64 + php-8.4: + image: datadog/dd-trace-ci:php-8.4_buster + build: + context: . + dockerfile: php-8.4/Dockerfile + x-bake: *bake + args: + phpVersion: "8.4" + phpTarGzUrl: https://downloads.php.net/~saki/php-8.4.0RC3.tar.gz + phpSha256Hash: "1937d125c9bb42bc4d8dcd3b8bb25d377814aea50be492bbc64b3554b73af371" + php-8.3: image: datadog/dd-trace-ci:php-8.3_buster build: @@ -19,8 +28,8 @@ services: x-bake: *bake args: phpVersion: "8.3" - phpTarGzUrl: https://www.php.net/distributions/php-8.3.9.tar.gz - phpSha256Hash: "f484dec6ee005c83f899af02fc021e1bc3b1d7b3f143ca062ef66b0fcee96566" + phpTarGzUrl: https://www.php.net/distributions/php-8.3.13.tar.gz + phpSha256Hash: "ffe34317d2688ed3161809c90ca4135c84ebfdfd12a46880a264d7d1e1d7739a" php-8.2: image: datadog/dd-trace-ci:php-8.2_buster @@ -30,8 +39,8 @@ services: x-bake: *bake args: phpVersion: "8.2" - phpTarGzUrl: https://www.php.net/distributions/php-8.2.21.tar.gz - phpSha256Hash: "0c6323699309a4d2e71057f01bc071b199f240973c349287b667a3ab36a496c6" + phpTarGzUrl: https://www.php.net/distributions/php-8.2.25.tar.gz + phpSha256Hash: "7fe7ba6e3e66cd0e61cfa95341e6aefc8790030a7867333f54aef5fb78aad18b" php-8.1: image: datadog/dd-trace-ci:php-8.1_buster diff --git a/dockerfiles/ci/buster/php-7.0/0001-Fix-stream_cookie_seeker-signature-under-musl.patch b/dockerfiles/ci/buster/php-7.0/0001-Fix-stream_cookie_seeker-signature-under-musl.patch new file mode 100644 index 0000000000..99ebdecd34 --- /dev/null +++ b/dockerfiles/ci/buster/php-7.0/0001-Fix-stream_cookie_seeker-signature-under-musl.patch @@ -0,0 +1,37 @@ +From 684f0d9e5946e92008404b3d5a131edc4f34f7da Mon Sep 17 00:00:00 2001 +From: Arnaud Le Blanc +Date: Thu, 4 Apr 2024 16:10:28 +0200 +Subject: [PATCH] Fix stream_cookie_seeker signature under musl + +--- + main/streams/cast.c | 10 +++------- + 1 file changed, 3 insertions(+), 7 deletions(-) + +diff --git a/main/streams/cast.c b/main/streams/cast.c +index 3bad65fbac1f5..8d9f4a9d2d54b 100644 +--- a/main/streams/cast.c ++++ b/main/streams/cast.c +@@ -104,6 +104,9 @@ static ssize_t stream_cookie_writer(void *cookie, const char *buffer, size_t siz + + # ifdef COOKIE_SEEKER_USES_OFF64_T + static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence) ++# else ++static int stream_cookie_seeker(void *cookie, off_t *position, int whence) ++# endif + { + + *position = php_stream_seek((php_stream *)cookie, (zend_off_t)*position, whence); +@@ -113,13 +116,6 @@ static int stream_cookie_seeker(void *cookie, off64_t *position, int whence) + } + return 0; + } +-# else +-static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence) +-{ +- +- return php_stream_seek((php_stream *)cookie, position, whence); +-} +-# endif + + static int stream_cookie_closer(void *cookie) + { diff --git a/dockerfiles/ci/buster/php-7.0/0001-fix-broken-sprintf-detection.patch b/dockerfiles/ci/buster/php-7.0/0001-fix-broken-sprintf-detection.patch new file mode 100644 index 0000000000..0aa9196d3c --- /dev/null +++ b/dockerfiles/ci/buster/php-7.0/0001-fix-broken-sprintf-detection.patch @@ -0,0 +1,11 @@ +--- a/Zend/acinclude.m4 2024-10-24 07:14:03.431931000 +0000 ++++ b/Zend/acinclude.m4 2024-10-24 07:14:19.239931008 +0000 +@@ -67,7 +67,7 @@ + dnl + AC_DEFUN([AC_ZEND_BROKEN_SPRINTF],[ + AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[ +- AC_TRY_RUN([main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[ ++ AC_TRY_RUN([int main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[ + ac_cv_broken_sprintf=no + ],[ + ac_cv_broken_sprintf=yes diff --git a/dockerfiles/ci/buster/php-7.0/0001-fix-build-scripts.patch b/dockerfiles/ci/buster/php-7.0/0001-fix-build-scripts.patch new file mode 100644 index 0000000000..935111c681 --- /dev/null +++ b/dockerfiles/ci/buster/php-7.0/0001-fix-build-scripts.patch @@ -0,0 +1,91 @@ +--- a/acinclude.m4 2024-10-24 19:18:39.914585008 +0000 ++++ b/acinclude.m4 2024-10-24 19:19:21.978743014 +0000 +@@ -1171,7 +1171,7 @@ + AC_TRY_RUN([ + #include + +-main() { ++int main() { + char buf[27]; + struct tm t; + time_t old = 0; +@@ -1187,7 +1187,7 @@ + ],[ + AC_TRY_RUN([ + #include +-main() { ++int main() { + struct tm t, *s; + time_t old = 0; + char buf[27], *p; +@@ -1225,7 +1225,7 @@ + #include + #include + $1 +- main() { ++ int main() { + int fd = open("conftest_in", O_WRONLY|O_CREAT, 0600); + + if (fd < 0) exit(1); +@@ -1368,7 +1368,7 @@ + #define PATH_MAX 1024 + #endif + +-main() { ++int main() { + DIR *dir; + char entry[sizeof(struct dirent)+PATH_MAX]; + struct dirent *pentry = (struct dirent *) &entry; +@@ -1487,7 +1487,7 @@ + dnl + AC_DEFUN([PHP_AC_BROKEN_SPRINTF],[ + AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[ +- AC_TRY_RUN([main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[ ++ AC_TRY_RUN([int main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[ + ac_cv_broken_sprintf=no + ],[ + ac_cv_broken_sprintf=yes +@@ -1511,7 +1511,7 @@ + AC_CACHE_CHECK(whether snprintf is broken, ac_cv_broken_snprintf,[ + AC_TRY_RUN([ + #define NULL (0L) +-main() { ++int main() { + char buf[20]; + int res = 0; + res = res || (snprintf(buf, 2, "marcus") != 6); +@@ -1794,7 +1794,7 @@ + + cookie_io_functions_t funcs = {reader, writer, seeker, closer}; + +-main() { ++int main() { + struct cookiedata g = { 0 }; + FILE *fp = fopencookie(&g, "r", funcs); + +@@ -1911,7 +1911,7 @@ + if test "$found" = "yes"; then + ac_libs=$LIBS + LIBS="$LIBS -l$2" +- AC_TRY_RUN([main() { return (0); }],[found=yes],[found=no],[found=no]) ++ AC_TRY_RUN([int main() { return (0); }],[found=yes],[found=no],[found=no]) + LIBS=$ac_libs + fi + +@@ -2647,7 +2647,7 @@ + + X + cat >conftest.$ac_ext < +Date: Thu, 4 Apr 2024 16:10:28 +0200 +Subject: [PATCH] Fix stream_cookie_seeker signature under musl + +--- + main/streams/cast.c | 10 +++------- + 1 file changed, 3 insertions(+), 7 deletions(-) + +diff --git a/main/streams/cast.c b/main/streams/cast.c +index 3bad65fbac1f5..8d9f4a9d2d54b 100644 +--- a/main/streams/cast.c ++++ b/main/streams/cast.c +@@ -104,6 +104,9 @@ static ssize_t stream_cookie_writer(void *cookie, const char *buffer, size_t siz + + # ifdef COOKIE_SEEKER_USES_OFF64_T + static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence) ++# else ++static int stream_cookie_seeker(void *cookie, off_t *position, int whence) ++# endif + { + + *position = php_stream_seek((php_stream *)cookie, (zend_off_t)*position, whence); +@@ -113,13 +116,6 @@ static int stream_cookie_seeker(void *cookie, off64_t *position, int whence) + } + return 0; + } +-# else +-static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence) +-{ +- +- return php_stream_seek((php_stream *)cookie, position, whence); +-} +-# endif + + static int stream_cookie_closer(void *cookie) + { diff --git a/dockerfiles/ci/buster/php-7.1/0001-fix-broken-sprintf-detection.patch b/dockerfiles/ci/buster/php-7.1/0001-fix-broken-sprintf-detection.patch new file mode 100644 index 0000000000..0aa9196d3c --- /dev/null +++ b/dockerfiles/ci/buster/php-7.1/0001-fix-broken-sprintf-detection.patch @@ -0,0 +1,11 @@ +--- a/Zend/acinclude.m4 2024-10-24 07:14:03.431931000 +0000 ++++ b/Zend/acinclude.m4 2024-10-24 07:14:19.239931008 +0000 +@@ -67,7 +67,7 @@ + dnl + AC_DEFUN([AC_ZEND_BROKEN_SPRINTF],[ + AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[ +- AC_TRY_RUN([main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[ ++ AC_TRY_RUN([int main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[ + ac_cv_broken_sprintf=no + ],[ + ac_cv_broken_sprintf=yes diff --git a/dockerfiles/ci/buster/php-7.1/0001-fix-build-scripts.patch b/dockerfiles/ci/buster/php-7.1/0001-fix-build-scripts.patch new file mode 100644 index 0000000000..136e3ab5ae --- /dev/null +++ b/dockerfiles/ci/buster/php-7.1/0001-fix-build-scripts.patch @@ -0,0 +1,100 @@ +--- a/acinclude.m4 2024-10-24 19:01:57.116321002 +0000 ++++ b/acinclude.m4 2024-10-24 19:02:48.937505012 +0000 +@@ -1171,7 +1171,7 @@ + AC_TRY_RUN([ + #include + +-main() { ++int main() { + char buf[27]; + struct tm t; + time_t old = 0; +@@ -1187,7 +1187,7 @@ + ],[ + AC_TRY_RUN([ + #include +-main() { ++int main() { + struct tm t, *s; + time_t old = 0; + char buf[27], *p; +@@ -1225,7 +1225,7 @@ + #include + #include + $1 +- main() { ++ int main() { + int fd = open("conftest_in", O_WRONLY|O_CREAT, 0600); + + if (fd < 0) exit(1); +@@ -1255,7 +1255,7 @@ + #include + #include + $1 +- main() { ++ int main() { + char buf[3]; + int fd = open("conftest_in", O_RDONLY); + if (fd < 0) exit(1); +@@ -1368,7 +1368,7 @@ + #define PATH_MAX 1024 + #endif + +-main() { ++int main() { + DIR *dir; + char entry[sizeof(struct dirent)+PATH_MAX]; + struct dirent *pentry = (struct dirent *) &entry; +@@ -1487,7 +1487,7 @@ + dnl + AC_DEFUN([PHP_AC_BROKEN_SPRINTF],[ + AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[ +- AC_TRY_RUN([main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[ ++ AC_TRY_RUN([int main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[ + ac_cv_broken_sprintf=no + ],[ + ac_cv_broken_sprintf=yes +@@ -1511,7 +1511,7 @@ + AC_CACHE_CHECK(whether snprintf is broken, ac_cv_broken_snprintf,[ + AC_TRY_RUN([ + #define NULL (0L) +-main() { ++int main() { + char buf[20]; + int res = 0; + res = res || (snprintf(buf, 2, "marcus") != 6); +@@ -1794,7 +1794,7 @@ + + cookie_io_functions_t funcs = {reader, writer, seeker, closer}; + +-main() { ++int main() { + struct cookiedata g = { 0 }; + FILE *fp = fopencookie(&g, "r", funcs); + +@@ -1911,7 +1911,7 @@ + if test "$found" = "yes"; then + ac_libs=$LIBS + LIBS="$LIBS -l$2" +- AC_TRY_RUN([main() { return (0); }],[found=yes],[found=no],[found=no]) ++ AC_TRY_RUN([int main() { return (0); }],[found=yes],[found=no],[found=no]) + LIBS=$ac_libs + fi + +@@ -2647,7 +2647,7 @@ + + X + cat >conftest.$ac_ext < +Date: Thu, 4 Apr 2024 16:10:28 +0200 +Subject: [PATCH] Fix stream_cookie_seeker signature under musl + +--- + main/streams/cast.c | 10 +++------- + 1 file changed, 3 insertions(+), 7 deletions(-) + +diff --git a/main/streams/cast.c b/main/streams/cast.c +index 3bad65fbac1f5..8d9f4a9d2d54b 100644 +--- a/main/streams/cast.c ++++ b/main/streams/cast.c +@@ -104,6 +104,9 @@ static ssize_t stream_cookie_writer(void *cookie, const char *buffer, size_t siz + + # ifdef COOKIE_SEEKER_USES_OFF64_T + static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence) ++# else ++static int stream_cookie_seeker(void *cookie, off_t *position, int whence) ++# endif + { + + *position = php_stream_seek((php_stream *)cookie, (zend_off_t)*position, whence); +@@ -113,13 +116,6 @@ static int stream_cookie_seeker(void *cookie, off64_t *position, int whence) + } + return 0; + } +-# else +-static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence) +-{ +- +- return php_stream_seek((php_stream *)cookie, position, whence); +-} +-# endif + + static int stream_cookie_closer(void *cookie) + { diff --git a/dockerfiles/ci/buster/php-7.2/0001-fix-broken-sprintf-detection.patch b/dockerfiles/ci/buster/php-7.2/0001-fix-broken-sprintf-detection.patch new file mode 100644 index 0000000000..0aa9196d3c --- /dev/null +++ b/dockerfiles/ci/buster/php-7.2/0001-fix-broken-sprintf-detection.patch @@ -0,0 +1,11 @@ +--- a/Zend/acinclude.m4 2024-10-24 07:14:03.431931000 +0000 ++++ b/Zend/acinclude.m4 2024-10-24 07:14:19.239931008 +0000 +@@ -67,7 +67,7 @@ + dnl + AC_DEFUN([AC_ZEND_BROKEN_SPRINTF],[ + AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[ +- AC_TRY_RUN([main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[ ++ AC_TRY_RUN([int main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[ + ac_cv_broken_sprintf=no + ],[ + ac_cv_broken_sprintf=yes diff --git a/dockerfiles/ci/buster/php-7.2/0001-fix-build-scripts.patch b/dockerfiles/ci/buster/php-7.2/0001-fix-build-scripts.patch new file mode 100644 index 0000000000..326e5531af --- /dev/null +++ b/dockerfiles/ci/buster/php-7.2/0001-fix-build-scripts.patch @@ -0,0 +1,100 @@ +--- a/acinclude.m4 2024-10-24 18:37:07.605265007 +0000 ++++ b/acinclude.m4 2024-10-24 18:37:46.078994011 +0000 +@@ -1158,7 +1158,7 @@ + AC_TRY_RUN([ + #include + +-main() { ++int main() { + char buf[27]; + struct tm t; + time_t old = 0; +@@ -1174,7 +1174,7 @@ + ],[ + AC_TRY_RUN([ + #include +-main() { ++int main() { + struct tm t, *s; + time_t old = 0; + char buf[27], *p; +@@ -1212,7 +1212,7 @@ + #include + #include + $1 +- main() { ++ int main() { + int fd = open("conftest_in", O_WRONLY|O_CREAT, 0600); + + if (fd < 0) exit(1); +@@ -1242,7 +1242,7 @@ + #include + #include + $1 +- main() { ++ int main() { + char buf[3]; + int fd = open("conftest_in", O_RDONLY); + if (fd < 0) exit(1); +@@ -1355,7 +1355,7 @@ + #define PATH_MAX 1024 + #endif + +-main() { ++int main() { + DIR *dir; + char entry[sizeof(struct dirent)+PATH_MAX]; + struct dirent *pentry = (struct dirent *) &entry; +@@ -1474,7 +1474,7 @@ + dnl + AC_DEFUN([PHP_AC_BROKEN_SPRINTF],[ + AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[ +- AC_TRY_RUN([main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[ ++ AC_TRY_RUN([int main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[ + ac_cv_broken_sprintf=no + ],[ + ac_cv_broken_sprintf=yes +@@ -1498,7 +1498,7 @@ + AC_CACHE_CHECK(whether snprintf is broken, ac_cv_broken_snprintf,[ + AC_TRY_RUN([ + #define NULL (0L) +-main() { ++int main() { + char buf[20]; + int res = 0; + res = res || (snprintf(buf, 2, "marcus") != 6); +@@ -1781,7 +1781,7 @@ + + cookie_io_functions_t funcs = {reader, writer, seeker, closer}; + +-main() { ++int main() { + struct cookiedata g = { 0 }; + FILE *fp = fopencookie(&g, "r", funcs); + +@@ -1898,7 +1898,7 @@ + if test "$found" = "yes"; then + ac_libs=$LIBS + LIBS="$LIBS -l$2" +- AC_TRY_RUN([main() { return (0); }],[found=yes],[found=no],[found=no]) ++ AC_TRY_RUN([int main() { return (0); }],[found=yes],[found=no],[found=no]) + LIBS=$ac_libs + fi + +@@ -2697,7 +2697,7 @@ + + X + cat >conftest.$ac_ext < + +-main() { ++int main() { + char buf[27]; + struct tm t; + time_t old = 0; +@@ -1171,7 +1171,7 @@ + ],[ + AC_RUN_IFELSE([AC_LANG_SOURCE([[ + #include +-main() { ++int main() { + struct tm t, *s; + time_t old = 0; + char buf[27], *p; +@@ -1471,7 +1471,7 @@ + dnl + AC_DEFUN([PHP_AC_BROKEN_SPRINTF],[ + AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[ +- AC_RUN_IFELSE([AC_LANG_SOURCE([[main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }]])],[ ++ AC_RUN_IFELSE([AC_LANG_SOURCE([[int main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }]])],[ + ac_cv_broken_sprintf=no + ],[ + ac_cv_broken_sprintf=yes +@@ -1495,7 +1495,7 @@ + AC_CACHE_CHECK(whether snprintf is broken, ac_cv_broken_snprintf,[ + AC_RUN_IFELSE([AC_LANG_SOURCE([[ + #define NULL (0L) +-main() { ++int main() { + char buf[20]; + int res = 0; + res = res || (snprintf(buf, 2, "marcus") != 6); +@@ -1931,7 +1931,7 @@ + if test "$found" = "yes"; then + ac_libs=$LIBS + LIBS="$LIBS -l$2" +- AC_RUN_IFELSE([AC_LANG_SOURCE([[main() { return (0); }]])],[found=yes],[found=no],[found=no]) ++ AC_RUN_IFELSE([AC_LANG_SOURCE([[int main() { return (0); }]])],[found=yes],[found=no],[found=no]) + LIBS=$ac_libs + fi + +@@ -2679,7 +2679,7 @@ + + X + cat >conftest.$ac_ext < + +-main() { ++int main() { + char buf[27]; + struct tm t; + time_t old = 0; +@@ -1136,7 +1136,7 @@ + ],[ + AC_RUN_IFELSE([AC_LANG_SOURCE([[ + #include +-main() { ++int main() { + struct tm t, *s; + time_t old = 0; + char buf[27], *p; +@@ -1597,7 +1597,7 @@ + if test "$found" = "yes"; then + ac_libs=$LIBS + LIBS="$LIBS -l$2" +- AC_RUN_IFELSE([AC_LANG_SOURCE([[main() { return (0); }]])],[found=yes],[found=no],[found=no]) ++ AC_RUN_IFELSE([AC_LANG_SOURCE([[int main() { return (0); }]])],[found=yes],[found=no],[found=no]) + LIBS=$ac_libs + fi + +@@ -2285,7 +2285,7 @@ + + #define TEXT "This is the test message -- " + +-main() ++int main() + { + int n; diff --git a/dockerfiles/ci/buster/php-7.4/Dockerfile b/dockerfiles/ci/buster/php-7.4/Dockerfile index 4d24ea1b89..1167ab8f4a 100644 --- a/dockerfiles/ci/buster/php-7.4/Dockerfile +++ b/dockerfiles/ci/buster/php-7.4/Dockerfile @@ -1,12 +1,14 @@ -FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster as src +FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster AS src ARG phpTarGzUrl ARG phpSha256Hash +COPY php-7.4/0001-fix-build-scripts.patch /home/circleci RUN set -eux; \ curl -fsSL -o /tmp/php.tar.gz "${phpTarGzUrl}"; \ (echo "${phpSha256Hash} /tmp/php.tar.gz" | sha256sum -c -); \ tar xf /tmp/php.tar.gz -C "${PHP_SRC_DIR}" --strip-components=1; \ rm -f /tmp/php.tar.gz; \ cd ${PHP_SRC_DIR}; \ + patch -p1 < /home/circleci/0001-fix-build-scripts.patch; \ ./buildconf --force; FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster AS build @@ -26,25 +28,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION $SHARED_BUILD COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION $SHARED_BUILD COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-zts +FROM build AS php-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR zts $PHP_VERSION $SHARED_BUILD COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug-zts-asan +FROM build AS php-debug-zts-asan ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts-asan $PHP_VERSION $SHARED_BUILD \ && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan @@ -56,7 +58,7 @@ COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh RUN cp /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/debug-zts-asan/bin/php -FROM datadog/dd-trace-ci:buster as final +FROM datadog/dd-trace-ci:buster AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug diff --git a/dockerfiles/ci/buster/php-8.0/Dockerfile b/dockerfiles/ci/buster/php-8.0/Dockerfile index db8142a801..5162f86024 100644 --- a/dockerfiles/ci/buster/php-8.0/Dockerfile +++ b/dockerfiles/ci/buster/php-8.0/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster as src +FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster AS src ARG phpTarGzUrl ARG phpSha256Hash COPY 0001-Better-support-for-cross-compilation.patch /home/circleci @@ -32,25 +32,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION $SHARED_BUILD COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION $SHARED_BUILD COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-zts +FROM build AS php-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR zts $PHP_VERSION $SHARED_BUILD COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug-zts-asan +FROM build AS php-debug-zts-asan ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts-asan $PHP_VERSION $SHARED_BUILD \ && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan @@ -62,7 +62,7 @@ COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh RUN cp /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/debug-zts-asan/bin/php -FROM datadog/dd-trace-ci:buster as final +FROM datadog/dd-trace-ci:buster AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug diff --git a/dockerfiles/ci/buster/php-8.1/0002-fix-tsrm-jit-aarch64.patch b/dockerfiles/ci/buster/php-8.1/0002-fix-tsrm-jit-aarch64.patch new file mode 100644 index 0000000000..cc5383dbc4 --- /dev/null +++ b/dockerfiles/ci/buster/php-8.1/0002-fix-tsrm-jit-aarch64.patch @@ -0,0 +1,131 @@ +From e4d2a3e53aeb94446616860a945b1b3293f4d912 Mon Sep 17 00:00:00 2001 +From: nielsdos <7771979+nielsdos@users.noreply.github.com> +Date: Fri, 12 May 2023 20:04:51 +0200 +Subject: [PATCH] Fix GH-11188: Error when building TSRM in ARM64 + +Although the issue mentioned FreeBSD, this is a broader problem: +the current ARM64 code to load the TLS offset assumes a setup with +the non-default TLS model. This problem can also apply on some +configurations on other platforms. +--- + TSRM/TSRM.c | 11 +++++++- + TSRM/TSRM.h | 3 +++ + ext/opcache/jit/zend_jit_arm64.dasc | 39 +++++++++++++++++++++++++++-- + 3 files changed, 50 insertions(+), 3 deletions(-) + +diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c +index 61871da3fa81c..9770adc926a73 100644 +--- a/TSRM/TSRM.c ++++ b/TSRM/TSRM.c +@@ -777,11 +777,20 @@ TSRM_API size_t tsrm_get_ls_cache_tcb_offset(void) + asm("adrp %0, #__tsrm_ls_cache@TLVPPAGE\n\t" + "ldr %0, [%0, #__tsrm_ls_cache@TLVPPAGEOFF]" + : "=r" (ret)); +-# else ++# elif defined(TSRM_TLS_MODEL_DEFAULT) ++ /* Surplus Static TLS space isn't guaranteed. */ ++ ret = 0; ++# elif defined(TSRM_TLS_MODEL_INITIAL_EXEC) ++ asm("adrp %0, :gottprel:_tsrm_ls_cache\n\t" ++ "ldr %0, [%0, #:gottprel_lo12:_tsrm_ls_cache]" ++ : "=r" (ret)); ++# elif defined(TSRM_TLS_MODEL_LOCAL_EXEC) + asm("mov %0, xzr\n\t" + "add %0, %0, #:tprel_hi12:_tsrm_ls_cache, lsl #12\n\t" + "add %0, %0, #:tprel_lo12_nc:_tsrm_ls_cache" + : "=r" (ret)); ++# else ++# error "TSRM TLS model not set" + # endif + return ret; + #else +diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h +index 60b65ca8ec762..1b7c904fdb62c 100644 +--- a/TSRM/TSRM.h ++++ b/TSRM/TSRM.h +@@ -150,10 +150,13 @@ TSRM_API const char *tsrm_api_name(void); + + #if !__has_attribute(tls_model) || defined(__FreeBSD__) || defined(__MUSL__) || defined(__HAIKU__) + # define TSRM_TLS_MODEL_ATTR ++# define TSRM_TLS_MODEL_DEFAULT + #elif __PIC__ + # define TSRM_TLS_MODEL_ATTR __attribute__((tls_model("initial-exec"))) ++# define TSRM_TLS_MODEL_INITIAL_EXEC + #else + # define TSRM_TLS_MODEL_ATTR __attribute__((tls_model("local-exec"))) ++# define TSRM_TLS_MODEL_LOCAL_EXEC + #endif + + #define TSRM_SHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)+1) +diff --git a/ext/opcache/jit/zend_jit_arm64.dasc b/ext/opcache/jit/zend_jit_arm64.dasc +index 910105aa5bbff..f6b34e3baf36d 100644 +--- a/ext/opcache/jit/zend_jit_arm64.dasc ++++ b/ext/opcache/jit/zend_jit_arm64.dasc +@@ -110,6 +110,8 @@ static void* dasm_labels[zend_lb_MAX]; + + #if ZTS + static size_t tsrm_ls_cache_tcb_offset = 0; ++static size_t tsrm_tls_index = 0; ++static size_t tsrm_tls_offset = 0; + # ifdef __APPLE__ + struct TLVDescriptor { + void* (*thunk)(struct TLVDescriptor*); +@@ -117,6 +119,13 @@ struct TLVDescriptor { + uint64_t offset; + }; + typedef struct TLVDescriptor TLVDescriptor; ++# elif defined(__FreeBSD__) ++/* https://github.com/freebsd/freebsd-src/blob/c52ca7dd09066648b1cc40f758289404d68ab886/libexec/rtld-elf/aarch64/reloc.c#L180-L184 */ ++typedef struct TLSDescriptor { ++ void* thunk; ++ int index; ++ size_t offset; ++} TLSDescriptor; + # endif + #endif + +@@ -494,8 +503,14 @@ static bool logical_immediate_p(uint64_t value, uint32_t reg_size) + | MEM_ACCESS_64_WITH_UOFFSET_64 ldr, reg, TMP3, (((TLVDescriptor*)tsrm_ls_cache_tcb_offset)->offset), TMP1 + ||#else + | .long 0xd53bd051 // TODO: hard-coded: mrs TMP3, tpidr_el0 +-|| ZEND_ASSERT(tsrm_ls_cache_tcb_offset <= LDR_STR_PIMM64); +-| ldr reg, [TMP3, #tsrm_ls_cache_tcb_offset] ++|| if (tsrm_ls_cache_tcb_offset == 0) { ++| ldr TMP3, [TMP3, #0] ++| MEM_ACCESS_64_WITH_UOFFSET_64 ldr, TMP3, TMP3, tsrm_tls_index, TMP1 ++| MEM_ACCESS_64_WITH_UOFFSET_64 ldr, reg, TMP3, tsrm_tls_offset, TMP1 ++|| } else { ++|| ZEND_ASSERT(tsrm_ls_cache_tcb_offset <= LDR_STR_PIMM64); ++| ldr reg, [TMP3, #tsrm_ls_cache_tcb_offset] ++|| } + ||#endif + |.endmacro + +@@ -2754,7 +2769,27 @@ static int zend_jit_setup(void) + + #if ZTS + tsrm_ls_cache_tcb_offset = tsrm_get_ls_cache_tcb_offset(); ++# if defined(__FreeBSD__) ++ if (tsrm_ls_cache_tcb_offset == 0) { ++ TLSDescriptor **where; ++ ++ __asm__( ++ "adrp %0, :tlsdesc:_tsrm_ls_cache\n" ++ "add %0, %0, :tlsdesc_lo12:_tsrm_ls_cache\n" ++ : "=r" (where)); ++ /* See https://github.com/ARM-software/abi-aa/blob/2a70c42d62e9c3eb5887fa50b71257f20daca6f9/aaelf64/aaelf64.rst ++ * section "Relocations for thread-local storage". ++ * The first entry holds a pointer to the variable's TLS descriptor resolver function and the second entry holds ++ * a platform-specific offset or pointer. */ ++ TLSDescriptor *tlsdesc = where[1]; ++ ++ tsrm_tls_offset = tlsdesc->offset; ++ /* Index is offset by 1 on FreeBSD (https://github.com/freebsd/freebsd-src/blob/22ca6db50f4e6bd75a141f57cf953d8de6531a06/lib/libc/gen/tls.c#L88) */ ++ tsrm_tls_index = (tlsdesc->index + 1) * 8; ++ } ++# else + ZEND_ASSERT(tsrm_ls_cache_tcb_offset != 0); ++# endif + #endif + + memset(sp_adj, 0, sizeof(sp_adj)); diff --git a/dockerfiles/ci/buster/php-8.1/Dockerfile b/dockerfiles/ci/buster/php-8.1/Dockerfile index e2bab90455..8aac78ad5a 100644 --- a/dockerfiles/ci/buster/php-8.1/Dockerfile +++ b/dockerfiles/ci/buster/php-8.1/Dockerfile @@ -3,10 +3,11 @@ FROM datadog/dd-trace-ci:buster AS base ARG phpVersion ENV PHP_VERSION=${phpVersion} -FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster as src +FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster AS src ARG phpTarGzUrl ARG phpSha256Hash COPY php-8.1/0001-Introduce-DD_IGNORE_ARGINFO_ZPP_CHECK-env-var-to-ski.patch /home/circleci +COPY php-8.1/0002-fix-tsrm-jit-aarch64.patch /home/circleci RUN set -eux; \ curl -fsSL -o /tmp/php.tar.gz "${phpTarGzUrl}"; \ (echo "${phpSha256Hash} /tmp/php.tar.gz" | sha256sum -c -); \ @@ -14,6 +15,7 @@ RUN set -eux; \ rm -f /tmp/php.tar.gz; \ cd ${PHP_SRC_DIR}; \ git apply /home/circleci/0001-Introduce-DD_IGNORE_ARGINFO_ZPP_CHECK-env-var-to-ski.patch; \ + git apply /home/circleci/0002-fix-tsrm-jit-aarch64.patch; \ ./buildconf --force; FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster AS build @@ -31,25 +33,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-zts +FROM build AS php-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR zts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug-zts-asan +FROM build AS php-debug-zts-asan ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts-asan $PHP_VERSION \ && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan @@ -61,7 +63,7 @@ COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh RUN cp /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/debug-zts-asan/bin/php -FROM base as final +FROM base AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug diff --git a/dockerfiles/ci/buster/php-8.2/Dockerfile b/dockerfiles/ci/buster/php-8.2/Dockerfile index 7fbb88ba7c..34c610e6b3 100644 --- a/dockerfiles/ci/buster/php-8.2/Dockerfile +++ b/dockerfiles/ci/buster/php-8.2/Dockerfile @@ -3,7 +3,7 @@ FROM datadog/dd-trace-ci:buster AS base ARG phpVersion ENV PHP_VERSION=${phpVersion} -FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster as src +FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster AS src ARG phpTarGzUrl ARG phpSha256Hash COPY 0001-Delete-timers-on-fork.patch /home/circleci @@ -33,25 +33,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-zts +FROM build AS php-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR zts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug-zts-asan +FROM build AS php-debug-zts-asan ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts-asan $PHP_VERSION \ && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan @@ -63,7 +63,7 @@ COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh RUN cp /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/debug-zts-asan/bin/php -FROM base as final +FROM base AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug diff --git a/dockerfiles/ci/buster/php-8.3/Dockerfile b/dockerfiles/ci/buster/php-8.3/Dockerfile index 18e9f1fc77..80f84240fd 100644 --- a/dockerfiles/ci/buster/php-8.3/Dockerfile +++ b/dockerfiles/ci/buster/php-8.3/Dockerfile @@ -6,7 +6,7 @@ ENV LSAN_OPTIONS="suppressions=/home/circleci/suppr.txt,print_suppressions=0,use COPY php-8.3/suppr.txt /home/circleci/suppr.txt -FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster as src +FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster AS src ARG phpTarGzUrl ARG phpSha256Hash COPY php-8.3/0001-Introduce-DD_IGNORE_ARGINFO_ZPP_CHECK-env-var-to-ski.patch /home/circleci @@ -34,25 +34,25 @@ RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ COPY build-php.sh /home/circleci COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR -FROM build as php-debug +FROM build AS php-debug ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-nts +FROM build AS php-nts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-zts +FROM build AS php-zts ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR zts $PHP_VERSION COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh -FROM build as php-debug-zts-asan +FROM build AS php-debug-zts-asan ARG TARGETPLATFORM RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts-asan $PHP_VERSION \ && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan @@ -64,7 +64,7 @@ COPY build-extensions.sh /home/circleci RUN /home/circleci/build-extensions.sh RUN cp /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/debug-zts-asan/bin/php -FROM base as final +FROM base AS final COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR COPY --chown=circleci:circleci --from=php-debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug diff --git a/dockerfiles/ci/buster/php-8.3/suppr.txt b/dockerfiles/ci/buster/php-8.3/suppr.txt index 94e010b06a..741c68ed25 100644 --- a/dockerfiles/ci/buster/php-8.3/suppr.txt +++ b/dockerfiles/ci/buster/php-8.3/suppr.txt @@ -4,3 +4,4 @@ leak:add_to_global leak:_dl_map_object_deps leak:__res_context_send leak:_dl_make_tlsdesc_dynamic +leak:_dl_catch_exception diff --git a/dockerfiles/ci/buster/php-8.4/Dockerfile b/dockerfiles/ci/buster/php-8.4/Dockerfile new file mode 100644 index 0000000000..9c0558a10e --- /dev/null +++ b/dockerfiles/ci/buster/php-8.4/Dockerfile @@ -0,0 +1,88 @@ +FROM datadog/dd-trace-ci:buster AS base + +ARG phpVersion +ENV PHP_VERSION=${phpVersion} +ENV LSAN_OPTIONS="suppressions=/home/circleci/suppr.txt,print_suppressions=0" + +COPY php-8.4/suppr.txt /home/circleci/suppr.txt + +FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster AS src +ARG phpTarGzUrl +ARG phpSha256Hash +RUN set -eux; \ + curl -fsSL -o /tmp/php.tar.gz "${phpTarGzUrl}"; \ + (echo "${phpSha256Hash} /tmp/php.tar.gz" | sha256sum -c -); \ + tar xf /tmp/php.tar.gz -C "${PHP_SRC_DIR}" --strip-components=1; \ + rm -f /tmp/php.tar.gz; \ + cd ${PHP_SRC_DIR}; \ + ./buildconf --force; + +FROM --platform=$BUILDPLATFORM datadog/dd-trace-ci:buster AS build +ARG phpVersion +ENV PHP_VERSION=${phpVersion} +ENV PHP_INSTALL_DIR=${PHP_INSTALL_DIR} +ARG TARGETPLATFORM +ARG BUILDPLATFORM +# install cross-compiling packages +RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \ + sudo dpkg --add-architecture ${TARGETPLATFORM#linux/}; \ + sudo apt update; \ + sudo apt-get install -y --no-install-recommends valgrind:${TARGETPLATFORM#linux/} $(echo $DEVLIBS | sed "s/\(\s\|$\)/:${TARGETPLATFORM#linux/}\1/g"); \ + fi +COPY build-php.sh /home/circleci +COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR + +FROM build AS php-debug +ARG TARGETPLATFORM +RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug $PHP_VERSION +COPY build-extensions.sh /home/circleci +RUN /home/circleci/build-extensions.sh + +FROM build AS php-nts +ARG TARGETPLATFORM +RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR nts $PHP_VERSION +COPY build-extensions.sh /home/circleci +RUN /home/circleci/build-extensions.sh + +FROM build AS php-zts +ARG TARGETPLATFORM +RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR zts $PHP_VERSION +COPY build-extensions.sh /home/circleci +RUN /home/circleci/build-extensions.sh + +FROM build AS php-debug-zts-asan +ARG TARGETPLATFORM +RUN /home/circleci/build-php.sh $TARGETPLATFORM $PHP_INSTALL_DIR debug-zts-asan $PHP_VERSION \ + && mv /tmp/build-php/sapi/cli/php /tmp/build-php/sapi/cli/php-asan +# for reasons the asan build just ... crashes in qemu (or executed via bytecode interpreter). The binary itself however perfectly works on the target platform +# just put a working php binary there to continue installation and be happy, then copy back later. +COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug/bin/php /tmp/build-php/sapi/cli/php +RUN set -eux; ln -s $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug; cd /tmp/build-php; touch sapi/cli/php; make install; switch-php debug-zts-asan; +COPY build-extensions.sh /home/circleci +RUN /home/circleci/build-extensions.sh +RUN cp /tmp/build-php/sapi/cli/php-asan $PHP_INSTALL_DIR/debug-zts-asan/bin/php + +FROM base AS final +COPY --chown=circleci:circleci --from=src $PHP_SRC_DIR $PHP_SRC_DIR +COPY --chown=circleci:circleci --from=php-debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan $PHP_INSTALL_DIR/debug-zts-asan +COPY --chown=circleci:circleci --from=php-debug $PHP_INSTALL_DIR/debug $PHP_INSTALL_DIR/debug +COPY --chown=circleci:circleci --from=php-nts $PHP_INSTALL_DIR/nts $PHP_INSTALL_DIR/nts +COPY --chown=circleci:circleci --from=php-zts $PHP_INSTALL_DIR/zts $PHP_INSTALL_DIR/zts + +USER root + +RUN set -eux; \ + # Enable the apache config \ + echo "LoadModule php_module /usr/lib/apache2/modules/libphp.so" | tee /etc/apache2/mods-enabled/php.load; \ + # Set the default PHP version + switch-php debug; + +# Install Composer +COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer + +COPY welcome /etc/motd +RUN sudo sed -i "s/VERSIONS/$(ls $PHP_INSTALL_DIR | xargs)/" /etc/motd + +USER circleci + +CMD ["php-fpm", "-F"] diff --git a/dockerfiles/ci/buster/php-8.4/suppr.txt b/dockerfiles/ci/buster/php-8.4/suppr.txt new file mode 100644 index 0000000000..39c643abb5 --- /dev/null +++ b/dockerfiles/ci/buster/php-8.4/suppr.txt @@ -0,0 +1 @@ +leak:timer_create diff --git a/dockerfiles/ci/centos/7/base.Dockerfile b/dockerfiles/ci/centos/7/base.Dockerfile index 80edfaa49b..7de9f359d0 100644 --- a/dockerfiles/ci/centos/7/base.Dockerfile +++ b/dockerfiles/ci/centos/7/base.Dockerfile @@ -32,6 +32,7 @@ RUN set -eux; \ sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/CentOS-SCLo-*.repo; \ yum update nss nss-util nss-sysinit nss-tools; \ yum install -y --nogpgcheck devtoolset-7; \ + yum install -y --nogpgcheck devtoolset-9; \ yum clean all; ENV SRC_DIR=/usr/local/src @@ -94,10 +95,10 @@ RUN source scl_source enable devtoolset-7; set -eux; \ ../configure && make -j $(nproc) && make install; \ cd - && rm -fr build -# Required: CMake >= 3.0.2 (default version is 2.8.12.2) +# Required: CMake >= 3.20.0 (default version is 2.8.12.2) # Required to build libzip from source (has to be a separate RUN layer) RUN source scl_source enable devtoolset-7; set -eux; \ - /root/download-src.sh cmake https://github.com/Kitware/CMake/releases/download/v3.18.4/cmake-3.18.4.tar.gz; \ + /root/download-src.sh cmake https://github.com/Kitware/CMake/releases/download/v3.28.6/cmake-3.28.6.tar.gz; \ cd "${SRC_DIR}/cmake"; \ mkdir -v 'build' && cd 'build'; \ ../bootstrap && make -j $(nproc) && make install; \ @@ -108,17 +109,58 @@ RUN source scl_source enable devtoolset-7; set -eux; \ /root/download-src.sh libzip https://libzip.org/download/libzip-1.7.3.tar.gz; \ cd "${SRC_DIR}/libzip"; \ mkdir build && cd build; \ - cmake .. && make -j $(nproc) && make install; + cmake .. && make -j $(nproc) && make install; \ + cd - && rm -fr build + +# PHP 8.4 requires OpenSSL >= 1.1.1 +RUN source scl_source enable devtoolset-7; set -ex; \ + /root/download-src.sh openssl https://openssl.org/source/old/1.1.1/openssl-1.1.1w.tar.gz; \ + cd "${SRC_DIR}/openssl"; \ + mkdir -v 'build' && cd 'build'; \ + ../config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl shared zlib; \ + make -j $(nproc) && make install; \ + echo "export PATH=/usr/local/openssl/bin:\$PATH" > /etc/profile.d/openssl.sh; \ + echo "export LD_LIBRARY_PATH=/usr/local/openssl/lib:\$LD_LIBRARY_PATH" >> /etc/profile.d/openssl.sh; \ + source /etc/profile.d/openssl.sh; \ + openssl version; \ + cd - && rm -fr build + +# PHP 8.4 requires zlib >= 1.2.11 +RUN source scl_source enable devtoolset-7; set -ex; \ + /root/download-src.sh zlib https://zlib.net/fossils/zlib-1.2.11.tar.gz; \ + cd "${SRC_DIR}/zlib"; \ + mkdir -v 'build' && cd 'build'; \ + ../configure --prefix=/usr/local/zlib; \ + make -j $(nproc) && make install; \ + cd - && rm -fr build -ENV PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig" +# PHP 8.4 requires curl >= 7.61.0 +RUN source scl_source enable devtoolset-7; set -ex; \ + /root/download-src.sh curl https://curl.se/download/curl-7.61.1.tar.gz; \ + cd "${SRC_DIR}/curl"; \ + mkdir -v 'build' && cd 'build'; \ + ../configure --prefix=/usr/local/curl; \ + make -j $(nproc) && make install; \ + cd - && rm -fr build + +# PHP 8.4 requires sqlite3 >= 3.43 +RUN source scl_source enable devtoolset-7; set -ex; \ + /root/download-src.sh sqlite3 https://www.sqlite.org/2024/sqlite-autoconf-3460000.tar.gz; \ + cd "${SRC_DIR}/sqlite3"; \ + mkdir -v 'build' && cd 'build'; \ + ../configure --prefix=/usr/local/sqlite3; \ + make -j $(nproc) && make install; \ + cd - && rm -fr build + +ENV PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/openssl/lib/pkgconfig:/usr/local/zlib/lib/pkgconfig:/usr/local/curl/lib/pkgconfig:/usr/local/sqlite3/lib/pkgconfig" # Caution, takes a very long time! Since we have to build one from source, -# I picked LLVM 16, which matches Rust 1.71. +# I picked LLVM 17, which matches Rust 1.76. # Ordinarily we leave sources, but LLVM is 2GiB just for the sources... # Minimum: libclang. Nice-to-have: full toolchain including linker to play # with cross-language link-time optimization. Needs to match rustc -Vv's llvm # version. -RUN source scl_source enable devtoolset-7 \ +RUN source scl_source enable devtoolset-9 \ && yum install -y python3 \ && /root/download-src.sh ninja https://github.com/ninja-build/ninja/archive/refs/tags/v1.11.0.tar.gz \ && mkdir -vp "${SRC_DIR}/ninja/build" \ @@ -129,7 +171,7 @@ RUN source scl_source enable devtoolset-7 \ && cd - \ && rm -fr "${SRC_DIR}/ninja" \ && cd /usr/local/src \ - && git clone --depth 1 -b release/16.x https://github.com/llvm/llvm-project.git \ + && git clone --depth 1 -b release/17.x https://github.com/llvm/llvm-project.git \ && mkdir -vp llvm-project/build \ && cd llvm-project/build \ && cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_TARGETS_TO_BUILD=host -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ../llvm \ diff --git a/dockerfiles/ci/centos/7/docker-compose.yml b/dockerfiles/ci/centos/7/docker-compose.yml index cdedb1d81b..20e9a2a83a 100644 --- a/dockerfiles/ci/centos/7/docker-compose.yml +++ b/dockerfiles/ci/centos/7/docker-compose.yml @@ -95,8 +95,8 @@ services: x-bake: *bake args: phpVersion: "8.2" - phpTarGzUrl: https://www.php.net/distributions/php-8.2.21.tar.gz - phpSha256Hash: "0c6323699309a4d2e71057f01bc071b199f240973c349287b667a3ab36a496c6" + phpTarGzUrl: https://www.php.net/distributions/php-8.2.25.tar.gz + phpSha256Hash: "7fe7ba6e3e66cd0e61cfa95341e6aefc8790030a7867333f54aef5fb78aad18b" image: 'datadog/dd-trace-ci:php-8.2_centos-7' php-8.3: @@ -106,6 +106,17 @@ services: x-bake: *bake args: phpVersion: "8.3" - phpTarGzUrl: https://www.php.net/distributions/php-8.3.9.tar.gz - phpSha256Hash: "f484dec6ee005c83f899af02fc021e1bc3b1d7b3f143ca062ef66b0fcee96566" + phpTarGzUrl: https://www.php.net/distributions/php-8.3.13.tar.gz + phpSha256Hash: "ffe34317d2688ed3161809c90ca4135c84ebfdfd12a46880a264d7d1e1d7739a" image: 'datadog/dd-trace-ci:php-8.3_centos-7' + + php-8.4: + build: + context: . + dockerfile: php.Dockerfile + x-bake: *bake + args: + phpVersion: "8.4" + phpTarGzUrl: https://downloads.php.net/~saki/php-8.4.0RC3.tar.gz + phpSha256Hash: "1937d125c9bb42bc4d8dcd3b8bb25d377814aea50be492bbc64b3554b73af371" + image: 'datadog/dd-trace-ci:php-8.4_centos-7' diff --git a/dockerfiles/ci/centos/7/php-8.4/configure.sh b/dockerfiles/ci/centos/7/php-8.4/configure.sh new file mode 100755 index 0000000000..26b056395b --- /dev/null +++ b/dockerfiles/ci/centos/7/php-8.4/configure.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +if [ -z "${PHP_SRC_DIR}" ]; then + echo "Please set PHP_SRC_DIR" + exit 1 +fi + +# needed for CentOS7 vs PHP 8.3 on amd64, otherwise you get a: +# ld: dynamic STT_GNU_IFUNC symbol `mb_wchar_to_utf16le' with pointer equality in `ext/mbstring/libmbfl/filters/mbfilter_utf16.o' can not be used when making an executable; recompile with -fPIE and relink with -pie +# see also https://github.com/php/php-src/issues/11603 +if [ "$(uname -m)" = "x86_64" ]; then + export LDFLAGS=-pie + export CFLAGS=-fPIE +fi + +${PHP_SRC_DIR}/configure \ + --enable-option-checking=fatal \ + --enable-calendar \ + --enable-cgi \ + --enable-exif \ + --enable-fpm \ + --enable-ftp \ + --enable-mbstring \ + --enable-mysqlnd \ + --enable-opcache \ + --enable-phpdbg \ + --enable-pcntl \ + --enable-shmop \ + --enable-sockets \ + --enable-sysvmsg \ + --enable-sysvsem \ + --enable-sysvshm \ + --with-apxs2 \ + --with-bz2 \ + --with-curl \ + --with-ffi \ + --with-fpm-user=www-data \ + --with-fpm-group=www-data \ + --with-libedit \ + --with-mhash \ + --with-mysqli=mysqlnd \ + --with-gettext \ + --with-openssl \ + --with-pdo-mysql=mysqlnd \ + --with-pear \ + --with-readline \ + --with-sodium \ + --with-xsl \ + --with-zip \ + --with-zlib \ + $@ diff --git a/dockerfiles/ci/centos/7/php.Dockerfile b/dockerfiles/ci/centos/7/php.Dockerfile index df73de9c8b..57162c8d52 100644 --- a/dockerfiles/ci/centos/7/php.Dockerfile +++ b/dockerfiles/ci/centos/7/php.Dockerfile @@ -1,4 +1,4 @@ -FROM datadog/dd-trace-ci:centos-7 as base +FROM datadog/dd-trace-ci:centos-7 AS base ENV PHP_SRC_DIR=/usr/local/src/php ENV PHP_INSTALL_DIR=/opt/php @@ -9,6 +9,10 @@ ENV PHP_INSTALL_DIR_DEBUG_NTS=${PHP_INSTALL_DIR}/${phpVersion}-debug ENV PHP_INSTALL_DIR_NTS=${PHP_INSTALL_DIR}/${phpVersion} ENV PHP_VERSION=${phpVersion} +# Need a new `cert.pem` as otherwise pecl will not work +RUN cd /usr/local/openssl/; \ + curl -Lo cert.pem http://curl.haxx.se/ca/cacert.pem; + # Download and extract PHP source ARG phpTarGzUrl ARG phpSha256Hash @@ -19,10 +23,11 @@ RUN set -eux; \ (echo "${phpSha256Hash} /tmp/php.tar.gz" | sha256sum -c -); \ tar xf /tmp/php.tar.gz -C "${PHP_SRC_DIR}" --strip-components=1; \ rm -f /tmp/php.tar.gz; \ - [ $(expr substr ${PHP_VERSION} 1 1) = 7 ] || ${PHP_SRC_DIR}/buildconf --force; + [ $(expr substr ${PHP_VERSION} 1 1) = 7 ] || ${PHP_SRC_DIR}/buildconf --force + COPY php-${PHP_VERSION}/configure.sh /root/ -FROM base as php-zts +FROM base AS php-zts RUN bash -c 'set -eux; \ mkdir -p /tmp/build-php && cd /tmp/build-php \ && /root/configure.sh \ @@ -37,7 +42,7 @@ RUN bash -c 'set -eux; \ && [ $(expr substr ${PHP_VERSION} 1 1) = 7 ] || ${PHP_INSTALL_DIR_ZTS}/bin/pecl install parallel \ && [ $(expr substr ${PHP_VERSION} 1 1) = 7 ] || echo "extension=parallel" >> ${PHP_INSTALL_DIR_ZTS}/conf.d/parallel.ini -FROM base as php-debug +FROM base AS php-debug RUN bash -c 'set -eux; \ mkdir -p /tmp/build-php && cd /tmp/build-php \ && /root/configure.sh \ @@ -50,7 +55,7 @@ RUN bash -c 'set -eux; \ && cp .libs/libphp*.so ${PHP_INSTALL_DIR_DEBUG_NTS}/lib/apache2handler-libphp.so \ && mkdir -p ${PHP_INSTALL_DIR_DEBUG_NTS}/conf.d' -FROM base as php-nts +FROM base AS php-nts RUN bash -c 'set -eux; \ mkdir -p /tmp/build-php && cd /tmp/build-php \ && /root/configure.sh \ @@ -62,7 +67,7 @@ RUN bash -c 'set -eux; \ && cp .libs/libphp*.so ${PHP_INSTALL_DIR_NTS}/lib/apache2handler-libphp.so \ && mkdir -p ${PHP_INSTALL_DIR_NTS}/conf.d' -FROM base as final +FROM base AS final COPY --from=php-zts $PHP_INSTALL_DIR_ZTS $PHP_INSTALL_DIR_ZTS COPY --from=php-debug $PHP_INSTALL_DIR_DEBUG_NTS $PHP_INSTALL_DIR_DEBUG_NTS COPY --from=php-nts $PHP_INSTALL_DIR_NTS $PHP_INSTALL_DIR_NTS diff --git a/dockerfiles/ci/windows/Dockerfile b/dockerfiles/ci/windows/Dockerfile index 295f22cb36..12df27bb72 100644 --- a/dockerfiles/ci/windows/Dockerfile +++ b/dockerfiles/ci/windows/Dockerfile @@ -5,9 +5,7 @@ ARG phpTarGzUrl ARG phpVersion ENV PHP_VERSION=${phpVersion} -ADD ${phpTarGzUrl} /php-sdk/php-src.tar.gz -RUN tar xzf php-src.tar.gz -RUN move php-%PHP_VERSION% php-src +RUN powershell "Invoke-WebRequest %phpTarGzUrl% -OutFile /php-sdk/php-src.tar.gz; tar xzf php-src.tar.gz; move php-%phpVersion% php-src; Remove-Item /php-sdk/php-src.tar.gz" ADD setup_deps.bat /php-sdk/setup_deps.bat diff --git a/dockerfiles/ci/windows/basetools.Dockerfile b/dockerfiles/ci/windows/basetools.Dockerfile index 4765bcb4cb..b2e8c4403d 100644 --- a/dockerfiles/ci/windows/basetools.Dockerfile +++ b/dockerfiles/ci/windows/basetools.Dockerfile @@ -4,21 +4,9 @@ FROM datadog/dd-trace-ci:windows-base-$vsVersion RUN powershell.exe "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; $Env:chocolateyVersion = '0.10.15'; $Env:chocolateyUseWindowsCompression = 'false'; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')); ''" # I really need some sane file editing utilities -ADD https://ftp.nluug.nl/pub/vim/pc/vim90w32.zip /tmp/vim90w32.zip -RUN powershell.exe Expand-Archive /tmp/vim90w32.zip /tmp -RUN move C:\tmp\vim\vim90\tee.exe C:\Windows\tee.exe -RUN move C:\tmp\vim\vim90\vim.exe C:\Windows\vim.exe -RUN move C:\tmp\vim\vim90\xxd.exe C:\Windows\xxd.exe +RUN powershell "Invoke-WebRequest https://ftp.nluug.nl/pub/vim/pc/vim90w32.zip -OutFile /tmp/vim90w32.zip; Expand-Archive /tmp/vim90w32.zip /tmp; move C:\tmp\vim\vim90\tee.exe C:\Windows\tee.exe; move C:\tmp\vim\vim90\vim.exe C:\Windows\vim.exe; move C:\tmp\vim\vim90\xxd.exe C:\Windows\xxd.exe; Remove-Item /tmp/vim90w32.zip; Remove-Item -Recurse C:\tmp\vim" -ADD https://github.com/git-for-windows/git/releases/download/v2.41.0.windows.3/Git-2.41.0.3-64-bit.exe /tmp/git-setup.exe -RUN /tmp/git-setup.exe /VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /COMPONENTS="icons,ext\reg\shellhere,assoc,assoc_sh" - -RUN git clone https://github.com/php/php-sdk-binary-tools.git /php-sdk -# prevent permission confusion -RUN git config --global --add safe.directory C:/php-sdk - -ADD https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe /tmp/rustup-init.exe -RUN /tmp/rustup-init.exe -y --default-toolchain=1.71.0 +RUN powershell "Invoke-WebRequest https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe -OutFile /tmp/rustup-init.exe; cmd /S /C /tmp/rustup-init.exe --profile minimal -y --default-toolchain=1.76.0; Remove-Item /tmp/rustup-init.exe" RUN choco install -y cmake RUN choco install -y nasm @@ -28,6 +16,7 @@ RUN powershell "[Environment]::SetEnvironmentVariable('PATH', $env:PATH + ';C:\P # initial setup -WORKDIR /php-sdk ARG sdkVersion -RUN git checkout php-sdk-%sdkVersion% \ No newline at end of file +RUN powershell "cd /tmp; Invoke-WebRequest https://github.com/php/php-sdk-binary-tools/archive/refs/tags/php-sdk-%sdkVersion%.zip -OutFile php-sdk.zip; Expand-Archive php-sdk.zip; move php-sdk\php-sdk-binary-tools-php-sdk-%sdkVersion% /php-sdk; Remove-Item php-sdk; Remove-Item php-sdk.zip" + +WORKDIR /php-sdk diff --git a/dockerfiles/ci/windows/docker-compose.yml b/dockerfiles/ci/windows/docker-compose.yml index 337cc390bc..db9d073d47 100644 --- a/dockerfiles/ci/windows/docker-compose.yml +++ b/dockerfiles/ci/windows/docker-compose.yml @@ -26,6 +26,14 @@ services: context: . dockerfile: vs16.Dockerfile + vs17-base: + image: datadog/dd-trace-ci:windows-base-vs17 + build: + platforms: + - windows/amd64 + context: . + dockerfile: vs17.Dockerfile + vc14: image: datadog/dd-trace-ci:windows-vc14 build: @@ -59,6 +67,29 @@ services: vsVersion: "vs16" sdkVersion: "2.2.0" + vs17: + image: datadog/dd-trace-ci:windows-vs17 + build: + platforms: + - windows/amd64 + context: . + dockerfile: basetools.Dockerfile + args: + vsVersion: "vs17" + sdkVersion: "2.3.0" + + php-8.4: + image: datadog/dd-trace-ci:php-8.4_windows + build: + platforms: + - windows/amd64 + context: . + args: + phpVersion: "8.4.0RC3" + vsVersion: "vs17" + phpTarGzUrl: https://downloads.php.net/~saki/php-8.4.0RC3.tar.gz + phpSha256Hash: "1937d125c9bb42bc4d8dcd3b8bb25d377814aea50be492bbc64b3554b73af371" + php-8.3: image: datadog/dd-trace-ci:php-8.3_windows build: diff --git a/dockerfiles/ci/windows/vc15.Dockerfile b/dockerfiles/ci/windows/vc15.Dockerfile index 24a637970c..3c1114c01b 100644 --- a/dockerfiles/ci/windows/vc15.Dockerfile +++ b/dockerfiles/ci/windows/vc15.Dockerfile @@ -1,4 +1,4 @@ FROM mcr.microsoft.com/windows/servercore:1809 ADD https://aka.ms/vs/15/release/vs_buildtools.exe /tmp/vs_buildtools.exe -RUN /tmp/vs_buildtools.exe --quiet --wait --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.Net.Component.4.7.SDK --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK.17763 +RUN powershell "cmd /S /C /tmp/vs_buildtools.exe --quiet --wait --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest --add Microsoft.VisualStudio.Component.VC.CoreBuildTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK.17763; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\'; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\Hostx86'; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\lib\onecore'; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\lib\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Redist\MSVC\14.16.27012\onecore'; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Redist\MSVC\14.16.27012\debug_nonredist\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\bin\arm'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\arm'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\arm64'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\ucrt\arm'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\ucrt\arm64'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\ucrt\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\arm'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\arm64'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Testing'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\cppwinrt\'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\winrt\'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\References'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Remote\ARM'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Remote\x86'; Remove-Item -Recurse 'C:\Users\ContainerAdministrator\AppData\Local\Temp\*'" diff --git a/dockerfiles/ci/windows/vs16.Dockerfile b/dockerfiles/ci/windows/vs16.Dockerfile index 69c72d474d..0e7c441c47 100644 --- a/dockerfiles/ci/windows/vs16.Dockerfile +++ b/dockerfiles/ci/windows/vs16.Dockerfile @@ -1,4 +1,4 @@ FROM mcr.microsoft.com/windows/servercore:ltsc2019 ADD https://aka.ms/vs/16/release/vs_buildtools.exe /tmp/vs_buildtools.exe -RUN /tmp/vs_buildtools.exe --quiet --wait --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.Net.Component.4.8.SDK --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK.19041 +RUN powershell "cmd /S /C /tmp/vs_buildtools.exe --quiet --wait --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest --add Microsoft.VisualStudio.Component.VC.CoreBuildTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK.19041; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\'; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx86'; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\lib\onecore'; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\lib\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Redist\MSVC\14.29.30133\onecore'; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Redist\MSVC\14.29.30133\debug_nonredist\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\bin\arm'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\arm'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\arm64'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\arm'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\arm64'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\arm'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\arm64'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Testing'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\cppwinrt\'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\winrt\'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\References'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Remote\ARM'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Remote\x86'; Remove-Item -Recurse 'C:\Users\ContainerAdministrator\AppData\Local\Temp\*'" diff --git a/dockerfiles/ci/windows/vs17.Dockerfile b/dockerfiles/ci/windows/vs17.Dockerfile new file mode 100644 index 0000000000..d28649f84a --- /dev/null +++ b/dockerfiles/ci/windows/vs17.Dockerfile @@ -0,0 +1,4 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2019 + +ADD https://aka.ms/vs/17/release/vs_buildtools.exe /tmp/vs_buildtools.exe +RUN powershell "cmd /S /C /tmp/vs_buildtools.exe --quiet --wait --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest --add Microsoft.VisualStudio.Component.VC.CoreBuildTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK.19041; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\'; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.40.33807\bin\Hostx86'; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.40.33807\lib\onecore'; Remove-Item -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.40.33807\lib\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\bin\arm'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\arm'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\arm64'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\arm'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\arm64'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\arm'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\arm64'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x86'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Testing'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\cppwinrt\'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\winrt\'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\References'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Remote\ARM'; Remove-Item -Recurse 'C:\Program Files (x86)\Windows Kits\10\Remote\x86'; Remove-Item -Recurse 'C:\Users\ContainerAdministrator\AppData\Local\Temp\*'" diff --git a/dockerfiles/ci/xfail_tests/7.0.list b/dockerfiles/ci/xfail_tests/7.0.list index 7947c6b2aa..04c443765c 100644 --- a/dockerfiles/ci/xfail_tests/7.0.list +++ b/dockerfiles/ci/xfail_tests/7.0.list @@ -358,3 +358,12 @@ tests/classes/clone_002.phpt tests/classes/clone_004.phpt tests/lang/type_hints_002.phpt tests/output/ob_start_basic_002.phpt + +Zend/tests/dval_to_lval_64.phpt +Zend/tests/int_overflow_64bit.phpt +ext/standard/tests/math/decbin_variation1_64bit.phpt +ext/standard/tests/math/dechex_variation1_64bit.phpt +ext/standard/tests/math/decoct_variation1_64bit.phpt +ext/standard/tests/strings/bug47842.phpt +ext/standard/tests/strings/vprintf_variation15_64bit.phpt +ext/standard/tests/strings/vsprintf_variation15_64bit.phpt diff --git a/dockerfiles/ci/xfail_tests/7.1.list b/dockerfiles/ci/xfail_tests/7.1.list index ff77854962..4c948b42c5 100644 --- a/dockerfiles/ci/xfail_tests/7.1.list +++ b/dockerfiles/ci/xfail_tests/7.1.list @@ -374,3 +374,12 @@ tests/classes/clone_002.phpt tests/classes/clone_004.phpt tests/lang/type_hints_002.phpt tests/output/ob_start_basic_002.phpt + +Zend/tests/dval_to_lval_64.phpt +Zend/tests/int_overflow_64bit.phpt +ext/standard/tests/math/decbin_variation1_64bit.phpt +ext/standard/tests/math/dechex_variation1_64bit.phpt +ext/standard/tests/math/decoct_variation1_64bit.phpt +ext/standard/tests/strings/bug47842.phpt +ext/standard/tests/strings/vprintf_variation15_64bit.phpt +ext/standard/tests/strings/vsprintf_variation15_64bit.phpt diff --git a/dockerfiles/ci/xfail_tests/7.2.list b/dockerfiles/ci/xfail_tests/7.2.list index 157761dd23..5f1885dc35 100644 --- a/dockerfiles/ci/xfail_tests/7.2.list +++ b/dockerfiles/ci/xfail_tests/7.2.list @@ -322,3 +322,12 @@ tests/classes/clone_004.phpt tests/lang/bug45392.phpt tests/lang/type_hints_002.phpt tests/output/ob_start_basic_002.phpt + +Zend/tests/dval_to_lval_64.phpt +Zend/tests/int_overflow_64bit.phpt +ext/standard/tests/math/decbin_variation1_64bit.phpt +ext/standard/tests/math/dechex_variation1_64bit.phpt +ext/standard/tests/math/decoct_variation1_64bit.phpt +ext/standard/tests/strings/bug47842.phpt +ext/standard/tests/strings/vprintf_variation15_64bit.phpt +ext/standard/tests/strings/vsprintf_variation15_64bit.phpt diff --git a/dockerfiles/ci/xfail_tests/7.3.list b/dockerfiles/ci/xfail_tests/7.3.list index d5bb3e8e3d..125284d720 100644 --- a/dockerfiles/ci/xfail_tests/7.3.list +++ b/dockerfiles/ci/xfail_tests/7.3.list @@ -353,3 +353,12 @@ tests/classes/clone_004.phpt tests/lang/bug45392.phpt tests/lang/type_hints_002.phpt tests/output/ob_start_basic_002.phpt + +Zend/tests/dval_to_lval_64.phpt +Zend/tests/int_overflow_64bit.phpt +ext/standard/tests/math/decbin_variation1_64bit.phpt +ext/standard/tests/math/dechex_variation1_64bit.phpt +ext/standard/tests/math/decoct_variation1_64bit.phpt +ext/standard/tests/strings/bug47842.phpt +ext/standard/tests/strings/vprintf_variation15_64bit.phpt +ext/standard/tests/strings/vsprintf_variation15_64bit.phpt diff --git a/dockerfiles/ci/xfail_tests/7.4.list b/dockerfiles/ci/xfail_tests/7.4.list index 436febec59..51e8866d5c 100644 --- a/dockerfiles/ci/xfail_tests/7.4.list +++ b/dockerfiles/ci/xfail_tests/7.4.list @@ -439,3 +439,12 @@ tests/classes/tostring_001.phpt tests/lang/bug45392.phpt tests/lang/type_hints_002.phpt tests/output/ob_start_basic_002.phpt + +Zend/tests/dval_to_lval_64.phpt +Zend/tests/int_overflow_64bit.phpt +ext/standard/tests/math/decbin_variation1_64bit.phpt +ext/standard/tests/math/dechex_variation1_64bit.phpt +ext/standard/tests/math/decoct_variation1_64bit.phpt +ext/standard/tests/strings/bug47842.phpt +ext/standard/tests/strings/vprintf_variation15_64bit.phpt +ext/standard/tests/strings/vsprintf_variation15_64bit.phpt diff --git a/dockerfiles/ci/xfail_tests/8.2.list b/dockerfiles/ci/xfail_tests/8.2.list index f63e984ba5..90cb979663 100644 --- a/dockerfiles/ci/xfail_tests/8.2.list +++ b/dockerfiles/ci/xfail_tests/8.2.list @@ -162,6 +162,7 @@ ext/standard/tests/serialize/005.phpt ext/standard/tests/streams/bug78902.phpt ext/standard/tests/streams/proc_open_bug69900.phpt ext/standard/tests/streams/stream_context_tcp_nodelay_fopen.phpt +ext/standard/tests/strings/gh15613.phpt ext/standard/tests/strings/implode1.phpt ext/standard/tests/strings/sprintf_variation54.phpt ext/zend_test/tests/ diff --git a/dockerfiles/ci/xfail_tests/8.3.list b/dockerfiles/ci/xfail_tests/8.3.list index cf52679333..d8be6fa790 100644 --- a/dockerfiles/ci/xfail_tests/8.3.list +++ b/dockerfiles/ci/xfail_tests/8.3.list @@ -166,6 +166,7 @@ ext/standard/tests/streams/proc_open_bug69900.phpt ext/standard/tests/streams/stream_context_tcp_nodelay_fopen.phpt ext/standard/tests/strings/implode1.phpt ext/standard/tests/strings/sprintf_variation54.phpt +ext/standard/tests/strings/gh15613.phpt ext/zend_test/tests/ sapi/cli/tests/bug80092.phpt sapi/cli/tests/upload_2G.phpt diff --git a/dockerfiles/ci/xfail_tests/8.4.list b/dockerfiles/ci/xfail_tests/8.4.list new file mode 100644 index 0000000000..7b64bb933d --- /dev/null +++ b/dockerfiles/ci/xfail_tests/8.4.list @@ -0,0 +1,192 @@ +Zend/tests/014.phpt +Zend/tests/arginfo_zpp_mismatch.phpt +Zend/tests/arginfo_zpp_mismatch_strict.phpt +Zend/tests/bug63882_2.phpt +Zend/tests/bug69315.phpt +Zend/tests/bug70258.phpt +Zend/tests/bug70805.phpt +Zend/tests/bug70805_1.phpt +Zend/tests/bug70805_2.phpt +Zend/tests/bug71539_5.phpt +Zend/tests/bug72038.phpt +Zend/tests/bug75921.phpt +Zend/tests/bug78182.phpt +Zend/tests/bug81104.phpt +Zend/tests/fibers/gh10496-001.phpt +Zend/tests/fibers/destructors_005.phpt +Zend/tests/fibers/out-of-memory-in-fiber.phpt +Zend/tests/fibers/out-of-memory-in-nested-fiber.phpt +Zend/tests/fibers/out-of-memory-in-recursive-fiber.phpt +Zend/tests/gc_031.phpt +Zend/tests/gc_037.phpt +Zend/tests/gc_045.phpt +Zend/tests/get_defined_functions_basic.phpt +Zend/tests/get_required_files.phpt +Zend/tests/gh7958.phpt +Zend/tests/gh10346.phpt +Zend/tests/gh11189.phpt +Zend/tests/gh11189_1.phpt +Zend/tests/gh12073.phpt +Zend/tests/list_keyed_conversions.phpt +Zend/tests/multibyte/multibyte_encoding_004.phpt +Zend/tests/object_gc_in_shutdown.phpt +Zend/tests/offset_array.phpt +Zend/tests/stack_limit/stack_limit_013.phpt +Zend/tests/strict_001.phpt +Zend/tests/type_declarations/scalar_return_basic_64bit.phpt +Zend/tests/type_declarations/scalar_strict_64bit.phpt +Zend/tests/weakrefs/gh10043-007.phpt +Zend/tests/weakrefs/weakmap_basic_map_behavior.phpt +Zend/tests/weakrefs/weakmap_error_conditions.phpt +ext/curl/tests/bug45161.phpt +ext/curl/tests/bug64267.phpt +ext/curl/tests/bug76675.phpt +ext/curl/tests/bug77535.phpt +ext/curl/tests/bug79033.phpt +ext/curl/tests/curl_int_cast.phpt +ext/curl/tests/curl_postfields_array.phpt +ext/curl/tests/curl_setopt_CURLOPT_ACCEPT_ENCODING.phpt +ext/curl/tests/curl_setopt_CURLOPT_DEBUGFUNCTION.phpt +ext/date/tests/bug52113.phpt +ext/dom/tests/dom_set_attr_node.phpt +ext/dom/tests/dom003.phpt +ext/dom/tests/modern/xml/XMLDocument_xpath_errors.phpt +ext/fileinfo/tests/finfo_open_error.phpt +ext/json/tests/json_decode_exceptions.phpt +ext/json/tests/json_encode_exceptions.phpt +ext/mbstring/tests/zend_multibyte-01.phpt +ext/mbstring/tests/zend_multibyte-02.phpt +ext/mbstring/tests/zend_multibyte-06.phpt +ext/openssl/tests/bug46127.phpt +ext/openssl/tests/bug48182.phpt +ext/openssl/tests/bug54992.phpt +ext/openssl/tests/bug65538_001.phpt +ext/openssl/tests/bug65538_003.phpt +ext/openssl/tests/bug65729.phpt +ext/openssl/tests/bug68265.phpt +ext/openssl/tests/bug68879.phpt +ext/openssl/tests/bug68920.phpt +ext/openssl/tests/bug69215.phpt +ext/openssl/tests/bug72333.phpt +ext/openssl/tests/bug74159.phpt +ext/openssl/tests/bug77390.phpt +ext/openssl/tests/capture_peer_cert_001.phpt +ext/openssl/tests/openssl_encrypt_ccm.phpt +ext/openssl/tests/openssl_peer_fingerprint_basic.phpt +ext/openssl/tests/openssl_x509_checkpurpose_basic.phpt +ext/openssl/tests/peer_verification.phpt +ext/openssl/tests/san_peer_matching.phpt +ext/openssl/tests/session_meta_capture.phpt +ext/openssl/tests/session_meta_capture_tlsv13.phpt +ext/openssl/tests/stream_crypto_flags_001.phpt +ext/openssl/tests/stream_crypto_flags_002.phpt +ext/openssl/tests/stream_crypto_flags_003.phpt +ext/openssl/tests/stream_crypto_flags_004.phpt +ext/openssl/tests/stream_security_level.phpt +ext/openssl/tests/stream_server_reneg_limit.phpt +ext/openssl/tests/stream_verify_peer_name_001.phpt +ext/openssl/tests/stream_verify_peer_name_002.phpt +ext/openssl/tests/stream_verify_peer_name_003.phpt +ext/openssl/tests/streams_crypto_method.phpt +ext/openssl/tests/tls_min_v1.0_max_v1.1_wrapper.phpt +ext/openssl/tests/tls_wrapper.phpt +ext/openssl/tests/tls_wrapper_with_tls_v1.3.phpt +ext/openssl/tests/tlsv1.0_wrapper.phpt +ext/openssl/tests/tlsv1.1_wrapper.phpt +ext/openssl/tests/tlsv1.2_wrapper.phpt +ext/openssl/tests/tlsv1.3_wrapper.phpt +ext/pcntl/tests/pcntl_unshare_01.phpt +ext/pcntl/tests/pcntl_unshare_02.phpt +ext/pcntl/tests/pcntl_unshare_03.phpt +ext/pdo/tests/pdo_023.phpt +ext/pdo/tests/pdo_030.phpt +ext/pdo_sqlite/tests/bug43831.phpt +ext/pdo_sqlite/tests/bug44327_2.phpt +ext/pdo_sqlite/tests/bug44327_3.phpt +ext/pdo_sqlite/tests/bug48773.phpt +ext/pdo_sqlite/tests/pdo_fetch_func_001.phpt +ext/pdo_sqlite/tests/pdo_sqlite_lastinsertid.phpt +ext/phar/tests/031.phpt +ext/phar/tests/032.phpt +ext/phar/tests/fatal_error_webphar.phpt +ext/phar/tests/phar_buildfromiterator10.phpt +ext/phar/tests/phar_buildfromiterator8.phpt +ext/phar/tests/phar_metadata_write4.phpt +ext/phar/tests/phar_oo_002.phpt +ext/phar/tests/phar_oo_005.phpt +ext/phar/tests/phar_oo_007.phpt +ext/readline/tests/libedit_callback_handler_install_001.phpt +ext/readline/tests/libedit_callback_handler_remove_001.phpt +ext/simplexml/tests/bug51615.phpt +ext/soap/tests/bugs/bug77088.phpt +ext/spl/tests/bug40091.phpt +ext/spl/tests/bug44144.phpt +ext/spl/tests/bug48493.phpt +ext/spl/tests/bug62978.phpt +ext/spl/tests/bug65006.phpt +ext/spl/tests/bug71236.phpt +ext/spl/tests/bug75049.phpt +ext/spl/tests/fixedarray_003.phpt +ext/spl/tests/gh8318.phpt +ext/spl/tests/gh10011.phpt +ext/spl/tests/spl_autoload_002.phpt +ext/spl/tests/spl_autoload_004.phpt +ext/spl/tests/spl_autoload_006.phpt +ext/spl/tests/spl_autoload_008.phpt +ext/spl/tests/spl_autoload_013.phpt +ext/standard/tests/array/array_map_variation4.phpt +ext/standard/tests/array/array_reverse_variation4.phpt +ext/standard/tests/array/array_unique_variation3.phpt +ext/standard/tests/file/bug52820.phpt +ext/standard/tests/file/disk_free_space_basic.phpt +ext/standard/tests/file/file_get_contents_file_put_contents_5gb.phpt +ext/standard/tests/file/lstat_stat_variation10.phpt +ext/standard/tests/filters/bug54350.phpt +ext/standard/tests/general_functions/bug73973.phpt +ext/standard/tests/general_functions/floatval.phpt +ext/standard/tests/general_functions/floatval_variation1.phpt +ext/standard/tests/general_functions/get_included_files.phpt +ext/standard/tests/general_functions/gettype_settype_basic.phpt +ext/standard/tests/general_functions/print_r.phpt +ext/standard/tests/general_functions/print_r_64bit.phpt +ext/standard/tests/general_functions/proc_open_null.phpt +ext/standard/tests/general_functions/proc_open_redirect.phpt +ext/standard/tests/general_functions/strval.phpt +ext/standard/tests/general_functions/type.phpt +ext/standard/tests/general_functions/var_dump_64bit.phpt +ext/standard/tests/gh14643_longname.phpt +ext/standard/tests/math/base_convert_variation1.phpt +ext/standard/tests/math/bindec_variation1_64bit.phpt +ext/standard/tests/math/hexdec_variation1_64bit.phpt +ext/standard/tests/math/octdec_variation1.phpt +ext/standard/tests/network/bug80067.phpt +ext/standard/tests/network/syslog_new_line.phpt +ext/standard/tests/network/syslog_null_byte.phpt +ext/standard/tests/serialize/005.phpt +ext/standard/tests/streams/bug78902.phpt +ext/standard/tests/streams/proc_open_bug69900.phpt +ext/standard/tests/streams/stream_context_tcp_nodelay_fopen.phpt +ext/standard/tests/strings/gh15613.phpt +ext/standard/tests/strings/sprintf_variation54.phpt +ext/zend_test/tests/ +sapi/cli/tests/bug80092.phpt +sapi/cli/tests/upload_2G.phpt +sapi/fpm/tests/log-bm-in-shutdown-fn.phpt +sapi/fpm/tests/log-bm-limit-1024-msg-80.phpt +sapi/fpm/tests/log-bm-limit-2048-msg-4000.phpt +sapi/fpm/tests/log-bwd-limit-1050-msg-2048.phpt +sapi/fpm/tests/log-bwd-limit-1050-msg-2900.phpt +sapi/fpm/tests/log-bwd-limit-8000-msg-4096.phpt +sapi/fpm/tests/log-bwd-msg-with-nl.phpt +sapi/fpm/tests/log-bwp-limit-1024-msg-120.phpt +sapi/fpm/tests/log-bwp-limit-1500-msg-3300.phpt +sapi/fpm/tests/log-bwp-msg-flush-split-fallback.phpt +sapi/fpm/tests/log-bwp-msg-flush-split-real.phpt +sapi/fpm/tests/log-dwd-limit-1050-msg-2048.phpt +sapi/fpm/tests/log-dwd-limit-1050-msg-2900.phpt +sapi/fpm/tests/log-dwd-limit-8000-msg-4096.phpt +sapi/fpm/tests/log-dwp-limit-1000-msg-2000.phpt +sapi/phpdbg/tests/exceptions_003.phpt +sapi/phpdbg/tests/stepping_001.phpt +tests/lang/bug45392.phpt +tests/output/ob_start_basic_002.phpt diff --git a/dockerfiles/ci/xfail_tests/README.md b/dockerfiles/ci/xfail_tests/README.md index af3a122cef..524932ec0b 100644 --- a/dockerfiles/ci/xfail_tests/README.md +++ b/dockerfiles/ci/xfail_tests/README.md @@ -80,7 +80,7 @@ See https://github.com/php/php-src/pull/14895 and https://github.com/DataDog/dd- Temporarily disabled due to a too strict of a check for the precise php -v output. -## `Zend/tests/object_gc_in_shutdown.phpt`, `Zend/tests/bug81104.phpt`, `Zend/tests/gh11189(_1).phpt`, `Zend/tests/gh12073.phpt` +## `Zend/tests/object_gc_in_shutdown.phpt`, `Zend/tests/bug81104.phpt`, `Zend/tests/gh11189(_1).phpt`, `Zend/tests/gh12073.phpt`, `ext/standard/tests/gh14643_longname.phpt` Tests memory limits, which we exceed due to tracer being loaded. @@ -92,7 +92,7 @@ By _chance_ the internal comparison happens against another GC protected array w Test does http request to shut down server. -## `ext/curl/tests/curl_postfields_array.phpt`, `ext/curl/tests/curl_setopt_CURLOPT_ACCEPT_ENCODING.phpt` +## `ext/curl/tests/curl_postfields_array.phpt`, `ext/curl/tests/curl_setopt_CURLOPT_ACCEPT_ENCODING.phpt`, `ext/curl/tests/curl_setopt_CURLOPT_DEBUGFUNCTION.phpt` Distributed tracing headers are injected @@ -180,7 +180,7 @@ SKIP Test if socket_create_listen() returns false, when it cannot bind to the po ddtrace request init hook consumes more than 2 MB of memory and fails too early instead of testing what it should. -## `Zend/tests/fibers/gh10496-001.phpt`, `Zend/tests/weakrefs/gh10043-007.phpt` +## `Zend/tests/fibers/gh10496-001.phpt`, `Zend/tests/weakrefs/gh10043-007.phpt`, `Zend/tests/fibers/destructors_005.phpt` ddtrace affects the order of destructor execution due to creating span stacks etc. diff --git a/ext/collect_backtrace.c b/ext/collect_backtrace.c index a0f7c671fc..4ea860a687 100644 --- a/ext/collect_backtrace.c +++ b/ext/collect_backtrace.c @@ -354,7 +354,9 @@ void ddtrace_fetch_debug_backtrace(zval *return_value, int skip_last, int option if (prev_stack_frame) { zend_hash_del(prev_stack_frame, ZSTR_KNOWN(ZEND_STR_FILE)); zend_hash_del(prev_stack_frame, ZSTR_KNOWN(ZEND_STR_LINE)); - zend_hash_del(prev_stack_frame, key_locals); + if ((options & DDTRACE_DEBUG_BACKTRACE_CAPTURE_LOCALS)) { + zend_hash_del(prev_stack_frame, key_locals); + } } } if ((options & DEBUG_BACKTRACE_IGNORE_ARGS) == 0) { diff --git a/ext/coms.c b/ext/coms.c index f5baf81077..7a8e33c8ec 100644 --- a/ext/coms.c +++ b/ext/coms.c @@ -1204,9 +1204,24 @@ static struct _writer_thread_variables_t *_dd_create_thread_variables() { return thread; } -bool ddtrace_coms_init_and_start_writer(void) { +static bool _dd_coms_start_writer(void) { struct _writer_loop_data_t *writer = _dd_get_writer(); _dd_writer_set_operational_state(writer); + struct _writer_thread_variables_t *thread = _dd_create_thread_variables(); + writer->thread = thread; + writer->set_secbit = get_global_DD_TRACE_RETAIN_THREAD_CAPABILITIES(); + atomic_store(&writer->starting_up, true); + return pthread_create(&thread->self, NULL, &_dd_writer_loop, NULL) == 0; +} + +bool ddtrace_coms_restart_writer(void) { + ddtrace_coms_minit(ddtrace_coms_globals.initial_stack_size, ddtrace_coms_globals.max_payload_size, ddtrace_coms_globals.max_backlog_size, NULL); + return _dd_coms_start_writer(); +} + + +bool ddtrace_coms_init_and_start_writer(void) { + struct _writer_loop_data_t *writer = _dd_get_writer(); atomic_store(&writer->current_pid, getpid()); dd_agent_curl_headers = dd_agent_headers_alloc(); @@ -1216,16 +1231,7 @@ bool ddtrace_coms_init_and_start_writer(void) { } ddtrace_ffi_try("error creating config writer", ddog_create_agent_remote_config_writer(&dd_agent_config_writer, &ddtrace_coms_agent_config_handle)); - - struct _writer_thread_variables_t *thread = _dd_create_thread_variables(); - writer->thread = thread; - writer->set_secbit = get_global_DD_TRACE_RETAIN_THREAD_CAPABILITIES(); - atomic_store(&writer->starting_up, true); - if (pthread_create(&thread->self, NULL, &_dd_writer_loop, NULL) == 0) { - return true; - } else { - return false; - } + return _dd_coms_start_writer(); } static bool _dd_has_pid_changed(void) { diff --git a/ext/coms.h b/ext/coms.h index cfb7e1c0aa..f9ca900dca 100644 --- a/ext/coms.h +++ b/ext/coms.h @@ -66,6 +66,7 @@ uint32_t ddtrace_coms_next_group_id(void); void ddtrace_coms_set_test_session_token(const char *token, size_t token_len); bool ddtrace_coms_init_and_start_writer(void); +bool ddtrace_coms_restart_writer(void); bool ddtrace_coms_trigger_writer_flush(void); bool ddtrace_coms_set_writer_send_on_flush(bool send); bool ddtrace_in_writer_thread(void); diff --git a/ext/handlers_exception.c b/ext/handlers_exception.c index fd5827bfdf..96c8010d1d 100644 --- a/ext/handlers_exception.c +++ b/ext/handlers_exception.c @@ -456,10 +456,12 @@ static zend_object *ddtrace_custom_exception_new(zend_class_entry *class_type) { static zend_property_info *dd_add_exception_locals_property(zend_class_entry *ce) { zend_string *key = zend_string_init(ZEND_STRL("locals"), 1); + zval zv; + ZVAL_UNDEF(&zv); #if PHP_VERSION_ID >= 80000 - zend_property_info *prop = zend_declare_typed_property(ce, key, &EG(uninitialized_zval), ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ARRAY)); + zend_property_info *prop = zend_declare_typed_property(ce, key, &zv, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ARRAY)); #else - zend_declare_property_ex(ce, key, &EG(uninitialized_zval), ZEND_ACC_PRIVATE, NULL); + zend_declare_property_ex(ce, key, &zv, ZEND_ACC_PRIVATE, NULL); zend_property_info *prop = zend_hash_find_ptr(&ce->properties_info, key); #endif zend_string_release(key); diff --git a/ext/handlers_pcntl.c b/ext/handlers_pcntl.c index 2a2c074f8b..acff140cfe 100644 --- a/ext/handlers_pcntl.c +++ b/ext/handlers_pcntl.c @@ -23,19 +23,39 @@ static zif_handler dd_pcntl_rfork_handler = NULL; static zif_handler dd_pcntl_forkx_handler = NULL; #endif +#if defined(__SANITIZE_ADDRESS__) && !defined(_WIN32) +#define JOIN_BGS_BEFORE_FORK 1 +#endif + +static void dd_prefork() { +#if JOIN_BGS_BEFORE_FORK + if (!get_global_DD_TRACE_SIDECAR_TRACE_SENDER()) { + ddtrace_coms_flush_shutdown_writer_synchronous(); + } +#endif +} + static void dd_handle_fork(zval *return_value) { if (Z_LVAL_P(return_value) == 0) { dd_internal_handle_fork(); + } else { +#if JOIN_BGS_BEFORE_FORK + if (!get_global_DD_TRACE_SIDECAR_TRACE_SENDER()) { + ddtrace_coms_restart_writer(); + } +#endif } } ZEND_FUNCTION(ddtrace_pcntl_fork) { + dd_prefork(); dd_pcntl_fork_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); dd_handle_fork(return_value); } #if PHP_VERSION_ID >= 80100 ZEND_FUNCTION(ddtrace_pcntl_rfork) { + dd_prefork(); dd_pcntl_rfork_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); dd_handle_fork(return_value); } @@ -43,6 +63,7 @@ ZEND_FUNCTION(ddtrace_pcntl_rfork) { #if PHP_VERSION_ID >= 80200 ZEND_FUNCTION(ddtrace_pcntl_forkx) { + dd_prefork(); dd_pcntl_forkx_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); dd_handle_fork(return_value); } diff --git a/libdatadog b/libdatadog index 8d6b9cca27..085a91abb8 160000 --- a/libdatadog +++ b/libdatadog @@ -1 +1 @@ -Subproject commit 8d6b9cca2766c84512c0de407ab9c9008064dc9f +Subproject commit 085a91abb8fe6700a6faa528314ada665bc36852 diff --git a/loader/dd_library_loader.c b/loader/dd_library_loader.c index c614bbb144..3ff9c009e8 100644 --- a/loader/dd_library_loader.c +++ b/loader/dd_library_loader.c @@ -114,7 +114,7 @@ static bool ddloader_is_opcache_jit_enabled() { return false; } } - if (php_api_no > 20230831) { // PHP > 8.3 (https://php.watch/versions/8.4/opcache-jit-ini-default-changes) + if (php_api_no > 20230831) { // PHP > 8.3 (https://wiki.php.net/rfc/jit_config_defaults) // opcache.jit == disable (default: disable) zval *opcache_jit = ddloader_ini_get_configuration(ZEND_STRL("opcache.jit")); if (!opcache_jit || Z_TYPE_P(opcache_jit) != IS_STRING || strcmp(Z_STRVAL_P(opcache_jit), "disable") == 0 || strcmp(Z_STRVAL_P(opcache_jit), "off") == 0) { @@ -661,6 +661,7 @@ static int ddloader_api_no_check(int api_no) { case 420210902: // 8.1 case 420220829: // 8.2 case 420230831: // 8.3 + case 420240924: // 8.4 break; default: diff --git a/loader/tests/functional/test_incompatibility_jit.php b/loader/tests/functional/test_incompatibility_jit.php index 10cef519f0..12c5db7974 100644 --- a/loader/tests/functional/test_incompatibility_jit.php +++ b/loader/tests/functional/test_incompatibility_jit.php @@ -38,7 +38,7 @@ ], // JIT enabled [ - "config" => "-dzend_extension=opcache -dopcache.enable_cli=1 -ddatadog.trace.cli_enabled=1 -dopcache.jit_buffer_size=32M", + "config" => "-dzend_extension=opcache -dopcache.enable_cli=1 -ddatadog.trace.cli_enabled=1 -dopcache.jit_buffer_size=32M -dopcache.jit=tracing", "must_not_contain" => [], "must_contain" => [ $msg_disabled, @@ -53,7 +53,7 @@ ], // JIT enabled + force injection [ - "config" => "-dzend_extension=opcache -dopcache.enable_cli=1 -ddatadog.trace.cli_enabled=1 -dopcache.jit_buffer_size=32M", + "config" => "-dzend_extension=opcache -dopcache.enable_cli=1 -ddatadog.trace.cli_enabled=1 -dopcache.jit_buffer_size=32M -dopcache.jit=tracing", "env" => ['DD_INJECT_FORCE=1'], "must_not_contain" => [], "must_contain" => [ diff --git a/loader/tests/functional/test_telemetry_complete.php b/loader/tests/functional/test_telemetry_complete.php index 0116f1ebfa..75f2b6f9a5 100644 --- a/loader/tests/functional/test_telemetry_complete.php +++ b/loader/tests/functional/test_telemetry_complete.php @@ -20,9 +20,9 @@ { "metadata": { "runtime_name": "php", - "runtime_version": "%d.%d.%d", + "runtime_version": "%d.%d.%d%S", "language_name": "php", - "language_version": "%d.%d.%d", + "language_version": "%d.%d.%d%S", "tracer_version": "%s", "pid": %d }, diff --git a/package.xml b/package.xml index 1558e260a2..b3a1b23c01 100644 --- a/package.xml +++ b/package.xml @@ -146,7 +146,7 @@ The default value for datadog.trace.cli_enabled is now set to true (except for c 7.0 - 8.3.99 + 8.4.99 1.4.0 diff --git a/profiling/build.rs b/profiling/build.rs index 44a903ac07..b5b35294ea 100644 --- a/profiling/build.rs +++ b/profiling/build.rs @@ -329,6 +329,9 @@ fn cfg_php_feature_flags(vernum: u64) { if vernum >= 80300 { println!("cargo:rustc-cfg=php_gc_status_extended"); } + if vernum >= 80400 { + println!("cargo:rustc-cfg=php_frameless"); + } } fn cfg_zts() { diff --git a/profiling/src/profiling/stack_walking.rs b/profiling/src/profiling/stack_walking.rs index bddd6ac43c..38e1e6b575 100644 --- a/profiling/src/profiling/stack_walking.rs +++ b/profiling/src/profiling/stack_walking.rs @@ -2,6 +2,13 @@ use crate::bindings::{zai_str_from_zstr, zend_execute_data, zend_function}; use std::borrow::Cow; use std::str::Utf8Error; +#[cfg(php_frameless)] +use crate::bindings::zend_flf_functions; +#[cfg(php_frameless)] +use crate::bindings::{ + ZEND_FRAMELESS_ICALL_0, ZEND_FRAMELESS_ICALL_1, ZEND_FRAMELESS_ICALL_2, ZEND_FRAMELESS_ICALL_3, +}; + const COW_PHP_OPEN_TAG: Cow = Cow::Borrowed(" = Cow::Borrowed("[truncated]"); @@ -199,21 +206,46 @@ mod detail { let mut execute_data_ptr = top_execute_data; while let Some(execute_data) = unsafe { execute_data_ptr.as_ref() } { - let maybe_frame = unsafe { collect_call_frame(execute_data, string_set) }; - if let Some(frame) = maybe_frame { - samples.push(frame); - - /* -1 to reserve room for the [truncated] message. In case the - * backend and/or frontend have the same limit, without the -1 - * then ironically the [truncated] message would be truncated. - */ - if samples.len() == max_depth - 1 { - samples.push(ZendFrame { - function: COW_TRUNCATED, - file: None, - line: 0, - }); - break; + // allowed because it's only used on the frameless path + #[allow(unused_variables)] + if let Some(func) = unsafe { execute_data.func.as_ref() } { + #[cfg(php_frameless)] + if !func.is_internal() { + let opline = unsafe { &*execute_data.opline }; + match opline.opcode as u32 { + ZEND_FRAMELESS_ICALL_0 + | ZEND_FRAMELESS_ICALL_1 + | ZEND_FRAMELESS_ICALL_2 + | ZEND_FRAMELESS_ICALL_3 => { + let func = unsafe { + &**zend_flf_functions.offset(opline.extended_value as isize) + }; + samples.push(ZendFrame { + function: extract_function_name(func).map(Cow::Owned).unwrap(), + file: None, + line: 0, + }); + } + _ => {} + } + } + + let maybe_frame = unsafe { collect_call_frame(execute_data, string_set) }; + if let Some(frame) = maybe_frame { + samples.push(frame); + + /* -1 to reserve room for the [truncated] message. In case the + * backend and/or frontend have the same limit, without the -1 + * then ironically the [truncated] message would be truncated. + */ + if samples.len() == max_depth - 1 { + samples.push(ZendFrame { + function: COW_TRUNCATED, + file: None, + line: 0, + }); + break; + } } } diff --git a/profiling/src/wall_time.rs b/profiling/src/wall_time.rs index 42f7277843..ea4d238734 100644 --- a/profiling/src/wall_time.rs +++ b/profiling/src/wall_time.rs @@ -1,20 +1,78 @@ //! This module has code related to generating wall-time profiles. Due to //! implementation reasons, it has cpu-time code as well. -use crate::bindings::{ - zend_execute_data, zend_execute_internal, zend_interrupt_function, zval, VmInterruptFn, - ZEND_ACC_CALL_VIA_TRAMPOLINE, -}; -use crate::{profiling::Profiler, zend, REQUEST_LOCALS}; -use std::mem::MaybeUninit; +use crate::bindings::{zend_execute_data, zend_interrupt_function, VmInterruptFn}; +use crate::{profiling::Profiler, REQUEST_LOCALS}; use std::sync::atomic::Ordering; -/// The engine's previous [zend::zend_execute_internal] value, or -/// [zend::execute_internal] if none. This is a highly active path, so although -/// it could be made safe with Mutex, the cost is too high. -static mut PREV_EXECUTE_INTERNAL: MaybeUninit< - unsafe extern "C" fn(execute_data: *mut zend_execute_data, return_value: *mut zval), -> = MaybeUninit::uninit(); +#[cfg(not(php_frameless))] +mod execute_internal { + use super::*; + use crate::zend; + use std::mem::MaybeUninit; + use zend::{zend_execute_internal, zval, ZEND_ACC_CALL_VIA_TRAMPOLINE}; + + /// The engine's previous [zend::zend_execute_internal] value, or + /// [zend::execute_internal] if none. This is a highly active path, so although + /// it could be made safe with Mutex, the cost is too high. + static mut PREV_EXECUTE_INTERNAL: MaybeUninit< + unsafe extern "C" fn(execute_data: *mut zend_execute_data, return_value: *mut zval), + > = MaybeUninit::uninit(); + + /// Returns true if the func tied to the execute_data is a trampoline. + /// # Safety + /// This is only safe to execute _before_ executing the trampoline, because + /// the trampoline may free the `execute_data.func` _without_ setting it + /// to NULL: + /// https://heap.space/xref/PHP-8.2/Zend/zend_closures.c?r=af2110e6#60-63 + /// So no code can inspect the func after the call has been made, which is + /// why you would call this function: find out before you call the function + /// if indeed you need to skip certain code after it has been executed. + unsafe fn execute_data_func_is_trampoline(execute_data: *const zend_execute_data) -> bool { + if execute_data.is_null() { + return false; + } + + if (*execute_data).func.is_null() { + return false; + } + ((*(*execute_data).func).common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0 + } + + /// Overrides the engine's zend_execute_internal hook in order to process pending VM interrupts + /// while the internal function is still on top of the call stack. The VM does not process the + /// interrupt until the call returns so that it could theoretically jump to a different opcode, + /// like a fiber scheduler. + /// For our particular case this is problematic. For example, when the user does something like + /// `sleep(seconds: 10)`, the normal interrupt handling will not trigger until sleep returns, + /// so we'd then attribute all that time spent sleeping to whatever runs next. This is why we + /// intercept `zend_execute_internal` and process our own VM interrupts, but it doesn't delegate + /// to the previous VM interrupt hook, as it's not expecting to be called from this state. + extern "C" fn execute_internal(execute_data: *mut zend_execute_data, return_value: *mut zval) { + // SAFETY: called before executing the trampoline. + let leaf_frame = if unsafe { execute_data_func_is_trampoline(execute_data) } { + // SAFETY: if is_trampoline is set, then there must be a valid execute_data. + unsafe { *execute_data }.prev_execute_data + } else { + execute_data + }; + + // SAFETY: PREV_EXECUTE_INTERNAL was written during minit, doesn't change during runtime. + let prev_execute_internal = unsafe { *PREV_EXECUTE_INTERNAL.as_mut_ptr() }; + + // SAFETY: calling prev_execute without modification will be safe. + unsafe { prev_execute_internal(execute_data, return_value) }; + + // See safety section of `execute_data_func_is_trampoline` docs for why + // the leaf frame is used instead of the execute_data ptr. + ddog_php_prof_interrupt_function(leaf_frame); + } + + pub unsafe fn minit() { + PREV_EXECUTE_INTERNAL.write(zend_execute_internal.unwrap_or(zend::execute_internal)); + zend_execute_internal = Some(execute_internal); + } +} /// The engine's previous `zend_interrupt_function` value, if there is one. /// Note that because of things like Apache reload which call minit more than @@ -75,53 +133,6 @@ extern "C" fn ddog_php_prof_interrupt_function_wrapper(execute_data: *mut zend_e } } -/// Returns true if the func tied to the execute_data is a trampoline. -/// # Safety -/// This is only safe to execute _before_ executing the trampoline, because the trampoline may -/// free the `execute_data.func` _without_ setting it to NULL: -/// https://heap.space/xref/PHP-8.2/Zend/zend_closures.c?r=af2110e6#60-63 -/// So no code can inspect the func after the call has been made, which is why you would call this function: find out before you -/// call the function if indeed you need to skip certain code after it has been executed. -unsafe fn execute_data_func_is_trampoline(execute_data: *const zend_execute_data) -> bool { - if execute_data.is_null() { - return false; - } - - if (*execute_data).func.is_null() { - return false; - } - ((*(*execute_data).func).common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0 -} - -/// Overrides the engine's zend_execute_internal hook in order to process pending VM interrupts -/// while the internal function is still on top of the call stack. The VM does not process the -/// interrupt until the call returns so that it could theoretically jump to a different opcode, -/// like a fiber scheduler. -/// For our particular case this is problematic. For example, when the user does something like -/// `sleep(seconds: 10)`, the normal interrupt handling will not trigger until sleep returns, so -/// we'd then attribute all that time spent sleeping to whatever runs next. This is why we intercept -/// `zend_execute_internal` and process our own VM interrupts, but it doesn't delegate to the -/// previous VM interrupt hook, as it's not expecting to be called from this state. -pub extern "C" fn execute_internal(execute_data: *mut zend_execute_data, return_value: *mut zval) { - // SAFETY: called before executing the trampoline. - let leaf_frame = if unsafe { execute_data_func_is_trampoline(execute_data) } { - // SAFETY: if is_trampoline is set, then there must be a valid execute_data. - unsafe { *execute_data }.prev_execute_data - } else { - execute_data - }; - - // SAFETY: PREV_EXECUTE_INTERNAL was written during minit, doesn't change during runtime. - let prev_execute_internal = unsafe { *PREV_EXECUTE_INTERNAL.as_mut_ptr() }; - - // SAFETY: calling prev_execute without modification will be safe. - unsafe { prev_execute_internal(execute_data, return_value) }; - - // See safety section of `execute_data_func_is_trampoline` docs for why the leaf frame is used - // instead of the execute_data ptr. - ddog_php_prof_interrupt_function(leaf_frame); -} - /// # Safety /// Only call during PHP's minit phase. pub unsafe fn minit() { @@ -133,6 +144,6 @@ pub unsafe fn minit() { }; zend_interrupt_function = Some(function); - PREV_EXECUTE_INTERNAL.write(zend_execute_internal.unwrap_or(zend::execute_internal)); - zend_execute_internal = Some(execute_internal); + #[cfg(not(php_frameless))] + execute_internal::minit(); } diff --git a/profiling/tests/correctness/exceptions_zts.json b/profiling/tests/correctness/exceptions_zts.json index add3caab44..11126b549c 100644 --- a/profiling/tests/correctness/exceptions_zts.json +++ b/profiling/tests/correctness/exceptions_zts.json @@ -6,7 +6,7 @@ "profile-type": "exception-samples", "stack-content": [ { - "regular_expression": "<\\?php|{closure}", + "regular_expression": "<\\?php|{closure(:.*/exceptions_zts\\.php:\\d+)*}", "percent": 100, "labels": [ { diff --git a/profiling/tests/correctness/strange_frames.json b/profiling/tests/correctness/strange_frames.json index b9c10caa60..d0b83f649f 100644 --- a/profiling/tests/correctness/strange_frames.json +++ b/profiling/tests/correctness/strange_frames.json @@ -6,7 +6,7 @@ "profile-type": "sample", "stack-content": [ { - "regular_expression": " + --FILE-- --EXPECT-- diff --git a/tests/ext/request-replayer/dd_trace_exception_span_event.phpt b/tests/ext/request-replayer/dd_trace_exception_span_event.phpt index 0f92f47a60..44d538e596 100644 --- a/tests/ext/request-replayer/dd_trace_exception_span_event.phpt +++ b/tests/ext/request-replayer/dd_trace_exception_span_event.phpt @@ -53,4 +53,4 @@ var_dump($span['meta']['events']); ?> --EXPECTF-- Caught exception: Exception in method -string(%d) "[{"name":"exception","time_unix_nano":%d,"attributes":{"exception.message":"override message","exception.type":"Exception","exception.stacktrace":"#0 %s(%d): ExceptionClass->{closure}()\n#1 %s(%d): ExceptionClass->exceptionMethod()\n#2 {main}","custom.attribute":"custom value"}}]" +string(%d) "[{"name":"exception","time_unix_nano":%d,"attributes":{"exception.message":"override message","exception.type":"Exception","exception.stacktrace":"#0 %s(%d): ExceptionClass->{%s}()\n#1 %s(%d): ExceptionClass->exceptionMethod()\n#2 {main}","custom.attribute":"custom value"}}]" diff --git a/tests/ext/sandbox-prehook/dd_trace_method_binds_called_object.phpt b/tests/ext/sandbox-prehook/dd_trace_method_binds_called_object.phpt index 3fbda3ac62..941c3a1ba9 100644 --- a/tests/ext/sandbox-prehook/dd_trace_method_binds_called_object.phpt +++ b/tests/ext/sandbox-prehook/dd_trace_method_binds_called_object.phpt @@ -27,7 +27,11 @@ DDTrace\trace_method('DatePeriod', 'getStartDate', ['prehook' => function () { $foo = new Foo(); $foo->testBinding(); -$period = new DatePeriod('R7/2019-08-21T00:00:00Z/P1D'); +if (PHP_VERSION_ID >= 80400) { + $period = DatePeriod::createFromISO8601String('R7/2019-08-21T00:00:00Z/P1D'); +} else { + $period = new DatePeriod('R7/2019-08-21T00:00:00Z/P1D'); +} $period->getStartDate(); ?> --EXPECTF-- diff --git a/tests/ext/sandbox/install_hook/override_argument_jit.phpt b/tests/ext/sandbox/install_hook/override_argument_jit.phpt index 147f1743f5..a0b8f88e82 100644 --- a/tests/ext/sandbox/install_hook/override_argument_jit.phpt +++ b/tests/ext/sandbox/install_hook/override_argument_jit.phpt @@ -7,7 +7,7 @@ overrideArguments() works with JIT (Issue #2174) --INI-- opcache.enable=1 opcache.enable_cli = 1 -opcache.jit_buffer_size=512M +opcache.jit_buffer_size=128M opcache.jit=1255 zend_extension=opcache.so --FILE-- diff --git a/tests/ext/sandbox/install_hook/remove_executing_hook.phpt b/tests/ext/sandbox/install_hook/remove_executing_hook.phpt index 25adfbdd69..d853102064 100644 --- a/tests/ext/sandbox/install_hook/remove_executing_hook.phpt +++ b/tests/ext/sandbox/install_hook/remove_executing_hook.phpt @@ -27,10 +27,10 @@ foo(); (\n \n \n <\/DDTrace\\install_hook>)? - - <\{closure}> + + <\{closure(:.+:\d)*}> Removing hook(\n \n \n <\/DDTrace\\remove_hook>)? - <\/\{closure}> + <\/\{closure(:.+:\d)*}> Called <\/foo> -<\/file '.+'> \ No newline at end of file +<\/file '.+'> diff --git a/tests/ext/sandbox/install_hook/suppress_call_jit.phpt b/tests/ext/sandbox/install_hook/suppress_call_jit.phpt index 8cc4fa096e..cca86a1463 100644 --- a/tests/ext/sandbox/install_hook/suppress_call_jit.phpt +++ b/tests/ext/sandbox/install_hook/suppress_call_jit.phpt @@ -7,7 +7,7 @@ suppressCall() works with JIT --INI-- opcache.enable=1 opcache.enable_cli = 1 -opcache.jit_buffer_size=512M +opcache.jit_buffer_size=128M opcache.jit=1255 zend_extension=opcache.so --FILE-- diff --git a/tests/ext/sandbox/install_hook/trace_closure.phpt b/tests/ext/sandbox/install_hook/trace_closure.phpt index 2f7f5f657f..f0ffc8fc43 100644 --- a/tests/ext/sandbox/install_hook/trace_closure.phpt +++ b/tests/ext/sandbox/install_hook/trace_closure.phpt @@ -1,5 +1,11 @@ --TEST-- Tracing Closures via install_hook() +--SKIPIF-- += 80400) { + die('skip: test only stable on PHP >= 8.4'); +} +?> --INI-- datadog.trace.generate_root_span=0 --ENV-- @@ -67,7 +73,7 @@ spans(\DDTrace\SpanData) (8) { intval (trace_closure.php, 0, cli) result => 0 _dd.p.tid => %s - test\trace_closure.php:7\{closure} (trace_closure.php, 1, cli) + test\trace_closure.php:7\{%s} (trace_closure.php, 1, cli) closure.declaration => %stests%cext%csandbox%cinstall_hook%ctrace_closure.php:7 result => 1 _dd.p.tid => %s @@ -82,7 +88,7 @@ spans(\DDTrace\SpanData) (8) { intval (trace_closure.php, 0, cli) result => 1 _dd.p.tid => %s - test\trace_closure.php:7\{closure} (trace_closure.php, 1, cli) + test\trace_closure.php:7\{%s} (trace_closure.php, 1, cli) closure.declaration => %stests%cext%csandbox%cinstall_hook%ctrace_closure.php:7 result => 2 _dd.p.tid => %s diff --git a/tests/ext/sandbox/install_hook/trace_closure_ge_php_84.phpt b/tests/ext/sandbox/install_hook/trace_closure_ge_php_84.phpt new file mode 100644 index 0000000000..cdcd2210bc --- /dev/null +++ b/tests/ext/sandbox/install_hook/trace_closure_ge_php_84.phpt @@ -0,0 +1,102 @@ +--TEST-- +Tracing Closures via install_hook() +--SKIPIF-- += 8.4'); +} +?> +--INI-- +datadog.trace.generate_root_span=0 +datadog.trace.auto_flush_enabled=0 +--FILE-- +getClosure(); + +$topLevelClosure = function($a) { + return $a + 1; +}; + +function foo() { + return function($a) { + return $a + 2; + }; +} + +class bar { + static function foo() { + return function($a) { + return $a + 3; + }; + } +} + +$closures = [$internalFakeClosure, $topLevelClosure, foo(), bar::foo()]; +$hooks = []; + +foreach ($closures as $i => $closure) { + $hooks[] = \DDTrace\install_hook($closure, function(\DDTrace\HookData $hook) use ($i) { + $hook->span()->resource = $i; + }, function(\DDTrace\HookData $hook) { + $hook->span()->meta['result'] = $hook->returned; + }, \DDTrace\HOOK_INSTANCE); + + $closure(0); +} + +foo()(0); // Not traced + +// Still traced +foreach ($closures as $closure) { + $closure(1); +} + +foreach ($hooks as $hook) { + \DDTrace\remove_hook($hook); +} + +// Not traced +foreach ($closures as $closure) { + $closure(2); +} + +include __DIR__ . '/../dd_dumper.inc'; +\dd_dump_spans(true); + +?> +--EXPECTF-- +spans(\DDTrace\SpanData) (8) { + intval (trace_closure_ge_php_84.php, 0, cli) + result => 0 + _dd.p.tid => %s + {closure:%s.php:7\{closure} (trace_closure_ge_php_84.php, 1, cli) + closure.declaration => %stests%cext%csandbox%cinstall_hook%ctrace_closure_ge_php_84.php:7 + result => 1 + _dd.p.tid => %s + test\foo.{closure} (trace_closure_ge_php_84.php, 2, cli) + closure.declaration => %stests%cext%csandbox%cinstall_hook%ctrace_closure_ge_php_84.php:12 + result => 2 + _dd.p.tid => %s + test\bar.foo.{closure} (trace_closure_ge_php_84.php, 3, cli) + closure.declaration => %stests%cext%csandbox%cinstall_hook%ctrace_closure_ge_php_84.php:19 + result => 3 + _dd.p.tid => %s + intval (trace_closure_ge_php_84.php, 0, cli) + result => 1 + _dd.p.tid => %s + {closure:%s.php:7\{closure} (trace_closure_ge_php_84.php, 1, cli) + closure.declaration => %stests%cext%csandbox%cinstall_hook%ctrace_closure_ge_php_84.php:7 + result => 2 + _dd.p.tid => %s + test\foo.{closure} (trace_closure_ge_php_84.php, 2, cli) + closure.declaration => %stests%cext%csandbox%cinstall_hook%ctrace_closure_ge_php_84.php:12 + result => 3 + _dd.p.tid => %s + test\bar.foo.{closure} (trace_closure_ge_php_84.php, 3, cli) + closure.declaration => %stests%cext%csandbox%cinstall_hook%ctrace_closure_ge_php_84.php:19 + result => 4 + _dd.p.tid => %s +} diff --git a/tests/ext/sandbox/install_hook/trace_generator.phpt b/tests/ext/sandbox/install_hook/trace_generator.phpt index 3b06212db8..59c9b31b0a 100644 --- a/tests/ext/sandbox/install_hook/trace_generator.phpt +++ b/tests/ext/sandbox/install_hook/trace_generator.phpt @@ -1,9 +1,14 @@ --TEST-- Tracing Closures via install_hook() +--SKIPIF-- += 80400) { + die('skip: test only stable on PHP >= 8.4'); +} +?> --INI-- datadog.trace.generate_root_span=0 ---ENV-- -DD_TRACE_AUTO_FLUSH_ENABLED=0 +datadog.trace.auto_flush_enabled=0 --FILE-- --EXPECTF-- spans(\DDTrace\SpanData) (1) { - test\trace_generator.php:%d\{closure} (trace_generator.php, test\trace_generator.php:%d\{closure}, cli) + test\trace_generator.php:%d\{%s} (trace_generator.php, test\trace_generator.php:%d\{%s}, cli) closure.declaration => %s:%d result => 3 _dd.p.tid => %s diff --git a/tests/ext/sandbox/install_hook/trace_generator_ge_php_84.phpt b/tests/ext/sandbox/install_hook/trace_generator_ge_php_84.phpt new file mode 100644 index 0000000000..acf844f37c --- /dev/null +++ b/tests/ext/sandbox/install_hook/trace_generator_ge_php_84.phpt @@ -0,0 +1,45 @@ +--TEST-- +Tracing Closures via install_hook() +--SKIPIF-- += 8.4'); +} +?> +--INI-- +datadog.trace.generate_root_span=0 +datadog.trace.auto_flush_enabled=0 +--FILE-- +span(); +}, function(\DDTrace\HookData $hook) { + $hook->span()->meta['result'] = $hook->returned; +}); + +foreach ($topLevelClosure() as $val) { +} + +include __DIR__ . '/../dd_dumper.inc'; +\dd_dump_spans(true); + +?> +--EXPECTF-- +spans(\DDTrace\SpanData) (1) { + {closure:%s.php:%d\{closure} (trace_generator_ge_php_84.php, {closure:%s.php:%d\{closure}, cli) + closure.declaration => %s:%d + result => 3 + _dd.p.tid => %s + (trace_generator_ge_php_84.php, cli) +} diff --git a/tests/ext/sandbox/install_hook/trace_generator_jit.phpt b/tests/ext/sandbox/install_hook/trace_generator_jit.phpt index 45736d3c19..78ff88113b 100644 --- a/tests/ext/sandbox/install_hook/trace_generator_jit.phpt +++ b/tests/ext/sandbox/install_hook/trace_generator_jit.phpt @@ -6,7 +6,7 @@ generator hooking works with JIT --INI-- opcache.enable=1 opcache.enable_cli = 1 -opcache.jit_buffer_size=512M +opcache.jit_buffer_size=128M opcache.jit=1255 zend_extension=opcache.so --FILE-- diff --git a/tests/ext/sandbox/safe_to_string_metadata.phpt b/tests/ext/sandbox/safe_to_string_metadata.phpt index 82b916a096..76cc84fb04 100644 --- a/tests/ext/sandbox/safe_to_string_metadata.phpt +++ b/tests/ext/sandbox/safe_to_string_metadata.phpt @@ -1,5 +1,11 @@ --TEST-- Span metadata is safely converted to strings without errors or exceptions +--SKIPIF-- += 80400) { + die('skip: test only stable on PHP < 8.4'); +} +?> --FILE-- = 8.4'); +} +?> +--FILE-- +format('Y-m-d'); + } +} + +function meta_to_string() {} + +DDTrace\trace_function('meta_to_string', function (SpanData $span, array $args) { + $span->name = 'MetaToString'; + $span->meta = []; + foreach ($args as $key => $arg) { + $span->meta['arg.' . $key] = $arg; + } +}); + +$allTheTypes = [ + ['recursive'], + 'already a string', + 42, + 4.2, + true, + false, + null, + function () {}, + new DateTime('2019-09-10'), + new MyDt('2019-09-10'), + ['foo' => 0], + ['bar' => [1, "key" => 2]], + fopen('php://memory', 'rb'), // resource + MY_STRING, + MY_INT, + MY_BOOL, + MyDt::CLASS_CONST_FLOAT, +]; +$allTheTypes[0][1] = &$allTheTypes[0]; + +call_user_func_array('meta_to_string', $allTheTypes); + +list($span) = dd_trace_serialize_closed_spans(); +unset($span['meta']['process_id']); +$last = -1; +foreach ($span['meta'] as $key => $value) { + $index = (int)substr($key, 4); + if ($last != $index) { + echo PHP_EOL; + if ($index == 0) { + unset($allTheTypes[$index][1]); // *RECURSION* is inconsistent across PHP versions + } + var_dump($allTheTypes[$index]); + $last = $index; + } + echo "$key: "; + var_dump($value); +} +?> +--EXPECTF-- + +array(1) { + [0]=> + string(9) "recursive" +} +arg.0.0: string(9) "recursive" +arg.0.1: string(0) "" + +string(16) "already a string" +arg.1: string(16) "already a string" + +int(42) +arg.2: string(2) "42" + +float(4.2) +arg.3: string(3) "4.2" + +bool(true) +arg.4: string(4) "true" + +bool(false) +arg.5: string(5) "false" + +NULL +arg.6: string(4) "null" + +object(Closure)#%d (3) { + ["name"]=> + string(%d) "{closure%s}" + ["file"]=> + string(%d) "%s" + ["line"]=> + int(%d) +} +arg.7: string(0) "" + +object(DateTime)#%d (3) { + ["date"]=> + string(26) "2019-09-10 00:00:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(3) "UTC" +} +arg.8.date: string(26) "2019-09-10 00:00:00.000000" +arg.8.timezone_type: string(1) "3" +arg.8.timezone: string(3) "UTC" + +object(MyDt)#%d (3) { + ["date"]=> + string(26) "2019-09-10 00:00:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(3) "UTC" +} +arg.9.date: string(26) "2019-09-10 00:00:00.000000" +arg.9.timezone_type: string(1) "3" +arg.9.timezone: string(3) "UTC" + +array(1) { + ["foo"]=> + int(0) +} +arg.10.foo: string(1) "0" + +array(1) { + ["bar"]=> + array(2) { + [0]=> + int(1) + ["key"]=> + int(2) + } +} +arg.11.bar.0: string(1) "1" +arg.11.bar.key: string(1) "2" + +resource(%d) of type (stream) +arg.12: string(%d) "Resource id #%d" + +string(17) "string from const" +arg.13: string(17) "string from const" + +int(42) +arg.14: string(2) "42" + +bool(true) +arg.15: string(4) "true" + +float(4.2) +arg.16: string(3) "4.2" diff --git a/tests/ext/startup_logging_skipif.inc b/tests/ext/startup_logging_skipif.inc index 7f3022d227..025e7532f3 100644 --- a/tests/ext/startup_logging_skipif.inc +++ b/tests/ext/startup_logging_skipif.inc @@ -2,3 +2,4 @@ include_once 'startup_logging.inc'; if (!dd_get_php_cgi()) die('skip: php-cgi SAPI required'); +if (PHP_VERSION_ID < 70200) die('skip: TEST_PHP_EXTRA_ARGS not available on PHP 7.0 and 7.1'); diff --git a/tests/opcache/basic.phpt b/tests/opcache/basic.phpt index e8b34e6bad..ba7d1cbff2 100644 --- a/tests/opcache/basic.phpt +++ b/tests/opcache/basic.phpt @@ -31,6 +31,10 @@ echo "Done."; ?> --EXPECT-- bool(true) +Executed negativeMethod +Executed negative_function +Executed negativeMethod NegativeClass::negative_method +Executed negative_function negative_function Done. diff --git a/tests/opcache/file_cache.phpt b/tests/opcache/file_cache.phpt index 6d5f3f77c1..94c43b6840 100644 --- a/tests/opcache/file_cache.phpt +++ b/tests/opcache/file_cache.phpt @@ -34,6 +34,10 @@ Datadog\negative_function(); echo "Done."; ?> --EXPECT-- +Executed negativeMethod +Executed negative_function +Executed negativeMethod NegativeClass::negative_method +Executed negative_function negative_function Done. diff --git a/tests/opcache/include.php b/tests/opcache/include.php index f227564fc6..7b33ad8d31 100644 --- a/tests/opcache/include.php +++ b/tests/opcache/include.php @@ -6,9 +6,11 @@ final class NegativeClass { public static function negativeMethod() { + echo "Executed negativeMethod\n"; } } function negative_function() { + echo "Executed negative_function\n"; } diff --git a/tests/opcache/preload.phpt b/tests/opcache/preload.phpt index 40fad34a9d..723060a63d 100644 --- a/tests/opcache/preload.phpt +++ b/tests/opcache/preload.phpt @@ -24,13 +24,17 @@ Datadog\negative_function(); echo "negative_function\n"; }); -// call again (should not be traced) +// call again Datadog\NegativeClass::negativeMethod(); Datadog\negative_function(); echo "Done."; ?> --EXPECT-- +Executed negativeMethod +Executed negative_function +Executed negativeMethod NegativeClass::negative_method +Executed negative_function negative_function Done. diff --git a/tests/opcache/protect_memory.phpt b/tests/opcache/protect_memory.phpt index be910f64f7..de2ebfc77a 100644 --- a/tests/opcache/protect_memory.phpt +++ b/tests/opcache/protect_memory.phpt @@ -32,6 +32,10 @@ echo "Done."; ?> --EXPECT-- bool(true) +Executed negativeMethod +Executed negative_function +Executed negativeMethod NegativeClass::negative_method +Executed negative_function negative_function Done. diff --git a/tests/opcache/resolver_cached.phpt b/tests/opcache/resolver_cached.phpt index 07cf65266a..e4ba530ee1 100644 --- a/tests/opcache/resolver_cached.phpt +++ b/tests/opcache/resolver_cached.phpt @@ -17,7 +17,11 @@ passthru($cmd); ?> --EXPECT-- +Executed negativeMethod NegativeClass::negative_method +Executed negative_function negative_function +Executed negativeMethod NegativeClass::negative_method +Executed negative_function negative_function diff --git a/tooling/bin/generate-final-artifact.sh b/tooling/bin/generate-final-artifact.sh index 7170826cc9..77334b6980 100755 --- a/tooling/bin/generate-final-artifact.sh +++ b/tooling/bin/generate-final-artifact.sh @@ -33,7 +33,7 @@ for architecture in "${architectures[@]}"; do tmp_folder_final_musl_trace=$tmp_folder_final_musl/dd-library-php/trace tmp_folder_final_windows_trace=$tmp_folder_final_windows/dd-library-php/trace - php_apis=(20190902 20200930 20210902 20220829 20230831) + php_apis=(20190902 20200930 20210902 20220829 20230831 20240924) if [[ -z ${DDTRACE_MAKE_PACKAGES_ASAN:-} ]]; then php_apis+=(20151012 20160303 20170718 20180731) fi @@ -67,7 +67,7 @@ for architecture in "${architectures[@]}"; do ######################## if [[ -z ${DDTRACE_MAKE_PACKAGES_ASAN:-} ]]; then # Extension - php_apis=(20160303 20170718 20180731 20190902 20200930 20210902 20220829 20230831) + php_apis=(20160303 20170718 20180731 20190902 20200930 20210902 20220829 20230831 20240924) for version in "${php_apis[@]}" do mkdir -v -p \ @@ -109,7 +109,7 @@ for architecture in "${architectures[@]}"; do tmp_folder_final_musl_appsec=$tmp_folder_final_musl/dd-library-php/appsec # Extensions - php_apis=(20151012 20160303 20170718 20180731 20190902 20200930 20210902 20220829 20230831); + php_apis=(20151012 20160303 20170718 20180731 20190902 20200930 20210902 20220829 20230831 20240924); for php_api in "${php_apis[@]}"; do mkdir -p \ ${tmp_folder_final_gnu_appsec}/ext/$php_api \ diff --git a/tooling/bin/generate-ssi-package.sh b/tooling/bin/generate-ssi-package.sh index 6d60d84f2c..99fbef708a 100755 --- a/tooling/bin/generate-ssi-package.sh +++ b/tooling/bin/generate-ssi-package.sh @@ -45,7 +45,7 @@ for architecture in "${architectures[@]}"; do # Trace ######################## - php_apis=(20151012 20160303 20170718 20180731 20190902 20200930 20210902 20220829 20230831) + php_apis=(20151012 20160303 20170718 20180731 20190902 20200930 20210902 20220829 20230831 20240924) for php_api in "${php_apis[@]}"; do mkdir -p ${gnu}/trace/ext/$php_api ${musl}/trace/ext/$php_api # gnu diff --git a/zend_abstract_interface/hook/tests/internal/request.cc b/zend_abstract_interface/hook/tests/internal/request.cc index dab0029c05..83da03d753 100644 --- a/zend_abstract_interface/hook/tests/internal/request.cc +++ b/zend_abstract_interface/hook/tests/internal/request.cc @@ -26,18 +26,18 @@ extern "C" { static zai_hook_test_fixed_t zai_hook_test_fixed_first = {42}; static zai_hook_test_fixed_t zai_hook_test_fixed_second = {42}; - static bool zai_hook_test_begin(zend_ulong invocation, zend_execute_data *ex, zai_hook_test_fixed_t *fixed, zai_hook_test_dynamic_t *dynamic) { + static bool zai_hook_test_begin(zend_ulong invocation, zend_execute_data *ex, void *fixed, void *dynamic) { zai_hook_test_begin_fixed = fixed; zai_hook_test_begin_dynamic = dynamic; - CHECK(dynamic->u == 0); + CHECK(((zai_hook_test_dynamic_t *)dynamic)->u == 0); zai_hook_test_begin_check++; return zai_hook_test_begin_return; } - static void zai_hook_test_end(zend_ulong invocation, zend_execute_data *ex, zval *rv, zai_hook_test_fixed_t *fixed, zai_hook_test_dynamic_t *dynamic) { + static void zai_hook_test_end(zend_ulong invocation, zend_execute_data *ex, zval *rv, void *fixed, void *dynamic) { zai_hook_test_end_fixed = fixed; zai_hook_test_end_dynamic = dynamic; @@ -336,7 +336,8 @@ HOOK_TEST_CASE("unresolved removal", { extern "C" { static zai_hook_test_dynamic_t zai_hook_add_test_begin_dynamic = {42}; - static bool zai_hook_test_hook_add_begin(zend_ulong invocation, zend_execute_data *ex, zai_hook_test_fixed_t *fixed, zai_hook_test_dynamic_t *dynamic) { + static bool zai_hook_test_hook_add_begin(zend_ulong invocation, zend_execute_data *ex, void *fixed, void *dynamic_ptr) { + zai_hook_test_dynamic_t *dynamic = (zai_hook_test_dynamic_t *)dynamic_ptr; CHECK(dynamic->u == 0); dynamic->u = 1; @@ -363,8 +364,8 @@ extern "C" { return true; } - static void zai_hook_test_hook_add_end(zend_ulong invocation, zend_execute_data *ex, zval *rv, zai_hook_test_fixed_t *fixed, zai_hook_test_dynamic_t *dynamic) { - zai_hook_add_test_begin_dynamic = *dynamic; + static void zai_hook_test_hook_add_end(zend_ulong invocation, zend_execute_data *ex, zval *rv, void *fixed, void *dynamic) { + zai_hook_add_test_begin_dynamic = *(zai_hook_test_dynamic_t *)dynamic; CHECK(zai_hook_test_end_check == 2); // called last zai_hook_test_end_check++; diff --git a/zend_abstract_interface/hook/tests/internal/static.cc b/zend_abstract_interface/hook/tests/internal/static.cc index 7d3fb35c2d..de2a1e4136 100644 --- a/zend_abstract_interface/hook/tests/internal/static.cc +++ b/zend_abstract_interface/hook/tests/internal/static.cc @@ -24,7 +24,7 @@ extern "C" { static zai_hook_test_fixed_t zai_hook_test_fixed_first = {42}; static zai_hook_test_fixed_t zai_hook_test_fixed_second = {42}; - static bool zai_hook_test_begin(zend_ulong invocation, zend_execute_data *ex, zai_hook_test_fixed_t *fixed, zai_hook_test_dynamic_t *dynamic) { + static bool zai_hook_test_begin(zend_ulong invocation, zend_execute_data *ex, void *fixed, void *dynamic) { zai_hook_test_begin_fixed = fixed; zai_hook_test_begin_dynamic = dynamic; @@ -33,7 +33,7 @@ extern "C" { return zai_hook_test_begin_return; } - static void zai_hook_test_end(zend_ulong invocation, zend_execute_data *ex, zval *rv, zai_hook_test_fixed_t *fixed, zai_hook_test_dynamic_t *dynamic) { + static void zai_hook_test_end(zend_ulong invocation, zend_execute_data *ex, zval *rv, void *fixed, void *dynamic) { zai_hook_test_end_fixed = fixed; zai_hook_test_end_dynamic = dynamic; diff --git a/zend_abstract_interface/interceptor/php7/interceptor.c b/zend_abstract_interface/interceptor/php7/interceptor.c index fe52e4a8f2..1f621d4051 100644 --- a/zend_abstract_interface/interceptor/php7/interceptor.c +++ b/zend_abstract_interface/interceptor/php7/interceptor.c @@ -526,7 +526,7 @@ static void zai_interceptor_execute_internal(zend_execute_data *execute_data, zv static zend_generator *zai_interceptor_get_original_executing_generator(zend_generator *gen) { if (gen->node.children) { - return (zend_generator *)(((char *)gen->execute_data->prev_execute_data) - (uintptr_t)(&((zend_generator*)0)->execute_fake)); + return (zend_generator *)(((char *)gen->execute_data->prev_execute_data) - (uintptr_t)XtOffsetOf(zend_generator, execute_fake)); } return gen; } @@ -1146,11 +1146,12 @@ void zai_interceptor_startup(zend_module_entry *module_entry) { prev_generator_resumption_handler = zend_get_user_opcode_handler(ZAI_INTERCEPTOR_GENERATOR_RESUMPTION_OP); zend_set_user_opcode_handler(ZAI_INTERCEPTOR_GENERATOR_RESUMPTION_OP, zai_interceptor_generator_resumption_handler); - generator_resumption_op_template.opcode = ZAI_INTERCEPTOR_GENERATOR_RESUMPTION_OP; + generator_resumption_op_template.opcode = ZEND_USER_OPCODE; SET_UNUSED(generator_resumption_op_template.result); SET_UNUSED(generator_resumption_op_template.op1); SET_UNUSED(generator_resumption_op_template.op2); ZEND_VM_SET_OPCODE_HANDLER(&generator_resumption_op_template); + generator_resumption_op_template.opcode = ZAI_INTERCEPTOR_GENERATOR_RESUMPTION_OP; prev_exception_hook = zend_throw_exception_hook; zend_throw_exception_hook = zai_interceptor_exception_hook; @@ -1171,16 +1172,18 @@ void zai_interceptor_startup(zend_module_entry *module_entry) { prev_generator_create_handler = zend_get_user_opcode_handler(ZEND_GENERATOR_CREATE); zend_set_user_opcode_handler(ZEND_GENERATOR_CREATE, zai_interceptor_generator_create_handler); - zai_interceptor_generator_create_wrapper[0].opcode = ZAI_INTERCEPTOR_POST_GENERATOR_CREATE_OP; + zai_interceptor_generator_create_wrapper[0].opcode = ZEND_USER_OPCODE; SET_UNUSED(zai_interceptor_generator_create_wrapper[0].result); SET_UNUSED(zai_interceptor_generator_create_wrapper[0].op1); SET_UNUSED(zai_interceptor_generator_create_wrapper[0].op2); ZEND_VM_SET_OPCODE_HANDLER(&zai_interceptor_generator_create_wrapper[0]); - zai_interceptor_generator_create_wrapper[1].opcode = ZAI_INTERCEPTOR_POST_GENERATOR_CREATE_OP; + zai_interceptor_generator_create_wrapper[0].opcode = ZAI_INTERCEPTOR_POST_GENERATOR_CREATE_OP; + zai_interceptor_generator_create_wrapper[1].opcode = ZEND_USER_OPCODE; SET_UNUSED(zai_interceptor_generator_create_wrapper[1].result); SET_UNUSED(zai_interceptor_generator_create_wrapper[1].op1); SET_UNUSED(zai_interceptor_generator_create_wrapper[1].op2); ZEND_VM_SET_OPCODE_HANDLER(&zai_interceptor_generator_create_wrapper[1]); + zai_interceptor_generator_create_wrapper[1].opcode = ZAI_INTERCEPTOR_POST_GENERATOR_CREATE_OP; #endif INIT_NS_CLASS_ENTRY(zai_interceptor_bailout_ce, "Zend Abstract Interface", "BailoutHandler", NULL); diff --git a/zend_abstract_interface/interceptor/php7/resolver.c b/zend_abstract_interface/interceptor/php7/resolver.c index 2515a1617c..b53c2d5044 100644 --- a/zend_abstract_interface/interceptor/php7/resolver.c +++ b/zend_abstract_interface/interceptor/php7/resolver.c @@ -355,8 +355,9 @@ void zai_interceptor_setup_resolving_post_startup(void) { SET_UNUSED(op->result); SET_UNUSED(op->op1); SET_UNUSED(op->op2); - op->opcode = ZAI_INTERCEPTOR_POST_DECLARE_OP; + op->opcode = ZEND_USER_OPCODE; ZEND_VM_SET_OPCODE_HANDLER(op); + op->opcode = ZAI_INTERCEPTOR_POST_DECLARE_OP; prev_exception_hook = zend_throw_exception_hook; zend_throw_exception_hook = zai_interceptor_exception_hook; diff --git a/zend_abstract_interface/interceptor/php8/interceptor.c b/zend_abstract_interface/interceptor/php8/interceptor.c index 699a475c27..b9e77f1f9c 100644 --- a/zend_abstract_interface/interceptor/php8/interceptor.c +++ b/zend_abstract_interface/interceptor/php8/interceptor.c @@ -13,7 +13,7 @@ # include #endif -#if 1 +#if PHP_VERSION_ID < 80400 int zai_registered_observers = 0; #endif @@ -44,8 +44,12 @@ static inline bool zai_hook_memory_table_del(zend_execute_data *index) { } #if defined(__x86_64__) || defined(__aarch64__) -# if defined(__GNUC__) && !defined(__clang__) +# if defined(__GNUC__) +# if defined(__clang__) +__attribute__((no_sanitize("address"))) +# else __attribute__((no_sanitize_address)) +# endif # endif static void zai_hook_safe_finish(zend_execute_data *execute_data, zval *retval, zai_frame_memory *frame_memory) { if (!CG(unclean_shutdown)) { @@ -64,21 +68,23 @@ static void zai_hook_safe_finish(zend_execute_data *execute_data, zval *retval, const size_t stack_size = 1 << 17; const size_t stack_top_offset = 0x400; void *volatile stack = malloc(stack_size); - if (SETJMP(target) == 0) { - void *stacktop = stack + stack_size; + void *stacktop = stack + stack_size; #if PHP_VERSION_ID >= 80300 - register + register void *volatile +#else + void * #endif - void *stacktarget = stacktop - stack_top_offset; + stacktarget = stacktop - stack_top_offset; #ifdef __SANITIZE_ADDRESS__ - void *volatile fake_stack; - __sanitizer_start_switch_fiber((void**) &fake_stack, stacktop, stack_size); + void *volatile fake_stack; + __sanitizer_start_switch_fiber((void**) &fake_stack, stacktop, stack_size); #define STACK_REG "5" #else #define STACK_REG "4" #endif + if (SETJMP(target) == 0) { register zend_execute_data *ex = execute_data; register zval *rv = retval; register zai_hook_memory_t *hook_data = &frame_memory->hook_data; @@ -89,11 +95,11 @@ static void zai_hook_safe_finish(zend_execute_data *execute_data, zval *retval, #if defined(__x86_64__) "mov %" STACK_REG ", %%rsp" #elif defined(__aarch64__) -#ifdef __SANITIZE_ADDRESS__ +#if defined(__SANITIZE_ADDRESS__) && !defined(__clang__) "ldr x7, [sp, #72]\n\t" // magic, but I have no idea what else to do here #endif "mov sp, %" STACK_REG "\n\t" -#ifdef __SANITIZE_ADDRESS__ +#if defined(__SANITIZE_ADDRESS__) && !defined(__clang__) "str x7, [sp, #72]" #endif #endif @@ -101,14 +107,18 @@ static void zai_hook_safe_finish(zend_execute_data *execute_data, zval *retval, #ifdef __SANITIZE_ADDRESS__ , "+r"(fake_stack) #endif +#if PHP_VERSION_ID >= 80300 + , "+r"(stacktarget) +#else : "r"(stacktarget) -#if defined(__SANITIZE_ADDRESS__) && defined(__aarch64__) +#endif +#if defined(__SANITIZE_ADDRESS__) && defined(__aarch64__) && !defined(__clang__) : "x7" #endif ); #ifdef __SANITIZE_ADDRESS__ - __sanitizer_finish_switch_fiber(fake_stack, &bottom, &capacity); + __sanitizer_finish_switch_fiber(NULL, &bottom, &capacity); #endif #if PHP_VERSION_ID >= 80300 @@ -116,7 +126,11 @@ static void zai_hook_safe_finish(zend_execute_data *execute_data, zval *retval, void *stack_limit = EG(stack_limit); EG(stack_base) = stacktarget; - EG(stack_limit) = (void*)((uintptr_t)stacktarget - stack_top_offset - EG(reserved_stack_size) * 2); + EG(stack_limit) = (void*)((uintptr_t)stacktarget - stack_top_offset +#ifdef ZEND_CHECK_STACK_LIMIT + - EG(reserved_stack_size) * 2 +#endif + ); #endif zai_hook_finish(ex, rv, hook_data); @@ -134,7 +148,7 @@ static void zai_hook_safe_finish(zend_execute_data *execute_data, zval *retval, } #ifdef __SANITIZE_ADDRESS__ - __sanitizer_finish_switch_fiber(NULL, &bottom, &capacity); + __sanitizer_finish_switch_fiber(fake_stack, &bottom, &capacity); #endif free(stack); @@ -329,8 +343,13 @@ void (*zai_interceptor_replace_observer)(zend_function *func, bool remove, zend_ void zai_interceptor_replace_observer(zend_function *func, bool remove, zend_observer_fcall_end_handler *next_end_handler); #endif +#if PHP_VERSION_ID < 80400 +#define ZAI_GENERATOR_YIELD_OFFSET (-1) +#else +#define ZAI_GENERATOR_YIELD_OFFSET 0 +#endif static void zai_interceptor_observer_generator_yield(zend_execute_data *ex, zval *retval, zend_generator *generator, zai_frame_memory *frame_memory) { - if (generator->execute_data && (generator->execute_data->opline - 1)->opcode == ZEND_YIELD_FROM) { + if (generator->execute_data && generator->execute_data->opline[ZAI_GENERATOR_YIELD_OFFSET].opcode == ZEND_YIELD_FROM) { // There are two cases here: // a) yield from array or iterator // Here we can just wrap the iterator or array into our custom iterator, transparently without observable side effects @@ -441,12 +460,12 @@ static inline zend_observer_fcall_handlers zai_interceptor_determine_handlers(ze #if PHP_VERSION_ID < 80200 #define ZEND_OBSERVER_DATA(function) \ ZEND_OP_ARRAY_EXTENSION((&(function)->op_array), zend_observer_fcall_op_array_extension) -#else +#elif PHP_VERSION_ID < 80400 #define ZEND_OBSERVER_DATA(function) \ ZEND_OP_ARRAY_EXTENSION((&(function)->common), zend_observer_fcall_op_array_extension) #endif -#if 1 +#if PHP_VERSION_ID < 80400 #define ZEND_OBSERVER_NOT_OBSERVED ((void *) 2) #if PHP_VERSION_ID < 80200 @@ -604,7 +623,7 @@ void zai_interceptor_replace_observer(zend_function *func, bool remove, zend_obs } #else void zai_interceptor_replace_observer(zend_function *func, bool remove, zend_observer_fcall_end_handler *next_end_handler) { - if (!ZEND_MAP_PTR(func->op_array.run_time_cache) || !RUN_TIME_CACHE(&func->common) || !ZEND_OBSERVER_DATA(func) || (func->common.fn_flags & ZEND_ACC_HEAP_RT_CACHE) != 0) { + if (!ZEND_MAP_PTR(func->op_array.run_time_cache) || !RUN_TIME_CACHE(&func->common) || !*ZEND_OBSERVER_DATA(func) || (func->common.fn_flags & ZEND_ACC_HEAP_RT_CACHE) != 0) { return; } @@ -616,9 +635,9 @@ void zai_interceptor_replace_observer(zend_function *func, bool remove, zend_obs zend_observer_fcall_handlers handlers = zai_interceptor_determine_handlers(func); if (remove) { - zend_observer_remove_begin_handler(func, handlers.begin); - zend_observer_remove_end_handler(func, handlers.end); - // TODO get next end_handler for PHP 8.4 + zend_observer_fcall_begin_handler next_begin; + zend_observer_remove_begin_handler(func, handlers.begin, &next_begin); + zend_observer_remove_end_handler(func, handlers.end, next_end_handler); } else { zend_observer_add_begin_handler(func, handlers.begin); zend_observer_add_end_handler(func, handlers.end); @@ -904,7 +923,7 @@ zend_result zai_interceptor_post_startup(void) { zai_hook_post_startup(); zai_interceptor_setup_resolving_post_startup(); -#if 1 +#if PHP_VERSION_ID < 80400 zai_registered_observers = (zend_op_array_extension_handles - zend_observer_fcall_op_array_extension) / 2; #endif diff --git a/zend_abstract_interface/jit_utils/jit_blacklist.c b/zend_abstract_interface/jit_utils/jit_blacklist.c index 50c07c6674..2cf685eaf5 100644 --- a/zend_abstract_interface/jit_utils/jit_blacklist.c +++ b/zend_abstract_interface/jit_utils/jit_blacklist.c @@ -9,6 +9,7 @@ #include #endif + #if PHP_VERSION_ID >= 80100 #include #else @@ -66,6 +67,7 @@ typedef struct _zend_func_info { } zend_func_info; #endif +#if PHP_VERSION_ID < 80400 typedef struct _zend_jit_op_array_trace_extension { zend_func_info func_info; const zend_op_array *op_array; @@ -86,6 +88,7 @@ typedef union _zend_op_trace_info { #define ZEND_OP_TRACE_INFO(opline, offset) \ ((zend_op_trace_info*)(((char*)opline) + offset)) +#endif #define ZEND_FUNC_INFO(op_array) \ ((zend_func_info*)((op_array)->reserved[zend_func_info_rid])) @@ -103,6 +106,19 @@ void zai_jit_minit(void) { zend_llist_apply(&zend_extensions, zai_jit_find_opcache_handle); } +#if PHP_VERSION_ID >= 80400 +void (*zai_jit_blacklist_function)(zend_op_array *), (*zai_jit_unprotect)(void); +static void zai_jit_fetch_symbols(void) { + if (!zai_jit_blacklist_function) { + ZEND_ASSERT(opcache_handle); // assert the handle is there is zend_func_info_rid != -1 + + zai_jit_blacklist_function = (void (*)(zend_op_array *)) DL_FETCH_SYMBOL(opcache_handle, "zend_jit_blacklist_function"); + if (zai_jit_blacklist_function == NULL) { + zai_jit_blacklist_function = (void (*)(zend_op_array *)) DL_FETCH_SYMBOL(opcache_handle, "_zend_jit_blacklist_function"); + } + } +} +#else void (*zai_jit_protect)(void), (*zai_jit_unprotect)(void); static void zai_jit_fetch_symbols(void) { if (!zai_jit_protect) { @@ -123,6 +139,7 @@ static void zai_jit_fetch_symbols(void) { static inline bool zai_is_func_recv_opcode(zend_uchar opcode) { return opcode == ZEND_RECV || opcode == ZEND_RECV_INIT || opcode == ZEND_RECV_VARIADIC; } +#endif #if PHP_VERSION_ID < 80100 static inline bool check_pointer_near(void *a, void *b) { @@ -162,6 +179,12 @@ int zai_get_zend_func_rid(zend_op_array *op_array) { } void zai_jit_blacklist_function_inlining(zend_op_array *op_array) { +#if PHP_VERSION_ID >= 80400 + if (opcache_handle) { + zai_jit_fetch_symbols(); + zai_jit_blacklist_function(op_array); + } +#else if (zai_get_zend_func_rid(op_array) < 0) { return; } @@ -230,4 +253,5 @@ void zai_jit_blacklist_function_inlining(zend_op_array *op_array) { #endif } } +#endif } diff --git a/zend_abstract_interface/sandbox/tests/error.cc b/zend_abstract_interface/sandbox/tests/error.cc index 6004207200..0333c0f240 100644 --- a/zend_abstract_interface/sandbox/tests/error.cc +++ b/zend_abstract_interface/sandbox/tests/error.cc @@ -23,7 +23,9 @@ static int fatal_errors[] = { static int non_fatal_errors[] = { E_DEPRECATED, E_NOTICE, - E_STRICT, +#if PHP_VERSION_ID < 80400 + E_STRICT, // deprecated in 8.4 +#endif E_USER_DEPRECATED, E_USER_NOTICE, }; diff --git a/zend_abstract_interface/symbols/call.c b/zend_abstract_interface/symbols/call.c index 4f70c0749f..07c90843f5 100644 --- a/zend_abstract_interface/symbols/call.c +++ b/zend_abstract_interface/symbols/call.c @@ -56,7 +56,11 @@ zend_execute_data *zai_set_observed_frame(zend_execute_data *execute_data) { size_t cache_size = zend_internal_run_time_cache_reserved_size(); void **rt_cache = ecalloc(cache_size, 1); // Set the begin handler to not observed and the end handler (where ever it is) to NULL (implicitly due to ecalloc) +#if PHP_VERSION_ID >= 80400 + rt_cache[zend_observer_fcall_internal_function_extension] = ZEND_OBSERVER_NOT_OBSERVED; +#else rt_cache[zend_observer_fcall_op_array_extension] = ZEND_OBSERVER_NOT_OBSERVED; +#endif ZEND_MAP_PTR_INIT(dummy_observable_func.op_array.run_time_cache, rt_cache); // We have a run_time cache with nothing observed, meaning no uncontrolled code will be executed now