google / gopacket

Provides packet processing capabilities for Go
BSD 3-Clause "New" or "Revised" License
6.32k stars 1.13k forks source link

pcap.go:388: internal compiler error: bad checknil #479

Closed flavio-fernandes closed 5 years ago

flavio-fernandes commented 6 years ago

Vagrant box ubuntu/trusty64 (virtualbox, 20171128.0.0)

Using the following script to compile a simple app that uses pcap, I hit the following issue when using master 79cff32cd2cb4b955635abee1ed8a632133d3420

This is the command I'm using, from a script I use to build the app :

cd /vagrant/nfvapp && go build nfvapp.go && echo yay

# github.com/google/gopacket/pcap
checknil [7fcbf27f16c8]
.   NAME-pcap.pp u(1) a(1) g(4) l(700) x(0+0) class(PAUTO) f(1) ld(1) tc(1) used(1) pcap._Ctype_uintptr_t
/home/vagrant/go/src/github.com/google/gopacket/pcap/pcap.go:388: internal compiler error: bad checknil

After finding a good starting point (v1.1.14) I was able to determine that the following commit seems to be causing the compilation failure.

git bisect start
git bisect good v1.1.14
git bisect bad 79cff32cd2cb4b955635abee1ed8a632133d3420
...
vagrant@compute1:~/go/src/github.com/google/gopacket$ git bisect bad
47e614fcdb33f819d0074378e15aa2628ae88b3f is the first bad commit
commit 47e614fcdb33f819d0074378e15aa2628ae88b3f
Author: Graeme Connell <gsconnell@gmail.com>
Date:   Tue Oct 10 09:54:59 2017 -0600

    Stop pointers-of-pointers from escaping with cgo.

    Yet more evidence that escape analysis in Go is really weird.  It
    appears that the pointers to pkthdr and bufptr were being allocated on
    the heap... attaching them to the handle itself appears to have helped
    out with this.

    This has pretty hacky cast-to-uintptr magic in it to get around cgo's
    error:

      panic: runtime error: cgo argument has Go pointer to Go pointer

:040000 040000 0bca543880de3be8940edf339b80102f1a4b46db 70d8d65f09dfbfc4b0961be1fe141b1f526a52ab M  pcap
flavio-fernandes commented 6 years ago

Hi @gconnell . Any chance you can tell what is causing this issue? ^^

notti commented 5 years ago

This looks like golang/go#7413 and indeed trusty ships with golang 1.2. I could verify this with the official trusty docker image. As mentioned in the golang issue this was fixed for golang 1.3 which is included in trusty-backports. I did a quick test in the same docker image with golang 1.3 from backports - and there go get worked. But one will run into additional problems with afpacket, bsdpf, and pcapgo/capture, since those need golang.org/x/sys/unix which in turn needs at least golang 1.6.

@flavio-fernandes does using a newer golang version work for you? @gconnell is there a minimum go version for gopacket?

gconnell commented 5 years ago

I'm sure there is a minimum go version for gopacket, but I have no clue what it is. In effect, if it compiles in Travis we tend to allow it to be committed... and Travis updates its Go relatively consistently with major releases. So there's a chance at any time that some depends-on-latest stuff might sneak in.

If we wanted, we could probably enforce a guaranteed minimum supported version by adding different Go version tests to our Travis, but we don't (I think) yet have that.

flavio-fernandes commented 5 years ago

@notti sorry for delay.

Yes, using 1.5 or newer seems to work ok Using 1.4 or older does not.

Using gimme to jump to different golang versions.

https://gist.github.com/flavio-fernandes/fb1e84c7ba4162438837077f2df1f0ba

vagrant@vagrant-ubuntu-trusty-64:~$ echo $GOPATH
/home/vagrant/go
vagrant@vagrant-ubuntu-trusty-64:~$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$ cd ; rm -rf go ; mkdir -pv ~/go ; eval "$(gimme stable)"
mkdir: created directory ‘/home/vagrant/go’
go version go1.11.2 linux/amd64
vagrant@vagrant-ubuntu-trusty-64:~$ go version ; go get github.com/google/gopacket
go version go1.11.2 linux/amd64
vagrant@vagrant-ubuntu-trusty-64:~$ cd /vagrant/nfvapp && go build nfvapp.go && echo yay
yay
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$ cd ; rm -rf go ; mkdir -pv ~/go ; eval "$(gimme 1.6)"
mkdir: created directory ‘/home/vagrant/go’
go version go1.6 linux/amd64
vagrant@vagrant-ubuntu-trusty-64:~$ go version ; go get github.com/google/gopacket
go version go1.6 linux/amd64
vagrant@vagrant-ubuntu-trusty-64:~$ cd /vagrant/nfvapp && go build nfvapp.go && echo yay
yay
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$ cd ; rm -rf go ; mkdir -pv ~/go ; eval "$(gimme 1.5)"
mkdir: created directory ‘/home/vagrant/go’
go version go1.5 linux/amd64
vagrant@vagrant-ubuntu-trusty-64:~$ go version ; go get github.com/google/gopacket
go version go1.5 linux/amd64
vagrant@vagrant-ubuntu-trusty-64:~$ cd /vagrant/nfvapp && go build nfvapp.go && echo yay
yay
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$ cd ; rm -rf go ; mkdir -pv ~/go ; eval "$(gimme 1.4)"
mkdir: created directory ‘/home/vagrant/go’
go version go1.4 linux/amd64
vagrant@vagrant-ubuntu-trusty-64:~$ go version ; go get github.com/google/gopacket
go version go1.4 linux/amd64
vagrant@vagrant-ubuntu-trusty-64:~$ cd /vagrant/nfvapp && go build nfvapp.go && echo yay
go build github.com/google/gopacket/layers: /home/vagrant/.gimme/versions/go1.4.linux.amd64/pkg/tool/linux_amd64/6g: signal: killed
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$ cd ; rm -rf go ; mkdir -pv ~/go ; eval "$(gimme 1.2)"
mkdir: created directory ‘/home/vagrant/go’
go version go1.2 linux/amd64
vagrant@vagrant-ubuntu-trusty-64:~$ go version ; go get github.com/google/gopacket
go version go1.2 linux/amd64
vagrant@vagrant-ubuntu-trusty-64:~$ cd /vagrant/nfvapp && go build nfvapp.go && echo yay
# github.com/google/gopacket/pcap
checknil [7f00405747f0]
.   NAME-pcap.pp u(1) a(1) g(4) l(700) x(0+0) class(PAUTO) f(1) ld(1) tc(1) used(1) pcap._Ctype_uintptr_t
/home/vagrant/go/src/github.com/google/gopacket/pcap/pcap.go:396: internal compiler error: bad checknil
vagrant@vagrant-ubuntu-trusty-64:/vagrant/nfvapp$
notti commented 5 years ago

Thanks for the testing. I'll add something to the documentation to document this and maybe also testing with different go versions on travis.