CL 214429, among other things, created gccgo_link_c.txt as a copy of a
test formerly in go_test.go, but accidentally did so incorrectly:
it used -r instead of -n. This was not noticed because the new test
also incorrectly used [gccgo] when it should have used [exec:gccgo].
Fixing both of those, and also fixing the test to use a go.mod file,
revealed that "go build -n -compiler gccgo" doesn't work, because
it passes a non-existent tmpdir to pkgpath.ToSymbolFunc. This CL
fixes that too.
Change-Id: Id89296803b55412af3bd87aab992f32e26dbce0e
Reviewed-on: https://go-review.googlesource.com/c/go/+/341969
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
func (tools gccgoToolchain) gccgoCleanPkgpath(b *Builder, p *load.Package) string {
gccgoToSymbolFuncOnce.Do(func() {
- fn, err := pkgpath.ToSymbolFunc(tools.compiler(), b.WorkDir)
+ tmpdir := b.WorkDir
+ if cfg.BuildN {
+ tmpdir = os.TempDir()
+ }
+ fn, err := pkgpath.ToSymbolFunc(tools.compiler(), tmpdir)
if err != nil {
fmt.Fprintf(os.Stderr, "cmd/go: %v\n", err)
base.SetExitStatus(2)
# cmd/cgo: undefined reference when linking a C-library using gccgo
[!cgo] skip
-[!gccgo] skip
+[!exec:gccgo] skip
-go build -r -compiler gccgo cgoref
+go build -n -compiler gccgo
stderr 'gccgo.*\-L [^ ]*alibpath \-lalib' # make sure that Go-inline "#cgo LDFLAGS:" ("-L alibpath -lalib") passed to gccgo linking stage
--- cgoref/cgoref.go --
+-- go.mod --
+module m
+-- cgoref.go --
package main
// #cgo LDFLAGS: -L alibpath -lalib
// void f(void) {}
import "C"
-func main() { C.f() }
\ No newline at end of file
+func main() { C.f() }