[CCing bug-gnulib]
> Pádraig Brady wrote:
> > Solaris 11.4, SPARC-M8, 1 coreutils fail  (cfarm216)
> > ...
> > Putting truss in the test shows the failure after vfork:
> > 
> > vforkx(0)                                       = 26169
> > lwp_sigmask(SIG_SETMASK, 0x00000000, 0x00000000, 0x00000000, 0x00000000) = 
> > 0xFFBFFEFF [0xFFFFFFFF]
> >      Incurred fault #5, FLTACCESS  %pc = 0x100022468
> >        siginfo: SIGBUS BUS_ADRALN addr=0xFFFF2F682F68772C
> >      Received signal #10, SIGBUS [default]
> >        siginfo: SIGBUS BUS_ADRALN addr=0xFFFF2F682F68772C
> 
> Trouble with vfork on SPARC: not surprising. The "sliding register window"
> of the SPARC architecture is a beast to get correctly implemented in
> the kernel and in setjmp/longjmp. After vfork, the parent and the child
> are supposed to
>   - share the memory,
>   - but have distinct register sets.
> In other architectures this works reasonably, because the child process
> does only minimal changes to the memory contents before it exec()s.
> But on SPARC, due to the register window that can cause memory writes
> simply at subroutine invocation or return, this is very hairy.
> 
> >   * If I force ifdef out the VFORK call in gnulib's spawni it's OK
> >   * If I force the use of the system posix_spawnp it's Ok. Tested with:
> >     ./configure gl_cv_func_posix_spawnp_secure_exec=yes --quiet && gmake -j8
> >     gmake TESTS=tests/install/basic-1.sh SUBDIRS=. check

I don't immediately see what, in the spawni.c code, could violate the
unwritten rules for use of vfork().

But I've tested other SPARC platforms:
  - Linux (Debian 9)/SPARC
  - FreeBSD 12/SPARC
  - NetBSD 10/SPARC
  - OpenBSD 7.2/SPARC
and other Solaris platforms:
  - Solaris 10, 11 / x86_64
and the _only_ platforms that have a crash in the tests/install/basic-1.sh
test are Solaris 10, 11 / SPARC.

So, I'm just disabling the use of vfork() there. No further investigation
is planned, since the SPARC architecture is rarely used nowadays.

Bruno

From bbf98b12a1feece09cae9a390c5bdd851e885b9b Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Thu, 6 Nov 2025 20:41:07 +0100
Subject: [PATCH] posix_spawn-internal: Don't use vfork() on Solaris/SPARC.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reported by P??draig Brady <[email protected]> in
<https://lists.gnu.org/archive/html/coreutils/2025-11/msg00052.html>.

* lib/spawni.c (__spawni): Don't use vfork() on Solaris/SPARC.
---
 ChangeLog    | 7 +++++++
 lib/spawni.c | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 551a7acae0..e40604e420 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2025-11-06  Bruno Haible  <[email protected]>
+
+	posix_spawn-internal: Don't use vfork() on Solaris/SPARC.
+	Reported by P??draig Brady <[email protected]> in
+	<https://lists.gnu.org/archive/html/coreutils/2025-11/msg00052.html>.
+	* lib/spawni.c (__spawni): Don't use vfork() on Solaris/SPARC.
+
 2025-11-06  Bruno Haible  <[email protected]>
 
 	stdio-windows: Add fallback code for very old mingw without vasprintf.
diff --git a/lib/spawni.c b/lib/spawni.c
index a1f3f84a98..b99f8eeabb 100644
--- a/lib/spawni.c
+++ b/lib/spawni.c
@@ -882,7 +882,8 @@ __spawni (pid_t *pid, const char *file,
   (void) &flags;
 
   /* Generate the new process.  */
-#if HAVE_VFORK
+  /* Use of vfork() on Solaris/SPARC crashes; avoid it there.  */
+#if HAVE_VFORK && !(defined __sun && defined __sparc)
   if ((flags & POSIX_SPAWN_USEVFORK) != 0
       /* If no major work is done, allow using vfork.  Note that we
          might perform the path searching.  But this would be done by
-- 
2.51.0

Reply via email to