libgo patch committed: Expose the g variable

Message ID
State New
Headers show
  • libgo patch committed: Expose the g variable
Related show

Commit Message

Ian Lance Taylor July 15, 2019, 9:17 p.m.
This libgo patch by Cherry Zhang expose the thread-local g variable.

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.

The actual inlining is not yet implemented in gccgo, because it runs
into trouble when the address of the thread-local variable is cached
across a function call that changes threads.  We will need to develop
a mechanism to disable that caching for at least some functions.
There doesn't seem to be one currently.



Index: gcc/go/gofrontend/MERGE
--- gcc/go/gofrontend/MERGE	(revision 273494)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@ 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/runtime/proc.c
--- libgo/runtime/proc.c	(revision 273494)
+++ libgo/runtime/proc.c	(working copy)
@@ -65,7 +65,7 @@  static void gscanstack(G*);
 #define __thread
-static __thread G *g;
+__thread G *g __asm__(GOSYM_PREFIX "runtime.g");
@@ -320,7 +320,7 @@  runtime_mcall(FuncVal *fv)
 	if(gp != nil) {
-		__splitstack_getcontext((void*)(&g->stackcontext[0]));
+		__splitstack_getcontext((void*)(&gp->stackcontext[0]));
 		// We have to point to an address on the stack that is
 		// below the saved registers.