From: Iskander Sharipov Date: Tue, 30 Apr 2019 21:01:39 +0000 (+0300) Subject: cmd/asm: reject BSWAPW on amd64 X-Git-Tag: go1.13beta1~469 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=720af3c8c4a0223f605b45b80c6a46f46321c760;p=gostls13.git cmd/asm: reject BSWAPW on amd64 Since BSWAP operation on 16-bit registers is undefined, forbid the usage of BSWAPW. Users should rely on XCHGB instead. This behavior is consistent with what GAS does. Fixes #29167 Change-Id: I3b31e3dd2acfd039f7564a1c17e6068617bcde8d Reviewed-on: https://go-review.googlesource.com/c/go/+/174312 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- diff --git a/src/cmd/asm/internal/asm/line_test.go b/src/cmd/asm/internal/asm/line_test.go index 7462f24a1c..01b058bd95 100644 --- a/src/cmd/asm/internal/asm/line_test.go +++ b/src/cmd/asm/internal/asm/line_test.go @@ -28,6 +28,10 @@ func TestAMD64BadInstParser(t *testing.T) { {"VADDPD.BCST.Z.SAE X0, X1, X2", `Z suffix should be the last; can't combine rounding/SAE and broadcast`}, {"VADDPD.SAE.SAE X0, X1, X2", `duplicate suffix "SAE"`}, {"VADDPD.RZ_SAE.SAE X0, X1, X2", `bad suffix combination`}, + + // BSWAP on 16-bit registers is undefined. See #29167, + {"BSWAPW DX", `unrecognized instruction`}, + {"BSWAPW R11", `unrecognized instruction`}, }) } diff --git a/src/cmd/asm/internal/asm/testdata/amd64enc.s b/src/cmd/asm/internal/asm/testdata/amd64enc.s index 65aecf8faf..c02f51d125 100644 --- a/src/cmd/asm/internal/asm/testdata/amd64enc.s +++ b/src/cmd/asm/internal/asm/testdata/amd64enc.s @@ -588,8 +588,6 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$0 BSRQ (R11), R11 // 4d0fbd1b BSRQ DX, R11 // 4c0fbdda BSRQ R11, R11 // 4d0fbddb - BSWAPW DX // 660fca - BSWAPW R11 // 66410fcb BSWAPL DX // 0fca BSWAPL R11 // 410fcb BSWAPQ DX // 480fca diff --git a/src/cmd/internal/obj/x86/aenum.go b/src/cmd/internal/obj/x86/aenum.go index 67cf5b1b46..0377b39a41 100644 --- a/src/cmd/internal/obj/x86/aenum.go +++ b/src/cmd/internal/obj/x86/aenum.go @@ -69,7 +69,6 @@ const ( ABSRW ABSWAPL ABSWAPQ - ABSWAPW ABTCL ABTCQ ABTCW diff --git a/src/cmd/internal/obj/x86/anames.go b/src/cmd/internal/obj/x86/anames.go index ba47524201..a928f67bae 100644 --- a/src/cmd/internal/obj/x86/anames.go +++ b/src/cmd/internal/obj/x86/anames.go @@ -67,7 +67,6 @@ var Anames = []string{ "BSRW", "BSWAPL", "BSWAPQ", - "BSWAPW", "BTCL", "BTCQ", "BTCW", diff --git a/src/cmd/internal/obj/x86/asm6.go b/src/cmd/internal/obj/x86/asm6.go index 336446449b..93fd033460 100644 --- a/src/cmd/internal/obj/x86/asm6.go +++ b/src/cmd/internal/obj/x86/asm6.go @@ -961,7 +961,6 @@ var optab = {ABSRL, yml_rl, Pm, opBytes{0xbd}}, {ABSRQ, yml_rl, Pw, opBytes{0x0f, 0xbd}}, {ABSRW, yml_rl, Pq, opBytes{0xbd}}, - {ABSWAPW, ybswap, Pe, opBytes{0x0f, 0xc8}}, {ABSWAPL, ybswap, Px, opBytes{0x0f, 0xc8}}, {ABSWAPQ, ybswap, Pw, opBytes{0x0f, 0xc8}}, {ABTCL, ybtl, Pm, opBytes{0xba, 07, 0xbb}}, diff --git a/src/cmd/internal/obj/x86/obj6.go b/src/cmd/internal/obj/x86/obj6.go index 2fba397a87..d1ac707fd7 100644 --- a/src/cmd/internal/obj/x86/obj6.go +++ b/src/cmd/internal/obj/x86/obj6.go @@ -1206,7 +1206,6 @@ func stacksplit(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog, newprog obj.ProgA var unaryDst = map[obj.As]bool{ ABSWAPL: true, ABSWAPQ: true, - ABSWAPW: true, ACLFLUSH: true, ACLFLUSHOPT: true, ACMPXCHG16B: true,