Skip to content

x/tools/gopls: crash in bgsweep #73262

@adonovan

Description

@adonovan
#!stacks
"sigpanic" && "runtime.(*gcBits).bytep"

Issue created by stacks.

Crash in GC sweep.

// gcBits is an alloc/mark bitmap. This is always used as gcBits.x.
type gcBits struct {
	_ sys.NotInHeap
	x uint8
}

// bytep returns a pointer to the n'th byte of b.
func (b *gcBits) bytep(n uintptr) *uint8 {
	return addb(&b.x, n) <--------- SEGV
}
...
func addb(p *byte, n uintptr) *byte {
	return (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(p)) + n))
}

Weirdly, the arm64 code for bytep (when noninlined) shows a MOVB where I would have expected a full-width load. Can someone explain it? [Never mind: it's a nil check on the pointer; the result is discarded.]

b is invalid.

(NB, this disassembly is from go1.25 devel on darwin/arm64.)
runtime.(*gcBits).bytep STEXT size=16 args=0x10 locals=0x0 funcid=0x0 align=0x0 leaf
	0x0000 00000 	L2509	TEXT	runtime.(*gcBits).bytep(SB), LEAF|NOFRAME|ABIInternal, $0-16
	0x0000 00000 	L2509	FUNCDATA	$0, gclocals·g5+hNtRBP6YXNjfog7aZjQ==(SB)
	0x0000 00000 	L2509	FUNCDATA	$1, gclocals·g5+hNtRBP6YXNjfog7aZjQ==(SB)
	0x0000 00000 	L2509	FUNCDATA	$5, runtime.(*gcBits).bytep.arginfo1(SB)
	0x0000 00000 	L2509	FUNCDATA	$6, runtime.(*gcBits).bytep.argliveinfo(SB)
	0x0000 00000 	L2509	PCDATA	$3, $1
	0x0000 00000 	L2510	PCDATA	$0, $-2
	0x0000 00000 	L2510	MOVB	(R0), R27     load b.x, SEGV
	0x0004 00004 	L0980	ADD	R1, R0, R0            add n 
	0x0008 00008 	     	NOP
	0x0008 00008 	L2510	RET	(R30)
	0x0000 1b 00 80 39 00 00 01 8b c0 03 5f d6 00 00 00 00  ...9......_.....

This stack dWF4MQ was reported by telemetry:

golang.org/x/tools/gopls@v0.18.1 go1.23.6 linux/amd64 vscode (1)

@golang/compiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/memory-corruption"can't happen" gopls crashes (races, unsafe, miscompile, runtime bugs, faulty HW)gopls/telemetry-wins

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions