]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: use correct libraries during gccgo link
authorMichael Hudson-Doyle <michael.hudson@linaro.org>
Thu, 13 Mar 2014 03:05:54 +0000 (23:05 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 13 Mar 2014 03:05:54 +0000 (23:05 -0400)
Under some circumstances, gccgoToolchain's ld can pass the path of
build outputs that have been deleted to the link command.

Fixes #7303.

LGTM=rsc
R=golang-codereviews, dave, michael.hudson, rsc
CC=golang-codereviews
https://golang.org/cl/61970044

src/cmd/go/build.go

index 03ff3b207fe958bc7028b6991177eb042242287f..f653b5272725403b712b59227619226ee5d7a547 100644 (file)
@@ -1843,7 +1843,7 @@ func (gccgoToolchain) pack(b *builder, p *Package, objDir, afile string, ofiles
 func (tools gccgoToolchain) ld(b *builder, p *Package, out string, allactions []*action, mainpkg string, ofiles []string) error {
        // gccgo needs explicit linking with all package dependencies,
        // and all LDFLAGS from cgo dependencies.
-       afilesSeen := make(map[*Package]bool)
+       apackagesSeen := make(map[*Package]bool)
        afiles := []string{}
        sfiles := []string{}
        ldflags := b.gccArchArgs()
@@ -1851,14 +1851,23 @@ func (tools gccgoToolchain) ld(b *builder, p *Package, out string, allactions []
        usesCgo := false
        cxx := false
        objc := false
+
+       // Prefer the output of an install action to the output of a build action,
+       // because the install action will delete the output of the build action.
+       // Iterate over the list backward (reverse dependency order) so that we
+       // always see the install before the build.
+       for i := len(allactions) - 1; i >= 0; i-- {
+               a := allactions[i]
+               if !a.p.Standard {
+                       if a.p != nil && !apackagesSeen[a.p] {
+                               apackagesSeen[a.p] = true
+                               afiles = append(afiles, a.target)
+                       }
+               }
+       }
+
        for _, a := range allactions {
                if a.p != nil {
-                       if !a.p.Standard {
-                               if !afilesSeen[a.p] || a.objpkg != a.target {
-                                       afilesSeen[a.p] = true
-                                       afiles = append(afiles, a.target)
-                               }
-                       }
                        cgoldflags = append(cgoldflags, a.p.CgoLDFLAGS...)
                        if len(a.p.CgoFiles) > 0 {
                                usesCgo = true