* [PATCH] Use __attribute__((tls_model(""))), add hidden aliases to TLS vars
@ 2002-10-15 15:43 Jakub Jelinek
2002-10-15 20:04 ` Roland McGrath
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2002-10-15 15:43 UTC (permalink / raw)
To: Roland McGrath, Ulrich Drepper; +Cc: Glibc hackers
Hi!
The following patch uses IE model for all TLS vars defined in libc,
plus for errno, _res and h_errno uses a hidden alias when accessed
from libc.so, so that it doesn't have to be looked up.
2002-10-16 Jakub Jelinek <jakub@redhat.com>
* include/libc-symbols.h (attribute_tls_model_ie): Define.
* include/errno.h (errno): Define to __libc_errno in libc.so.
Add attribute_tls_model_ie.
* include/netdb.h (h_errno): Define to __libc_h_errno in libc.so.
Add attribute_tls_model_ie.
* include/resolv.h (_res): Define to __libc_res in libc.so. Add
attribute_tls_model_ie.
* inet/herrno.c (__libc_h_errno): Add hidden alias to h_errno.
(h_errno): Define.
* resolv/res_libc.c (__libc_res): Add hidden alias to _res.
(_res): Define.
* sysdeps/generic/bits/libc-tsd.h (__libc_tsd_define): Add
attribute_tls_model_ie.
* sysdeps/generic/errno-loc.c (errno): Only undefine if not using
__thread.
* sysdeps/generic/errno.c (__libc_errno): Add hidden alias to errno.
* sysdeps/unix/sysv/linux/i386/sysdep.h (SYSCALL_ERROR_HANDLER): Use
__libc_errno in USE___THREAD case.
* sysdeps/unix/sysv/linux/x86_64/sysdep.h (SYSCALL_ERROR_HANDLER):
Likewise.
* configure.in (HAVE_TLS_MODEL_ATTRIBUTE): Check for
__attribute__((tls_model (""))).
* configure: Rebuilt.
* config.h.in (HAVE_TLS_MODEL_ATTRIBUTE): Add.
--- libc/include/libc-symbols.h.jj 2002-10-02 10:26:31.000000000 +0200
+++ libc/include/libc-symbols.h 2002-10-15 21:13:14.000000000 +0200
@@ -445,6 +445,12 @@
# define attribute_hidden
#endif
+#if defined HAVE_TLS_MODEL_ATTRIBUTE
+# define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
+#else
+# define attribute_tls_model_ie
+#endif
+
/* Handling on non-exported internal names. We have to do this only
for shared code. */
#ifdef SHARED
--- libc/include/errno.h.jj 2002-10-11 16:24:33.000000000 +0200
+++ libc/include/errno.h 2002-10-15 22:53:12.000000000 +0200
@@ -24,8 +24,12 @@ extern int errno attribute_hidden;
# if USE___THREAD
# undef errno
-# define errno errno /* For #ifndef errno tests. */
-extern __thread int errno;
+# ifndef NOT_IN_libc
+# define errno __libc_errno
+# else
+# define errno errno /* For #ifndef errno tests. */
+# endif
+extern __thread int errno attribute_tls_model_ie;
# define __set_errno(val) (errno = (val))
# else
# define __set_errno(val) (*__errno_location ()) = (val)
--- libc/include/netdb.h.jj 2002-10-11 16:24:34.000000000 +0200
+++ libc/include/netdb.h 2002-10-15 22:55:30.000000000 +0200
@@ -6,8 +6,12 @@
# include <tls.h>
# if USE___THREAD
# undef h_errno
-# define h_errno h_errno /* For #ifndef h_errno tests. */
-extern __thread int h_errno;
+# ifndef NOT_IN_libc
+# define h_errno __libc_h_errno
+# else
+# define h_errno h_errno /* For #ifndef h_errno tests. */
+# endif
+extern __thread int h_errno attribute_tls_model_ie;
# define __set_h_errno(x) (h_errno = (x))
# else
static inline int
--- libc/include/resolv.h.jj 2002-10-15 18:24:35.000000000 +0200
+++ libc/include/resolv.h 2002-10-15 22:56:02.000000000 +0200
@@ -16,7 +16,10 @@
# include <tls.h>
# if USE___THREAD
# undef _res
-extern __thread struct __res_state _res;
+# ifndef NOT_IN_libc
+# define _res __libc_res
+# endif
+extern __thread struct __res_state _res attribute_tls_model_ie;
# endif
# else
# ifndef __BIND_NOSTATIC
--- libc/inet/herrno.c.jj 2002-09-11 11:21:05.000000000 +0200
+++ libc/inet/herrno.c 2002-10-15 23:55:06.000000000 +0200
@@ -27,6 +27,9 @@
#if USE_TLS && HAVE___THREAD
__thread int h_errno;
+extern __thread int __libc_h_errno __attribute__ ((alias ("h_errno")))
+ attribute_hidden;
+# define h_errno __libc_h_errno
#else
int h_errno = 0;
weak_alias (h_errno, _h_errno)
--- libc/resolv/res_libc.c.jj 2002-09-11 11:21:09.000000000 +0200
+++ libc/resolv/res_libc.c 2002-10-15 23:55:36.000000000 +0200
@@ -27,6 +27,9 @@
#if USE_TLS && HAVE___THREAD
/* With __thread support, this per-thread variable is used in all cases. */
__thread struct __res_state _res;
+extern __thread struct __res_state __libc_res __attribute__ ((alias ("_res")))
+ attribute_hidden;
+# define _res __libc_res
#else
/* The resolver state for use by single-threaded programs. */
struct __res_state _res;
--- libc/sysdeps/generic/bits/libc-tsd.h.jj 2002-10-11 16:24:49.000000000 +0200
+++ libc/sysdeps/generic/bits/libc-tsd.h 2002-10-15 21:02:24.000000000 +0200
@@ -52,7 +52,8 @@
translate directly into variables by macro magic. */
#if USE___THREAD
-# define __libc_tsd_define(CLASS, KEY) CLASS __thread void *__libc_tsd_##KEY;
+# define __libc_tsd_define(CLASS, KEY) \
+ CLASS __thread void *__libc_tsd_##KEY attribute_tls_model_ie;
# define __libc_tsd_address(KEY) (&__libc_tsd_##KEY)
# define __libc_tsd_get(KEY) (__libc_tsd_##KEY)
--- libc/sysdeps/generic/errno-loc.c.jj 2002-07-23 10:05:49.000000000 +0200
+++ libc/sysdeps/generic/errno-loc.c 2002-10-15 22:57:39.000000000 +0200
@@ -20,11 +20,9 @@
#include <errno.h>
#include <tls.h>
-#undef errno
-#if USE_TLS && HAVE___THREAD
-extern __thread int errno;
-#else
+#if !(USE_TLS && HAVE___THREAD)
+#undef errno
extern int errno;
#endif
--- libc/sysdeps/generic/errno.c.jj 2002-10-11 12:51:23.000000000 +0200
+++ libc/sysdeps/generic/errno.c 2002-10-15 23:02:50.000000000 +0200
@@ -23,6 +23,8 @@
#if USE___THREAD
__thread int errno;
+extern __thread int __libc_errno __attribute__ ((alias ("errno")))
+ attribute_hidden;
#else
/* This differs from plain `int errno;' in that it doesn't create
a common definition, but a plain symbol that resides in .bss,
--- libc/sysdeps/unix/sysv/linux/i386/sysdep.h.jj 2002-10-13 21:59:29.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/i386/sysdep.h 2002-10-15 23:06:09.000000000 +0200
@@ -114,7 +114,7 @@ __i686.get_pc_thunk.reg: \
# define SYSCALL_ERROR_HANDLER \
0:SETUP_PIC_REG (cx); \
addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
- movl errno@gotntpoff(%ecx), %ecx; \
+ movl __libc_errno@GOTNTPOFF(%ecx), %ecx; \
xorl %edx, %edx; \
subl %eax, %edx; \
movl %edx, %gs:0(%ecx); \
--- libc/sysdeps/unix/sysv/linux/x86_64/sysdep.h.jj 2002-10-15 20:41:01.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/x86_64/sysdep.h 2002-10-15 23:05:18.000000000 +0200
@@ -95,7 +95,7 @@
#elif USE___THREAD
# define SYSCALL_ERROR_HANDLER \
0: \
- movq errno@GOTTPOFF(%rip), %rcx; \
+ movq __libc_errno@GOTTPOFF(%rip), %rcx; \
xorq %rdx, %rdx; \
subq %rax, %rdx; \
movl %edx, %fs:(%rcx); \
--- libc/configure.in.jj 2002-10-10 14:01:48.000000000 +0200
+++ libc/configure.in 2002-10-15 21:06:39.000000000 +0200
@@ -1624,6 +1624,22 @@ if test "$libc_cv_gcc___thread" = yes; t
AC_DEFINE(HAVE___THREAD)
fi
+if test "$libc_cv_gcc___thread" = yes; then
+ dnl Check whether the compiler supports the tls_model attribute.
+ AC_CACHE_CHECK([for tls_model attribute], libc_cv_gcc_tls_model_attr, [dnl
+ cat > conftest.c <<\EOF
+extern __thread int a __attribute__((tls_model ("initial-exec")));
+EOF
+ if AC_TRY_COMMAND([${CC-cc} $CFLAGS -S -Werror conftest.c >&AC_FD_CC]); then
+ libc_cv_gcc_tls_model_attr=yes
+ else
+ libc_cv_gcc_tls_model_attr=no
+ fi
+ rm -f conftest*])
+ if test "$libc_cv_gcc_tls_model_attr" = yes; then
+ AC_DEFINE(HAVE_TLS_MODEL_ATTRIBUTE)
+ fi
+fi
dnl Check whether we have the gd library available.
AC_MSG_CHECKING(for libgd)
--- libc/configure.jj 2002-10-10 14:01:48.000000000 +0200
+++ libc/configure 2002-10-15 21:07:16.000000000 +0200
@@ -3772,6 +3772,31 @@ EOF
fi
+if test "$libc_cv_gcc___thread" = yes; then
+ echo $ac_n "checking for tls_model attribute""... $ac_c" 1>&6
+echo "configure:3778: checking for tls_model attribute" >&5
+if eval "test \"`echo '$''{'libc_cv_gcc_tls_model_attr'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.c <<\EOF
+extern __thread int a __attribute__((tls_model ("initial-exec")));
+EOF
+ if { ac_try='${CC-cc} $CFLAGS -S -Werror conftest.c >&5'; { (eval echo configure:3785: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
+ libc_cv_gcc_tls_model_attr=yes
+ else
+ libc_cv_gcc_tls_model_attr=no
+ fi
+ rm -f conftest*
+fi
+
+echo "$ac_t""$libc_cv_gcc_tls_model_attr" 1>&6
+ if test "$libc_cv_gcc_tls_model_attr" = yes; then
+ cat >> confdefs.h <<\EOF
+#define HAVE_TLS_MODEL_ATTRIBUTE 1
+EOF
+
+ fi
+fi
echo $ac_n "checking for libgd""... $ac_c" 1>&6
echo "configure:3778: checking for libgd" >&5
--- libc/config.h.in.jj 2002-10-11 16:24:28.000000000 +0200
+++ libc/config.h.in 2002-10-15 20:56:23.000000000 +0200
@@ -101,6 +101,9 @@
/* Define if the __thread keyword is supported. */
#undef HAVE___THREAD
+/* Define if the compiler supports __attribute__((tls_model(""))). */
+#undef HAVE_TLS_MODEL_ATTRIBUTE
+
/* Define if the regparm attribute shall be used for local functions
(gcc on ix86 only). */
#undef USE_REGPARMS
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Use __attribute__((tls_model(""))), add hidden aliases to TLS vars
2002-10-15 15:43 [PATCH] Use __attribute__((tls_model(""))), add hidden aliases to TLS vars Jakub Jelinek
@ 2002-10-15 20:04 ` Roland McGrath
0 siblings, 0 replies; 2+ messages in thread
From: Roland McGrath @ 2002-10-15 20:04 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Ulrich Drepper, Glibc hackers
Cool, I'll put that in. I was going to get to that myself but hadn't yet
installed the compiler that supports it.
It occurs to me you could use libc_hidden_proto instead of macros.
But that is uglier in the asm, and both ways do the same thing.
One thing that concerns me is if a program (erroneously) does
"__thread int errno;" (sans extern) or suchlike. Then the program
and libpthread will use its errno, but libc will only set __libc_errno.
It would be nice if this produced a link-time error like a multiple
definition with a non-shared object would. But AFAIK no .so symbol will
ever produce a multiple definition error. Perhaps we could do some hack in
the linker script.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-10-15 22:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-15 15:43 [PATCH] Use __attribute__((tls_model(""))), add hidden aliases to TLS vars Jakub Jelinek
2002-10-15 20:04 ` Roland McGrath
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).