This libgo patch by Cherry Zhang enables precise GC checks when using stack maps. The runtime package has bad pointer checks that currently don't work with the conservative collector used by gccgo. With stack maps, the GC is precise and the checks should work. Enable them. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline.
Ian
Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 269404) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -14e48e756af205a68374c872f3bd03d62ccd70bb +3f8ddaa1d773309b6a4b8e4640f8b9675d9764c6 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: libgo/go/runtime/mgcmark.go =================================================================== --- libgo/go/runtime/mgcmark.go (revision 269196) +++ libgo/go/runtime/mgcmark.go (working copy) @@ -1106,9 +1106,9 @@ func scanstackblockwithmap(pc, b0, n0 ui // Preemption must be disabled. //go:nowritebarrier func shade(b uintptr) { - if obj, span, objIndex := findObject(b, 0, 0, true); obj != 0 { + if obj, span, objIndex := findObject(b, 0, 0, !usestackmaps); obj != 0 { gcw := &getg().m.p.ptr().gcw - greyobject(obj, 0, 0, span, gcw, objIndex, true) + greyobject(obj, 0, 0, span, gcw, objIndex, !usestackmaps) } } Index: libgo/go/runtime/mgcsweep.go =================================================================== --- libgo/go/runtime/mgcsweep.go (revision 269216) +++ libgo/go/runtime/mgcsweep.go (working copy) @@ -342,8 +342,10 @@ func (s *mspan) sweep(preserve bool) boo // it is not otherwise a problem. So we disable the test for gccgo. nfreedSigned := int(nfreed) if nalloc > s.allocCount { - // print("runtime: nelems=", s.nelems, " nalloc=", nalloc, " previous allocCount=", s.allocCount, " nfreed=", nfreed, "\n") - // throw("sweep increased allocation count") + if usestackmaps { + print("runtime: nelems=", s.nelems, " nalloc=", nalloc, " previous allocCount=", s.allocCount, " nfreed=", nfreed, "\n") + throw("sweep increased allocation count") + } // For gccgo, adjust the freed count as a signed number. nfreedSigned = int(s.allocCount) - int(nalloc) Index: libgo/go/runtime/runtime1.go =================================================================== --- libgo/go/runtime/runtime1.go (revision 269216) +++ libgo/go/runtime/runtime1.go (working copy) @@ -362,7 +362,9 @@ func parsedebugvars() { // At that point, if debug.invalidptr is set, we crash. // This is not a problem, assuming that M1 really is dead and // the pointer we discovered to it will not be used. - // debug.invalidptr = 1 + if usestackmaps { + debug.invalidptr = 1 + } for p := gogetenv("GODEBUG"); p != ""; { field := ""