From: Michael Hudson-Doyle Date: Tue, 1 Dec 2015 02:39:41 +0000 (+1300) Subject: cmd/internal/obj: fix stack barriers in ppc64le shared libs X-Git-Tag: go1.6beta1~233 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3a1bed82a66c9ff4bf659e5603a8f7c0120435c3;p=gostls13.git cmd/internal/obj: fix stack barriers in ppc64le shared libs runtime.stackBarrier is a strange function: it is only ever "called" by smashing its address into a LR slot on the stack. Calling it like this certainly does not adhere to the rule that r12 is set to the global entry point before calling it and the prologue instrutions that compute r2 from r12 in fact just corrupt r2, which is bad because the function that stackBarrier returns to probably uses r2 to access global data. Fortunately stackBarrier itself does not access any global data and so does not depend on the value of r2, meaning we can ignore the ABI rules and simply skip inserting the prologue instructions into this specific function. Fixes 64bit.go, append.go and fixedbugs/issue13169.go from "cd test; go run run.go -linkshared". Change-Id: I606864133a83935899398e2d42edd08a946aab24 Reviewed-on: https://go-review.googlesource.com/17281 Reviewed-by: Austin Clements --- diff --git a/src/cmd/internal/obj/ppc64/obj9.go b/src/cmd/internal/obj/ppc64/obj9.go index 696f6e5834..11be4d79f6 100644 --- a/src/cmd/internal/obj/ppc64/obj9.go +++ b/src/cmd/internal/obj/ppc64/obj9.go @@ -471,7 +471,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) { q = p - if ctxt.Flag_shared != 0 && cursym.Name != "runtime.duffzero" && cursym.Name != "runtime.duffcopy" { + if ctxt.Flag_shared != 0 && cursym.Name != "runtime.duffzero" && cursym.Name != "runtime.duffcopy" && cursym.Name != "runtime.stackBarrier" { // When compiling Go into PIC, all functions must start // with instructions to load the TOC pointer into r2: // @@ -482,7 +482,10 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) { // but it's a bit subtle. However, it is both safe and // necessary to leave the prologue off duffzero and // duffcopy as we rely on being able to jump to a specific - // instruction offset for them. + // instruction offset for them, and stackBarrier is only + // ever called from an overwritten LR-save slot on the + // stack (when r12 will not be remotely the right thing) + // but fortunately does not access global data. // // These are AWORDS because there is no (afaict) way to // generate the addis instruction except as part of the