diff options
author | Elias Naur <mail@eliasnaur.com> | 2019-04-08 17:57:53 +0200 |
---|---|---|
committer | Elias Naur <mail@eliasnaur.com> | 2019-04-08 20:21:51 +0000 |
commit | f18c31a49c1105be0341b32392a433cf65f227da (patch) | |
tree | 415cc2ec371e080b634b73b4e529737668a194d2 /src/runtime/cgo | |
parent | 973c0312e36fd56b6b2111a07a19de63e0dcbf03 (diff) | |
download | go-f18c31a49c1105be0341b32392a433cf65f227da.tar.gz go-f18c31a49c1105be0341b32392a433cf65f227da.zip |
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>
Diffstat (limited to 'src/runtime/cgo')
-rw-r--r-- | src/runtime/cgo/gcc_android.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/runtime/cgo/gcc_android.c b/src/runtime/cgo/gcc_android.c index 5075023282..321a5150b9 100644 --- a/src/runtime/cgo/gcc_android.c +++ b/src/runtime/cgo/gcc_android.c @@ -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; } |