]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: start support for -linkshared
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Wed, 1 Apr 2015 02:53:52 +0000 (15:53 +1300)
committerIan Lance Taylor <iant@golang.org>
Sat, 11 Apr 2015 17:19:00 +0000 (17:19 +0000)
This will fruitlessly rebuild stale packages that are in a shared
library.

Change-Id: I66a6e1adf7818558e7d1351ab215a5021b4a8a6b
Reviewed-on: https://go-review.googlesource.com/8333
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/build.go
src/cmd/go/doc.go
src/cmd/go/test.go
src/cmd/go/testflag.go

index c8a37b64d106b22945a79404e6152139defa0d80..1b86c9a69da0e8c33feea46a85534a597c024a4f 100644 (file)
@@ -77,6 +77,9 @@ and test commands:
 
        -buildmode mode
                build mode to use. See 'go help buildmodes' for more.
+       -linkshared
+               link against shared libraries previously created with
+               -buildmode=shared
        -compiler name
                name of compiler to use, as in runtime.Compiler (gccgo or gc).
        -gccgoflags 'arg list'
@@ -149,6 +152,7 @@ var buildGccgoflags []string // -gccgoflags flag
 var buildRace bool           // -race flag
 var buildToolExec []string   // -toolexec flag
 var buildBuildmode string    // -buildmode flag
+var buildLinkshared bool     // -linkshared flag
 
 var buildContext = build.Default
 var buildToolchain toolchain = noToolchain{}
@@ -204,6 +208,7 @@ func addBuildFlags(cmd *Command) {
        cmd.Flag.BoolVar(&buildRace, "race", false, "")
        cmd.Flag.Var((*stringsFlag)(&buildToolExec), "toolexec", "")
        cmd.Flag.StringVar(&buildBuildmode, "buildmode", "default", "")
+       cmd.Flag.BoolVar(&buildLinkshared, "linkshared", false, "")
 }
 
 func addBuildFlagsNX(cmd *Command) {
@@ -307,6 +312,15 @@ func buildModeInit() {
        default:
                fatalf("buildmode=%s not supported", buildBuildmode)
        }
+       if buildLinkshared {
+               if goarch != "amd64" || goos != "linux" {
+                       fmt.Fprintf(os.Stderr, "go %s: -linkshared is only supported on linux/amd64\n", flag.Args()[0])
+                       os.Exit(2)
+               }
+               codegenArg = "-dynlink"
+               // TODO(mwhudson): remove -w when that gets fixed in linker.
+               buildLdflags = append(buildLdflags, "-linkshared", "-w")
+       }
        if ldBuildmode != "" {
                buildLdflags = append(buildLdflags, "-buildmode="+ldBuildmode)
        }
index 95b8094a6777a6157ffb2170f31df9003b59017d..9d10d4f3fb97c7dbcfadfb0f20372fc896f11771 100644 (file)
@@ -97,6 +97,9 @@ and test commands:
 
        -buildmode mode
                build mode to use. See 'go help buildmodes' for more.
+       -linkshared
+               link against shared libraries previously created with
+               -buildmode=shared
        -compiler name
                name of compiler to use, as in runtime.Compiler (gccgo or gc).
        -gccgoflags 'arg list'
index e96ed22361b3e0aeb94671d2e176a3d6ace7e4ef..03e9eeda9ba2d2608d77598757297bdbbce1e81d 100644 (file)
@@ -314,6 +314,7 @@ func runTest(cmd *Command, args []string) {
        findExecCmd() // initialize cached result
 
        raceInit()
+       buildModeInit()
        pkgs := packagesForBuild(pkgArgs)
        if len(pkgs) == 0 {
                fatalf("no packages to test")
index 5652e5466c42c1dd0591e8cbf51b67358f4fa5ac..8767c2525b2140ba95a142ae52dcb3de25201751 100644 (file)
@@ -48,6 +48,7 @@ var testFlagDefn = []*testFlagSpec{
        {name: "tags"},
        {name: "compiler"},
        {name: "race", boolVar: &buildRace},
+       {name: "linkshared", boolVar: &buildLinkshared},
        {name: "installsuffix"},
 
        // passed to 6.out, adding a "test." prefix to the name if necessary: -v becomes -test.v.
@@ -115,7 +116,7 @@ func testFlags(args []string) (packageNames, passToTest []string) {
                var err error
                switch f.name {
                // bool flags.
-               case "a", "c", "i", "n", "x", "v", "race", "cover", "work":
+               case "a", "c", "i", "n", "x", "v", "race", "cover", "work", "linkshared":
                        setBoolFlag(f.boolVar, value)
                case "o":
                        testO = value