Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/cmd/gotype: undeclared name: _Ctype_struct_bpf_program #25439

Open
gustafj opened this issue May 17, 2018 · 2 comments

Comments

@gustafj
Copy link

commented May 17, 2018

Cgo struct types of the form _Ctype_struct_ seems to be unknown to gotype.

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

go version go1.10.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOOS="linux"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"

What did you do?

Lint using gotype a dummy package which imports github.com/google/gopacket/pcap.

$ go get -u github.com/google/gopacket/pcap

$ cat $GOPATH/src/github.com/google/dummy/dummy.go
package dummy
import _ "github.com/google/gopacket/pcap"

$ gotype dummy.go

What did you expect to see?

No output (as in everything is OK).

What did you see instead?

dummy.go:2:10: could not import github.com/google/gopacket/pcap (type-checking package "github.com/google/gopacket/pcap" failed ($GOPATH/src/github.com/google/gopacket/pcap/pcap.go:533:49: undeclared name: _Ctype_struct_bpf_program))

Running gotype on github.com/google/gopacket/pcap directly gives:

$ gotype pcap.go
pcap.go:533:49: undeclared name: _Ctype_struct_bpf_program
pcap.go:203:7: undeclared name: _Ctype_struct_bpf_program
pcap.go:661:66: undeclared name: _Ctype_struct_bpf_program
pcap.go:801:34: undeclared name: _Ctype_struct_pcap_addr
pcap.go:401:17: invalid operation: p.pkthdr (variable of type *invalid type) has no field or method ts
pcap.go:403:19: invalid operation: p.pkthdr (variable of type *invalid type) has no field or method ts
pcap.go:406:27: invalid operation: p.pkthdr (variable of type *invalid type) has no field or method caplen
pcap.go:407:20: invalid operation: p.pkthdr (variable of type *invalid type) has no field or method len
pcap.go:425:4: invalid operation: p (variable of type *Handle) has no field or method waitForPacket
pcap.go:488:13: undeclared name: _Ctype_struct_pcap_stat

@gopherbot gopherbot added this to the Unreleased milestone May 17, 2018

@bcmills

This comment has been minimized.

Copy link
Member

commented May 17, 2018

@griesemer

This comment has been minimized.

Copy link
Contributor

commented May 21, 2018

go/types doesn't know anything about C; it only knows about the .go files (or package) it is presented with. Since go/types is not run via the go command, cgo is not run and it doesn't see the cgo generated files (which contain the relevant definitions).

When go/types sees an import "C", it "fakes" that import and silently suppresses all errors that would arise from qualified identifiers of the form C.foo . Thus it "works" ok with C.foo style identifiers.

There's no easy fix.

@griesemer griesemer self-assigned this May 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.