From 3ba83fc77a5d52a4d4d010b47f8f50b34cc09438 Mon Sep 17 00:00:00 2001
Message-ID: <3ba83fc77a5d52a4d4d010b47f8f50b34cc09438.1707730887.git.rekado@elephly.net>
From: Ricardo Wurmus <rekado@elephly.net>
Date: Mon, 12 Feb 2024 10:41:10 +0100
Subject: [PATCH] WIP hurd

Change-Id: I61d0f0a3316ca437689bd399a083638db19b06a4
---
 gnu/local.mk                                  |  1 +
 gnu/packages/cross-base.scm                   |  4 +-
 gnu/packages/make-bootstrap.scm               |  4 +-
 .../patches/glibc-bootstrap-system-2.38.patch | 66 +++++++++++++++++++
 4 files changed, 73 insertions(+), 2 deletions(-)
 create mode 100644 gnu/packages/patches/glibc-bootstrap-system-2.38.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 9100686f3c..fe45dbb2a2 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1337,6 +1337,7 @@ dist_patch_DATA =                                         \
   %D%/packages/patches/glibc-boot-2.2.5.patch                  \
   %D%/packages/patches/glibc-bootstrap-system-2.2.5.patch      \
   %D%/packages/patches/glibc-bootstrap-system-2.16.0.patch     \
+  %D%/packages/patches/glibc-bootstrap-system-2.38.patch       \
   %D%/packages/patches/glibc-bootstrap-system.patch            \
   %D%/packages/patches/glibc-cross-objcopy.patch               \
   %D%/packages/patches/glibc-cross-objdump.patch               \
diff --git a/gnu/packages/cross-base.scm b/gnu/packages/cross-base.scm
index 952904ceef..5974694c10 100644
--- a/gnu/packages/cross-base.scm
+++ b/gnu/packages/cross-base.scm
@@ -707,7 +707,9 @@ (define* (cross-libc* target
                  (define cross-objdump
                    (search-input-file
                     inputs
-                    (string-append ,target "/bin/objdump")))
+                    ,(if (string=? "2.38" (package-version libc))
+                         (string-append "/bin/" target "-objdump")
+                         (string-append target "/bin/objdump"))))
 
                  (define cross-binutils
                    (dirname cross-objdump))
diff --git a/gnu/packages/make-bootstrap.scm b/gnu/packages/make-bootstrap.scm
index f640c8bb12..20ceff8d8b 100644
--- a/gnu/packages/make-bootstrap.scm
+++ b/gnu/packages/make-bootstrap.scm
@@ -73,7 +73,9 @@ (define glibc-for-bootstrap
       (inherit base)
       (source (origin (inherit (package-source base))
                       (patches (append (search-patches
-                                        "glibc-bootstrap-system.patch")
+                                        (if (string=? "2.38" (package-version base))
+                                            "glibc-bootstrap-system-2.38.patch"
+                                            "glibc-bootstrap-system.patch"))
                                    (origin-patches (package-source base))))))
       (arguments
        (substitute-keyword-arguments (package-arguments base)
diff --git a/gnu/packages/patches/glibc-bootstrap-system-2.38.patch b/gnu/packages/patches/glibc-bootstrap-system-2.38.patch
new file mode 100644
index 0000000000..0d28cf2816
--- /dev/null
+++ b/gnu/packages/patches/glibc-bootstrap-system-2.38.patch
@@ -0,0 +1,66 @@
+We want to allow builds in chroots that lack /bin/sh.  Thus, system(3)
+and popen(3) need to be tweaked to use the right shell.  For the bootstrap
+glibc, we just use whatever `sh' can be found in $PATH.  The final glibc
+instead uses the hard-coded absolute file name of `bash'.
+
+In addition, status should be initialized to 0 and not -1.
+
+diff --git a/libio/iopopen.c b/libio/iopopen.c
+index ebc381ed7c..e0d3ed1bc3 100644
+--- a/libio/iopopen.c
++++ b/libio/iopopen.c
+@@ -85,7 +85,7 @@ spawn_process (posix_spawn_file_actions_t *fa, FILE *fp, const char *command,
+       }
+     }
+ 
+-  err = __posix_spawn (&((_IO_proc_file *) fp)->pid, _PATH_BSHELL, fa, 0,
++  err = __posix_spawnp (&((_IO_proc_file *) fp)->pid, "sh", fa, 0,
+                      (char *const[]){ (char*) "sh", (char*) "-c", (char*) "--",
+                      (char *) command, NULL }, __environ);
+   if (err != 0)
+diff --git a/sysdeps/posix/system.c b/sysdeps/posix/system.c
+index a03f478fc7..94da6facf3 100644
+--- a/sysdeps/posix/system.c
++++ b/sysdeps/posix/system.c
+@@ -101,7 +101,7 @@ cancel_handler (void *arg)
+ static int
+ do_system (const char *line)
+ {
+-  int status = -1;
++  int status = 0;
+   int ret;
+   pid_t pid;
+   struct sigaction sa;
+@@ -145,7 +145,7 @@ do_system (const char *line)
+   __posix_spawnattr_setflags (&spawn_attr,
+                             POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK);
+ 
+-  ret = __posix_spawn (&pid, SHELL_PATH, 0, &spawn_attr,
++  ret = __posix_spawnp (&pid, SHELL_NAME, 0, &spawn_attr,
+                      (char *const[]){ (char *) SHELL_NAME,
+                                       (char *) "-c",
+                                       (char *) line, NULL },
+
+--- a/include/spawn.h
++++ b/include/spawn.h
+@@ -5,6 +5,9 @@
+ __typeof (posix_spawn) __posix_spawn;
+ libc_hidden_proto (__posix_spawn)
+
++__typeof (posix_spawnp) __posix_spawnp;
++libc_hidden_proto (__posix_spawnp)
++
+ __typeof (posix_spawn_file_actions_addclose)
+   __posix_spawn_file_actions_addclose attribute_hidden;
+
+--- a/posix/spawnp.c
++++ b/posix/spawnp.c
+@@ -31,6 +31,7 @@ __posix_spawnp (pid_t *pid, const char *file,
+                   SPAWN_XFLAGS_USE_PATH);
+ }
+ versioned_symbol (libc, __posix_spawnp, posix_spawnp, GLIBC_2_15);
++libc_hidden_def (__posix_spawnp)
+
+
+ #if SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_15)
+

base-commit: c5c91b3d2ec1aa7db49f7bf834e9eb4f6fdd9af8
-- 
2.41.0

Generated by Ricardo Wurmus using scpaste at Mon Feb 12 10:41:36 2024. CET. (original)