]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: support -buildmode=plugin on linux
authorDavid Crawshaw <crawshaw@golang.org>
Fri, 26 Aug 2016 12:51:58 +0000 (08:51 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Fri, 16 Sep 2016 17:54:59 +0000 (17:54 +0000)
Change-Id: I0c8a04457db28c55c35c9a186b63c40f40730e39
Reviewed-on: https://go-review.googlesource.com/27824
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/alldocs.go
src/cmd/go/build.go
src/cmd/go/help.go
src/cmd/go/pkg.go

index 1ff04f8206211cbe01682dc8a75934c482edccdd..522f7914732acf660037dff90fa4068e67e08be0 100644 (file)
 //             position independent executables (PIE). Packages not named
 //             main are ignored.
 //
+//     -buildmode=plugin
+//             Build the listed main packages, plus all packages that they
+//             import, into a Go plugin. Packages not named main are ignored.
+//
 //
 // File types
 //
index e2b018abba197149894e8b688189ebc60cf790d6..f656d708729a97b569d1ac42f40e4800ff109dff 100644 (file)
@@ -406,6 +406,21 @@ func buildModeInit() {
                        fatalf("-buildmode=shared and -o not supported together")
                }
                ldBuildmode = "shared"
+       case "plugin":
+               pkgsFilter = pkgsMain
+               if gccgo {
+                       codegenArg = "-fPIC"
+               } else {
+                       switch platform {
+                       case "linux/amd64", "linux/arm", "linux/arm64", "linux/386",
+                               "android/amd64", "android/arm", "android/arm64", "android/386":
+                       default:
+                               fatalf("-buildmode=plugin not supported on %s\n", platform)
+                       }
+                       codegenArg = "-dynlink"
+               }
+               exeSuffix = ".so"
+               ldBuildmode = "plugin"
        default:
                fatalf("buildmode=%s not supported", buildBuildmode)
        }
@@ -1665,7 +1680,7 @@ func (b *builder) install(a *action) (err error) {
        perm := os.FileMode(0666)
        if a1.link {
                switch buildBuildmode {
-               case "c-archive", "c-shared":
+               case "c-archive", "c-shared", "plugin":
                default:
                        perm = 0777
                }
@@ -2959,7 +2974,7 @@ func (tools gccgoToolchain) cc(b *builder, p *Package, objdir, ofile, cfile stri
 // maybePIC adds -fPIC to the list of arguments if needed.
 func (tools gccgoToolchain) maybePIC(args []string) []string {
        switch buildBuildmode {
-       case "c-shared", "shared":
+       case "c-shared", "shared", "plugin":
                args = append(args, "-fPIC")
        }
        return args
index d2b8444d8ed0436fe24d830e129d890daa99a5ae..8ad85e3b1f25bd3a248a0957b5ceaac5118a31bf 100644 (file)
@@ -577,5 +577,9 @@ are:
                Build the listed main packages and everything they import into
                position independent executables (PIE). Packages not named
                main are ignored.
+
+       -buildmode=plugin
+               Build the listed main packages, plus all packages that they
+               import, into a Go plugin. Packages not named main are ignored.
 `,
 }
index a352b601a7a591c4ff8a61c383a3d227c4c7daeb..69367eefb130bc80dc69fe9c095e09ae47218c52 100644 (file)
@@ -775,7 +775,7 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package
        useBindir := p.Name == "main"
        if !p.Standard {
                switch buildBuildmode {
-               case "c-archive", "c-shared":
+               case "c-archive", "c-shared", "plugin":
                        useBindir = false
                }
        }
@@ -846,11 +846,11 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package
                importPaths = append(importPaths, "syscall")
        }
 
-       // Currently build modes c-shared, pie, and -linkshared force
+       // Currently build modes c-shared, pie, plugin, and -linkshared force
        // external linking mode, and external linking mode forces an
        // import of runtime/cgo.
        pieCgo := buildBuildmode == "pie" && (buildContext.GOOS != "linux" || buildContext.GOARCH != "amd64")
-       if p.Name == "main" && !p.Goroot && (buildBuildmode == "c-shared" || pieCgo || buildLinkshared) {
+       if p.Name == "main" && !p.Goroot && (buildBuildmode == "c-shared" || buildBuildmode == "plugin" || pieCgo || buildLinkshared) {
                importPaths = append(importPaths, "runtime/cgo")
        }