1
0
mirror of https://github.com/golang/go synced 2024-09-25 03:10:12 -06:00

runtime,runtime/cgo: set up TLS storage for Android Q without cgo

Android Q frees a static TLS slot for us to use. Use the offset of
that slot as the default for our TLS offset.

As a result, runtime/cgo is no more a requirement for Android Q and
newer.

Updates #31343
Updates #29674

Change-Id: I759049b2e2865bd3d4fdc05a8cfc6db8b0da1f5d
Reviewed-on: https://go-review.googlesource.com/c/go/+/170955
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Elias Naur 2019-04-08 17:57:53 +02:00
parent 973c0312e3
commit f18c31a49c
5 changed files with 22 additions and 2 deletions

View File

@ -1564,5 +1564,8 @@ TEXT runtime·panicExtendSlice3CU(SB),NOSPLIT,$0-12
JMP runtime·goPanicExtendSlice3CU(SB)
#ifdef GOOS_android
// Use the free TLS_SLOT_APP slot #2 on Android Q.
// Earlier androids are set up in gcc_android.c.
DATA runtime·tls_g+0(SB)/4, $8
GLOBL runtime·tls_g+0(SB), NOPTR, $4
#endif

View File

@ -1713,5 +1713,8 @@ TEXT runtime·panicSlice3CU(SB),NOSPLIT,$0-16
JMP runtime·goPanicSlice3CU(SB)
#ifdef GOOS_android
// Use the free TLS_SLOT_APP slot #2 on Android Q.
// Earlier androids are set up in gcc_android.c.
DATA runtime·tls_g+0(SB)/8, $16
GLOBL runtime·tls_g+0(SB), NOPTR, $8
#endif

View File

@ -47,7 +47,7 @@ inittls(void **tlsg, void **tlsbase)
{
pthread_key_t k;
int i, err;
void *handle, *get_ver;
void *handle, *get_ver, *off;
// Check for Android Q where we can use the free TLS_SLOT_APP slot.
handle = dlopen("libc.so", RTLD_LAZY);
@ -60,7 +60,11 @@ inittls(void **tlsg, void **tlsbase)
get_ver = dlsym(handle, "android_get_device_api_level");
dlclose(handle);
if (get_ver != NULL) {
*tlsg = (void *)(TLS_SLOT_APP*sizeof(void *));
off = (void *)(TLS_SLOT_APP*sizeof(void *));
// tlsg is initialized to Q's free TLS slot. Verify it while we're here.
if (*tlsg != off) {
fatalf("tlsg offset wrong, got %ld want %ld\n", *tlsg, off);
}
return;
}

View File

@ -103,6 +103,11 @@ TEXT setg_gcc<>(SB),NOSPLIT,$0
B runtime·save_g(SB)
#ifdef TLSG_IS_VARIABLE
#ifdef GOOS_android
// Use the free TLS_SLOT_APP slot #2 on Android Q.
// Earlier androids are set up in gcc_android.c.
DATA runtime·tls_g+0(SB)/4, $8
#endif
GLOBL runtime·tls_g+0(SB), NOPTR, $4
#else
GLOBL runtime·tls_g+0(SB), TLSBSS, $4

View File

@ -43,6 +43,11 @@ nocgo:
RET
#ifdef TLSG_IS_VARIABLE
#ifdef GOOS_android
// Use the free TLS_SLOT_APP slot #2 on Android Q.
// Earlier androids are set up in gcc_android.c.
DATA runtime·tls_g+0(SB)/8, $16
#endif
GLOBL runtime·tls_g+0(SB), NOPTR, $8
#else
GLOBL runtime·tls_g+0(SB), TLSBSS, $8