Skip to content

🎉 New Feature: Add ASAN/UBSan PHP versions#20

Open
realFlowControl wants to merge 5 commits into
shivammathur:mainfrom
realFlowControl:florian/asan
Open

🎉 New Feature: Add ASAN/UBSan PHP versions#20
realFlowControl wants to merge 5 commits into
shivammathur:mainfrom
realFlowControl:florian/asan

Conversation

@realFlowControl

@realFlowControl realFlowControl commented Jan 8, 2026

Copy link
Copy Markdown

Related discussion: see PHP Foundation Slack

Description

This PR adds building of ASAN versions to PHP 8.0+

@realFlowControl realFlowControl marked this pull request as ready for review January 8, 2026 16:29
@realFlowControl

Copy link
Copy Markdown
Author

@shivammathur are you able to retry the two failing tests? It looks like they are unrelated to the PR itself

@shivammathur

Copy link
Copy Markdown
Owner

@realFlowControl

Looks like some extension is reporting leaks, but the logs do not show which one.
https://github.com/shivammathur/php-builder/actions/runs/20817146145/job/59838526006?pr=20#step:7:155

@shivammathur shivammathur force-pushed the main branch 3 times, most recently from f502151 to ea4758d Compare March 15, 2026 03:32
@shivammathur shivammathur force-pushed the main branch 23 times, most recently from dfb86f7 to f6d7b12 Compare April 29, 2026 08:52
@shivammathur shivammathur force-pushed the main branch 6 times, most recently from f7adefd to dda0407 Compare April 29, 2026 19:11
@realFlowControl realFlowControl force-pushed the florian/asan branch 2 times, most recently from 819fd04 to a765035 Compare May 20, 2026 11:28
@realFlowControl

Copy link
Copy Markdown
Author

@shivammathur I think I have it, could you trigger CI again for this PR?

@shivammathur shivammathur force-pushed the florian/asan branch 2 times, most recently from af31876 to 69808da Compare May 20, 2026 12:43
@realFlowControl

realFlowControl commented May 20, 2026

Copy link
Copy Markdown
Author

Looks like there is an ODR violation in PHP ... I'll have a look later this week.
Thanks for restarting the CI, we are pretty close I sense 😉

https://github.com/shivammathur/php-builder/actions/runs/26163595733/job/76987312204?pr=20#step:12:17

==243628==ERROR: AddressSanitizer: odr-violation (0xfffa38b5ffe0):
  [1] size=24 'g_sqlsrv_stream_wrapper' /tmp/sqlsrv-5.13.1/shared/core_stream.cpp:312:20 in /usr/lib/php/20250926/sqlsrv.so
  [2] size=24 'g_sqlsrv_stream_wrapper' /tmp/pdo_sqlsrv-5.13.1/shared/core_stream.cpp:312:20 in /usr/lib/php/20250926/pdo_sqlsrv.so
