]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: stop treating GOROOT binaries specially
authorRuss Cox <rsc@golang.org>
Thu, 5 Oct 2017 18:02:54 +0000 (14:02 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 5 Oct 2017 20:06:29 +0000 (20:06 +0000)
This was for cmd/cgo, and cmd/cgo isn't special anymore.

Change-Id: I71efaf553b24798b523c7102859428d36b470698
Reviewed-on: https://go-review.googlesource.com/68530
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/go/internal/cfg/cfg.go
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/work/build.go

index 0d8e264eb754cbd046c68ad89d46accc0a5b4f02..d45043e6dc77e0270988c811411ae7be577b44ef 100644 (file)
@@ -131,7 +131,7 @@ func isGOROOT(path string) bool {
 
 // ExternalLinkingForced reports whether external linking is being
 // forced even for programs that do not use cgo.
-func ExternalLinkingForced(inGoroot bool) bool {
+func ExternalLinkingForced() bool {
        // Some targets must use external linking even inside GOROOT.
        switch BuildContext.GOOS {
        case "android":
@@ -143,12 +143,6 @@ func ExternalLinkingForced(inGoroot bool) bool {
                }
        }
 
-       // Otherwise we disable forcing of external linking for GOROOT binaries.
-       // This is primarily for cgo, so we will be able to relax this soon.
-       if inGoroot {
-               return false
-       }
-
        if !BuildContext.CgoEnabled {
                return false
        }
index b902e29c50618041363b13c9166c976ec565c6f3..526e5a6767ece9851eaabb1ab982bafb22795d0a 100644 (file)
@@ -1124,16 +1124,7 @@ func LinkerDeps(p *Package) []string {
        var deps []string
 
        // External linking mode forces an import of runtime/cgo.
-       // TODO(rsc): The GOROOT exception here is mainly to avoid a circular
-       // dependency when building cmd/cgo, which the build of
-       // runtime/cgo needs, but as of CL 68338 we now build
-       // cmd/cgo during cmd/dist, so that exception is no longer
-       // needed. At some point it may be worthwhile to remove the
-       // GOROOT exception here.
-       // Note that the condition here should also match the condition
-       // in ../work/build.go's gcToolchain.ld that controls disabling
-       // external linking during the link step.
-       if cfg.ExternalLinkingForced(p.Goroot) {
+       if cfg.ExternalLinkingForced() {
                deps = append(deps, "runtime/cgo")
        }
        // On ARM with GOARM=5, it forces an import of math, for soft floating point.
index d28be759dc6101bf002ef3b67225077ec9db9262..be24082f05a466441cf25331d24c9e0476a6528b 100644 (file)
@@ -2541,20 +2541,6 @@ func (gcToolchain) ld(b *Builder, root *Action, out, importcfg string, allaction
                ldflags = append(ldflags, "-buildid="+root.Package.Internal.BuildID)
        }
        ldflags = append(ldflags, cfg.BuildLdflags...)
-       if root.Package.Goroot {
-               // Cannot force -linkmode=external inside GOROOT.
-               // cmd/cgo cannot be linkmode=external,
-               // because that implies having runtime/cgo available,
-               // and runtime/cgo is built using cmd/cgo.
-               // It's possible the restriction can be limited to just cmd/cgo,
-               // but the whole-GOROOT prohibition matches the similar
-               // logic in ../load/pkg.go that decides whether to add an
-               // implicit runtime/cgo dependency.
-               // TODO(rsc): We may be able to remove this exception
-               // now that CL 68338 has made cmd/cgo not a special case.
-               // See the longer comment in ../load/pkg.go.
-               ldflags = removeLinkmodeExternal(ldflags)
-       }
        ldflags = setextld(ldflags, compiler)
 
        // On OS X when using external linking to build a shared library,
@@ -2572,27 +2558,6 @@ func (gcToolchain) ld(b *Builder, root *Action, out, importcfg string, allaction
        return b.run(dir, root.Package.ImportPath, nil, cfg.BuildToolexec, base.Tool("link"), "-o", out, "-importcfg", importcfg, ldflags, mainpkg)
 }
 
-// removeLinkmodeExternal removes any attempt to set linkmode=external
-// from ldflags, modifies ldflags in place, and returns ldflags.
-func removeLinkmodeExternal(ldflags []string) []string {
-       out := ldflags[:0]
-       for i := 0; i < len(ldflags); i++ {
-               flag := ldflags[i]
-               if strings.HasPrefix(flag, "--") {
-                       flag = flag[1:]
-               }
-               if flag == "-linkmode" && i+1 < len(ldflags) && ldflags[i+1] == "external" {
-                       i++
-                       continue
-               }
-               if flag == "-linkmode=external" {
-                       continue
-               }
-               out = append(out, flag)
-       }
-       return out
-}
-
 func (gcToolchain) ldShared(b *Builder, toplevelactions []*Action, out, importcfg string, allactions []*Action) error {
        ldflags := []string{"-installsuffix", cfg.BuildContext.InstallSuffix}
        ldflags = append(ldflags, "-buildmode=shared")