mirror of
https://github.com/golang/go
synced 2024-11-24 05:10:19 -07:00
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: edaf02fa45
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>
This commit is contained in:
parent
a83a558733
commit
119213566a
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user