]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Remove <libc-tsd.h>
authorFlorian Weimer <fweimer@redhat.com>
Fri, 16 May 2025 17:53:09 +0000 (19:53 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 14 Aug 2025 09:49:20 +0000 (11:49 +0200)
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>
(cherry picked from commit 10a66a8e421b09682b774c795ef1da402235dddc)

ctype/ctype-info.c
include/ctype.h
include/rpc/rpc.h
locale/lc-ctype.c
locale/localeinfo.h
locale/uselocale.c
stdio-common/printf-parsemb.c
string/strerror.c
sunrpc/rpc_thread.c
sysdeps/generic/libc-tsd.h [deleted file]
time/strftime_l.c

index 9032547567b2c348198721b21049319cdca627d3..71d1c8e3b4660d54c7b5bff0e245b8661390515a 100644 (file)
 #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)
 
index 493a6f80ce8e8b8edc75578a0d33ba34551a7ace..e993adc86da43b7c3047834c6aa1e051fed532ac 100644 (file)
@@ -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
index f5cee6caef6284d25fd8adac047cde31749eb11a..936ea3cebb8101e158ca591aa72f94793a0175e1 100644 (file)
@@ -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)
 
index c77ec51cb89b839d754d186ceaaf9feb59c902e6..70556acaf0dc69bb6cce309873171d0b1e2d2a0c 100644 (file)
@@ -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>
index ed698faef1b3800359b0600d2f9d27f242497c64..bc8e92e4dca80d62b25ab04ff4f81e1f504e5954 100644 (file)
@@ -236,10 +236,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
index 8136caf61b4673fbf0cf36ef8eb5566140ec4328..0b247a77d5f47f81d447cbad19f22a515cd811fc 100644 (file)
@@ -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;
index ab9fafb5ecb12f16f6a43276630a66c3985b6900..8db18f11b32c9433fd56180dc2eeb6ac0700369f 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <ctype.h>
+#include <errno.h>
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
index 107d9d39c287bed4233bd68c6be66a96073b287e..efa4e903ead00a479b93f97a1c03cadc58106578 100644 (file)
@@ -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);
 }
index a04b7ec47fa4760cac6a635f4373405372aa1a71..e20f0a62302eb675b3f37bdaa3bb8af4e748dd51 100644 (file)
@@ -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 (file)
index ac0e99e..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/* libc-internal interface for thread-specific data.  Stub or TLS version.
-   Copyright (C) 1998-2024 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/>.  */
-
-#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 */
index 77adec905007d53add6060a4aab7e8e6009449d8..066c839c2feccdc130e321dc0233e29e6481521d 100644 (file)
@@ -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