From: Russ Cox Date: Thu, 25 May 2023 04:21:13 +0000 (-0400) Subject: runtime: add heapObjectsCanMove X-Git-Tag: go1.21rc1~236 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=055c186f53493da473c888869ad468861ba25f1a;p=gostls13.git runtime: add heapObjectsCanMove heapObjectsCanMove is always false in the current garbage collector. It exists for go4.org/unsafe/assume-no-moving-gc, which is an unfortunate idea that had an even more unfortunate implementation. Every time a new Go release happened, the package stopped building, and the authors had to add a new file with a new //go:build line, and then the entire ecosystem of packages with that as a dependency had to explicitly update to the new version. Many packages depend on assume-no-moving-gc transitively, through paths like inet.af/netaddr -> go4.org/intern -> assume-no-moving-gc. This was causing a significant amount of friction around each new release, so we added this bool for the package to //go:linkname instead. The bool is still unfortunate, but it's not as bad as breaking the ecosystem on every new release. If the Go garbage collector ever does move heap objects, we can set this to true to break all the programs using assume-no-moving-gc. Change-Id: I06c32bf6ccc4601c8eef741d7382b678aada3508 Reviewed-on: https://go-review.googlesource.com/c/go/+/498121 Run-TryBot: Russ Cox TryBot-Result: Gopher Robot Reviewed-by: Austin Clements --- diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index c8e68807ee..d3658df489 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -149,6 +149,24 @@ const ( sweepMinHeapDistance = 1024 * 1024 ) +// heapObjectsCanMove is always false in the current garbage collector. +// It exists for go4.org/unsafe/assume-no-moving-gc, which is an +// unfortunate idea that had an even more unfortunate implementation. +// Every time a new Go release happened, the package stopped building, +// and the authors had to add a new file with a new //go:build line, and +// then the entire ecosystem of packages with that as a dependency had to +// explicitly update to the new version. Many packages depend on +// assume-no-moving-gc transitively, through paths like +// inet.af/netaddr -> go4.org/intern -> assume-no-moving-gc. +// This was causing a significant amount of friction around each new +// release, so we added this bool for the package to //go:linkname +// instead. The bool is still unfortunate, but it's not as bad as +// breaking the ecosystem on every new release. +// +// If the Go garbage collector ever does move heap objects, we can set +// this to true to break all the programs using assume-no-moving-gc. +var heapObjectsCanMove = false + func gcinit() { if unsafe.Sizeof(workbuf{}) != _WorkbufSize { throw("size of Workbuf is suboptimal")