Import from CS git

This commit is contained in:
eabdullin 2025-12-08 07:55:06 +00:00
parent 6f91983eb9
commit 82f5125cec
10 changed files with 948 additions and 1 deletions

View File

@ -0,0 +1,45 @@
commit 0fceed254559836b57ee05188deac649bc505d05
Author: Florian Weimer <fweimer@redhat.com>
Date: Fri Sep 12 21:33:34 2025 +0200
nss: Group merge does not react to ERANGE during merge (bug 33361)
The break statement in CHECK_MERGE is expected to exit the surrounding
while loop, not the do-while loop with in the macro. Remove the
do-while loop from the macro. It is not needed to turn the macro
expansion into a single statement due to the way CHECK_MERGE is used
(and the statement expression would cover this anyway).
Reviewed-by: Collin Funk <collin.funk1@gmail.com>
diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c
index eae6c3480e..2b0735fb6a 100644
--- a/nss/getXXbyYY_r.c
+++ b/nss/getXXbyYY_r.c
@@ -157,19 +157,15 @@ __merge_einval (LOOKUP_TYPE *a,
#define CHECK_MERGE(err, status) \
({ \
- do \
+ if (err) \
{ \
- if (err) \
- { \
- __set_errno (err); \
- if (err == ERANGE) \
- status = NSS_STATUS_TRYAGAIN; \
- else \
- status = NSS_STATUS_UNAVAIL; \
- break; \
- } \
+ __set_errno (err); \
+ if (err == ERANGE) \
+ status = NSS_STATUS_TRYAGAIN; \
+ else \
+ status = NSS_STATUS_UNAVAIL; \
+ break; \
} \
- while (0); \
})
/* Type of the lookup function we need here. */

View File

@ -0,0 +1,159 @@
commit 28aff047818eb1726394296d27b9c7885340bead
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu May 14 17:44:15 2020 -0300
string: Implement strerror in terms of strerror_l
If the thread is terminated then __libc_thread_freeres will free the
storage via __glibc_tls_internal_free.
It is only within the calling thread that this matters. It makes
strerror MT-safe.
Checked on x86-64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
and s390x-linux-gnu.
Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Conflicts:
string/strerror_l.c
(Adjust for missing __get_errlist in RHEL-8)
diff --git a/include/string.h b/include/string.h
index bbc97082661caf42..875c855ea9c277dd 100644
--- a/include/string.h
+++ b/include/string.h
@@ -4,6 +4,7 @@
/* Some of these are defined as macros in the real string.h, so we must
prototype them before including it. */
#include <sys/types.h>
+#include <locale.h>
extern void *__memccpy (void *__dest, const void *__src,
int __c, size_t __n);
@@ -50,6 +51,8 @@ extern int __ffs (int __i) __attribute__ ((const));
extern char *__strerror_r (int __errnum, char *__buf, size_t __buflen);
+extern char *__strerror_l (int __errnum, locale_t __loc);
+
/* Called as part of the thread shutdown sequence. */
void __strerror_thread_freeres (void) attribute_hidden;
@@ -113,6 +116,7 @@ libc_hidden_proto (memmem)
extern __typeof (memmem) __memmem;
libc_hidden_proto (__memmem)
libc_hidden_proto (__ffs)
+libc_hidden_proto (__strerror_l)
#if IS_IN (libc)
/* Avoid hidden reference to IFUNC symbol __explicit_bzero_chk. */
diff --git a/string/strerror.c b/string/strerror.c
index 34f3db727b7eeefe..567be8b0018f76f9 100644
--- a/string/strerror.c
+++ b/string/strerror.c
@@ -15,29 +15,11 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <libintl.h>
-#include <stdio.h>
#include <string.h>
-#include <errno.h>
-
-/* Return a string describing the errno code in ERRNUM.
- The storage is good only until the next call to strerror.
- Writing to the storage causes undefined behavior. */
-libc_freeres_ptr (static char *buf);
+#include <locale/localeinfo.h>
char *
strerror (int errnum)
{
- char *ret = __strerror_r (errnum, NULL, 0);
- int saved_errno;
-
- if (__glibc_likely (ret != NULL))
- return ret;
- saved_errno = errno;
- if (buf == NULL)
- buf = malloc (1024);
- __set_errno (saved_errno);
- if (buf == NULL)
- return _("Unknown error");
- return __strerror_r (errnum, buf, 1024);
+ return __strerror_l (errnum, __libc_tsd_get (locale_t, LOCALE));
}
diff --git a/string/strerror_l.c b/string/strerror_l.c
index 2a62b1f12c343980..61329e8f2d4795d1 100644
--- a/string/strerror_l.c
+++ b/string/strerror_l.c
@@ -20,8 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/param.h>
-#include <libc-symbols.h>
+#include <errno.h>
static __thread char *last_value;
@@ -38,23 +37,28 @@ translate (const char *str, locale_t loc)
/* Return a string describing the errno code in ERRNUM. */
char *
-strerror_l (int errnum, locale_t loc)
+__strerror_l (int errnum, locale_t loc)
{
-
-
- if (__builtin_expect (errnum < 0 || errnum >= _sys_nerr_internal
- || _sys_errlist_internal[errnum] == NULL, 0))
+ int saved_errno = errno;
+ char *err;
+ if (__glibc_unlikely (errnum < 0 || errnum >= _sys_nerr_internal
+ || _sys_errlist_internal[errnum] == NULL))
{
free (last_value);
if (__asprintf (&last_value, "%s%d",
translate ("Unknown error ", loc), errnum) == -1)
last_value = NULL;
- return last_value;
+ err = last_value;
}
+ else
+ err = (char *) translate (_sys_errlist_internal[errnum], loc);
- return (char *) translate (_sys_errlist_internal[errnum], loc);
+ __set_errno (saved_errno);
+ return err;
}
+weak_alias (__strerror_l, strerror_l)
+libc_hidden_def (__strerror_l)
void
__strerror_thread_freeres (void)
diff --git a/sysdeps/mach/strerror_l.c b/sysdeps/mach/strerror_l.c
index 7111124439080d47..8509e6bf4beb713e 100644
--- a/sysdeps/mach/strerror_l.c
+++ b/sysdeps/mach/strerror_l.c
@@ -42,7 +42,7 @@ translate (const char *str, locale_t loc)
/* Return a string describing the errno code in ERRNUM. */
char *
-strerror_l (int errnum, locale_t loc)
+__strerror_l (int errnum, locale_t loc)
{
int system;
int sub;
@@ -86,6 +86,8 @@ strerror_l (int errnum, locale_t loc)
return (char *) translate (es->subsystem[sub].codes[code], loc);
}
+weak_alias (__strerror_l, strerror_l)
+libc_hidden_def (__strerror_l)
/* This is called when a thread is exiting to free the last_value string. */
void

View File

@ -0,0 +1,299 @@
commit 10a66a8e421b09682b774c795ef1da402235dddc
Author: Florian Weimer <fweimer@redhat.com>
Date: Fri May 16 19:53:09 2025 +0200
Remove <libc-tsd.h>
Use __thread variables directly instead. The macros do not save any
typing. It seems unlikely that a future port will lack __thread
variable support.
Some of the __libc_tsd_* variables are referenced from assembler
files, so keep their names. Previously, <libc-tls.h> included
<tls.h>, which in turn included <errno.h>, so a few direct includes
of <errno.h> are now required.
Reviewed-by: Frédéric Bérat <fberat@redhat.com>
Conflicts:
sysdeps/generic/libc-tsd.h
(File was deleted but had slightly different content)
diff --git a/ctype/ctype-info.c b/ctype/ctype-info.c
index bc4b84631709e1d7..4a8e24c001a89688 100644
--- a/ctype/ctype-info.c
+++ b/ctype/ctype-info.c
@@ -19,20 +19,20 @@
#include <ctype.h>
#include <locale/localeinfo.h>
-__libc_tsd_define (, const uint16_t *, CTYPE_B)
-__libc_tsd_define (, const int32_t *, CTYPE_TOLOWER)
-__libc_tsd_define (, const int32_t *, CTYPE_TOUPPER)
+__thread const uint16_t * __libc_tsd_CTYPE_B;
+__thread const int32_t * __libc_tsd_CTYPE_TOLOWER;
+__thread const int32_t * __libc_tsd_CTYPE_TOUPPER;
void
__ctype_init (void)
{
- const uint16_t **bp = __libc_tsd_address (const uint16_t *, CTYPE_B);
- *bp = (const uint16_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_CLASS) + 128;
- const int32_t **up = __libc_tsd_address (const int32_t *, CTYPE_TOUPPER);
- *up = ((int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOUPPER) + 128);
- const int32_t **lp = __libc_tsd_address (const int32_t *, CTYPE_TOLOWER);
- *lp = ((int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOLOWER) + 128);
+ __libc_tsd_CTYPE_B
+ = ((const uint16_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_CLASS)) + 128;
+ __libc_tsd_CTYPE_TOUPPER
+ = ((const int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOUPPER)) + 128;
+ __libc_tsd_CTYPE_TOLOWER =
+ ((const int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOLOWER)) + 128;
}
libc_hidden_def (__ctype_init)
diff --git a/include/ctype.h b/include/ctype.h
index 493a6f80ce8e8b8e..e993adc86da43b7c 100644
--- a/include/ctype.h
+++ b/include/ctype.h
@@ -24,33 +24,32 @@ libc_hidden_proto (toupper)
NL_CURRENT_INDIRECT. */
# include "../locale/localeinfo.h"
-# include <libc-tsd.h>
# ifndef CTYPE_EXTERN_INLINE /* Used by ctype/ctype-info.c, which see. */
# define CTYPE_EXTERN_INLINE extern inline
# endif
-__libc_tsd_define (extern, const uint16_t *, CTYPE_B)
-__libc_tsd_define (extern, const int32_t *, CTYPE_TOUPPER)
-__libc_tsd_define (extern, const int32_t *, CTYPE_TOLOWER)
+extern __thread const uint16_t * __libc_tsd_CTYPE_B;
+extern __thread const int32_t * __libc_tsd_CTYPE_TOUPPER;
+extern __thread const int32_t * __libc_tsd_CTYPE_TOLOWER;
CTYPE_EXTERN_INLINE const uint16_t ** __attribute__ ((const))
__ctype_b_loc (void)
{
- return __libc_tsd_address (const uint16_t *, CTYPE_B);
+ return &__libc_tsd_CTYPE_B;
}
CTYPE_EXTERN_INLINE const int32_t ** __attribute__ ((const))
__ctype_toupper_loc (void)
{
- return __libc_tsd_address (const int32_t *, CTYPE_TOUPPER);
+ return &__libc_tsd_CTYPE_TOUPPER;
}
CTYPE_EXTERN_INLINE const int32_t ** __attribute__ ((const))
__ctype_tolower_loc (void)
{
- return __libc_tsd_address (const int32_t *, CTYPE_TOLOWER);
+ return &__libc_tsd_CTYPE_TOLOWER;
}
# ifndef __NO_CTYPE
diff --git a/include/rpc/rpc.h b/include/rpc/rpc.h
index f5cee6caef6284d2..936ea3cebb8101e1 100644
--- a/include/rpc/rpc.h
+++ b/include/rpc/rpc.h
@@ -3,8 +3,6 @@
# ifndef _ISOMAC
-#include <libc-tsd.h>
-
/* Now define the internal interfaces. */
extern unsigned long _create_xid (void);
@@ -47,7 +45,7 @@ extern void __rpc_thread_key_cleanup (void) attribute_hidden;
extern void __rpc_thread_destroy (void) attribute_hidden;
-__libc_tsd_define (extern, struct rpc_thread_variables *, RPC_VARS)
+extern __thread struct rpc_thread_variables *__libc_tsd_RPC_VARS;
#define RPC_THREAD_VARIABLE(x) (__rpc_thread_variables()->x)
diff --git a/locale/lc-ctype.c b/locale/lc-ctype.c
index 417db1a6b6a72458..f8b50a07bcf6352d 100644
--- a/locale/lc-ctype.c
+++ b/locale/lc-ctype.c
@@ -64,12 +64,9 @@ _nl_postload_ctype (void)
in fact using the global locale. */
if (_NL_CURRENT_LOCALE == &_nl_global_locale)
{
- __libc_tsd_set (const uint16_t *, CTYPE_B,
- (void *) _nl_global_locale.__ctype_b);
- __libc_tsd_set (const int32_t *, CTYPE_TOUPPER,
- (void *) _nl_global_locale.__ctype_toupper);
- __libc_tsd_set (const int32_t *, CTYPE_TOLOWER,
- (void *) _nl_global_locale.__ctype_tolower);
+ __libc_tsd_CTYPE_B = _nl_global_locale.__ctype_b;
+ __libc_tsd_CTYPE_TOUPPER = _nl_global_locale.__ctype_toupper;
+ __libc_tsd_CTYPE_TOLOWER = _nl_global_locale.__ctype_tolower;
}
#include <shlib-compat.h>
diff --git a/locale/localeinfo.h b/locale/localeinfo.h
index 68822a6319b0e684..e81ab8a59977d2dd 100644
--- a/locale/localeinfo.h
+++ b/locale/localeinfo.h
@@ -214,10 +214,8 @@ extern struct __locale_struct _nl_global_locale attribute_hidden;
/* This fetches the thread-local locale_t pointer, either one set with
uselocale or &_nl_global_locale. */
-#define _NL_CURRENT_LOCALE (__libc_tsd_get (locale_t, LOCALE))
-#include <libc-tsd.h>
-__libc_tsd_define (extern, locale_t, LOCALE)
-
+#define _NL_CURRENT_LOCALE __libc_tsd_LOCALE
+extern __thread locale_t __libc_tsd_LOCALE;
/* For static linking it is desireable to avoid always linking in the code
and data for every category when we can tell at link time that they are
diff --git a/locale/uselocale.c b/locale/uselocale.c
index 5ba77c563903be33..a1f5463ea691281d 100644
--- a/locale/uselocale.c
+++ b/locale/uselocale.c
@@ -34,7 +34,7 @@ __uselocale (locale_t newloc)
{
const locale_t locobj
= newloc == LC_GLOBAL_LOCALE ? &_nl_global_locale : newloc;
- __libc_tsd_set (locale_t, LOCALE, locobj);
+ __libc_tsd_LOCALE = locobj;
#ifdef NL_CURRENT_INDIRECT
/* Now we must update all the per-category thread-local variables to
@@ -62,11 +62,9 @@ __uselocale (locale_t newloc)
#endif
/* Update the special tsd cache of some locale data. */
- __libc_tsd_set (const uint16_t *, CTYPE_B, (void *) locobj->__ctype_b);
- __libc_tsd_set (const int32_t *, CTYPE_TOLOWER,
- (void *) locobj->__ctype_tolower);
- __libc_tsd_set (const int32_t *, CTYPE_TOUPPER,
- (void *) locobj->__ctype_toupper);
+ __libc_tsd_CTYPE_B = locobj->__ctype_b;
+ __libc_tsd_CTYPE_TOLOWER = locobj->__ctype_tolower;
+ __libc_tsd_CTYPE_TOUPPER = locobj->__ctype_toupper;
}
return oldloc == &_nl_global_locale ? LC_GLOBAL_LOCALE : oldloc;
diff --git a/stdio-common/printf-parsemb.c b/stdio-common/printf-parsemb.c
index ecbc4e31696bd162..4e13cd2ba9260df9 100644
--- a/stdio-common/printf-parsemb.c
+++ b/stdio-common/printf-parsemb.c
@@ -17,6 +17,7 @@
<http://www.gnu.org/licenses/>. */
#include <ctype.h>
+#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
diff --git a/string/strerror.c b/string/strerror.c
index 567be8b0018f76f9..1f15e9b1bf622145 100644
--- a/string/strerror.c
+++ b/string/strerror.c
@@ -21,5 +21,5 @@
char *
strerror (int errnum)
{
- return __strerror_l (errnum, __libc_tsd_get (locale_t, LOCALE));
+ return __strerror_l (errnum, __libc_tsd_LOCALE);
}
diff --git a/sunrpc/rpc_thread.c b/sunrpc/rpc_thread.c
index 0abe6dc172040125..ba2a0fc09e1eb52f 100644
--- a/sunrpc/rpc_thread.c
+++ b/sunrpc/rpc_thread.c
@@ -3,7 +3,6 @@
#include <assert.h>
#include <libc-lock.h>
-#include <libc-tsd.h>
#include <shlib-compat.h>
#include <libc-symbols.h>
diff --git a/sysdeps/generic/libc-tsd.h b/sysdeps/generic/libc-tsd.h
deleted file mode 100644
index 73e792dd0a4afa1c..0000000000000000
--- a/sysdeps/generic/libc-tsd.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* libc-internal interface for thread-specific data. Stub or TLS version.
- Copyright (C) 1998-2018 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- 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
- <http://www.gnu.org/licenses/>. */
-
-#ifndef _GENERIC_LIBC_TSD_H
-#define _GENERIC_LIBC_TSD_H 1
-
-/* This file defines the following macros for accessing a small fixed
- set of thread-specific `void *' data used only internally by libc.
-
- __libc_tsd_define(CLASS, TYPE, KEY) -- Define or declare a datum with TYPE
- for KEY. CLASS can be `static' for
- keys used in only one source file,
- empty for global definitions, or
- `extern' for global declarations.
- __libc_tsd_address(TYPE, KEY) -- Return the `TYPE *' pointing to
- the current thread's datum for KEY.
- __libc_tsd_get(TYPE, KEY) -- Return the `TYPE' datum for KEY.
- __libc_tsd_set(TYPE, KEY, VALUE) -- Set the datum for KEY to VALUE.
-
- The set of available KEY's will usually be provided as an enum,
- and contains (at least):
- _LIBC_TSD_KEY_MALLOC
- _LIBC_TSD_KEY_DL_ERROR
- _LIBC_TSD_KEY_RPC_VARS
- All uses must be the literal _LIBC_TSD_* name in the __libc_tsd_* macros.
- Some implementations may not provide any enum at all and instead
- using string pasting in the macros. */
-
-#include <tls.h>
-
-/* When full support for __thread variables is available, this interface is
- just a trivial wrapper for it. Without TLS, this is the generic/stub
- implementation for wholly single-threaded systems.
-
- We don't define an enum for the possible key values, because the KEYs
- translate directly into variables by macro magic. */
-
-#define __libc_tsd_define(CLASS, TYPE, KEY) \
- CLASS __thread TYPE __libc_tsd_##KEY attribute_tls_model_ie;
-
-#define __libc_tsd_address(TYPE, KEY) (&__libc_tsd_##KEY)
-#define __libc_tsd_get(TYPE, KEY) (__libc_tsd_##KEY)
-#define __libc_tsd_set(TYPE, KEY, VALUE) (__libc_tsd_##KEY = (VALUE))
-
-#endif /* libc-tsd.h */
diff --git a/time/strftime_l.c b/time/strftime_l.c
index c71f9f47a9525046..3d05fceeedc31c65 100644
--- a/time/strftime_l.c
+++ b/time/strftime_l.c
@@ -40,6 +40,7 @@
#endif
#include <ctype.h>
+#include <errno.h>
#include <sys/types.h> /* Some systems define `time_t' here. */
#ifdef TIME_WITH_SYS_TIME

