]> Cypherpunks repositories - gostls13.git/commitdiff
runtime,runtime/cgo: set up TLS storage for Android Q without cgo
authorElias Naur <mail@eliasnaur.com>
Mon, 8 Apr 2019 15:57:53 +0000 (17:57 +0200)
committerElias Naur <mail@eliasnaur.com>
Mon, 8 Apr 2019 20:21:51 +0000 (20:21 +0000)
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>
src/runtime/asm_386.s
src/runtime/asm_amd64.s
src/runtime/cgo/gcc_android.c
src/runtime/tls_arm.s
src/runtime/tls_arm64.s

index 89954361842a1dc6ca910057492603dd6cc1d6f0..61aae47c08fa8fa3ba6163d7132d28aa5bed44ae 100644 (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
index 149b04dfdf6c90956962621fe615379dc1473a18..7b2fdf0d3db87187838d105d092c5c7a247130b8 100644 (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
index 5075023282f196571d342e540c447cb33a4ec876..321a5150b958b1122c5694dee3f2e1545fb189e4 100644 (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;
        }
 
index 400c16a1775820cdba79b316b917449c7c0d8642..9b8855e1709517c6abc89904050e72e798d39dcb 100644 (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
index 62ae6faf21b353f0b3d1b0c52e07e2a87ce89173..fb8627db29bd29826b0c9cb9a0807526099309b8 100644 (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