Skip to content

Commit

Permalink
runtime/cgo: fix unaligned tlsbase pointer.
Browse files Browse the repository at this point in the history
According to disassembly of /usr/lib/dyld:
_pthread_getspecific:
2fe17060        ee1d1f70        mrc     15, 0, r1, cr13, cr0, {3}
2fe17064        e3c11003        bic     r1, r1, golang#3      ; 0x3
2fe17068        e0810100        add     r0, r1, r0, lsl golang#2
2fe1706c        e5900000        ldr     r0, [r0]
2fe17070        e12fff1e        bx      lr
the result from mrc might not be properly aligned, I don't know why.
  • Loading branch information
minux committed Nov 26, 2014
1 parent e116818 commit 075aa51
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/runtime/cgo/gcc_darwin_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inittls(void **tlsg, void **tlsbase)
fprintf(stderr, "runtime/cgo: pthread_key_create failed: %d\n", err);
abort();
}
fprintf(stderr, "k = %d\n", (int)k); // debug
fprintf(stderr, "runtime/cgo: k = %d, tlsbase = %p\n", (int)k, tlsbase); // debug
pthread_setspecific(k, (void*)magic1);
for (i=0; i<PTHREAD_KEYS_MAX; i++) {
if (*(tlsbase+i) == (void*)magic1) {
Expand Down Expand Up @@ -95,5 +95,6 @@ x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
g->stacklo = (uintptr)&attr - size + 4096;
pthread_attr_destroy(&attr);

inittls(tlsg, tlsbase);
// yes, tlsbase from mrc might not be correctly aligned.
inittls(tlsg, (void**)((uintptr)tlsbase & ~3));
}

0 comments on commit 075aa51

Please sign in to comment.