Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | From aae44527c8065d54f6acaf87c82cba1ac96fae59 Mon Sep 17 00:00:00 2001 |
| 2 | From: Ian Lance Taylor <iant@golang.org> |
| 3 | Date: Fri, 18 Aug 2017 17:46:03 -0700 |
| 4 | Subject: [PATCH] cmd/go: -buildmode=pie forces external linking mode on all |
| 5 | systems |
| 6 | |
| 7 | The go tool assumed that -buildmode=pie implied internal linking on |
| 8 | linux-amd64. However, that was changed by CL 36417 for issue #18968. |
| 9 | |
| 10 | Fixes #21452 |
| 11 | |
| 12 | Change-Id: I8ed13aea52959cc5c53223f4c41ba35329445545 |
| 13 | Reviewed-on: https://go-review.googlesource.com/57231 |
| 14 | Run-TryBot: Ian Lance Taylor <iant@golang.org> |
| 15 | TryBot-Result: Gobot Gobot <gobot@golang.org> |
| 16 | Reviewed-by: Avelino <t@avelino.xxx> |
| 17 | Reviewed-by: Rob Pike <r@golang.org> |
| 18 | --- |
| 19 | Upstream-Status: Backport |
| 20 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 21 | |
| 22 | src/cmd/go/internal/load/pkg.go | 7 ++++--- |
| 23 | 1 file changed, 4 insertions(+), 3 deletions(-) |
| 24 | |
| 25 | diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go |
| 26 | index 2660d3f..d40773b 100644 |
| 27 | --- a/src/cmd/go/internal/load/pkg.go |
| 28 | +++ b/src/cmd/go/internal/load/pkg.go |
| 29 | @@ -954,11 +954,12 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) *Package |
| 30 | |
| 31 | if cfg.BuildContext.CgoEnabled && p.Name == "main" && !p.Goroot { |
| 32 | // Currently build modes c-shared, pie (on systems that do not |
| 33 | - // support PIE with internal linking mode), plugin, and |
| 34 | - // -linkshared force external linking mode, as of course does |
| 35 | + // support PIE with internal linking mode (currently all |
| 36 | + // systems: issue #18968)), plugin, and -linkshared force |
| 37 | + // external linking mode, as of course does |
| 38 | // -ldflags=-linkmode=external. External linking mode forces |
| 39 | // an import of runtime/cgo. |
| 40 | - pieCgo := cfg.BuildBuildmode == "pie" && (cfg.BuildContext.GOOS != "linux" || cfg.BuildContext.GOARCH != "amd64") |
| 41 | + pieCgo := cfg.BuildBuildmode == "pie" |
| 42 | linkmodeExternal := false |
| 43 | for i, a := range cfg.BuildLdflags { |
| 44 | if a == "-linkmode=external" { |
| 45 | -- |
| 46 | 2.14.1 |
| 47 | |