Skip to content

Commit 1192135

Browse files
jochen42cherrymui
authored andcommitted
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: edaf02f GitHub-Pull-Request: #45989 Reviewed-on: https://go-review.googlesource.com/c/go/+/317569 Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Cherry Mui <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Bryan C. Mills <[email protected]>
1 parent a83a558 commit 1192135

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/cmd/go/internal/work/exec.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,18 +2963,24 @@ func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe
29632963
linkobj := str.StringList(ofile, outObj, mkAbsFiles(p.Dir, p.SysoFiles))
29642964
dynobj := objdir + "_cgo_.o"
29652965

2966-
// we need to use -pie for Linux/ARM to get accurate imported sym
29672966
ldflags := cgoLDFLAGS
29682967
if (cfg.Goarch == "arm" && cfg.Goos == "linux") || cfg.Goos == "android" {
2969-
// -static -pie doesn't make sense, and causes link errors.
2970-
// Issue 26197.
2971-
n := make([]string, 0, len(ldflags))
2972-
for _, flag := range ldflags {
2973-
if flag != "-static" {
2974-
n = append(n, flag)
2968+
if !str.Contains(ldflags, "-no-pie") {
2969+
// we need to use -pie for Linux/ARM to get accurate imported sym (added in https://golang.org/cl/5989058)
2970+
// this seems to be outdated, but we don't want to break existing builds depending on this (Issue 45940)
2971+
ldflags = append(ldflags, "-pie")
2972+
}
2973+
if str.Contains(ldflags, "-pie") && str.Contains(ldflags, "-static") {
2974+
// -static -pie doesn't make sense, and causes link errors.
2975+
// Issue 26197.
2976+
n := make([]string, 0, len(ldflags)-1)
2977+
for _, flag := range ldflags {
2978+
if flag != "-static" {
2979+
n = append(n, flag)
2980+
}
29752981
}
2982+
ldflags = n
29762983
}
2977-
ldflags = append(n, "-pie")
29782984
}
29792985
if err := b.gccld(a, p, objdir, dynobj, ldflags, linkobj); err != nil {
29802986
return err

0 commit comments

Comments
 (0)