Skip to content

cmd/gc: closure variables have invalid offset in debug info #4915

@DanielMorsing

Description

@DanielMorsing
Compile the following program

package main

func main() {
        var y int
        var foo = func(){
                y = 10
        }
        foo()
}

which turns into

--- prog list "func·001" ---
0014 (a.go:5) TEXT    func·001+0(SB),$0-0
0015 (a.go:5) LOCALS  ,$0
0016 (a.go:5) TYPE    &y+-1000000000(SP){*int},$8
0017 (a.go:5) MOVQ    8(DX),BX
0018 (a.go:6) MOVQ    $10,(BX)
0019 (a.go:5) RET     ,

The offset from the type instruction makes it into the debug info, causing a segfault
when doing "info locals" in gdb

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions