]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
runtime: expose the g variable
authorIan Lance Taylor <ian@gcc.gnu.org>
Mon, 15 Jul 2019 21:17:16 +0000 (21:17 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Mon, 15 Jul 2019 21:17:16 +0000 (21:17 +0000)
    Currently, getg is implemented in C, which loads the thread-local
    g variable. The g variable is declared static in C.

    This CL exposes the g variable, so it can be accessed from the Go
    side. This allows the Go compiler to inline getg calls to direct
    access of g.

    Currently, the actual inlining is only implemented in the gollvm
    compiler. The g variable is thread-local and the compiler backend
    may choose to cache the TLS address in a register or on stack. If
    a thread switch happens the cache may become invalid. I don't
    know how to disable the TLS address cache in gccgo, therefore
    the inlining of getg is not implemented. In the future gccgo may
    gain this if we know how to do it safely.

    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/186238

From-SVN: r273499

gcc/go/gofrontend/MERGE
libgo/runtime/proc.c

index 28fc22309dd92dca546255ab1910f951ab6ee7c8..4e19c524837845401389e556c7fc9b8f0acf2bc6 100644 (file)
@@ -1,4 +1,4 @@
-70ceba5e95716653b9f829a457a44a829175d4da
+0e51b7e9c03c6f6bc3d06343f2050f17349ccdc3
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 26125ccf1619bef02c8961e4c93902275edfb1d6..523dfd9ff146cf1bbcd48ce45d6398ec084aa409 100644 (file)
@@ -65,7 +65,7 @@ static void gscanstack(G*);
 #define __thread
 #endif
 
-static __thread G *g;
+__thread G *g __asm__(GOSYM_PREFIX "runtime.g");
 
 #ifndef SETCONTEXT_CLOBBERS_TLS
 
@@ -320,7 +320,7 @@ runtime_mcall(FuncVal *fv)
        if(gp != nil) {
 
 #ifdef USING_SPLIT_STACK
-               __splitstack_getcontext((void*)(&g->stackcontext[0]));
+               __splitstack_getcontext((void*)(&gp->stackcontext[0]));
 #else
                // We have to point to an address on the stack that is
                // below the saved registers.