diff options
author | jochen weber <jochen.weber80@gmail.com> | 2021-05-14 12:45:13 +0000 |
---|---|---|
committer | Cherry Mui <cherryyz@google.com> | 2021-09-20 15:19:44 +0000 |
commit | 119213566a8e0da729a8bccc7d7f7d525f0c1cf9 (patch) | |
tree | 67498a664ee0cbd4acfd578d964f91c89dfe837a /src | |
parent | a83a5587331392fc9483d183e446586b463ad8aa (diff) | |
download | go-119213566a8e0da729a8bccc7d7f7d525f0c1cf9.tar.gz go-119213566a8e0da729a8bccc7d7f7d525f0c1cf9.zip |
cmd/cgo: remove hardcoded '-pie' ldflag for linux/arm
a minimally invasive fix proposal for #45940. which keeps the fix for #26197.
an alternative for (#26197) could be to fail if we have both flags. adding/removing a flag without an message to the user is inconvenient.
Change-Id: I6ac2524d81ff57202fbe3032a53afd5106270a9e
GitHub-Last-Rev: edaf02fa455329b5d794a139f99874b5e8cc12d1
GitHub-Pull-Request: golang/go#45989
Reviewed-on: https://go-review.googlesource.com/c/go/+/317569
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/go/internal/work/exec.go | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index f7fae9fdd9..f82028aef6 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -2963,18 +2963,24 @@ func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe linkobj := str.StringList(ofile, outObj, mkAbsFiles(p.Dir, p.SysoFiles)) dynobj := objdir + "_cgo_.o" - // we need to use -pie for Linux/ARM to get accurate imported sym ldflags := cgoLDFLAGS if (cfg.Goarch == "arm" && cfg.Goos == "linux") || cfg.Goos == "android" { - // -static -pie doesn't make sense, and causes link errors. - // Issue 26197. - n := make([]string, 0, len(ldflags)) - for _, flag := range ldflags { - if flag != "-static" { - n = append(n, flag) + if !str.Contains(ldflags, "-no-pie") { + // we need to use -pie for Linux/ARM to get accurate imported sym (added in https://golang.org/cl/5989058) + // this seems to be outdated, but we don't want to break existing builds depending on this (Issue 45940) + ldflags = append(ldflags, "-pie") + } + if str.Contains(ldflags, "-pie") && str.Contains(ldflags, "-static") { + // -static -pie doesn't make sense, and causes link errors. + // Issue 26197. + n := make([]string, 0, len(ldflags)-1) + for _, flag := range ldflags { + if flag != "-static" { + n = append(n, flag) + } } + ldflags = n } - ldflags = append(n, "-pie") } if err := b.gccld(a, p, objdir, dynobj, ldflags, linkobj); err != nil { return err |