Skip to content

Commit 9f9d614

Browse files
committed
Sync up posix_spawn_file_actions_addchdir_polyfill implementation between llbuild1 and llbuild3
1 parent fd935d3 commit 9f9d614

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

lib/Basic/Subprocess.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,17 @@ static bool posix_spawn_file_actions_addchdir_supported() {
355355
// Implementation mostly copied from _CFPosixSpawnFileActionsChdir in swift-corelibs-foundation
356356
static int posix_spawn_file_actions_addchdir_polyfill(posix_spawn_file_actions_t * __restrict file_actions,
357357
const char * __restrict path) {
358-
#if (defined(__GLIBC__) && !__GLIBC_PREREQ(2, 29)) || (defined(__OpenBSD__)) || (defined(__ANDROID__) && __ANDROID_API__ < 34) || (defined(__QNX__))
358+
#if defined(__GLIBC__) && !__GLIBC_PREREQ(2, 29)
359359
// Glibc versions prior to 2.29 don't support posix_spawn_file_actions_addchdir_np, impacting:
360360
// - Amazon Linux 2 (EoL mid-2025)
361+
return ENOSYS;
362+
#elif defined(__ANDROID__) && __ANDROID_API__ < 34
363+
// Android versions prior to 14 (API level 34) don't support posix_spawn_file_actions_addchdir_np
364+
return ENOSYS;
365+
#elif defined(__OpenBSD__) || defined(__QNX__)
361366
// Currently missing as of:
362367
// - OpenBSD 7.5 (April 2024)
363368
// - QNX 8 (December 2023)
364-
// - Android <= 14
365369
return ENOSYS;
366370
#elif defined(__APPLE__) && defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
367371
// Conditionally available on macOS if building with a deployment target older than 10.15

src/llbuild3/LocalExecutor.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,27 @@ int pthread_fchdir_np(int fd)
9494

9595
#if !defined(_WIN32) && defined(HAVE_POSIX_SPAWN)
9696
// Implementation mostly copied from _CFPosixSpawnFileActionsChdir in swift-corelibs-foundation
97-
static int posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t * __restrict file_actions,
98-
const char * __restrict path) {
97+
static int posix_spawn_file_actions_addchdir_polyfill(posix_spawn_file_actions_t * __restrict file_actions,
98+
const char * __restrict path) {
9999
#if defined(__GLIBC__) && !__GLIBC_PREREQ(2, 29)
100100
// Glibc versions prior to 2.29 don't support posix_spawn_file_actions_addchdir_np, impacting:
101101
// - Amazon Linux 2 (EoL mid-2025)
102102
return ENOSYS;
103+
#elif defined(__ANDROID__) && __ANDROID_API__ < 34
104+
// Android versions prior to 14 (API level 34) don't support posix_spawn_file_actions_addchdir_np
105+
return ENOSYS;
106+
#elif defined(__OpenBSD__) || defined(__QNX__)
107+
// Currently missing as of:
108+
// - OpenBSD 7.5 (April 2024)
109+
// - QNX 8 (December 2023)
110+
return ENOSYS;
103111
#elif defined(__APPLE__) && defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
104112
// Conditionally available on macOS if building with a deployment target older than 10.15
105113
if (__builtin_available(macOS 10.15, *)) {
106114
return posix_spawn_file_actions_addchdir_np(file_actions, path);
107115
}
108116
return ENOSYS;
109-
#elif defined(__OpenBSD__)
110-
// Currently missing as of:
111-
// - OpenBSD 7.5 (April 2024)
112-
return ENOSYS;
113-
#elif defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) || (defined(__ANDROID__) && __ANDROID_API__ >= 34) || defined(__musl__)
117+
#elif defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__ANDROID__) || defined(__musl__)
114118
// Pre-standard posix_spawn_file_actions_addchdir_np version available in:
115119
// - Solaris 11.3 (October 2015)
116120
// - Glibc 2.29 (February 2019)
@@ -123,7 +127,6 @@ static int posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t * __rest
123127
// Standardized posix_spawn_file_actions_addchdir version (POSIX.1-2024, June 2024) available in:
124128
// - Solaris 11.4 (August 2018)
125129
// - NetBSD 10.0 (March 2024)
126-
// - QNX 8 (December 2023)
127130
return posix_spawn_file_actions_addchdir((posix_spawn_file_actions_t *)file_actions, path);
128131
#endif
129132
}
@@ -1106,7 +1109,7 @@ void spawnProcess(
11061109
bool usePosixSpawnChdirFallback = true;
11071110
const auto workingDir = attr.workingDir;
11081111
if (!workingDir.empty() &&
1109-
posix_spawn_file_actions_addchdir(&fileActions, workingDir.c_str()) != ENOSYS) {
1112+
posix_spawn_file_actions_addchdir_polyfill(&fileActions, workingDir.c_str()) != ENOSYS) {
11101113
usePosixSpawnChdirFallback = false;
11111114
}
11121115

0 commit comments

Comments
 (0)