From: Cherry Zhang Date: Mon, 21 Nov 2016 23:23:12 +0000 (-0500) Subject: runtime/internal/atomic: crash on unaligned 64-bit ops on 32-bit MIPS X-Git-Tag: go1.8beta1~82 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=526b2f85ce8e4b1b16f3122e0a5700c04b6de199;p=gostls13.git runtime/internal/atomic: crash on unaligned 64-bit ops on 32-bit MIPS This check was originally implemented by Vladimir in https://go-review.googlesource.com/c/31489/1/src/runtime/internal/atomic/atomic_mipsx.go#30 but removed due to my comment (Sorry!). This CL adds it back. Fixes #17786. Change-Id: I7ff4c2539fc9e2afd8199964b587a8ccf093b896 Reviewed-on: https://go-review.googlesource.com/33431 Run-TryBot: Cherry Zhang Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/runtime/internal/atomic/atomic_mipsx.go b/src/runtime/internal/atomic/atomic_mipsx.go index 20b000c7a0..93a1f1a9dd 100644 --- a/src/runtime/internal/atomic/atomic_mipsx.go +++ b/src/runtime/internal/atomic/atomic_mipsx.go @@ -25,7 +25,11 @@ func spinUnlock(state *uint32) //go:nosplit func lockAndCheck(addr *uint64) { - // force dereference before taking lock + // ensure 8-byte alignement + if uintptr(unsafe.Pointer(addr))&7 != 0 { + addr = nil + } + // force dereference before taking lock _ = *addr spinLock(&lock.state) diff --git a/src/runtime/internal/atomic/atomic_test.go b/src/runtime/internal/atomic/atomic_test.go index f7ba90a073..879a82f9c8 100644 --- a/src/runtime/internal/atomic/atomic_test.go +++ b/src/runtime/internal/atomic/atomic_test.go @@ -87,8 +87,8 @@ func TestUnaligned64(t *testing.T) { if unsafe.Sizeof(int(0)) != 4 { t.Skip("test only runs on 32-bit systems") } - case "amd64p32", "mips", "mipsle": - // amd64p32 and mips can handle unaligned atomics. + case "amd64p32": + // amd64p32 can handle unaligned atomics. t.Skipf("test not needed on %v", runtime.GOARCH) } diff --git a/src/sync/atomic/atomic_test.go b/src/sync/atomic/atomic_test.go index c151f46fa9..6d0831c3f9 100644 --- a/src/sync/atomic/atomic_test.go +++ b/src/sync/atomic/atomic_test.go @@ -1401,8 +1401,8 @@ func TestUnaligned64(t *testing.T) { if unsafe.Sizeof(int(0)) != 4 { t.Skip("test only runs on 32-bit systems") } - case "amd64p32", "mips", "mipsle": - // amd64p32 and mips can handle unaligned atomics. + case "amd64p32": + // amd64p32 can handle unaligned atomics. t.Skipf("test not needed on %v", runtime.GOARCH) }