Skip to content

Commit d04b024

Browse files
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. This is a backport of https://go.dev/cl/497117 from the main repo. For golang/go#60287 Change-Id: Ie0bf76b588724265d75dd9a96984dd6cc207f84e Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/511675 Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 92152c8 commit d04b024

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

libgo/go/cmd/go/internal/work/gccgo.go

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

415415
for _, a := range allactions {
416-
// Gather CgoLDFLAGS, but not from standard packages.
417-
// The go tool can dig up runtime/cgo from GOROOT and
418-
// think that it should use its CgoLDFLAGS, but gccgo
419-
// doesn't use runtime/cgo.
420416
if a.Package == nil {
421417
continue
422418
}
423-
if !a.Package.Standard {
424-
cgoldflags = append(cgoldflags, a.Package.CgoLDFLAGS...)
425-
}
426419
if len(a.Package.CgoFiles) > 0 {
427420
usesCgo = true
428421
}
@@ -452,9 +445,6 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string
452445

453446
ldflags = append(ldflags, cgoldflags...)
454447
ldflags = append(ldflags, envList("CGO_LDFLAGS", "")...)
455-
if root.Package != nil {
456-
ldflags = append(ldflags, root.Package.CgoLDFLAGS...)
457-
}
458448
if cfg.Goos != "aix" {
459449
ldflags = str.StringList("-Wl,-(", ldflags, "-Wl,-)")
460450
}

libgo/go/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 cgoref
7+
! go build -x -compiler gccgo cgoref
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
-- cgoref/cgoref.go --
1112
package main

0 commit comments

Comments
 (0)