These globals were registered at these points:
  [1]:
    #0 0xfffa4bb92420 in __asan_register_globals ../../../../src/libsanitizer/asan/asan_globals.cpp:350
    #1 0xfffa4c26bb10  (/lib/ld-linux-aarch64.so.1+0x4b10) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #2 0xfffa4c26bc20  (/lib/ld-linux-aarch64.so.1+0x4c20) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #3 0xfffa4c2683ac in _dl_catch_exception (/lib/ld-linux-aarch64.so.1+0x13ac) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #4 0xfffa4c271d18  (/lib/ld-linux-aarch64.so.1+0xad18) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #5 0xfffa4c268338 in _dl_catch_exception (/lib/ld-linux-aarch64.so.1+0x1338) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #6 0xfffa4c272118  (/lib/ld-linux-aarch64.so.1+0xb118) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #7 0xfffa4aa01570  (/lib/aarch64-linux-gnu/libc.so.6+0x81570) (BuildId: d5ef86dde36cbd3289566cf5098226035d76f2e1)
    #8 0xfffa4c268338 in _dl_catch_exception (/lib/ld-linux-aarch64.so.1+0x1338) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #9 0xfffa4c268458  (/lib/ld-linux-aarch64.so.1+0x1458) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #10 0xfffa4aa00ff0  (/lib/aarch64-linux-gnu/libc.so.6+0x80ff0) (BuildId: d5ef86dde36cbd3289566cf5098226035d76f2e1)
    #11 0xfffa4aa0164c in dlopen (/lib/aarch64-linux-gnu/libc.so.6+0x8164c) (BuildId: d5ef86dde36cbd3289566cf5098226035d76f2e1)
    #12 0xfffa4bbb9320 in dlopen ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:6341
    #13 0xab135b8caed8 in php_load_shlib /tmp/php-build/source/8.6/ext/standard/dl.c:86
    #14 0xab135b8cb094 in php_load_extension /tmp/php-build/source/8.6/ext/standard/dl.c:150
    #15 0xab135c776800 in zend_llist_apply /tmp/php-build/source/8.6/Zend/zend_llist.c:182
    #16 0xab135bc4407c in php_ini_register_extensions /tmp/php-build/source/8.6/main/php_ini.c:743
    #17 0xab135bc25208 in php_module_startup /tmp/php-build/source/8.6/main/main.c:2357
    #18 0xab135aa498f8 in main /tmp/php-build/source/8.6/sapi/cli/php_cli.c:1337
    #19 0xfffa4a9a84c0  (/lib/aarch64-linux-gnu/libc.so.6+0x284c0) (BuildId: d5ef86dde36cbd3289566cf5098226035d76f2e1)
    #20 0xfffa4a9a8594 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28594) (BuildId: d5ef86dde36cbd3289566cf5098226035d76f2e1)
    #21 0xab135aa49f6c in _start (/usr/bin/php8.6+0x3649f6c) (BuildId: 6b4968badf03bc648c3e5ace4137468cb6600697)

  [2]:
    #0 0xfffa4bb92420 in __asan_register_globals ../../../../src/libsanitizer/asan/asan_globals.cpp:350
    #1 0xfffa4c26bb10  (/lib/ld-linux-aarch64.so.1+0x4b10) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #2 0xfffa4c26bc20  (/lib/ld-linux-aarch64.so.1+0x4c20) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #3 0xfffa4c2683ac in _dl_catch_exception (/lib/ld-linux-aarch64.so.1+0x13ac) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #4 0xfffa4c271d18  (/lib/ld-linux-aarch64.so.1+0xad18) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #5 0xfffa4c268338 in _dl_catch_exception (/lib/ld-linux-aarch64.so.1+0x1338) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #6 0xfffa4c272118  (/lib/ld-linux-aarch64.so.1+0xb118) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #7 0xfffa4aa01570  (/lib/aarch64-linux-gnu/libc.so.6+0x81570) (BuildId: d5ef86dde36cbd3289566cf5098226035d76f2e1)
    #8 0xfffa4c268338 in _dl_catch_exception (/lib/ld-linux-aarch64.so.1+0x1338) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #9 0xfffa4c268458  (/lib/ld-linux-aarch64.so.1+0x1458) (BuildId: f3d28c5cab7887a8195f6b130d76b8faf126b168)
    #10 0xfffa4aa00ff0  (/lib/aarch64-linux-gnu/libc.so.6+0x80ff0) (BuildId: d5ef86dde36cbd3289566cf5098226035d76f2e1)
    #11 0xfffa4aa0164c in dlopen (/lib/aarch64-linux-gnu/libc.so.6+0x8164c) (BuildId: d5ef86dde36cbd3289566cf5098226035d76f2e1)
    #12 0xfffa4bbb9320 in dlopen ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:6341
    #13 0xab135b8caed8 in php_load_shlib /tmp/php-build/source/8.6/ext/standard/dl.c:86
    #14 0xab135b8cb094 in php_load_extension /tmp/php-build/source/8.6/ext/standard/dl.c:150
    #15 0xab135c776800 in zend_llist_apply /tmp/php-build/source/8.6/Zend/zend_llist.c:182
    #16 0xab135bc4407c in php_ini_register_extensions /tmp/php-build/source/8.6/main/php_ini.c:743
    #17 0xab135bc25208 in php_module_startup /tmp/php-build/source/8.6/main/main.c:2357
    #18 0xab135aa498f8 in main /tmp/php-build/source/8.6/sapi/cli/php_cli.c:1337
    #19 0xfffa4a9a84c0  (/lib/aarch64-linux-gnu/libc.so.6+0x284c0) (BuildId: d5ef86dde36cbd3289566cf5098226035d76f2e1)
    #20 0xfffa4a9a8594 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28594) (BuildId: d5ef86dde36cbd3289566cf5098226035d76f2e1)
    #21 0xab135aa49f6c in _start (/usr/bin/php8.6+0x3649f6c) (BuildId: 6b4968badf03bc648c3e5ace4137468cb6600697)

==243628==HINT: if you don't care about these errors you may set ASAN_OPTIONS=detect_odr_violation=0
SUMMARY: AddressSanitizer: odr-violation: global 'g_sqlsrv_stream_wrapper' at /tmp/sqlsrv-5.13.1/shared/core_stream.cpp:312:20 in /usr/lib/php/20250926/sqlsrv.so
==243628==ABORTING

@realFlowControl

Copy link
Copy Markdown
Author

I guess there is not anything we can do against this ODR violation, I added a suppression rule that should push us passed this problem. I'll analyze if this is actually a problem, I doubt it. It is a side product of pdo_sqlsrv and sqlsrv extensions both embedding the same shared shared/core_stream.cpp file from upstream.

Could you re-trigger the CI please?

@realFlowControl

Copy link
Copy Markdown
Author

I created an upstream issue for the ODR violation: microsoft/msphpsql#1632

Comment thread scripts/get-matrix.sh
Comment thread .github/workflows/build.yml Outdated
Comment thread scripts/build.sh
@realFlowControl

Copy link
Copy Markdown
Author

@shivammathur could you give that CI job a bump please

@realFlowControl

Copy link
Copy Markdown
Author

And another one here, sorry 😞

@shivammathur

Copy link
Copy Markdown
Owner

I have run it again, I will try to have a look why this is flaky this weekend.

On systemd runners (github-test), `service php-fpm restart` is handled
by systemd, which starts php-fpm.service without the ASAN env vars that
test_sapi.sh writes to /etc/default/php-fpm<ver>. php-fpm then runs with
ASAN defaults (detect_leaks=1, detect_odr_violation=2) and aborts, so
Apache/nginx get no FastCGI backend and the SAPI check fails.

Write a systemd drop-in with ASAN_OPTIONS/UBSAN_OPTIONS/ZEND_DONT_UNLOAD_MODULES
and reload the daemon so the systemd-managed php-fpm picks them up, and
wrap switch_sapi with a timeout to guard against a php-fpm start hang.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants