Adverse ABIs
After last week's release candidate I started receiving some bug reports that Xdebug nearly instantaneously crashed PHP. Upon further investigation, it turned out to only be a problem on macOS, which is good as that's not affecting everybody, but bad as I don't have a macOS machine to try to reproduce things on.
I did some screen sharing with Frédéric Marand in order to dive down what the problem was, but we couldn't really get to the problem. It looked like there was nothing really wrong, until Xdebug called the php_addslashes C function (which is the internal implementation of addslashes). This matched the exact same location as David Vuorio showed in his stack trace in the bug tracker.
Still tearing my hairs out, I contacted Nikita Popov to see if he knew whether there was anything special about php_addslashes. His reply:
And his suspicion turned out to be right.
PHP 7.3 has received many optimisations. One of them is the use of specific CPU instructions to speed up certain tasks. In this case, the PCMPESTRM instruction is used to find whether a string has characters that need to be escaped.
Upon build time, PHP's ./configure script checks whether the CPU it is built on supports these newer CPU instructions. If so, it then uses some header magic to use a specialised version of php_addslashes. This works fine if both PHP and the extension that uses php_addslashes are compiled on the same machine. However, if PHP is compiled on a machine without support, and the extension (Xdebug) is compiled on a machine with support, then the ABI (calling convention) of the php_addslashes C function is different. A crash will then occur when the extension tries to call the PHP php_addslashes function "in the wrong way". And that is exactly what happened here: the PHP binary that came from Homebrew uses a different ABI then the Xdebug binary that users compiled themselves. Modifying the installed headers made the problem go away.
Nikita soon fixed this in the PHP 7.3 branch with a hack to make sure that the ABI among PHP 7.3 versions stays the same, and a proper fix for PHP 7.4 and later to prevent this situation from occurring in the feature. Xdebug works around it for PHP 7.3.0 and PHP 7.3.1. Instead of relying on PHP's implementation of php_addslashes (xdebug_add_slashes), it uses its own. It also uses its own implementations of php_base64_encode and php_base64_decode which exhibit a similar issue. As Xdebug's implementations are slightly modified to work better for Xdebug, there is a minimal performance improvement too.
Time for Release Candidate 2!
Life Line
Merge branch 'xdebug_3_5'
Merged pull request #1060
Style fixes, and make log message type and text consistent
Fixed issue #2395: Change Windows Named Pipe control socket implement…
I've just finished reading "Children of Ruin", by Adrian Tchaikovsky.
The second book in the series, following Children of Time (the one with the spiders).
Great read, but a little creepy at times.
I walked 8.4km in 1h21m38s
Merged pull request #1061
Pin PHPStan version
I walked 9.3km in 1h32m07s
I've just put the first event in my calendar for... 2027.
Looking forwards to seeing a match in the snooker Masters at Ally Pally!
Under the Waterloo station arches at Leake Street.
This specific area is set aside for grafity artists.
RE: https://phpc.social/@phpc_tv/115917245540319542
This means you can now follow @xdebug from Mastodon too!
I walked 9.0km in 1h30m55s
I hiked 18.2km in 3h39m00s
Created a bar and an events_venue; Deleted a pub
Updated a restaurant; Deleted a clothes shop
I walked 8.5km in 1h22m28s
I walked 5.0km in 47m19s
Added Trogolo, and fixed duplicated addresses
I've finished my first book of the year, The Basic Soldering Guide Handbook.
Now I "just" need to put the learned knowledge into practise.
I walked 1.8km in 19m57s
Merged pull request #1058
Sort Xdebug modes in particular order, change performance label






Shortlink
This article has a short URL available: https://drck.me/abi-woes-eq2