From 055c186f53493da473c888869ad468861ba25f1a Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 25 May 2023 00:21:13 -0400 Subject: [PATCH] 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 --- src/runtime/mgc.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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") -- 2.48.1