From: Vladimir Stefanovic Date: Wed, 31 Aug 2016 14:58:56 +0000 (+0200) Subject: runtime: 8-byte align the heap_live field for atomic access X-Git-Tag: go1.8beta1~322 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d3a3b74aa1eec3417a754d798a4cad487949fa77;p=gostls13.git runtime: 8-byte align the heap_live field for atomic access mheap_.heap_live is an atomically accessed uint64. It is currently not 8-byte aligned on 32-bit platforms, which has been okay because it's only accessed via Xadd64, which doesn't require alignment on 386 or ARM32. However, Xadd64 on MIPS32 does require 8-byte alignment. Add a padding field to force 8-byte alignment of heap_live and prevent an alignment check crash on MIPS32. Change-Id: I7eddf7883aec7a0a7e0525af5d58ed4338a401d0 Reviewed-on: https://go-review.googlesource.com/31635 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/runtime/mstats.go b/src/runtime/mstats.go index 02a2914dab..b80ab11389 100644 --- a/src/runtime/mstats.go +++ b/src/runtime/mstats.go @@ -100,6 +100,8 @@ type mstats struct { // must be complete. gc_trigger uint64 + _ uint32 // force 8-byte alignment of heap_live and prevent an alignment check crash on MIPS32. + // heap_live is the number of bytes considered live by the GC. // That is: retained by the most recent GC plus allocated // since then. heap_live <= heap_alloc, since heap_alloc @@ -411,6 +413,11 @@ func init() { println(sizeof_C_MStats, unsafe.Sizeof(memStats)) throw("MStats vs MemStatsType size mismatch") } + + if unsafe.Offsetof(memstats.heap_live)%8 != 0 { + println(unsafe.Offsetof(memstats.heap_live)) + throw("memstats.heap_live not aligned to 8 bytes") + } } // ReadMemStats populates m with memory allocator statistics.