about summary refs log tree commit diff
path: root/src/env/__init_tls.c
diff options
context:
space:
mode:
authorSzabolcs Nagy <nsz@port70.net>2015-03-11 12:48:12 +0000
committerRich Felker <dalias@aerifal.cx>2015-03-11 18:53:48 -0400
commit204a69d2d917f413eacb086020b63d6dc6da0672 (patch)
treeffa1ecefe51649524b192d013f1d5337da160e39 /src/env/__init_tls.c
parenta46677af1863f3d050f216a43dfdf4818210c266 (diff)
downloadmusl-204a69d2d917f413eacb086020b63d6dc6da0672.tar.gz
musl-204a69d2d917f413eacb086020b63d6dc6da0672.tar.xz
musl-204a69d2d917f413eacb086020b63d6dc6da0672.zip
copy the dtv pointer to the end of the pthread struct for TLS_ABOVE_TP archs
There are two main abi variants for thread local storage layout:

 (1) TLS is above the thread pointer at a fixed offset and the pthread
 struct is below that. So the end of the struct is at known offset.

 (2) the thread pointer points to the pthread struct and TLS starts
 below it. So the start of the struct is at known (zero) offset.

Assembly code for the dynamic TLSDESC callback needs to access the
dynamic thread vector (dtv) pointer which is currently at the front
of the pthread struct. So in case of (1) the asm code needs to hard
code the offset from the end of the struct which can easily break if
the struct changes.

This commit adds a copy of the dtv at the end of the struct. New members
must not be added after dtv_copy, only before it. The size of the struct
is increased a bit, but there is opportunity for size optimizations.
Diffstat (limited to 'src/env/__init_tls.c')
-rw-r--r--src/env/__init_tls.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c
index b0dad429..e651c7a7 100644
--- a/src/env/__init_tls.c
+++ b/src/env/__init_tls.c
@@ -54,7 +54,7 @@ void *__copy_tls(unsigned char *mem)
 	td = (pthread_t)mem;
 	mem -= T.size;
 #endif
-	td->dtv = dtv;
+	td->dtv = td->dtv_copy = dtv;
 	dtv[1] = mem;
 	memcpy(mem, T.image, T.len);
 	return td;