View File

@ -0,0 +1,60 @@
commit a894f04d877653bea1639fc9a4adf73bd9347bf4
Author: Florian Weimer <fweimer@redhat.com>
Date: Fri May 16 19:53:09 2025 +0200
Optimize __libc_tsd_* thread variable access
These variables are not exported, and libc.so TLS is initial-exec
anyway. Declare these variables as hidden and use the initial-exec
TLS model.
Reviewed-by: Frédéric Bérat <fberat@redhat.com>
diff --git a/include/ctype.h b/include/ctype.h
index e993adc86da43b7c..0f6e7fc7ea28f821 100644
--- a/include/ctype.h
+++ b/include/ctype.h
@@ -29,9 +29,12 @@ libc_hidden_proto (toupper)
# define CTYPE_EXTERN_INLINE extern inline
# endif
-extern __thread const uint16_t * __libc_tsd_CTYPE_B;
-extern __thread const int32_t * __libc_tsd_CTYPE_TOUPPER;
-extern __thread const int32_t * __libc_tsd_CTYPE_TOLOWER;
+extern __thread const uint16_t * __libc_tsd_CTYPE_B
+ attribute_hidden attribute_tls_model_ie;
+extern __thread const int32_t * __libc_tsd_CTYPE_TOUPPER
+ attribute_hidden attribute_tls_model_ie;
+extern __thread const int32_t * __libc_tsd_CTYPE_TOLOWER
+ attribute_hidden attribute_tls_model_ie;
CTYPE_EXTERN_INLINE const uint16_t ** __attribute__ ((const))
diff --git a/include/rpc/rpc.h b/include/rpc/rpc.h
index 936ea3cebb8101e1..ba967833ad8d8ac3 100644
--- a/include/rpc/rpc.h
+++ b/include/rpc/rpc.h
@@ -45,7 +45,8 @@ extern void __rpc_thread_key_cleanup (void) attribute_hidden;
extern void __rpc_thread_destroy (void) attribute_hidden;
-extern __thread struct rpc_thread_variables *__libc_tsd_RPC_VARS;
+extern __thread struct rpc_thread_variables *__libc_tsd_RPC_VARS
+ attribute_hidden attribute_tls_model_ie;
#define RPC_THREAD_VARIABLE(x) (__rpc_thread_variables()->x)
diff --git a/locale/localeinfo.h b/locale/localeinfo.h
index e81ab8a59977d2dd..37af156c47bde8f1 100644
--- a/locale/localeinfo.h
+++ b/locale/localeinfo.h
@@ -215,7 +215,8 @@ extern struct __locale_struct _nl_global_locale attribute_hidden;
/* This fetches the thread-local locale_t pointer, either one set with
uselocale or &_nl_global_locale. */
#define _NL_CURRENT_LOCALE __libc_tsd_LOCALE
-extern __thread locale_t __libc_tsd_LOCALE;
+extern __thread locale_t __libc_tsd_LOCALE
+ attribute_hidden attribute_tls_model_ie;
/* For static linking it is desireable to avoid always linking in the code
and data for every category when we can tell at link time that they are

View File

@ -0,0 +1,66 @@
commit e0c0f856f58ceb68800a964c36c15c606e7a8c4c
Author: Florian Weimer <fweimer@redhat.com>
Date: Fri May 16 19:53:09 2025 +0200
Use proper extern declaration for _nl_C_LC_CTYPE_{class,toupper,tolower}
The existing initializers already contain explicit casts. Keep them
due to int/uint32_t mismatch.
Reviewed-by: Frédéric Bérat <fberat@redhat.com>
diff --git a/ctype/ctype-info.c b/ctype/ctype-info.c
index 4a8e24c001a89688..18f80ba4f64f72b2 100644
--- a/ctype/ctype-info.c
+++ b/ctype/ctype-info.c
@@ -41,10 +41,7 @@ libc_hidden_def (__ctype_init)
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3)
/* Defined in locale/C-ctype.c. */
-extern const char _nl_C_LC_CTYPE_class[] attribute_hidden;
extern const char _nl_C_LC_CTYPE_class32[] attribute_hidden;
-extern const char _nl_C_LC_CTYPE_toupper[] attribute_hidden;
-extern const char _nl_C_LC_CTYPE_tolower[] attribute_hidden;
extern const char _nl_C_LC_CTYPE_class_upper[] attribute_hidden;
extern const char _nl_C_LC_CTYPE_class_lower[] attribute_hidden;
extern const char _nl_C_LC_CTYPE_class_alpha[] attribute_hidden;
diff --git a/include/ctype.h b/include/ctype.h
index 0f6e7fc7ea28f821..a15e5b66781535d4 100644
--- a/include/ctype.h
+++ b/include/ctype.h
@@ -66,6 +66,11 @@ __ctype_tolower_loc (void)
# define __isdigit_l(c, l) ({ int __c = (c); __c >= '0' && __c <= '9'; })
# endif /* Not __NO_CTYPE. */
+/* For use in initializers. */
+extern const char _nl_C_LC_CTYPE_class[] attribute_hidden;
+extern const uint32_t _nl_C_LC_CTYPE_toupper[] attribute_hidden;
+extern const uint32_t _nl_C_LC_CTYPE_tolower[] attribute_hidden;
+
# endif /* IS_IN (libc). */
#endif /* Not _ISOMAC. */
diff --git a/locale/xlocale.c b/locale/xlocale.c
index 8a52c48e5837e552..5b9199e36aa5b60a 100644
--- a/locale/xlocale.c
+++ b/locale/xlocale.c
@@ -19,18 +19,13 @@
#include <locale.h>
#include "localeinfo.h"
+#include <ctype.h>
#define DEFINE_CATEGORY(category, category_name, items, a) \
extern struct __locale_data _nl_C_##category;
#include "categories.def"
#undef DEFINE_CATEGORY
-/* Defined in locale/C-ctype.c. */
-extern const char _nl_C_LC_CTYPE_class[] attribute_hidden;
-extern const char _nl_C_LC_CTYPE_toupper[] attribute_hidden;
-extern const char _nl_C_LC_CTYPE_tolower[] attribute_hidden;
-
-
const struct __locale_struct _nl_C_locobj attribute_hidden =
{
.__locales =

View File

@ -0,0 +1,39 @@
commit 12956e0a330e3d90fc196f7d7a047ce613f78920
Author: Carlos O'Donell <carlos@redhat.com>
Date: Thu Jun 8 06:43:44 2023 -0400
ctype: Reformat Makefile.
Reflow and sort Makefile.
Code generation changes present due to link order changes.
No regressions on x86_64 and i686.
diff --git a/ctype/Makefile b/ctype/Makefile
index e3ccf31d38137b9e..8f35209e0dab0baf 100644
--- a/ctype/Makefile
+++ b/ctype/Makefile
@@ -24,9 +24,18 @@ include ../Makeconfig
headers := ctype.h
-routines := ctype ctype-c99 ctype-extn ctype-c99_l ctype_l isctype
-aux := ctype-info
-
-tests := test_ctype
+routines := \
+ ctype \
+ ctype-c99 \
+ ctype-c99_l \
+ ctype-extn \
+ ctype_l \
+ isctype \
+ # routines
+aux := ctype-info
+
+tests := \
+ test_ctype \
+ # tests
include ../Rules

View File

@ -0,0 +1,197 @@
commit 2745db8dd3ec31045acd761b612516490085bc20
Author: Florian Weimer <fweimer@redhat.com>
Date: Fri May 16 19:53:09 2025 +0200
ctype: Fallback initialization of TLS using relocations (bug 19341, bug 32483)
This ensures that the ctype data pointers in TLS are valid
in secondary namespaces even without initialization via
__ctype_init.
Reviewed-by: Frédéric Bérat <fberat@redhat.com>
diff --git a/ctype/Makefile b/ctype/Makefile
index 8f35209e0dab0baf..571d2391b74daa3f 100644
--- a/ctype/Makefile
+++ b/ctype/Makefile
@@ -36,6 +36,23 @@ aux := ctype-info
tests := \
test_ctype \
+ tst-ctype-tls-dlmopen \
+ tst-ctype-tls-dlopen-static \
# tests
+tests-static := \
+ tst-ctype-tls-dlopen-static \
+ # tests-static
+
+modules-names := \
+ tst-ctype-tls-mod \
+ # modules-names
+
include ../Rules
+
+$(objpfx)tst-ctype-tls-dlmopen: $(shared-thread-library)
+$(objpfx)tst-ctype-tls-dlmopen.out: $(objpfx)tst-ctype-tls-mod.so
+$(objpfx)tst-ctype-tls-dlopen-static: $(static-thread-library)
+$(objpfx)tst-ctype-tls-dlopen-static.out: $(objpfx)tst-ctype-tls-mod.so
+tst-ctype-tls-dlopen-static-ENV = \
+ LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx):$(common-objpfx)elf
diff --git a/ctype/ctype-info.c b/ctype/ctype-info.c
index 18f80ba4f64f72b2..34e718243ece2f92 100644
--- a/ctype/ctype-info.c
+++ b/ctype/ctype-info.c
@@ -19,9 +19,17 @@
#include <ctype.h>
#include <locale/localeinfo.h>
-__thread const uint16_t * __libc_tsd_CTYPE_B;
-__thread const int32_t * __libc_tsd_CTYPE_TOLOWER;
-__thread const int32_t * __libc_tsd_CTYPE_TOUPPER;
+/* Fallback initialization using relocations. See the _nl_C_locobj
+ initializers in locale/xlocale.c. Usually, this is overwritten by
+ __ctype_init before user code runs, but this does not happen for
+ threads in secondary namespaces. With the initializers, secondary
+ namespaces at least get locale data from the C locale. */
+__thread const uint16_t * __libc_tsd_CTYPE_B
+ = (const uint16_t *) _nl_C_LC_CTYPE_class + 128;
+__thread const int32_t * __libc_tsd_CTYPE_TOLOWER
+ = (const int32_t *) _nl_C_LC_CTYPE_tolower + 128;
+__thread const int32_t * __libc_tsd_CTYPE_TOUPPER
+ = (const int32_t *) _nl_C_LC_CTYPE_toupper + 128;
void
diff --git a/ctype/tst-ctype-tls-dlmopen.c b/ctype/tst-ctype-tls-dlmopen.c
new file mode 100644
index 0000000000000000..f7eeb65551344b72
--- /dev/null
+++ b/ctype/tst-ctype-tls-dlmopen.c
@@ -0,0 +1,2 @@
+#define DO_STATIC_TEST 0
+#include "tst-ctype-tls-skeleton.c"
diff --git a/ctype/tst-ctype-tls-dlopen-static.c b/ctype/tst-ctype-tls-dlopen-static.c
new file mode 100644
index 0000000000000000..c2c09c362cc95906
--- /dev/null
+++ b/ctype/tst-ctype-tls-dlopen-static.c
@@ -0,0 +1,2 @@
+#define DO_STATIC_TEST 1
+#include "tst-ctype-tls-skeleton.c"
diff --git a/ctype/tst-ctype-tls-mod.c b/ctype/tst-ctype-tls-mod.c
new file mode 100644
index 0000000000000000..52cbb9dcb67e1800
--- /dev/null
+++ b/ctype/tst-ctype-tls-mod.c
@@ -0,0 +1,37 @@
+/* Wrappers for <ctype.h> macros in a secondary namespace.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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
+ <https://www.gnu.org/licenses/>. */
+
+#include <ctype.h>
+
+int
+my_isalpha (int ch)
+{
+ return isalpha (ch);
+}
+
+int
+my_toupper (int ch)
+{
+ return toupper (ch);
+}
+
+int
+my_tolower (int ch)
+{
+ return tolower (ch);
+}
diff --git a/ctype/tst-ctype-tls-skeleton.c b/ctype/tst-ctype-tls-skeleton.c
new file mode 100644
index 0000000000000000..8c53e35899f12b8f
--- /dev/null
+++ b/ctype/tst-ctype-tls-skeleton.c
@@ -0,0 +1,67 @@
+/* Test that <ctype.h> in a secondary namespace works.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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
+ <https://www.gnu.org/licenses/>. */
+
+/* Before this file is included, define DO_STATIC_TEST to 0 or 1.
+ With 0, dlmopen is used for the test. With 1, dlopen is used. */
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <support/xdlfcn.h>
+#include <support/xthread.h>
+
+static int (*my_isalpha) (int);
+static int (*my_toupper) (int);
+static int (*my_tolower) (int);
+
+static void *
+checks (void *ignore)
+{
+ TEST_VERIFY (my_isalpha ('a'));
+ TEST_VERIFY (!my_isalpha ('0'));
+ TEST_COMPARE (my_toupper ('a'), 'A');
+ TEST_COMPARE (my_toupper ('A'), 'A');
+ TEST_COMPARE (my_tolower ('a'), 'a');
+ TEST_COMPARE (my_tolower ('A'), 'a');
+ return NULL;
+}
+
+static int
+do_test (void)
+{
+ char *dso = xasprintf ("%s/ctype/tst-ctype-tls-mod.so", support_objdir_root);
+#if DO_STATIC_TEST
+ void *handle = xdlopen (dso, RTLD_LAZY);
+#else
+ void *handle = xdlmopen (LM_ID_NEWLM, dso, RTLD_LAZY);
+#endif
+ my_isalpha = xdlsym (handle, "my_isalpha");
+ my_toupper = xdlsym (handle, "my_toupper");
+ my_tolower = xdlsym (handle, "my_tolower");
+
+ checks (NULL);
+ xpthread_join (xpthread_create (NULL, checks, NULL));
+
+ xdlclose (handle);
+ free (dso);
+
+ return 0;
+}
+
+#include <support/test-driver.c>

