PLT and improves the performance of some of our code via better icache
and iTLB performance.
(tmsriram, google-local)
+
+elf/dl-tls.c
+nptl/Makefile
+nptl/tst-tls77.c
+nptl/tst-tls77mod.c
+ Fix b/19824366 with tweaks to TLS dynamic loading, and add a test. Note that
+ upstream commit
+ https://sourceware.org/git/?p=glibc.git&a=commit&h=f8aeae347377f3dfa8cbadde057adf1827fb1d44
+ fixes this problem in a different way, so this patch is not needed upstream.
memalign and not malloc. */
__signal_safe_free (dtv[modid].pointer.val);
- /* This module is loaded dynamically- We defer memory
- allocation. */
- dtv[modid].pointer.is_static = false;
- dtv[modid].pointer.val = TLS_DTV_UNALLOCATED;
+ /* Google-local fix for issues solved differently upstream. */
+ if (map->l_tls_offset == NO_TLS_OFFSET
+ || map->l_tls_offset == FORCED_DYNAMIC_TLS_OFFSET)
+ {
+ /* This module is loaded dynamically- We defer memory
+ allocation. */
+ dtv[modid].pointer.is_static = false;
+ dtv[modid].pointer.val = TLS_DTV_UNALLOCATED;
+ }
if (modid == req_modid)
the_map = map;
}
else
{
- void **pp = &dtv[GET_ADDR_MODULE].pointer.val;
+ void ** volatile pp = &dtv[GET_ADDR_MODULE].pointer.val;
while (atomic_forced_read (*pp) == TLS_DTV_UNALLOCATED)
{
/* for lack of a better (safe) thing to do, just spin.
endif
ifeq ($(build-shared),yes)
tests += tst-atfork2 tst-tls3 tst-tls4 tst-tls5 tst-tls7 tst-_res1 tst-fini1 \
- tst-stackguard1
+ tst-stackguard1 tst-tls77
tests-nolibpthread += tst-fini1
ifeq ($(have-z-execstack),yes)
tests += tst-execstack
tst-tls5mod tst-tls5moda tst-tls5modb tst-tls5modc \
tst-tls5modd tst-tls5mode tst-tls5modf \
tst-_res1mod1 tst-_res1mod2 tst-execstack-mod tst-fini1mod \
- tst-tls7mod
+ tst-tls7mod tst-tls77mod
extra-test-objs += $(addsuffix .os,$(strip $(modules-names))) tst-cleanup4aux.o
test-extras += $(modules-names) tst-cleanup4aux
test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
tst-tls5mode.so-no-z-defs = yes
tst-tls5modf.so-no-z-defs = yes
tst-tls7mod.so-no-z-defs = yes
+tst-tls77mod.so-no-z-defs = yes
ifeq ($(build-shared),yes)
# Build all the modules even when not actually running test programs.
'$(test-wrapper-env)'
endif
+$(objpfx)tst-tls77: $(libdl) $(shared-thread-library)
+LDFLAGS-tst-tls77 = -rdynamic
+$(objpfx)tst-tls77.out: $(objpfx)tst-tls77mod.so
+$(objpfx)tst-tls77mod.so: $(shared-thread-library)
+
$(objpfx)tst-dlsym1: $(libdl) $(shared-thread-library)
$(objpfx)tst-fini1: $(shared-thread-library) $(objpfx)tst-fini1mod.so
--- /dev/null
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <dlfcn.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pthreaddef.h>
+
+static pthread_t th;
+
+pthread_barrier_t b;
+
+void *(*dfp)(void*) = NULL;
+
+void *
+caller(void *x)
+{
+ pthread_barrier_wait (&b);
+
+ if (dfp)
+ dfp(NULL);
+
+ return NULL;
+}
+
+int
+do_test (void)
+{
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ pthread_attr_t a;
+
+ if (pthread_attr_init (&a) != 0)
+ {
+ puts ("attr_init failed");
+ exit (1);
+ }
+
+ if (pthread_attr_setstacksize (&a, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ if (pthread_create (&th, &a, caller, 0) != 0)
+ {
+ puts ("pthread_create failed");
+ exit (1);
+ }
+
+ void *h = dlopen ("tst-tls77mod.so", RTLD_LAZY);
+ if (h == NULL)
+ {
+ puts ("dlopen failed");
+ exit (1);
+ }
+
+ dfp = dlsym (h, "toucher");
+ if (dfp == NULL)
+ {
+ printf ("dlsym for toucher failed %s\n", dlerror ());
+ return 1;
+ }
+
+ pthread_barrier_wait (&b);
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ if (pthread_attr_destroy (&a) != 0)
+ {
+ puts ("attr_destroy failed");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
--- /dev/null
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <pthread.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pthreaddef.h>
+
+__thread int tlsvar;
+
+__thread int iexecvar __attribute__ ((tls_model ("initial-exec")));
+
+void *
+toucher (void *arg)
+{
+ tlsvar++;
+
+ printf ("tlsvar=%d iexecvar=%d\n", tlsvar, iexecvar);
+
+ iexecvar++;
+
+ printf ("tlsvar=%d iexecvar=%d\n", tlsvar, iexecvar);
+
+ return NULL;
+}