]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't fail in ToSymbolFunc when using -n
authorIan Lance Taylor <iant@golang.org>
Thu, 12 Aug 2021 22:51:26 +0000 (15:51 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 9 May 2022 20:39:32 +0000 (20:39 +0000)
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>

src/cmd/go/internal/work/gccgo.go
src/cmd/go/testdata/script/gccgo_link_c.txt

index cfd9bcc0c2fa43eaac9dc5653f3393db215bf984..d37b8df07b463bae29da1df643b30212018ba5da 100644 (file)
@@ -605,7 +605,11 @@ var gccgoToSymbolFunc func(string) string
 
 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)
index 422adea93d07daaeff6acee5e16eea72505bc54f..b9a4c70b7eecfc6d51d8f0a2f6cfd188b5ed5346 100644 (file)
@@ -2,15 +2,17 @@
 # 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() }