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

cmd/go: with -compiler=gccgo should build C files even if CGO_ENABLED=0 #41758

Open
ianlancetaylor opened this issue Oct 2, 2020 · 1 comment
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

When using gccgo, it is sometimes necessary to include C files in a package to provide functionality that when using gc would be implemented in assembler. On tip cmd/go does not build these C files if the environment variable CGO_ENABLED=0. This causes some valid packages to fail to build with gccgo.

The correct fix may be that if the package has an import "C", then C files should not be built if CGO_ENABLED=0. But if the package does not have an import "C", then C files should be built.

An example package that uses this is golang.org/x/sys/unix. Using the gccgo version of the go tool (I need to use the gccgo version here because https://golang.org/cl/219817 is not yet ported to the main go tool):

> go test
PASS
ok  	golang.org/x/sys/unix	0.863s
> CGO_ENABLED=0 gccgoenv go test
# golang.org/x/sys/unix.test
/home/iant/gopath/src/golang.org/x/sys/unix/gccgo.go:48: error: undefined reference to 'golang.x2eorg..z2fx..z2fsys..z2funix.realSyscallNoError'
/home/iant/gopath/src/golang.org/x/sys/unix/gccgo.go:21: error: undefined reference to 'golang.x2eorg..z2fx..z2fsys..z2funix.realSyscallNoError'
/home/iant/gopath/src/golang.org/x/sys/unix/gccgo.go:28: error: undefined reference to 'golang.x2eorg..z2fx..z2fsys..z2funix.realSyscall'
/home/iant/gopath/src/golang.org/x/sys/unix/gccgo.go:35: error: undefined reference to 'golang.x2eorg..z2fx..z2fsys..z2funix.realSyscall'
/home/iant/gopath/src/golang.org/x/sys/unix/gccgo.go:42: error: undefined reference to 'golang.x2eorg..z2fx..z2fsys..z2funix.realSyscall'
/home/iant/gopath/src/golang.org/x/sys/unix/gccgo.go:53: error: undefined reference to 'golang.x2eorg..z2fx..z2fsys..z2funix.realSyscall'
/home/iant/gopath/src/golang.org/x/sys/unix/gccgo.go:21: error: undefined reference to 'golang.x2eorg..z2fx..z2fsys..z2funix.realSyscallNoError'
/home/iant/gopath/src/golang.org/x/sys/unix/gccgo.go:21: error: undefined reference to 'golang.x2eorg..z2fx..z2fsys..z2funix.realSyscallNoError'
collect2: error: ld returned 1 exit status
FAIL	golang.org/x/sys/unix [build failed]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

1 participant