mirror of
https://github.com/golang/go.git
synced 2025-05-30 19:52:53 +00:00
cmd/go: support -buildmode=plugin on linux
Change-Id: I0c8a04457db28c55c35c9a186b63c40f40730e39 Reviewed-on: https://go-review.googlesource.com/27824 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
0cbb12f0bb
commit
c19382319a
@ -866,6 +866,10 @@
|
||||
// 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
|
||||
//
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
`,
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user