View File

@ -0,0 +1,27 @@
Downstream-only patch to adjust for libdl being shipped separately in
RHEL-8. Upstream, libdl has been moved into libc and we do not need to
link against it separately.
diff --git a/ctype/Makefile b/ctype/Makefile
index 571d2391b74daa3f..a8204d1787751151 100644
--- a/ctype/Makefile
+++ b/ctype/Makefile
@@ -50,9 +50,16 @@ modules-names := \
include ../Rules
-$(objpfx)tst-ctype-tls-dlmopen: $(shared-thread-library)
+$(objpfx)tst-ctype-tls-dlmopen: $(shared-thread-library) $(libdl)
$(objpfx)tst-ctype-tls-dlmopen.out: $(objpfx)tst-ctype-tls-mod.so
-$(objpfx)tst-ctype-tls-dlopen-static: $(static-thread-library)
+
+$(objpfx)tst-ctype-tls-dlopen-static: \
+ $(static-thread-library) \
+ $(common-objpfx)dlfcn/libdl.a
+
+# Suppress linker warning when linking statically linked test against libdl
+LDFLAGS-tst-ctype-tls-dlopen-static = -Wl,--no-fatal-warnings
+
$(objpfx)tst-ctype-tls-dlopen-static.out: $(objpfx)tst-ctype-tls-mod.so
tst-ctype-tls-dlopen-static-ENV = \
LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx):$(common-objpfx)elf

