about summary refs log tree commit diff
path: root/sysdeps/mach/hurd/i386
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2023-04-11 18:06:03 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-04-11 18:45:47 +0000
commit5473a1747a7bd10a7a271c7e01e942711a707bb8 (patch)
tree1b60927728041a1337a2848abd663995771b8d28 /sysdeps/mach/hurd/i386
parentcd019ddd892e182277fadd6aedccc57fa3923c8d (diff)
downloadglibc-5473a1747a7bd10a7a271c7e01e942711a707bb8.tar.gz
glibc-5473a1747a7bd10a7a271c7e01e942711a707bb8.tar.xz
glibc-5473a1747a7bd10a7a271c7e01e942711a707bb8.zip
Revert "hurd: Only check for TLS initialization inside rtld or in static builds"
This reverts commit b37899d34d2190ef4b454283188f22519f096048.

Apparently we load libc.so (and thus start using its functions) before
calling TLS_INIT_TP, so libc.so functions should not actually assume
that TLS is always set up.
Diffstat (limited to 'sysdeps/mach/hurd/i386')
-rw-r--r--sysdeps/mach/hurd/i386/dl-tls-initialized.c21
-rw-r--r--sysdeps/mach/hurd/i386/tls.h43
2 files changed, 17 insertions, 47 deletions
diff --git a/sysdeps/mach/hurd/i386/dl-tls-initialized.c b/sysdeps/mach/hurd/i386/dl-tls-initialized.c
deleted file mode 100644
index 493ec2396c..0000000000
--- a/sysdeps/mach/hurd/i386/dl-tls-initialized.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Determine whether TLS is initialized, for i386/Hurd.
-   Copyright (C) 1995-2023 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 SHARED
-unsigned short __init1_desc;
-#endif
diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h
index 0ac8917a95..694be9fd64 100644
--- a/sysdeps/mach/hurd/i386/tls.h
+++ b/sysdeps/mach/hurd/i386/tls.h
@@ -69,6 +69,18 @@ _Static_assert (offsetof (tcbhead_t, __private_ss) == 0x30,
                   |  (desc->high_word & 0xff000000));			      \
   })
 
+/* Return 1 if TLS is not initialized yet.  */
+#ifndef SHARED
+extern unsigned short __init1_desc;
+#define __HURD_DESC_INITIAL(gs, ds) ((gs) == (ds) || (gs) == __init1_desc)
+#else
+#define __HURD_DESC_INITIAL(gs, ds) ((gs) == (ds))
+#endif
+
+#define __LIBC_NO_TLS()							      \
+  ({ unsigned short ds, gs;						      \
+     asm ("movw %%ds,%w0; movw %%gs,%w1" : "=q" (ds), "=q" (gs));	      \
+     __builtin_expect(__HURD_DESC_INITIAL(gs, ds), 0); })
 #endif
 
 /* The TCB can have any size and the memory following the address the
@@ -113,28 +125,6 @@ _Static_assert (offsetof (tcbhead_t, __private_ss) == 0x30,
 
 # define HURD_SEL_LDT(sel) (__builtin_expect ((sel) & 4, 0))
 
-#ifndef SHARED
-extern unsigned short __init1_desc;
-# define __HURD_DESC_INITIAL(gs, ds) ((gs) == (ds) || (gs) == __init1_desc)
-#else
-# define __HURD_DESC_INITIAL(gs, ds) ((gs) == (ds))
-#endif
-
-#if !defined (SHARED) || IS_IN (rtld)
-/* Return 1 if TLS is not initialized yet.  */
-extern inline bool __attribute__ ((unused))
-__LIBC_NO_TLS (void)
-{
-  unsigned short ds, gs;
-  asm ("movw %%ds, %w0\n"
-       "movw %%gs, %w1"
-       : "=q" (ds), "=q" (gs));
-  return __glibc_unlikely (__HURD_DESC_INITIAL (gs, ds));
-}
-
-/* Code to initially initialize the thread pointer.  This might need
-   special attention since 'errno' is not yet available and if the
-   operation can cause a failure 'errno' must not be touched.  */
 static inline bool __attribute__ ((unused))
 _hurd_tls_init (tcbhead_t *tcb)
 {
@@ -183,10 +173,11 @@ out:
   return success;
 }
 
-# define TLS_INIT_TP(descr) _hurd_tls_init ((tcbhead_t *) (descr))
-#else /* defined (SHARED) && !IS_IN (rtld) */
-# define __LIBC_NO_TLS() 0
-#endif
+/* Code to initially initialize the thread pointer.  This might need
+   special attention since 'errno' is not yet available and if the
+   operation can cause a failure 'errno' must not be touched.  */
+# define TLS_INIT_TP(descr) \
+    _hurd_tls_init ((tcbhead_t *) (descr))
 
 # if __GNUC_PREREQ (6, 0)