[php-src] PR #18629: Fix build on Apple Clang 17+
| From: | kocsismate | Date: | Fri, 23 May 2025 21:33:29 +0000 |
| Subject: | [php-src] PR #18629: Fix build on Apple Clang 17+ | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-31767@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/18629
Author: kocsismate
After upgrading my Xcode version, I got the following compilation errors:
```
In file included from php-src/ext/hash/hash_sha.c:20:
php-src/Zend/zend_cpuinfo.h:133:9: error: invalid cpu feature string for builtin [-Werror]
133 | return __builtin_cpu_supports("sse2");
| ^ ~~~~~~
php-src/Zend/zend_cpuinfo.h:141:9: error: invalid cpu feature string for builtin [-Werror]
141 | return __builtin_cpu_supports("sse3");
| ^ ~~~~~~
php-src/Zend/zend_cpuinfo.h:149:9: error: invalid cpu feature string for builtin [-Werror]
149 | return __builtin_cpu_supports("ssse3");
| ^ ~~~~~~~
php-src/Zend/zend_cpuinfo.h:157:9: error: invalid cpu feature string for builtin [-Werror]
157 | return __builtin_cpu_supports("sse4.1");
| ^ ~~~~~~~~
php-src/Zend/zend_cpuinfo.h:165:9: error: invalid cpu feature string for builtin [-Werror]
165 | return __builtin_cpu_supports("sse4.2");
| ^ ~~~~~~~~
php-src/Zend/zend_cpuinfo.h:173:9: error: invalid cpu feature string for builtin [-Werror]
173 | return __builtin_cpu_supports("avx");
| ^ ~~~~~
php-src/Zend/zend_cpuinfo.h:181:9: error: invalid cpu feature string for builtin [-Werror]
181 | return __builtin_cpu_supports("avx2");
```
In order to fix the errors, I added some preprocessor conditions that skip calling
__builtin_cpu_supports with the unsupported features on an Apple ARM when using Apple
Clang.
Alternatively, I could have used a configure script based approach (probably similarly to https://github.com/php/php-src/blob/a191e7a4b145afd86e5c5caddc66772d007c9c08/build/php.m4#L2458),
but I didn't really know how to implement a similar check there... So at last I sticked with
the original, maybe less elegant solution.