Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src FreeBSD bug report 161344: TLS area for the main thread is s...



details:   https://anonhg.NetBSD.org/src/rev/76a23ec29e38
branches:  trunk
changeset: 771266:76a23ec29e38
user:      joerg <joerg%NetBSD.org@localhost>
date:      Thu Nov 17 16:20:11 2011 +0000

description:
FreeBSD bug report 161344: TLS area for the main thread is set up to
early, if e.g. pointers to functions are used as initializers.

diffstat:

 libexec/ld.elf_so/rtld.c               |  17 +++++++++++++----
 tests/lib/libc/tls/dso/h_tls_dlopen.c  |  10 ++++++++--
 tests/lib/libc/tls/t_tls_dlopen.c      |  11 +++++++++--
 tests/lib/libc/tls/t_tls_dynamic.c     |  13 +++++++++++--
 tests/lib/libc/tls_dso/h_tls_dynamic.c |   7 +++++--
 5 files changed, 46 insertions(+), 12 deletions(-)

diffs (208 lines):

diff -r e87ccb26b4e1 -r 76a23ec29e38 libexec/ld.elf_so/rtld.c
--- a/libexec/ld.elf_so/rtld.c  Thu Nov 17 16:04:07 2011 +0000
+++ b/libexec/ld.elf_so/rtld.c  Thu Nov 17 16:20:11 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtld.c,v 1.153 2011/10/23 21:06:07 christos Exp $       */
+/*     $NetBSD: rtld.c,v 1.154 2011/11/17 16:20:11 joerg Exp $  */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.153 2011/10/23 21:06:07 christos Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.154 2011/11/17 16:20:11 joerg Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -642,13 +642,12 @@
        }
 
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
-       dbg(("initializing initial Thread Local Storage"));
+       dbg(("initializing initial Thread Local Storage offsets"));
        /*
         * All initial objects get the TLS space from the static block.
         */
        for (obj = _rtld_objlist; obj != NULL; obj = obj->next)
                _rtld_tls_offset_allocate(obj);
-       _rtld_tls_initial_allocation();
 #endif
 
        dbg(("relocating objects"));
@@ -659,6 +658,16 @@
        if (_rtld_do_copy_relocations(_rtld_objmain) == -1)
                _rtld_die();
 
+#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
+       dbg(("initializing Thread Local Storage for main thread"));
+       /*
+        * Set up TLS area for the main thread.
+        * This has to be done after all relocations are processed,
+        * since .tdata may contain relocations.
+        */
+       _rtld_tls_initial_allocation();
+#endif
+
        /*
         * Set the __progname,  environ and, __mainprog_obj before
         * calling anything that might use them.
diff -r e87ccb26b4e1 -r 76a23ec29e38 tests/lib/libc/tls/dso/h_tls_dlopen.c
--- a/tests/lib/libc/tls/dso/h_tls_dlopen.c     Thu Nov 17 16:04:07 2011 +0000
+++ b/tests/lib/libc/tls/dso/h_tls_dlopen.c     Thu Nov 17 16:20:11 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: h_tls_dlopen.c,v 1.1 2011/03/09 23:10:08 joerg Exp $   */
+/*     $NetBSD: h_tls_dlopen.c,v 1.2 2011/11/17 16:20:11 joerg Exp $   */
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,8 +32,10 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: h_tls_dlopen.c,v 1.1 2011/03/09 23:10:08 joerg Exp $");
+__RCSID("$NetBSD: h_tls_dlopen.c,v 1.2 2011/11/17 16:20:11 joerg Exp $");
 
+#include <atf-c.h>
+#include <unistd.h>
 #include <sys/tls.h>
 
 #if !defined(__HAVE_TLS_VARIANT_I) && !defined(__HAVE_TLS_VARIANT_II)
@@ -42,6 +44,8 @@
 
 extern __thread int var1;
 extern __thread int var2;
+extern __thread int *var3;
+__thread static pid_t (*local_var)(void) = getpid;
 
 void testf_dso_helper(int x, int y);
 
@@ -50,4 +54,6 @@
 {
        var1 = x;
        var2 = y;
+       var3 = &optind;
+       ATF_CHECK_EQ(local_var, getpid);
 }
