]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj: fix stack barriers in ppc64le shared libs
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Tue, 1 Dec 2015 02:39:41 +0000 (15:39 +1300)
committerMichael Hudson-Doyle <michael.hudson@canonical.com>
Wed, 2 Dec 2015 21:15:37 +0000 (21:15 +0000)
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 <austin@google.com>
src/cmd/internal/obj/ppc64/obj9.go

index 696f6e5834cadfa21a8a883f4e9659539a8cc83a..11be4d79f65293f08546c76c0251eb294012f41d 100644 (file)
@@ -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