View File

@ -0,0 +1,39 @@
commit e5363e6f460c2d58809bf10fc96d70fd1ef8b5b2
Author: Jens Remus <jremus@linux.ibm.com>
Date: Fri Jul 25 15:40:03 2025 +0200
Use TLS initial-exec model for __libc_tsd_CTYPE_* thread variables [BZ #33234]
Commit 10a66a8e421b ("Remove <libc-tsd.h>") removed the TLS initial-exec
(IE) model attribute from the __libc_tsd_CTYPE_* thread variable declarations
and definitions. Commit a894f04d8776 ("Optimize __libc_tsd_* thread
variable access") restored it on declarations.
Restore the TLS initial-exec model attribute on __libc_tsd_CTYPE_* thread
variable definitions.
This resolves test tst-locale1 failure on s390 32-bit, when using a
GNU linker without the fix from GNU binutils commit aefebe82dc89
("IBM zSystems: Fix offset relative to static TLS").
Reviewed-by: Florian Weimer <fweimer@redhat.com>
diff --git a/ctype/ctype-info.c b/ctype/ctype-info.c
index 34e718243ece2f92..e109c4e516bdac8a 100644
--- a/ctype/ctype-info.c
+++ b/ctype/ctype-info.c
@@ -24,11 +24,11 @@
__ctype_init before user code runs, but this does not happen for
threads in secondary namespaces. With the initializers, secondary
namespaces at least get locale data from the C locale. */
-__thread const uint16_t * __libc_tsd_CTYPE_B
+__thread const uint16_t * __libc_tsd_CTYPE_B attribute_tls_model_ie
= (const uint16_t *) _nl_C_LC_CTYPE_class + 128;
-__thread const int32_t * __libc_tsd_CTYPE_TOLOWER
+__thread const int32_t * __libc_tsd_CTYPE_TOLOWER attribute_tls_model_ie
= (const int32_t *) _nl_C_LC_CTYPE_tolower + 128;
-__thread const int32_t * __libc_tsd_CTYPE_TOUPPER
+__thread const int32_t * __libc_tsd_CTYPE_TOUPPER attribute_tls_model_ie
= (const int32_t *) _nl_C_LC_CTYPE_toupper + 128;

View File

@ -115,7 +115,7 @@ end \
Summary: The GNU libc libraries
Name: glibc
Version: %{glibcversion}
Release: %{glibcrelease}.25
Release: %{glibcrelease}.27
# In general, GPLv2+ is used by programs, LGPLv2+ is used for
# libraries.
@ -1286,6 +1286,15 @@ Patch1051: glibc-RHEL-18039-4.patch
Patch1052: glibc-RHEL-18039-5.patch
Patch1053: glibc-RHEL-18039-6.patch
Patch1054: glibc-RHEL-105326.patch
Patch1055: glibc-RHEL-114260.patch
Patch1056: glibc-RHEL-72011-1.patch
Patch1057: glibc-RHEL-72011-2.patch
Patch1058: glibc-RHEL-72011-3.patch
Patch1059: glibc-RHEL-72011-4.patch
Patch1060: glibc-RHEL-72011-5.patch
Patch1061: glibc-RHEL-72011-6.patch
Patch1062: glibc-RHEL-72011-7.patch
Patch1063: glibc-RHEL-72011-8.patch
##############################################################################
# Continued list of core "glibc" package information:
@ -2947,6 +2956,13 @@ fi
%{_libdir}/libpthread_nonshared.a
%changelog
* Thu Nov 20 2025 Arjun Shankar <arjun@redhat.com> - 2.28-251.27
- Fix a segmentation fault in multi-threaded multi-namespace programs using
ctype.h macros (RHEL-72011)
* Fri Oct 03 2025 DJ Delorie <dj@redhat.com> - 2.28-251.26
- nss: Group merge does not react to ERANGE during merge (RHEL-114260)
* Thu Jul 24 2025 Florian Weimer <fweimer@redhat.com> - 2.28-251.25
- CVE-2025-8058: Double free in regcomp (RHEL-105326)