]> Cypherpunks.ru repositories - gostls13.git/commit
runtime: fix user arena heap bits writing on big endian platforms
authorMichael Anthony Knyszek <mknyszek@google.com>
Thu, 9 Nov 2023 21:50:40 +0000 (21:50 +0000)
committerMichael Knyszek <mknyszek@google.com>
Fri, 10 Nov 2023 04:46:18 +0000 (04:46 +0000)
commitf7c5cbb82087c55aa82081e931e0142783700ce8
tree856f10a997b79d89eedc58fd7e0afc2a821720bc
parent1fc45e9a2b7f457451106d5bf7a40d86257d639e
runtime: fix user arena heap bits writing on big endian platforms

Currently the user arena code writes heap bits to the (*mspan).heapBits
space with the platform-specific byte ordering (the heap bits are
written and managed as uintptrs). However, the compiler always emits GC
metadata for types in little endian.

Because the scanning part of the code that loads through the type
pointer in the allocation header expects little endian ordering, we end
up with the wrong byte ordering in GC when trying to scan arena memory.

Fix this by writing out the user arena heap bits in little endian on big
endian platforms.

This means that the space returned by (*mspan).heapBits has a different
meaning for user arenas and small object spans, which is a little odd,
so I documented it. To reduce the chance of misuse of the writeHeapBits
API, which now writes out heap bits in a different ordering than
writeSmallHeapBits on big endian platforms, this change also renames
writeHeapBits to writeUserArenaHeapBits.

Much of this can be avoided in the future if the compiler were to write
out the pointer/scalar bits as an array of uintptr values instead of
plain bytes. That's too big of a change for right now though.

This change is a no-op on little endian platforms. I confirmed it by
checking for any assembly code differences in the runtime test binary.
There were none. With this change, the arena tests pass on ppc64.

Fixes #64048.

Change-Id: If077d003872fcccf5a154ff5d8441a58582061bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/541315
Run-TryBot: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/compile/internal/test/inl_test.go
src/runtime/mbitmap_allocheaders.go
src/runtime/mbitmap_noallocheaders.go