summaryrefslogtreecommitdiff
path: root/src/liblink/obj5.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-03-04 13:53:08 -0500
committerRuss Cox <rsc@golang.org>2014-03-04 13:53:08 -0500
commit342e17648d01ae1bca36494a61c19a09592c4d6d (patch)
treee79ee1d7e9465644fba07a3a6fd6f490c0764e8f /src/liblink/obj5.c
parent410479feaf8f12c564464a2d4734021d21d54ef9 (diff)
downloadgo-342e17648d01ae1bca36494a61c19a09592c4d6d.tar.gz
cmd/ld: clear unused ctxt before morestack
For non-closure functions, the context register is uninitialized on entry and will not be used, but morestack saves it and then the garbage collector treats it as live. This can be a source of memory leaks if the context register points at otherwise dead memory. Avoid this by introducing a parallel set of morestack functions that clear the context register, and use those for the non-closure functions. I hope this will help with some of the finalizer flakiness, but it probably won't. Fixes issue 7244. LGTM=dvyukov R=khr, dvyukov CC=golang-codereviews https://codereview.appspot.com/71030044
Diffstat (limited to 'src/liblink/obj5.c')
-rw-r--r--src/liblink/obj5.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/liblink/obj5.c b/src/liblink/obj5.c
index ce9d4f654..91d13d8c1 100644
--- a/src/liblink/obj5.c
+++ b/src/liblink/obj5.c
@@ -194,7 +194,7 @@ prg(void)
return p;
}
-static Prog* stacksplit(Link*, Prog*, int32);
+static Prog* stacksplit(Link*, Prog*, int32, int);
static void initdiv(Link*);
static void softfloat(Link*, LSym*);
@@ -237,9 +237,11 @@ addstacksplit(Link *ctxt, LSym *cursym)
autosize = 0;
- if(ctxt->symmorestack[0] == nil)
+ if(ctxt->symmorestack[0] == nil) {
ctxt->symmorestack[0] = linklookup(ctxt, "runtime.morestack", 0);
-
+ ctxt->symmorestack[1] = linklookup(ctxt, "runtime.morestack_noctxt", 0);
+ }
+
q = nil;
ctxt->cursym = cursym;
@@ -409,7 +411,7 @@ addstacksplit(Link *ctxt, LSym *cursym)
}
if(!(p->reg & NOSPLIT))
- p = stacksplit(ctxt, p, autosize); // emit split check
+ p = stacksplit(ctxt, p, autosize, !(cursym->text->from.scale&NEEDCTXT)); // emit split check
// MOVW.W R14,$-autosize(SP)
p = appendp(ctxt, p);
@@ -727,7 +729,7 @@ softfloat(Link *ctxt, LSym *cursym)
}
static Prog*
-stacksplit(Link *ctxt, Prog *p, int32 framesize)
+stacksplit(Link *ctxt, Prog *p, int32 framesize, int noctxt)
{
int32 arg;
@@ -851,7 +853,7 @@ stacksplit(Link *ctxt, Prog *p, int32 framesize)
p->as = ABL;
p->scond = C_SCOND_LS;
p->to.type = D_BRANCH;
- p->to.sym = ctxt->symmorestack[0];
+ p->to.sym = ctxt->symmorestack[noctxt];
// BLS start
p = appendp(ctxt, p);