From: Austin Clements Date: Tue, 16 Dec 2014 18:52:09 +0000 (-0500) Subject: cmd/9g: don't use R13 X-Git-Tag: go1.5beta1~2421 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bbd2127909c6040cd8bb75108a5ecc82eddfb405;p=gostls13.git cmd/9g: don't use R13 R13 is the C TLS pointer. Once we're calling to and from C code, if we clobber R13 in our code, sigtramp won't know whether to get the current g from REGG or from C TLS. The simplest solution is for Go code to preserve the C TLS pointer. This is equivalent to what other platforms do, except that on other platforms the TLS pointer is in a special register. Change-Id: I076e9cb83fd78843eb68cb07c748c4705c9a4c82 Reviewed-on: https://go-review.googlesource.com/2007 Reviewed-by: Minux Ma Reviewed-by: Russ Cox --- diff --git a/src/cmd/9g/gsubr.c b/src/cmd/9g/gsubr.c index e5cd5ed4bf..8abbde4531 100644 --- a/src/cmd/9g/gsubr.c +++ b/src/cmd/9g/gsubr.c @@ -262,8 +262,15 @@ afunclit(Addr *a, Node *n) static int resvd[] = { REGZERO, - REGSP, // reserved for SP, XXX: not reserved in 9c. - 30, // for g + REGSP, // reserved for SP + // We need to preserve the C ABI TLS pointer because sigtramp + // may happen during C code and needs to access the g. C + // clobbers REGG, so if Go were to clobber REGTLS, sigtramp + // won't know which convention to use. By preserving REGTLS, + // we can just retrieve g from TLS when we aren't sure. + REGTLS, + // TODO(austin): Consolidate REGTLS and REGG? + REGG, REGTMP, // REGTMP FREGCVI+NREG, FREGZERO+NREG, diff --git a/src/cmd/9g/reg.c b/src/cmd/9g/reg.c index 2d8dbc4f1a..6d40127ecc 100644 --- a/src/cmd/9g/reg.c +++ b/src/cmd/9g/reg.c @@ -185,7 +185,7 @@ regopt(Prog *firstp) } // Exclude registers with fixed functions - regbits = (1<