]> Cypherpunks repositories - gostls13.git/commitdiff
liblink, cmd/ld, runtime: set the type of runtime.tlsg in runtime
authorShenghou Ma <minux@golang.org>
Fri, 26 Dec 2014 05:48:33 +0000 (00:48 -0500)
committerMinux Ma <minux@golang.org>
Fri, 6 Feb 2015 05:39:51 +0000 (05:39 +0000)
In the old code, liblink, cmd/ld and runtime all have code determine
whether runtime.tlsg is an actual variable or a placeholder for TLS
relocation. This change consolidate them into one: the runtime/tls_arm.s
will ultimately determine the type of that variable.

Change-Id: I3b3f80791a1db4c2b7318f81a115972cd2237e43
Reviewed-on: https://go-review.googlesource.com/2118
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Dave Cheney <dave@cheney.net>
src/cmd/ld/lib.c
src/liblink/asm5.c
src/runtime/tls_arm.s

index fa08bc5f031716e5a72a14038a423dd4224fa2ed..192e28398bd50c852b75baca723099861503ec08 100644 (file)
@@ -257,7 +257,13 @@ loadlib(void)
        }
        
        tlsg = linklookup(ctxt, "runtime.tlsg", 0);
-       tlsg->type = STLSBSS;
+       // For most ports, runtime.tlsg is a placeholder symbol for TLS
+       // relocation. However, the Android and Darwin ports need it to
+       // be a real variable. Instead of hard-coding which platforms
+       // need it to be a real variable, we set the type to STLSBSS only
+       // when the runtime has not declared its type already.
+       if(tlsg->type == 0)
+               tlsg->type = STLSBSS;
        tlsg->size = PtrSize;
        tlsg->hide = 1;
        tlsg->reachable = 1;
index 8d597750b71a2e0a4574299c132f51bef91a865f..7b4ac47e852cbbc1b557049d053a338dc38f3223 100644 (file)
@@ -1638,8 +1638,9 @@ if(0 /*debug['G']*/) print("%ux: %s: arm %d\n", (uint32)(p->pc), p->from.sym->na
                        // runtime.tlsg is special.
                        // Its "address" is the offset from the TLS thread pointer
                        // to the thread-local g and m pointers.
-                       // Emit a TLS relocation instead of a standard one.
-                       if(rel->sym == ctxt->tlsg) {
+                       // Emit a TLS relocation instead of a standard one if it's
+                       // typed STLSBSS.
+                       if(rel->sym == ctxt->tlsg && ctxt->tlsg->type == STLSBSS) {
                                rel->type = R_TLS;
                                if(ctxt->flag_shared)
                                        rel->add += ctxt->pc - p->pcrel->pc - 8 - rel->siz;
index 7c5c0e215e2c4ab1c6dff0cf5a3171ee8acc5ff9..4b01d12c460a0450181b34e51bd285e781e0c38e 100644 (file)
@@ -17,6 +17,9 @@
 
 // On android, runtime.tlsg is a normal variable.
 // TLS offset is computed in x_cgo_inittls.
+#ifdef GOOS_android
+#define TLSG_IS_VARIABLE
+#endif
 
 // save_g saves the g register into pthread-provided
 // thread-local memory, so that we can call externally compiled
@@ -37,7 +40,7 @@ TEXT runtime·save_g(SB),NOSPLIT,$-4
        // $runtime.tlsg(SB) is a special linker symbol.
        // It is the offset from the TLS base pointer to our
        // thread-local storage for g.
-#ifdef GOOS_android
+#ifdef TLSG_IS_VARIABLE
        MOVW    runtime·tlsg(SB), R11
 #else
        MOVW    $runtime·tlsg(SB), R11
@@ -60,7 +63,7 @@ TEXT runtime·load_g(SB),NOSPLIT,$0
        // $runtime.tlsg(SB) is a special linker symbol.
        // It is the offset from the TLS base pointer to our
        // thread-local storage for g.
-#ifdef GOOS_android
+#ifdef TLSG_IS_VARIABLE
        MOVW    runtime·tlsg(SB), R11
 #else
        MOVW    $runtime·tlsg(SB), R11
@@ -68,3 +71,7 @@ TEXT runtime·load_g(SB),NOSPLIT,$0
        ADD     R11, R0
        MOVW    0(R0), g
        RET
+
+#ifdef TLSG_IS_VARIABLE
+GLOBL runtime·tlsg+0(SB), NOPTR, $4
+#endif