@@ -2963,18 +2963,24 @@ func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe
2963
2963
linkobj := str .StringList (ofile , outObj , mkAbsFiles (p .Dir , p .SysoFiles ))
2964
2964
dynobj := objdir + "_cgo_.o"
2965
2965
2966
- // we need to use -pie for Linux/ARM to get accurate imported sym
2967
2966
ldflags := cgoLDFLAGS
2968
2967
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
+ }
2975
2981
}
2982
+ ldflags = n
2976
2983
}
2977
- ldflags = append (n , "-pie" )
2978
2984
}
2979
2985
if err := b .gccld (a , p , objdir , dynobj , ldflags , linkobj ); err != nil {
2980
2986
return err
0 commit comments