]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: remove hardcoded '-pie' ldflag for linux/arm
authorjochen weber <jochen.weber80@gmail.com>
Fri, 14 May 2021 12:45:13 +0000 (12:45 +0000)
committerCherry Mui <cherryyz@google.com>
Mon, 20 Sep 2021 15:19:44 +0000 (15:19 +0000)
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>

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

index f7fae9fdd9617272311e4f1acaf30702333e22bb..f82028aef65d45e8cb69576dde31ea8565f702fe 100644 (file)
@@ -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