summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-10-14 19:56:50 -0400
committerRich Felker <dalias@aerifal.cx>2012-10-14 19:56:50 -0400
commitc62b9f39803221e250a490275f4cb23e9f737a6d (patch)
tree4392968a539106a0d9f0708b5daa368227e8373a
parent36be5284c2a79406778ac489928c6deb05857329 (diff)
downloadmusl-c62b9f39803221e250a490275f4cb23e9f737a6d.tar.gz
fix main program TLS alignment for dynamic-linked programs
this change brings the behavior in line with the static-linked code, which seems to be correct.
-rw-r--r--src/ldso/dynlink.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
index fbe7f7b9..5353979e 100644
--- a/src/ldso/dynlink.c
+++ b/src/ldso/dynlink.c
@@ -99,7 +99,7 @@ static jmp_buf rtld_fail;
static pthread_rwlock_t lock;
static struct debug debug;
static size_t *auxv;
-static size_t tls_cnt, tls_offset, tls_start, tls_align = 4*sizeof(size_t);
+static size_t tls_cnt, tls_offset, tls_align = 4*sizeof(size_t);
static pthread_mutex_t init_fini_lock = { ._m_type = PTHREAD_MUTEX_RECURSIVE };
struct debug *_dl_debug_addr = &debug;
@@ -699,7 +699,6 @@ void *__copy_tls(unsigned char *mem)
mem += libc.tls_size - sizeof(struct pthread);
mem -= (uintptr_t)mem & (tls_align-1);
- mem -= tls_start;
td = (pthread_t)mem;
for (p=head; p; p=p->next) {
@@ -755,7 +754,7 @@ void *__tls_get_addr(size_t *v)
static void update_tls_size()
{
size_t below_tp = (1+tls_cnt) * sizeof(void *) + tls_offset;
- size_t above_tp = sizeof(struct pthread) + tls_start + tls_align;
+ size_t above_tp = sizeof(struct pthread) + tls_align;
libc.tls_size = ALIGN(below_tp + above_tp, tls_align);
}
@@ -867,9 +866,9 @@ void *__dynlink(int argc, char **argv)
}
if (app->tls_size) {
app->tls_id = tls_cnt = 1;
- tls_offset = app->tls_offset = app->tls_size;
- tls_start = -((uintptr_t)app->tls_image + app->tls_size)
- & (app->tls_align-1);
+ tls_offset = app->tls_offset = app->tls_size
+ + ( -((uintptr_t)app->tls_image + app->tls_size)
+ & (app->tls_align-1) );
tls_align = MAXP2(tls_align, app->tls_align);
}
app->global = 1;