Skip to content

x/tools/gopls: SEGV loading m.used field from non-nil map pointer (in types.Scope.elems map) #76979

@adonovan

Description

@adonovan
#!stacks
"sigpanic" && "maps.(*Map).Used"

Issue created by stacks.

The crash indicates that the types.Scope's elems map is nonzero but an invalid pointer, since the load instruction is dominated by a nil check:

TEXT runtime.mapaccess1_faststr(SB) internal/runtime/maps/runtime_faststr_swiss.go
...
  runtime_faststr_swiss.go:110  0x40f920                4885db                  TESTQ BX, BX       m == nil?
  runtime_faststr_swiss.go:110  0x40f923                0f84ef000000            JE 0x40fa18                                                        
  map.go:394                    0x40f929                48833b00                CMPQ 0(BX), $0x0        load m.used, SEGV                                            
  runtime_faststr_swiss.go:110  0x40f92d                0f84e5000000            JE 0x40fa18                                                     

More memory corruption. Perhaps the types.Scope's elems field has been clobbered.

This stack aoCxtQ was reported by telemetry:

golang.org/x/tools/[email protected] go1.25.2 linux/amd64 gopls.client=other,vscode (1)

Use this command to reproduce the executable:
(HOME=$(mktemp -d); GOOS=linux GOARCH=amd64 GOTOOLCHAIN=go1.25.2 go install golang.org/x/tools/[email protected] && find $HOME/go/bin -type f)
To disassemble: go tool objdump exe | less

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions