Commit 3a1bed82 authored by Michael Hudson-Doyle's avatar Michael Hudson-Doyle

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/17281Reviewed-by: 's avatarAustin Clements <austin@google.com>
parent 5a049aa4
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment