Skip to content

Commit ef4fa59

Browse files
shivammathurarnaud-lbNattyNarwhalarshidkv12kocsismate
authored
Backport fixes for macOS 26 (#24031)
* Fix -Wdefault-const-init-field-unsafe with clang 21 (#21135) Fixes the following warning: Zend/zend_alloc.c:3469:18: error: default initialization of an object of type 'zend_mm_storage' (aka 'struct _zend_mm_storage') with const member leaves the object uninitialized [-Werror,-Wdefault-const-init-field-unsafe] 3469 | zend_mm_storage tmp_storage, *storage; | ^ Zend/zend_alloc.h:313:25: note: member 'handlers' declared 'const' here 313 | const zend_mm_handlers handlers; | ^ (cherry picked from commit 68a1062) * ext/standard: Use posix_spawn_file_actions_addchdir when available (#21553) posix_spawn_file_actions_addchdir is part of POSIX now, so some OSes (macOS at least) have started to deprecated the _np variant. Some support both names (Solaris, NetBSD), others don't yet (FreeBSD). Use the non-np variant when possible to avoid the deprecation warning on macOS and other platforms in the future. Fixes GH-21552 (cherry picked from commit c3a1214) * Fix GH-21720: macOS posix_spawn_file_actions_addchdir availability handling On Apple, select the addchdir variant by deployment target instead of the configure check: the link check passes whenever the SDK exports the symbol even if the running system is older, leaving a weakly linked reference that resolves to NULL at runtime and crashing proc_open() when $cwd is used. Closes GH-21722 (cherry picked from commit 8ce99bc) * Fix compilation errors up until Clang 21.0 (#22141) - The "pclmul" and "cldemote" CPU features are both only available on x86, and the relevant __builtin_cpu_supports() checks fail on Clang, so they shouldn't even be attempted to be run (similar fixes before: #18629). - The res.h file in Lexbor contains some unterminated strings (e.g. https://github.com/php/php-src/blob/d58d3d2fd6c1cfa7e3489a9859eda63086af762f/ext/lexbor/lexbor/html/tokenizer/res.h#L203), and a new compiler warning fails by default because of them. This needs to be suppressed. (cherry picked from commit a7aacec) * zend: ZEND_NONSTRING for clang >= 20 support (#19193) (cherry picked from commit e91d2c7) --------- Co-authored-by: Arnaud Le Blanc <365207+arnaud-lb@users.noreply.github.com> Co-authored-by: Calvin Buckley <calvinb@php.net> Co-authored-by: arshidkv12 <arshidkv12@gmail.com> Co-authored-by: Máté Kocsis <kocsismate@woohoolabs.com> Co-authored-by: David CARLIER <devnexen@gmail.com>
1 parent e50b8b0 commit ef4fa59

5 files changed

Lines changed: 28 additions & 9 deletions

File tree

‎Zend/zend_alloc.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,12 +3219,14 @@ ZEND_API zend_mm_heap *zend_mm_startup(void)
32193219
ZEND_API zend_mm_heap *zend_mm_startup_ex(const zend_mm_handlers *handlers, void *data, size_t data_size)
32203220
{
32213221
#if ZEND_MM_STORAGE
3222-
zend_mm_storage tmp_storage, *storage;
3222+
zend_mm_storage *storage;
3223+
zend_mm_storage tmp_storage = {
3224+
.handlers = *handlers,
3225+
.data = data,
3226+
};
32233227
zend_mm_chunk *chunk;
32243228
zend_mm_heap *heap;
32253229

3226-
memcpy((zend_mm_handlers*)&tmp_storage.handlers, handlers, sizeof(zend_mm_handlers));
3227-
tmp_storage.data = data;
32283230
chunk = (zend_mm_chunk*)handlers->chunk_alloc(&tmp_storage, ZEND_MM_CHUNK_SIZE, ZEND_MM_CHUNK_SIZE);
32293231
if (UNEXPECTED(chunk == NULL)) {
32303232
#if ZEND_MM_ERROR

‎ext/dom/config.m4‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if test "$PHP_DOM" != "no"; then
88
PHP_SETUP_LIBXML([DOM_SHARED_LIBADD], [
99
AC_DEFINE([HAVE_DOM], [1],
1010
[Define to 1 if the PHP extension 'dom' is available.])
11-
PHP_LEXBOR_CFLAGS="-I@ext_srcdir@/lexbor -DLEXBOR_STATIC"
11+
PHP_LEXBOR_CFLAGS="-Wno-unknown-warning-option -Wno-unterminated-string-initialization -I@ext_srcdir@/lexbor -DLEXBOR_STATIC"
1212
LEXBOR_DIR="lexbor/lexbor"
1313
LEXBOR_SOURCES=m4_normalize(["
1414
$LEXBOR_DIR/core/array_obj.c

‎ext/fileinfo/libmagic/apprentice.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ file_private struct {
184184
{ NULL, 0, NULL }
185185
};
186186

187-
#if __has_attribute(nonstring) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 15
187+
#if __has_attribute(nonstring) && defined(__GNUC__) && ((!defined(__clang__) && __GNUC__ >= 15) || (defined(__clang_major__) && __clang_major__ >= 20))
188188
# define ZEND_NONSTRING __attribute__((nonstring))
189189
#else
190190
# define ZEND_NONSTRING

‎ext/standard/config.m4‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ dnl
328328

329329
PHP_CHECK_FUNC(res_search, resolv, socket)
330330

331-
AC_CHECK_FUNCS([posix_spawn_file_actions_addchdir_np elf_aux_info])
331+
AC_CHECK_FUNCS([posix_spawn_file_actions_addchdir posix_spawn_file_actions_addchdir_np elf_aux_info])
332332

333333
dnl
334334
dnl Obsolete check for strptime() declaration. The strptime, where available,

‎ext/standard/proc_open.c‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include <fcntl.h>
3636
#endif
3737

38-
#ifdef HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR_NP
38+
#if defined(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR_NP) || defined(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)
3939
/* Only defined on glibc >= 2.29, FreeBSD CURRENT, musl >= 1.1.24,
4040
* MacOS Catalina or later..
4141
* It should be posible to modify this so it is also
@@ -44,7 +44,24 @@
4444
* to be really buggy.
4545
*/
4646
#include <spawn.h>
47+
#ifdef __APPLE__
48+
#include <AvailabilityMacros.h>
49+
#endif
4750
#define USE_POSIX_SPAWN
51+
52+
/* The non-_np variant is in macOS 26 (and _np deprecated). On Apple, it has to be selected by the
53+
* deployment target rather than the configure check: the link check passes whenever the SDK
54+
* exports the symbol even if the running system is older, in which case the weakly linked
55+
* reference resolves to NULL at runtime. */
56+
#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 260000
57+
#define POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR posix_spawn_file_actions_addchdir
58+
#elif defined(__APPLE__)
59+
#define POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR posix_spawn_file_actions_addchdir_np
60+
#elif defined(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)
61+
#define POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR posix_spawn_file_actions_addchdir
62+
#else
63+
#define POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR posix_spawn_file_actions_addchdir_np
64+
#endif
4865
#endif
4966

5067
/* This symbol is defined in ext/standard/config.m4.
@@ -1391,9 +1408,9 @@ PHP_FUNCTION(proc_open)
13911408
}
13921409

13931410
if (cwd) {
1394-
r = posix_spawn_file_actions_addchdir_np(&factions, cwd);
1411+
r = POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR(&factions, cwd);
13951412
if (r != 0) {
1396-
php_error_docref(NULL, E_WARNING, "posix_spawn_file_actions_addchdir_np() failed: %s", strerror(r));
1413+
php_error_docref(NULL, E_WARNING, ZEND_TOSTR(POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR) "() failed: %s", strerror(r));
13971414
}
13981415
}
13991416

0 commit comments

Comments
 (0)