From 0dd293b4d9095137c9952e16ca951f887b7e7018 Mon Sep 17 00:00:00 2001 From: Josselin Poiret Date: Mon, 22 May 2023 11:42:26 +0200 Subject: gnu: Add libc-for-target and glibc/hurd. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/packages/patches/glibc-2.37-hurd-clock_t_centiseconds.patch * gnu/packages/patches/glibc-2.37-hurd-local-clock_gettime_MONOTONIC.patch * gnu/packages/patches/glibc-2.37-versioned-locpath.patch: New patches. * gnu/local.mk (dist_patch_DATA): Register them. * gnu/packages/base.scm (glibc/hurd, libc-for-target): New variables. (glibc/hurd-headers): Use glibc/hurd. * gnu/packages/commencement.scm (glibc-final-with-bootstrap-bash)[outputs, source, arguments] (glibc-final)[source]: Use libc-for-target instead of glibc. * gnu/packages/cross-base.scm (cross-libc/deprecated, cross-libc*): Use libc-for-target. This part fixes https://issues.guix.gnu.org/63641#25 * gnu/packages/commencement.scm (%final-inputs): Change to memoized lambda taking "system". * gnu/packages/commencement.scm (canonical-package): Likewise, and update user, passing (%current-system). (make-gcc-toolchain): Update user, passing (%current-system). * gnu/packages/base.scm (%final-inputs): Likewise. * guix/scripts/refresh.scm (options->update-specs): Likewise. * guix/build-system/gnu.scm (standard-packages): Add optional "system" parameter. (lower): Update caller. Co-authored-by: Ludovic Courtès Co-authored-by: Janneke Nieuwenhuizen --- .../glibc-2.37-hurd-clock_t_centiseconds.patch | 61 +++++ ...c-2.37-hurd-local-clock_gettime_MONOTONIC.patch | 135 +++++++++++ .../patches/glibc-2.37-versioned-locpath.patch | 264 +++++++++++++++++++++ 3 files changed, 460 insertions(+) create mode 100644 gnu/packages/patches/glibc-2.37-hurd-clock_t_centiseconds.patch create mode 100644 gnu/packages/patches/glibc-2.37-hurd-local-clock_gettime_MONOTONIC.patch create mode 100644 gnu/packages/patches/glibc-2.37-versioned-locpath.patch (limited to 'gnu/packages/patches') diff --git a/gnu/packages/patches/glibc-2.37-hurd-clock_t_centiseconds.patch b/gnu/packages/patches/glibc-2.37-hurd-clock_t_centiseconds.patch new file mode 100644 index 0000000000..944b2fe8df --- /dev/null +++ b/gnu/packages/patches/glibc-2.37-hurd-clock_t_centiseconds.patch @@ -0,0 +1,61 @@ +Taken from: https://salsa.debian.org/glibc-team/glibc/-/blob/9ce19663f00176f30d6eab29fd14db3e7cd53dcf/debian/patches/hurd-i386/unsubmitted-clock_t_centiseconds.diff + +Some applications assume centisecond precision, or at most millisecond precision +(e.g. guile). This is a work-around for them. + +--- + getclktck.c | 5 ++--- + setitimer.c | 2 +- + times.c | 2 +- + 4 files changed, 8 insertions(+), 9 deletions(-) +commit d57f2f9b4bd007846af2fb4217486ea572579010 +Author: Richard Braun +Date: Tue Aug 27 11:35:31 2013 +0200 + + Express CPU time (clock_t of times(2)) in centiseconds + +diff --git a/sysdeps/mach/hurd/getclktck.c b/sysdeps/mach/hurd/getclktck.c +index 69be2cc..5f7d946 100644 +--- a/sysdeps/mach/hurd/getclktck.c ++++ b/sysdeps/mach/hurd/getclktck.c +@@ -18,12 +18,11 @@ + + #include + +-/* Return frequency of `times'. +- Since Mach reports CPU times in microseconds, we always use 1 million. */ ++/* Return frequency of `times'. */ + int + __getclktck (void) + { +- return 1000000; ++ return 100; + } + + /* Before glibc 2.2, the Hurd actually did this differently, so we +diff --git a/sysdeps/mach/hurd/setitimer.c b/sysdeps/mach/hurd/setitimer.c +index 39b6b16..4992c89 100644 +--- a/sysdeps/mach/hurd/setitimer.c ++++ b/sysdeps/mach/hurd/setitimer.c +@@ -42,7 +42,7 @@ quantize_timeval (struct timeval *tv) + static time_t quantum = -1; + + if (quantum == -1) +- quantum = 1000000 / __getclktck (); ++ quantum = 100 / __getclktck (); + + tv->tv_usec = ((tv->tv_usec + (quantum - 1)) / quantum) * quantum; + if (tv->tv_usec >= 1000000) +diff --git a/sysdeps/mach/hurd/times.c b/sysdeps/mach/hurd/times.c +index 9e13a75..593c33a 100644 +--- a/sysdeps/mach/hurd/times.c ++++ b/sysdeps/mach/hurd/times.c +@@ -29,7 +29,7 @@ + static inline clock_t + clock_from_time_value (const time_value_t *t) + { +- return t->seconds * 1000000 + t->microseconds; ++ return t->seconds * 100 + t->microseconds / 10000; + } + + /* Store the CPU time used by this process and all its diff --git a/gnu/packages/patches/glibc-2.37-hurd-local-clock_gettime_MONOTONIC.patch b/gnu/packages/patches/glibc-2.37-hurd-local-clock_gettime_MONOTONIC.patch new file mode 100644 index 0000000000..63e06b8519 --- /dev/null +++ b/gnu/packages/patches/glibc-2.37-hurd-local-clock_gettime_MONOTONIC.patch @@ -0,0 +1,135 @@ +Taken from: https://salsa.debian.org/glibc-team/glibc/-/blob/9ce19663f00176f30d6eab29fd14db3e7cd53dcf/debian/patches/hurd-i386/local-clock_gettime_MONOTONIC.diff + +Use the realtime clock for the monotonic clock. This is of course not a proper +implementation (which is being done in Mach), but will permit to fix at least +the iceweasel stack. + +vlc however doesn't build when _POSIX_CLOCK_SELECTION is enabled but +_POSIX_TIMERS is not, and they refuse to fix that (see #765578), so disable the +former. + +--- + sysdeps/mach/hurd/bits/posix_opt.h | 2 +- + sysdeps/unix/clock_gettime.c | 1 + + 2 files changed, 2 insertions(+), 1 deletion(-) +Index: glibc-2.27/sysdeps/mach/clock_gettime.c +=================================================================== +--- glibc-2.27.orig/sysdeps/mach/clock_gettime.c ++++ glibc-2.27/sysdeps/mach/clock_gettime.c +@@ -31,6 +31,10 @@ __clock_gettime (clockid_t clock_id, str + switch (clock_id) { + + case CLOCK_REALTIME: ++ case CLOCK_MONOTONIC: ++ case CLOCK_MONOTONIC_RAW: ++ case CLOCK_REALTIME_COARSE: ++ case CLOCK_MONOTONIC_COARSE: + { + /* __host_get_time can only fail if passed an invalid host_t. + __mach_host_self could theoretically fail (producing an +Index: glibc-2.27/rt/timer_create.c +=================================================================== +--- glibc-2.27.orig/rt/timer_create.c ++++ glibc-2.27/rt/timer_create.c +@@ -48,7 +48,7 @@ timer_create (clockid_t clock_id, struct + return -1; + } + +- if (clock_id != CLOCK_REALTIME) ++ if (clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC && clock_id != CLOCK_MONOTONIC_RAW && clock_id != CLOCK_REALTIME_COARSE && clock_id != CLOCK_MONOTONIC_COARSE) + { + __set_errno (EINVAL); + return -1; +Index: glibc-2.27/sysdeps/mach/hurd/bits/posix_opt.h +=================================================================== +--- glibc-2.27.orig/sysdeps/mach/hurd/bits/posix_opt.h ++++ glibc-2.27/sysdeps/mach/hurd/bits/posix_opt.h +@@ -163,10 +163,10 @@ + #define _POSIX_THREAD_PROCESS_SHARED -1 + + /* The monotonic clock might be available. */ +-#define _POSIX_MONOTONIC_CLOCK 0 ++#define _POSIX_MONOTONIC_CLOCK 200809L + +-/* The clock selection interfaces are available. */ +-#define _POSIX_CLOCK_SELECTION 200809L ++/* The clock selection interfaces are not really available yet. */ ++#define _POSIX_CLOCK_SELECTION -1 + + /* Advisory information interfaces could be available in future. */ + #define _POSIX_ADVISORY_INFO 0 +Index: glibc-upstream/sysdeps/posix/clock_getres.c +=================================================================== +--- glibc-upstream.orig/sysdeps/posix/clock_getres.c ++++ glibc-upstream/sysdeps/posix/clock_getres.c +@@ -52,6 +52,10 @@ __clock_getres (clockid_t clock_id, stru + switch (clock_id) + { + case CLOCK_REALTIME: ++ case CLOCK_MONOTONIC: ++ case CLOCK_MONOTONIC_RAW: ++ case CLOCK_REALTIME_COARSE: ++ case CLOCK_MONOTONIC_COARSE: + retval = realtime_getres (res); + break; + +--- ./sysdeps/mach/clock_nanosleep.c.original 2020-07-21 00:31:35.226113142 +0200 ++++ ./sysdeps/mach/clock_nanosleep.c 2020-07-21 00:31:49.026185761 +0200 +@@ -62,7 +62,7 @@ + __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req, + struct timespec *rem) + { +- if (clock_id != CLOCK_REALTIME ++ if ((clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC && clock_id != CLOCK_MONOTONIC_RAW && clock_id != CLOCK_REALTIME_COARSE && clock_id != CLOCK_MONOTONIC_COARSE) + || !valid_nanoseconds (req->tv_nsec) + || (flags != 0 && flags != TIMER_ABSTIME)) + return EINVAL; +Index: glibc-2.32/hurd/hurdlock.c +=================================================================== +--- glibc-2.32.orig/hurd/hurdlock.c ++++ glibc-2.32/hurd/hurdlock.c +@@ -47,7 +47,7 @@ int + __lll_abstimed_wait (void *ptr, int val, + const struct timespec *tsp, int flags, int clk) + { +- if (clk != CLOCK_REALTIME) ++ if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC) + return EINVAL; + + int mlsec = compute_reltime (tsp, clk); +@@ -59,7 +59,7 @@ int + __lll_abstimed_wait_intr (void *ptr, int val, + const struct timespec *tsp, int flags, int clk) + { +- if (clk != CLOCK_REALTIME) ++ if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC) + return EINVAL; + + int mlsec = compute_reltime (tsp, clk); +@@ -79,7 +79,7 @@ int + __lll_abstimed_xwait (void *ptr, int lo, int hi, + const struct timespec *tsp, int flags, int clk) + { +- if (clk != CLOCK_REALTIME) ++ if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC) + return EINVAL; + + int mlsec = compute_reltime (tsp, clk); +@@ -91,7 +91,7 @@ int + __lll_abstimed_lock (void *ptr, + const struct timespec *tsp, int flags, int clk) + { +- if (clk != CLOCK_REALTIME) ++ if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC) + return EINVAL; + + if (__lll_trylock (ptr) == 0) +@@ -177,7 +177,7 @@ __lll_robust_abstimed_lock (void *ptr, + int wait_time = 25; + unsigned int val; + +- if (clk != CLOCK_REALTIME) ++ if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC) + return EINVAL; + + while (1) diff --git a/gnu/packages/patches/glibc-2.37-versioned-locpath.patch b/gnu/packages/patches/glibc-2.37-versioned-locpath.patch new file mode 100644 index 0000000000..0acaeb1e46 --- /dev/null +++ b/gnu/packages/patches/glibc-2.37-versioned-locpath.patch @@ -0,0 +1,264 @@ +From d73ba2caa10b8e9f51ff4239cc32eeb4e0de4279 Mon Sep 17 00:00:00 2001 +Message-Id: +From: Josselin Poiret +Date: Sat, 13 May 2023 14:10:43 +0200 +Subject: [PATCH] Add versioned locpath + +From: Josselin Poiret + +The format of locale data can be incompatible between libc versions, and +loading incompatible data can lead to 'setlocale' returning EINVAL at best +or triggering an assertion failure at worst. See +https://lists.gnu.org/archive/html/guix-devel/2015-09/msg00717.html +for background information. + +To address that, this patch changes libc to honor a new 'GUIX_LOCPATH' +variable, and to look for locale data in version-specific sub-directories of +that variable. So, if GUIX_LOCPATH=/foo:/bar, locale data is searched for in +/foo/X.Y and /bar/X.Y, where X.Y is the libc version number. + +That way, a single 'GUIX_LOCPATH' setting can work even if different libc +versions coexist on the system. + + +This patch is adapted from the 2.35 patch. + +--- + locale/newlocale.c | 15 ++-------- + locale/setlocale.c | 68 +++++++++++++++++++++++++++++++++++++------- + string/Makefile | 1 + + string/argz-suffix.c | 56 ++++++++++++++++++++++++++++++++++++ + string/argz.h | 10 +++++++ + 5 files changed, 127 insertions(+), 23 deletions(-) + create mode 100644 string/argz-suffix.c + +diff --git a/locale/newlocale.c b/locale/newlocale.c +index 108d2428bf..6218e0fa77 100644 +--- a/locale/newlocale.c ++++ b/locale/newlocale.c +@@ -29,6 +29,7 @@ + /* Lock for protecting global data. */ + __libc_rwlock_define (extern , __libc_setlocale_lock attribute_hidden) + ++extern error_t compute_locale_search_path (char **, size_t *); + + /* Use this when we come along an error. */ + #define ERROR_RETURN \ +@@ -47,7 +48,6 @@ __newlocale (int category_mask, const char *locale, locale_t base) + locale_t result_ptr; + char *locale_path; + size_t locale_path_len; +- const char *locpath_var; + int cnt; + size_t names_len; + +@@ -101,17 +101,8 @@ __newlocale (int category_mask, const char *locale, locale_t base) + locale_path = NULL; + locale_path_len = 0; + +- locpath_var = getenv ("LOCPATH"); +- if (locpath_var != NULL && locpath_var[0] != '\0') +- { +- if (__argz_create_sep (locpath_var, ':', +- &locale_path, &locale_path_len) != 0) +- return NULL; +- +- if (__argz_add_sep (&locale_path, &locale_path_len, +- _nl_default_locale_path, ':') != 0) +- return NULL; +- } ++ if (compute_locale_search_path (&locale_path, &locale_path_len) != 0) ++ return NULL; + + /* Get the names for the locales we are interested in. We either + allow a composite name or a single name. */ +diff --git a/locale/setlocale.c b/locale/setlocale.c +index dd73fa4248..d8eb799384 100644 +--- a/locale/setlocale.c ++++ b/locale/setlocale.c +@@ -213,12 +213,65 @@ setdata (int category, struct __locale_data *data) + } + } + ++/* Return in *LOCALE_PATH and *LOCALE_PATH_LEN the locale data search path as ++ a colon-separated list. Return ENOMEN on error, zero otherwise. */ ++error_t ++compute_locale_search_path (char **locale_path, size_t *locale_path_len) ++{ ++ char* guix_locpath_var = getenv ("GUIX_LOCPATH"); ++ char *locpath_var = getenv ("LOCPATH"); ++ ++ if (guix_locpath_var != NULL && guix_locpath_var[0] != '\0') ++ { ++ /* Entries in 'GUIX_LOCPATH' take precedence over 'LOCPATH'. These ++ entries are systematically prefixed with "/X.Y" where "X.Y" is the ++ libc version. */ ++ if (__argz_create_sep (guix_locpath_var, ':', ++ locale_path, locale_path_len) != 0 ++ || __argz_suffix_entries (locale_path, locale_path_len, ++ "/" VERSION) != 0) ++ goto bail_out; ++ } ++ ++ if (locpath_var != NULL && locpath_var[0] != '\0') ++ { ++ char *reg_locale_path = NULL; ++ size_t reg_locale_path_len = 0; ++ ++ if (__argz_create_sep (locpath_var, ':', ++ ®_locale_path, ®_locale_path_len) != 0) ++ goto bail_out; ++ ++ if (__argz_append (locale_path, locale_path_len, ++ reg_locale_path, reg_locale_path_len) != 0) ++ goto bail_out; ++ ++ free (reg_locale_path); ++ } ++ ++ if (*locale_path != NULL) ++ { ++ /* Append the system default locale directory. */ ++ if (__argz_add_sep (locale_path, locale_path_len, ++ _nl_default_locale_path, ':') != 0) ++ goto bail_out; ++ } ++ ++ return 0; ++ ++ bail_out: ++ free (*locale_path); ++ *locale_path = NULL; ++ *locale_path_len = 0; ++ ++ return ENOMEM; ++} ++ + char * + setlocale (int category, const char *locale) + { + char *locale_path; + size_t locale_path_len; +- const char *locpath_var; + char *composite; + + /* Sanity check for CATEGORY argument. */ +@@ -249,17 +302,10 @@ setlocale (int category, const char *locale) + locale_path = NULL; + locale_path_len = 0; + +- locpath_var = getenv ("LOCPATH"); +- if (locpath_var != NULL && locpath_var[0] != '\0') ++ if (compute_locale_search_path (&locale_path, &locale_path_len) != 0) + { +- if (__argz_create_sep (locpath_var, ':', +- &locale_path, &locale_path_len) != 0 +- || __argz_add_sep (&locale_path, &locale_path_len, +- _nl_default_locale_path, ':') != 0) +- { +- __libc_rwlock_unlock (__libc_setlocale_lock); +- return NULL; +- } ++ __libc_rwlock_unlock (__libc_setlocale_lock); ++ return NULL; + } + + if (category == LC_ALL) +diff --git a/string/Makefile b/string/Makefile +index 3eced0d027..a7e68729ad 100644 +--- a/string/Makefile ++++ b/string/Makefile +@@ -51,6 +51,7 @@ routines := \ + argz-next \ + argz-replace \ + argz-stringify \ ++ argz-suffix \ + basename \ + bcopy \ + bzero \ +diff --git a/string/argz-suffix.c b/string/argz-suffix.c +new file mode 100644 +index 0000000000..505b0f248c +--- /dev/null ++++ b/string/argz-suffix.c +@@ -0,0 +1,56 @@ ++/* Copyright (C) 2015 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ Contributed by Ludovic Courtès . ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++#include ++#include ++#include ++#include ++ ++ ++error_t ++__argz_suffix_entries (char **argz, size_t *argz_len, const char *suffix) ++ ++{ ++ size_t suffix_len = strlen (suffix); ++ size_t count = __argz_count (*argz, *argz_len); ++ size_t new_argz_len = *argz_len + count * suffix_len; ++ char *new_argz = malloc (new_argz_len); ++ ++ if (new_argz) ++ { ++ char *p = new_argz, *entry; ++ ++ for (entry = *argz; ++ entry != NULL; ++ entry = argz_next (*argz, *argz_len, entry)) ++ { ++ p = stpcpy (p, entry); ++ p = stpcpy (p, suffix); ++ p++; ++ } ++ ++ free (*argz); ++ *argz = new_argz; ++ *argz_len = new_argz_len; ++ ++ return 0; ++ } ++ else ++ return ENOMEM; ++} ++weak_alias (__argz_suffix_entries, argz_suffix_entries) +diff --git a/string/argz.h b/string/argz.h +index cbc588a8e6..bc6e484c9d 100644 +--- a/string/argz.h ++++ b/string/argz.h +@@ -108,6 +108,16 @@ extern error_t argz_replace (char **__restrict __argz, + const char *__restrict __str, + const char *__restrict __with, + unsigned int *__restrict __replace_count); ++ ++/* Suffix each entry of ARGZ & ARGZ_LEN with SUFFIX. Return 0 on success, ++ and ENOMEN if memory cannot be allocated. */ ++extern error_t __argz_suffix_entries (char **__restrict __argz, ++ size_t *__restrict __argz_len, ++ const char *__restrict __suffix); ++extern error_t argz_suffix_entries (char **__restrict __argz, ++ size_t *__restrict __argz_len, ++ const char *__restrict __suffix); ++ + + /* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there + are no more. If entry is NULL, then the first entry is returned. This +-- +2.40.1 + -- cgit 1.4.1