aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/mach/hurd/i386
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2023-03-19 18:10:07 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-04-10 23:33:30 +0200
commitb37899d34d2190ef4b454283188f22519f096048 (patch)
treed21e03749c679cfa3659cc9acb126903668c7897 /sysdeps/mach/hurd/i386
parent4644fb9c4c10287c875dc60c345a3eb6f4c8e87b (diff)
downloadglibc-b37899d34d2190ef4b454283188f22519f096048.zip
glibc-b37899d34d2190ef4b454283188f22519f096048.tar.gz
glibc-b37899d34d2190ef4b454283188f22519f096048.tar.bz2
hurd: Only check for TLS initialization inside rtld or in static builds
When glibc is built as a shared library, TLS is always initialized by the call of TLS_INIT_TP () macro made inside the dynamic loader, prior to running the main program (see dl-call_tls_init_tp.h). We can take advantage of this: we know for sure that __LIBC_NO_TLS () will evaluate to 0 in all other cases, so let the compiler know that explicitly too. Also, only define _hurd_tls_init () and TLS_INIT_TP () under the same conditions (either !SHARED or inside rtld), to statically assert that this is the case. Other than a microoptimization, this also helps with avoiding awkward sharing of the __libc_tls_initialized variable between ld.so and libc.so that we would have to do otherwise -- we know for sure that no sharing is required, simply because __libc_tls_initialized would always be set to true inside libc.so. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-25-bugaevc@gmail.com>
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, 47 insertions, 17 deletions
diff --git a/sysdeps/mach/hurd/i386/dl-tls-initialized.c b/sysdeps/mach/hurd/i386/dl-tls-initialized.c
new file mode 100644
index 0000000..493ec23
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/dl-tls-initialized.c
@@ -0,0 +1,21 @@
+/* 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 0f8dd24..ee7b800 100644
--- a/sysdeps/mach/hurd/i386/tls.h
+++ b/sysdeps/mach/hurd/i386/tls.h
@@ -69,18 +69,6 @@ _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
@@ -125,6 +113,28 @@ extern unsigned short __init1_desc;
# 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)
{
@@ -168,11 +178,10 @@ out:
return success;
}
-/* 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))
+# define TLS_INIT_TP(descr) _hurd_tls_init ((tcbhead_t *) (descr))
+#else /* defined (SHARED) && !IS_IN (rtld) */
+# define __LIBC_NO_TLS() 0
+#endif
# if __GNUC_PREREQ (6, 0)