]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: check that masks and shifts are correct aligned
authorShenghou Ma <minux@golang.org>
Thu, 3 Sep 2015 06:44:26 +0000 (02:44 -0400)
committerMinux Ma <minux@golang.org>
Wed, 25 Nov 2015 00:46:57 +0000 (00:46 +0000)
We need a runtime check because the original issue is encountered
when running cross compiled windows program from linux. It's better
to give a meaningful crash message earlier than to segfault later.

The added test should not impose any measurable overhead to Go
programs.

For #12415.

Change-Id: Ib4a24ef560c09c0585b351d62eefd157b6b7f04c
Reviewed-on: https://go-review.googlesource.com/14207
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/asm_386.s
src/runtime/asm_amd64.s
src/runtime/asm_amd64p32.s
src/runtime/asm_arm.s
src/runtime/asm_arm64.s
src/runtime/asm_mips64x.s
src/runtime/asm_ppc64x.s
src/runtime/runtime1.go
src/runtime/stubs.go

index 587219060ab95ec7c2972df6133668f4d5578426..3dcb026f0c474677aa124e375333239992e821d7 100644 (file)
@@ -1188,6 +1188,15 @@ DATA shifts<>+0xfc(SB)/4, $0xff0f0e0d
 
 GLOBL shifts<>(SB),RODATA,$256
 
+TEXT ·checkASM(SB),NOSPLIT,$0-1
+       // check that masks<>(SB) and shifts<>(SB) are aligned to 16-byte
+       MOVL    $masks<>(SB), AX
+       MOVL    $shifts<>(SB), BX
+       ORL     BX, AX
+       TESTL   $15, AX
+       SETEQ   ret+0(FP)
+       RET
+
 TEXT runtime·memeq(SB),NOSPLIT,$0-13
        MOVL    a+0(FP), SI
        MOVL    b+4(FP), DI
index 7f14f61e2a817196cae48139535bc9ec2749caff..705238cb6d8f483e34e2a075faccfdc3e25315cb 100644 (file)
@@ -1222,6 +1222,15 @@ DATA masks<>+0xf0(SB)/8, $0xffffffffffffffff
 DATA masks<>+0xf8(SB)/8, $0x00ffffffffffffff
 GLOBL masks<>(SB),RODATA,$256
 
+TEXT ·checkASM(SB),NOSPLIT,$0-1
+       // check that masks<>(SB) and shifts<>(SB) are aligned to 16-byte
+       MOVQ    $masks<>(SB), AX
+       MOVQ    $shifts<>(SB), BX
+       ORQ     BX, AX
+       TESTQ   $15, AX
+       SETEQ   ret+0(FP)
+       RET
+
 // these are arguments to pshufb.  They move data down from
 // the high bytes of the register to the low bytes of the register.
 // index is how many bytes to move.
index 8119d91e1b80f8d63b1d426a060f3da8a857ecda..ecbc5975bb0954840cf33d3beb5b5b6607565b44 100644 (file)
@@ -1012,3 +1012,7 @@ TEXT runtime·prefetchnta(SB),NOSPLIT,$0-4
        MOVL    addr+0(FP), AX
        PREFETCHNTA     (AX)
        RET
+
+TEXT ·checkASM(SB),NOSPLIT,$0-1
+       MOVB    $1, ret+0(FP)
+       RET
index 48fc321df3170957df2773127eb58203857472d0..d8757fd0b91a05ce03dcea9292d7d870ec9d4dd3 100644 (file)
@@ -1030,3 +1030,8 @@ TEXT runtime·addmoduledata(SB),NOSPLIT,$0-4
        MOVW    saver9-4(SP), R9
        RET
 #endif
+
+TEXT ·checkASM(SB),NOSPLIT,$0-1
+       MOVW    $1, R3
+       MOVB    R3, ret+0(FP)
+       RET
index 33755b35c03ef0f7bd9021237df676c7ddab38df..8931daa2cdd5b43b92e86bd412148b9b295433d4 100644 (file)
@@ -996,4 +996,8 @@ TEXT runtime·addmoduledata(SB),NOSPLIT,$0-0
        MOVD    R0, runtime·lastmoduledatap(SB)
        MOVD    8(RSP), R27
        ADD     $0x10, RSP
+
+TEXT ·checkASM(SB),NOSPLIT,$0-1
+       MOVW    $1, R3
+       MOVB    R3, ret+0(FP)
        RET
index 8d0cf122cbcd9a1f4c75fae1adf9b9c588c11bbd..7d3d7c2ae2df8eef34bcc466524e86007b7e98b6 100644 (file)
@@ -818,3 +818,8 @@ TEXT runtime·prefetcht2(SB),NOSPLIT,$0-8
 
 TEXT runtime·prefetchnta(SB),NOSPLIT,$0-8
        RET
+
+TEXT ·checkASM(SB),NOSPLIT,$0-1
+       MOVW    $1, R1
+       MOVB    R1, ret+0(FP)
+       RET
index 37ba816175a6bf6c7ce22cff82a8b7c44d463bb7..1ecdf3b2cdbf902df8e1741b1b66647fb3d99736 100644 (file)
@@ -1079,4 +1079,8 @@ TEXT runtime·addmoduledata(SB),NOSPLIT|NOFRAME,$0-0
        MOVD    R3, runtime·lastmoduledatap(SB)
        MOVD    0(R1), R31
        ADD     $8, R1
+
+TEXT ·checkASM(SB),NOSPLIT,$0-1
+       MOVW    $1, R3
+       MOVB    R3, ret+0(FP)
        RET
index 71afd79b55915cf0c73e7fc5c9b7f9eb13837880..3c4f47dd2e50e9612822120a3fcc3febc8339cc1 100644 (file)
@@ -296,6 +296,10 @@ func check() {
        if _FixedStack != round2(_FixedStack) {
                throw("FixedStack is not power-of-2")
        }
+
+       if !checkASM() {
+               throw("assembly checks failed")
+       }
 }
 
 type dbgVar struct {
index 9ead56e897329eb864135ed79d094b0bda802359..f060182c22f369bd44dc536c7cfc51ab5a3fb26c 100644 (file)
@@ -270,3 +270,6 @@ func unixnanotime() int64 {
 func round(n, a uintptr) uintptr {
        return (n + a - 1) &^ (a - 1)
 }
+
+// checkASM returns whether assembly runtime checks have passed.
+func checkASM() bool