Skip to content

Commit 2229d52

Browse files
committed
gnugrep: iOS stackvma stub for vendored gnulib
gnugrep bundles gnulib's lib/stackvma.c, which introspects Mach VM regions to implement stack-overflow detection for libsigsegv. Its platform gate `#if defined __APPLE__ && defined __MACH__` fires on both macOS and iOS, but the macOS arm includes `<libc.h>` and `<nlist.h>` — BSD convenience headers Xcode ships on macOS only. Note: `<libc.h>` here is a macOS-specific grab-bag header that re-exports misc BSD extensions, *not* the standard C library (`<stdlib.h>`, `<string.h>`, etc., which iOS ships normally). `--without-libsigsegv-prefix` only disables linking against external libsigsegv; it doesn't exclude the vendored stackvma from the build. Replace stackvma.c with a stub `sigsegv_get_vma` returning -1 ("no info"). iOS sandboxes forbid mach task/vm introspection anyway, so stack-overflow detection would never work there; the stub matches reality.
1 parent fa398d4 commit 2229d52

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

pkgs/tools/text/gnugrep/default.nix

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ stdenv.mkDerivation {
3333
# https://lists.gnu.org/archive/html/bug-gnulib/2025-07/msg00021.html
3434
# Multiple upstream commits squashed with adjustments, see header
3535
./gnulib-float-h-tests-port-to-C23-PowerPC-GCC.patch
36-
];
36+
]
37+
# gnulib stackvma.c's __APPLE__ arm includes <libc.h>/<nlist.h> (macOS-only
38+
# BSD headers, not libc itself). Narrow via TARGET_OS_IPHONE so iOS hits the
39+
# existing `#else /* Hurd, Minix, ... */` no-op stub.
40+
++ lib.optional stdenv.hostPlatform.isiOS ./patches/ios-stackvma-skip-macos-branch.patch;
3741

3842
# Some gnulib tests fail
3943
# - on Musl: https://github.com/NixOS/nixpkgs/pull/228714
@@ -63,6 +67,11 @@ stdenv.mkDerivation {
6367
]
6468
++ lib.optional (!stdenv.hostPlatform.isWindows) runtimeShellPackage;
6569

70+
# External libsigsegv isn't packaged for iOS (vendored copy patched separately).
71+
configureFlags = lib.optionals stdenv.hostPlatform.isiOS [
72+
"--without-libsigsegv-prefix"
73+
];
74+
6675
# cygwin: FAIL: multibyte-white-space
6776
# freebsd: FAIL mb-non-UTF8-performance
6877
# x86_64-darwin: fails 'stack-overflow' tests on Rosetta 2 emulator
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--- a/lib/stackvma.c 2025-01-01 21:33:12.000000000 -0500
2+
+++ b/lib/stackvma.c 2026-04-23 09:37:32.499102018 -0400
3+
@@ -19,6 +19,10 @@
4+
5+
#include <config.h>
6+
7+
+#if defined __APPLE__ && defined __MACH__
8+
+# include <TargetConditionals.h>
9+
+#endif
10+
+
11+
/* On Solaris in 32-bit mode, when gnulib module 'largefile' is in use,
12+
prevent a compilation error
13+
"Cannot use procfs in the large file compilation environment"
14+
@@ -1361,7 +1365,8 @@
15+
16+
/* ---------------------------- stackvma-mach.c ---------------------------- */
17+
18+
-#elif (defined __APPLE__ && defined __MACH__) /* macOS */
19+
+#elif (defined __APPLE__ && defined __MACH__ \
20+
+ && (!defined TARGET_OS_IPHONE || !TARGET_OS_IPHONE)) /* macOS, not iOS */
21+
22+
#include <libc.h>
23+
#include <nlist.h>

0 commit comments

Comments
 (0)