Skip to content

Commit d3e3e11

Browse files
ianlancetaylorgopherbot
authored andcommitted
cmd/go: don't collect package CGOLDFLAGS when using gccgo
They are already collected via cmd/cgo. The gccgo_link_c test is tweaked to do real linking as with this change the cgo ldflags are not fully reflected in go build -n output, since they now only come from the built archive. Fixes #60287 Change-Id: Id433435fe8aeb9571327bf936e52a37f400cef4c Reviewed-on: https://go-review.googlesource.com/c/go/+/497117 Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Andrey Bokhanko <[email protected]>
1 parent 80a7315 commit d3e3e11

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

src/cmd/go/internal/work/gccgo.go

-10
Original file line numberDiff line numberDiff line change
@@ -386,16 +386,9 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string
386386
}
387387

388388
for _, a := range allactions {
389-
// Gather CgoLDFLAGS, but not from standard packages.
390-
// The go tool can dig up runtime/cgo from GOROOT and
391-
// think that it should use its CgoLDFLAGS, but gccgo
392-
// doesn't use runtime/cgo.
393389
if a.Package == nil {
394390
continue
395391
}
396-
if !a.Package.Standard {
397-
cgoldflags = append(cgoldflags, a.Package.CgoLDFLAGS...)
398-
}
399392
if len(a.Package.CgoFiles) > 0 {
400393
usesCgo = true
401394
}
@@ -425,9 +418,6 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string
425418

426419
ldflags = append(ldflags, cgoldflags...)
427420
ldflags = append(ldflags, envList("CGO_LDFLAGS", "")...)
428-
if root.Package != nil {
429-
ldflags = append(ldflags, root.Package.CgoLDFLAGS...)
430-
}
431421
if cfg.Goos != "aix" {
432422
ldflags = str.StringList("-Wl,-(", ldflags, "-Wl,-)")
433423
}

src/cmd/go/testdata/script/gccgo_link_c.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
[!cgo] skip
55
[!exec:gccgo] skip
66

7-
go build -n -compiler gccgo
7+
! go build -x -compiler gccgo
88
stderr 'gccgo.*\-L [^ ]*alibpath \-lalib' # make sure that Go-inline "#cgo LDFLAGS:" ("-L alibpath -lalib") passed to gccgo linking stage
9+
! stderr 'gccgo.*-lalib.*-lalib' # make sure -lalib is only passed once
910

1011
-- go.mod --
1112
module m

0 commit comments

Comments
 (0)