Skip to content

Fix macOS posix_spawn_file_actions_addchdir availability handling#21722

Open
arshidkv12 wants to merge 6 commits into
php:masterfrom
arshidkv12:mac
Open

Fix macOS posix_spawn_file_actions_addchdir availability handling#21722
arshidkv12 wants to merge 6 commits into
php:masterfrom
arshidkv12:mac

Conversation

@arshidkv12
Copy link
Copy Markdown
Contributor

Comment thread ext/standard/proc_open.c Outdated
/* The non-_np variant is in macOS 26 (and _np deprecated) */
#ifdef HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR
#define POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR posix_spawn_file_actions_addchdir
static inline int php_spawn_addchdir(
Copy link
Copy Markdown
Member

@NattyNarwhal NattyNarwhal Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be able to be simplified by checking __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__/__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ instead, since we don't need any real runtime differences, it's just a symbol name, and the old one is unlikely to go away right now even if it's deprecated. It should respect -mmacosx-version-min as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@NattyNarwhal
Copy link
Copy Markdown
Member

Still triggers the deprecation on 26;

/Users/calvin/src/php-src/ext/standard/proc_open.c:1409:7: error: 'posix_spawn_file_actions_addchdir_np' is deprecated: first deprecated in macOS
      26.0 - posix_spawn_file_actions_addchdir(3) has replaced posix_spawn_file_actions_addchdir_np(3) [-Werror,-Wdeprecated-declarations]
 1409 |                 r = POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR(&factions, cwd);
      |                     ^
/Users/calvin/src/php-src/ext/standard/proc_open.c:53:44: note: expanded from macro 'POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR'
   53 |         #define POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR posix_spawn_file_actions_addchdir_np
      |                                                   ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/spawn.h:182:9: note: 
      'posix_spawn_file_actions_addchdir_np' has been explicitly marked deprecated here
  182 | int     posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *,
      |         ^

I think you need the AvailabilityMacros.h header to use the unembellished macro names:

calvin@anika-5 php-src % echo | cc -dM -E -mmacosx-version-min=10.15 - | grep MAC_OS_X_VERSION_MIN_REQUIRED
#define __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 101500
calvin@anika-5 php-src % echo "#include <AvailabilityMacros.h>" | cc -dM -E -mmacosx-version-min=10.15 - | grep MAC_OS_X_VERSION_MIN_REQUIRED
#define MAC_OS_X_VERSION_MIN_REQUIRED __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
#define __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 101500
#define __MAC_OS_X_VERSION_MIN_REQUIRED __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__

@NattyNarwhal
Copy link
Copy Markdown
Member

Builds with -enable-werror for me on 26 (well, and -Wno-unterminated-string-initialization, but that's a lexbor thing).

@arshidkv12
Copy link
Copy Markdown
Contributor Author

Please check it

@NickSdot
Copy link
Copy Markdown
Contributor

I can reproduce this, and tested this PR's patch locally: it fixes the crash for me.

Environment:

  • macOS 15.7.3 (24G419)
  • arm64
  • Xcode 26.3 (Build version 17C529)
printf '#include <AvailabilityMacros.h>\nMAC_OS_X_VERSION_MIN_REQUIRED\n' | cc -E - | tail -n 1
150000
➜ nm -gU /usr/lib/system/libsystem_kernel.dylib | rg posix_spawn_file_actions_addchdir
0000000000015318 T _posix_spawn_file_actions_addchdir_np
➜ nm -m sapi/cli/php | grep posix_spawn_file_actions_addchdir
(undefined) external _posix_spawn_file_actions_addchdir_np (from libSystem)

Agent Feedback

I first hit this through the PHPT runner, which segfaulted immediately, but I was also able to reduce it to a minimal proc_open() repro:

<?php
echo "before\n";
$spec = [
    0 => ["pipe", "r"],
    1 => ["pipe", "w"],
    2 => ["pipe", "w"],
];
proc_open(["/bin/echo", "ok"], $spec, $pipes, getcwd(), []);
echo "after\n";

With current upstream proc_open.c, this prints:

before

and then segfaults.

From what I can tell, this started after commit c3a1214 (ext/standard: Use posix_spawn_file_actions_addchdir when available), which prefers posix_spawn_file_actions_addchdir() when the SDK advertises it.

With this PR's fix applied and rebuilt it works. On my setup that selects posix_spawn_file_actions_addchdir_np for MAC_OS_X_VERSION_MIN_REQUIRED == 150000, and the crash goes away:

  • the minimal proc_open() repro prints before / after
  • the PHPT runner works again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants