aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2021-10-29 01:18:24 +0000
committerBryan C. Mills <bcmills@google.com>2021-10-29 17:32:24 +0000
commita88575d662a7e8e4fbb31bf139bcffc063e2a734 (patch)
tree5c7fa89494829d58483fca59c6c4ee83e184cbb6 /src
parent645d07819b2224ba4d759829443f7c6442162c69 (diff)
downloadgo-a88575d662a7e8e4fbb31bf139bcffc063e2a734.tar.xz
Revert "cmd/go: remove support for -buildmode=shared"
This reverts CL 359096. Updates #47788. Reason for revert: -buildmode=shared may have actually been working in a few very specific cases. We should not remove -buildmode=shared until we have implemented an alternative to support those few cases. Change-Id: Ia962b06abacc11f6f29fc29d092773be175e32f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/359575 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/dist/test.go9
-rw-r--r--src/cmd/go/alldocs.go9
-rw-r--r--src/cmd/go/internal/help/helpdoc.go5
-rw-r--r--src/cmd/go/internal/list/list.go3
-rw-r--r--src/cmd/go/internal/work/build.go3
-rw-r--r--src/cmd/go/internal/work/init.go31
-rw-r--r--src/cmd/go/testdata/script/list_linkshared.txt16
-rw-r--r--src/cmd/internal/sys/supported.go7
8 files changed, 60 insertions, 23 deletions
diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go
index 87238cc74f..5935011e19 100644
--- a/src/cmd/dist/test.go
+++ b/src/cmd/dist/test.go
@@ -762,6 +762,9 @@ func (t *tester) registerTests() {
if t.supportedBuildmode("c-shared") {
t.registerHostTest("testcshared", "../misc/cgo/testcshared", "misc/cgo/testcshared", ".")
}
+ if t.supportedBuildmode("shared") {
+ t.registerTest("testshared", "../misc/cgo/testshared", t.goTest(), t.timeout(600), ".")
+ }
if t.supportedBuildmode("plugin") {
t.registerTest("testplugin", "../misc/cgo/testplugin", t.goTest(), t.timeout(600), ".")
}
@@ -1044,6 +1047,12 @@ func (t *tester) supportedBuildmode(mode string) bool {
return true
}
return false
+ case "shared":
+ switch pair {
+ case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-s390x":
+ return true
+ }
+ return false
case "plugin":
// linux-arm64 is missing because it causes the external linker
// to crash, see https://golang.org/issue/17138
diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go
index 1b9b22a812..487a8f580b 100644
--- a/src/cmd/go/alldocs.go
+++ b/src/cmd/go/alldocs.go
@@ -162,6 +162,9 @@
// flags has a similar effect.
// -ldflags '[pattern=]arg list'
// arguments to pass on each go tool link invocation.
+// -linkshared
+// build code that will be linked against shared libraries previously
+// created with -buildmode=shared.
// -mod mode
// module download mode to use: readonly, vendor, or mod.
// By default, if a vendor directory is present and the go version in go.mod
@@ -779,6 +782,7 @@
// Name string // package name
// Doc string // package documentation string
// Target string // install path
+// Shlib string // the shared library that contains this package (only set when -linkshared)
// Goroot bool // is this package in the Go root?
// Standard bool // is this package part of the standard Go library?
// Stale bool // would 'go install' do anything for this package?
@@ -1799,6 +1803,11 @@
// non-main packages are built into .a files (the default
// behavior).
//
+// -buildmode=shared
+// Combine all the listed non-main packages into a single shared
+// library that will be used when building with the -linkshared
+// option. Packages named main are ignored.
+//
// -buildmode=exe
// Build the listed main packages and everything they import into
// executables. Packages not named main are ignored.
diff --git a/src/cmd/go/internal/help/helpdoc.go b/src/cmd/go/internal/help/helpdoc.go
index 2bb3584eba..035235fe1b 100644
--- a/src/cmd/go/internal/help/helpdoc.go
+++ b/src/cmd/go/internal/help/helpdoc.go
@@ -726,6 +726,11 @@ are:
non-main packages are built into .a files (the default
behavior).
+ -buildmode=shared
+ Combine all the listed non-main packages into a single shared
+ library that will be used when building with the -linkshared
+ option. Packages named main are ignored.
+
-buildmode=exe
Build the listed main packages and everything they import into
executables. Packages not named main are ignored.
diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go
index f23fbe5fea..8c85ddcf21 100644
--- a/src/cmd/go/internal/list/list.go
+++ b/src/cmd/go/internal/list/list.go
@@ -23,8 +23,8 @@ import (
"cmd/go/internal/load"
"cmd/go/internal/modinfo"
"cmd/go/internal/modload"
- "cmd/go/internal/str"
"cmd/go/internal/work"
+ "cmd/go/internal/str"
)
var CmdList = &base.Command{
@@ -56,6 +56,7 @@ to -f '{{.ImportPath}}'. The struct being passed to the template is:
Name string // package name
Doc string // package documentation string
Target string // install path
+ Shlib string // the shared library that contains this package (only set when -linkshared)
Goroot bool // is this package in the Go root?
Standard bool // is this package part of the standard Go library?
Stale bool // would 'go install' do anything for this package?
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
index e39ffcbd50..9d0ad27f0d 100644
--- a/src/cmd/go/internal/work/build.go
+++ b/src/cmd/go/internal/work/build.go
@@ -116,6 +116,9 @@ and test commands:
flags has a similar effect.
-ldflags '[pattern=]arg list'
arguments to pass on each go tool link invocation.
+ -linkshared
+ build code that will be linked against shared libraries previously
+ created with -buildmode=shared.
-mod mode
module download mode to use: readonly, vendor, or mod.
By default, if a vendor directory is present and the go version in go.mod
diff --git a/src/cmd/go/internal/work/init.go b/src/cmd/go/internal/work/init.go
index 9111150233..dc368de1c1 100644
--- a/src/cmd/go/internal/work/init.go
+++ b/src/cmd/go/internal/work/init.go
@@ -233,20 +233,16 @@ func buildModeInit() {
}
ldBuildmode = "pie"
case "shared":
- if cfg.Goos == "linux" {
- switch cfg.Goarch {
- case "386", "amd64", "arm", "arm64", "ppc64le", "s390x":
- // -buildmode=shared was supported on these platforms at one point, but
- // never really worked in module mode.
- // Support was officially dropped as of Go 1.18.
- // (See https://golang.org/issue/47788.)
- base.Fatalf("-buildmode=shared no longer supported as of Go 1.18")
-
- // TODO(#47788): Remove supporting code for -buildmode=shared.
- // (For the Go 1.18 release, we will keep most of the code around but
- // disabled to avoid merge conflicts in case we need to revert quickly.)
- }
+ pkgsFilter = pkgsNotMain
+ if gccgo {
+ codegenArg = "-fPIC"
+ } else {
+ codegenArg = "-dynlink"
+ }
+ if cfg.BuildO != "" {
+ base.Fatalf("-buildmode=shared and -o not supported together")
}
+ ldBuildmode = "shared"
case "plugin":
pkgsFilter = oneMainPkg
if gccgo {
@@ -265,15 +261,6 @@ func buildModeInit() {
}
if cfg.BuildLinkshared {
- if cfg.Goos == "linux" {
- switch cfg.Goarch {
- case "386", "amd64", "arm", "arm64", "ppc64le", "s390x":
- base.Fatalf("-linkshared no longer supported as of Go 1.18")
- // TODO(#47788): Remove supporting code for linkshared.
- // (For the Go 1.18 release, we will keep most of the code around but
- // disabled to avoid merge conflicts in case we need to revert quickly.)
- }
- }
if !sys.BuildModeSupported(cfg.BuildToolchainName, "shared", cfg.Goos, cfg.Goarch) {
base.Fatalf("-linkshared not supported on %s/%s\n", cfg.Goos, cfg.Goarch)
}
diff --git a/src/cmd/go/testdata/script/list_linkshared.txt b/src/cmd/go/testdata/script/list_linkshared.txt
new file mode 100644
index 0000000000..baae1e2be8
--- /dev/null
+++ b/src/cmd/go/testdata/script/list_linkshared.txt
@@ -0,0 +1,16 @@
+env GO111MODULE=on
+
+# golang.org/issue/35759: 'go list -linkshared'
+# panicked if invoked on a test-only package.
+
+[!buildmode:shared] skip
+
+go list -f '{{.ImportPath}}: {{.Target}} {{.Shlib}}' -linkshared .
+stdout '^example.com: $'
+
+-- go.mod --
+module example.com
+
+go 1.14
+-- x.go --
+package x
diff --git a/src/cmd/internal/sys/supported.go b/src/cmd/internal/sys/supported.go
index 18ca50f927..4fa5aa495e 100644
--- a/src/cmd/internal/sys/supported.go
+++ b/src/cmd/internal/sys/supported.go
@@ -132,6 +132,13 @@ func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
}
return false
+ case "shared":
+ switch platform {
+ case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x":
+ return true
+ }
+ return false
+
case "plugin":
switch platform {
case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",