diff -r e87ccb26b4e1 -r 76a23ec29e38 tests/lib/libc/tls/t_tls_dlopen.c
--- a/tests/lib/libc/tls/t_tls_dlopen.c Thu Nov 17 16:04:07 2011 +0000
+++ b/tests/lib/libc/tls/t_tls_dlopen.c Thu Nov 17 16:20:11 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_tls_dlopen.c,v 1.1 2011/03/09 23:10:07 joerg Exp $   */
+/*     $NetBSD: t_tls_dlopen.c,v 1.2 2011/11/17 16:20:11 joerg Exp $   */
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,11 +32,12 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_tls_dlopen.c,v 1.1 2011/03/09 23:10:07 joerg Exp $");
+__RCSID("$NetBSD: t_tls_dlopen.c,v 1.2 2011/11/17 16:20:11 joerg Exp $");
 
 #include <atf-c.h>
 #include <dlfcn.h>
 #include <pthread.h>
+#include <unistd.h>
 
 #include <sys/tls.h>
 
@@ -56,18 +57,24 @@
 
 __thread int var1 = 1;
 __thread int var2;
+__thread int *var3 = &optind;
+int var4_helper;
+__thread int *var4 = &var4_helper;
 
 static void *
 testf(void *dummy)
 {
        ATF_CHECK_EQ(var1, 1);
        ATF_CHECK_EQ(var2, 0);
+       ATF_CHECK_EQ(var3, &optind);
+       ATF_CHECK_EQ(var4, &var4_helper);
        testf_helper(2, 2);
        ATF_CHECK_EQ(var1, 2);
        ATF_CHECK_EQ(var2, 2);
        testf_helper(3, 3);
        ATF_CHECK_EQ(var1, 3);
        ATF_CHECK_EQ(var2, 3);
+       ATF_CHECK_EQ(var3, &optind);
 
        return NULL;
 }
diff -r e87ccb26b4e1 -r 76a23ec29e38 tests/lib/libc/tls/t_tls_dynamic.c
--- a/tests/lib/libc/tls/t_tls_dynamic.c        Thu Nov 17 16:04:07 2011 +0000
+++ b/tests/lib/libc/tls/t_tls_dynamic.c        Thu Nov 17 16:20:11 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_tls_dynamic.c,v 1.1 2011/03/09 23:10:07 joerg Exp $  */
+/*     $NetBSD: t_tls_dynamic.c,v 1.2 2011/11/17 16:20:11 joerg Exp $  */
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,10 +32,11 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_tls_dynamic.c,v 1.1 2011/03/09 23:10:07 joerg Exp $");
+__RCSID("$NetBSD: t_tls_dynamic.c,v 1.2 2011/11/17 16:20:11 joerg Exp $");
 
 #include <atf-c.h>
 #include <pthread.h>
+#include <unistd.h>
 
 #include <sys/tls.h>
 
@@ -55,6 +56,11 @@
 
 extern __thread int var1;
 extern __thread int var2;
+extern __thread pid_t (*dso_var1)(void);
+
+__thread int *var3 = &optind;
+int var4_helper;
+__thread int *var4 = &var4_helper;
 
 static void *
 testf(void *dummy)
@@ -67,6 +73,9 @@
        testf_dso_helper(3, 3);
        ATF_CHECK_EQ(var1, 3);
        ATF_CHECK_EQ(var2, 3);
+       ATF_CHECK_EQ(var3, &optind);
+       ATF_CHECK_EQ(var4, &var4_helper);
+       ATF_CHECK_EQ(dso_var1, getpid);
 
        return NULL;
 }
diff -r e87ccb26b4e1 -r 76a23ec29e38 tests/lib/libc/tls_dso/h_tls_dynamic.c
--- a/tests/lib/libc/tls_dso/h_tls_dynamic.c    Thu Nov 17 16:04:07 2011 +0000
+++ b/tests/lib/libc/tls_dso/h_tls_dynamic.c    Thu Nov 17 16:20:11 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: h_tls_dynamic.c,v 1.1 2011/03/09 23:10:08 joerg Exp $  */
+/*     $NetBSD: h_tls_dynamic.c,v 1.2 2011/11/17 16:20:11 joerg Exp $  */
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,8 +32,9 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: h_tls_dynamic.c,v 1.1 2011/03/09 23:10:08 joerg Exp $");
+__RCSID("$NetBSD: h_tls_dynamic.c,v 1.2 2011/11/17 16:20:11 joerg Exp $");
 
+#include <unistd.h>
 #include <sys/tls.h>
 
 #if !defined(__HAVE_TLS_VARIANT_I) && !defined(__HAVE_TLS_VARIANT_II)
@@ -43,6 +44,8 @@
 __thread int var1 = 1;
 __thread int var2;
 
+__thread pid_t (*dso_var1)(void) = getpid;
+
 void testf_dso_helper(int x, int y);
 
 void



Home | Main Index | Thread Index | Old Index