]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.8] cmd/internal/obj/x86: use LEAx rather than ADDx when calling...
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Wed, 26 Apr 2017 23:56:42 +0000 (11:56 +1200)
committerRuss Cox <rsc@golang.org>
Fri, 20 Oct 2017 16:42:12 +0000 (12:42 -0400)
DUFFZERO on 386 is not marked as clobbering flags, but rewriteToUseGot rewrote
"ADUFFZERO $offset" to "MOVL runtime.duffxxx@GOT, CX; ADDL $offset, CX; CALL CX"
which does. Luckily the fix is easier than figuring out what the problem was:
replace the ADDL $offset, CX with LEAL $offset(CX), CX.

On amd64 DUFFZERO clobbers flags, on arm, arm64 and ppc64 ADD does not clobber
flags and s390x does not use the duff functions, so I'm fairly confident this
is the only fix required.

I don't know how to write a test though.

Change-Id: I69b0958f5f45771d61db5f5ecb4ded94e8960d4d
Reviewed-on: https://go-review.googlesource.com/41821
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/internal/obj/x86/obj6.go

index eb6f867ca7e4a188b22d08aac6d635876641f2e6..f3dfd329791fd76b1ebd04cebe2249db28928302 100644 (file)
@@ -322,15 +322,13 @@ func progedit(ctxt *obj.Link, p *obj.Prog) {
 
 // Rewrite p, if necessary, to access global data via the global offset table.
 func rewriteToUseGot(ctxt *obj.Link, p *obj.Prog) {
-       var add, lea, mov obj.As
+       var lea, mov obj.As
        var reg int16
        if p.Mode == 64 {
-               add = AADDQ
                lea = ALEAQ
                mov = AMOVQ
                reg = REG_R15
        } else {
-               add = AADDL
                lea = ALEAL
                mov = AMOVL
                reg = REG_CX
@@ -347,8 +345,10 @@ func rewriteToUseGot(ctxt *obj.Link, p *obj.Prog) {
                //     ADUFFxxx $offset
                // becomes
                //     $MOV runtime.duffxxx@GOT, $reg
-               //     $ADD $offset, $reg
+               //     $LEA $offset($reg), $reg
                //     CALL $reg
+               // (we use LEAx rather than ADDx because ADDx clobbers
+               // flags and duffzero on 386 does not otherwise do so)
                var sym *obj.LSym
                if p.As == obj.ADUFFZERO {
                        sym = obj.Linklookup(ctxt, "runtime.duffzero", 0)
@@ -365,9 +365,10 @@ func rewriteToUseGot(ctxt *obj.Link, p *obj.Prog) {
                p.To.Offset = 0
                p.To.Sym = nil
                p1 := obj.Appendp(ctxt, p)
-               p1.As = add
-               p1.From.Type = obj.TYPE_CONST
+               p1.As = lea
+               p1.From.Type = obj.TYPE_MEM
                p1.From.Offset = offset
+               p1.From.Reg = reg
                p1.To.Type = obj.TYPE_REG
                p1.To.Reg = reg
                p2 := obj.Appendp(ctxt, p1)