golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.93k stars 17.66k forks source link

cmd/link: panic during go test on tip #14783

Closed peterbourgon closed 8 years ago

peterbourgon commented 8 years ago

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?

go version devel +de4317c

  1. What operating system and processor architecture are you using (go env)?

linux/amd64

  1. What did you do? If possible, provide a recipe for reproducing the error. A complete runnable program is good. A link on play.golang.org is best.

Travis CI ran the tests for my project, here is the job: https://travis-ci.org/go-kit/kit/jobs/115414128

  1. What did you expect to see?

Tests pass.

  1. What did you see instead?
# testmain
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0xf0 pc=0x4bd077]
goroutine 1 [running]:
panic(0x5a4c40, 0xc820018180)
    /home/travis/.gimme/versions/go/src/runtime/panic.go:500 +0x189
cmd/link/internal/ld.decodetype_funcincount(0x0, 0x28)
    /home/travis/.gimme/versions/go/src/cmd/link/internal/ld/decodesym.go:182 +0x27
cmd/link/internal/ld.decode_methodsig(0xc82119fad0, 0x40070, 0x30, 0x1, 0x1, 0x0, 0x4)
    /home/travis/.gimme/versions/go/src/cmd/link/internal/ld/decodesym.go:281 +0x121
cmd/link/internal/ld.decodetype_methods(0xc82119fad0, 0x0, 0x0, 0x0)
    /home/travis/.gimme/versions/go/src/cmd/link/internal/ld/decodesym.go:355 +0x169
cmd/link/internal/ld.(*deadcodepass).flood(0xc820041ce0)
    /home/travis/.gimme/versions/go/src/cmd/link/internal/ld/deadcode.go:296 +0xd50
cmd/link/internal/ld.deadcode(0xc82059e000)
    /home/travis/.gimme/versions/go/src/cmd/link/internal/ld/deadcode.go:56 +0xc5
cmd/link/internal/ld.Ldmain()
    /home/travis/.gimme/versions/go/src/cmd/link/internal/ld/pobj.go:190 +0x1349
cmd/link/internal/amd64.Main()
    /home/travis/.gimme/versions/go/src/cmd/link/internal/amd64/obj.go:44 +0x19
main.main()
    /home/travis/.gimme/versions/go/src/cmd/link/main.go:27 +0x27c

The build output is a little confusing, mea culpa. It looks like the test that triggers this panic is from package kit/log, you can find that by searching that page for "build failed".

crawshaw commented 8 years ago

Is there something I can go get to reproduce this?

dgryski commented 8 years ago

go get -v -u github.com/go-kit/kit/log

davecheney commented 8 years ago

Thanks for the report. This looks like the *Lsym that decode_funcincount is trying to read into can be nil in some circumstances.

func decode_reloc_sym(s *LSym, off int32) *LSym {
    r := decode_reloc(s, off)
    if r == nil {
        return nil
    }
    return r.Sym
}
crawshaw commented 8 years ago

Reproduction:

package main                                                                    

var three = 3                                                                   

type CustomT func(...interface{}) error                                         

func (f CustomT) M() {                                                          
        if 4 < three {                                                          
                f.M()                                                           
        }                                                                       
}                                                                               

func main() {                                                                   
        var v CustomT                                                           
        v.M()                                                                   
}

I believe I understand the cause and will get a CL out soon.

gopherbot commented 8 years ago

CL https://golang.org/cl/20566 mentions this issue.