Skip to content

Commit b4a2af2

Browse files
cherrymuicagedmantis
authored andcommitted
[release-branch.go1.15] cmd/link: pass arch-specific flags to external linker when testing supported flag
When testing if a flag (e.g. "-no-pie") is supported by the external linker, pass arch-specific flags (like "-marm"). In particular, on the ARM builder, if CGO_LDFLAGS=-march=armv6 is set, the C toolchain fails to build if -marm is not passed. # cc -march=armv6 1.c 1.c: In function 'main': 1.c:3:1: sorry, unimplemented: Thumb-1 hard-float VFP ABI int main() { ^~~ This makes the Go linker think "-no-pie" is not supported when it actually is. Passing -marm makes it work. Fixes #46684. Change-Id: I4e8b71f08818993cbbcb2494b310c68d812d6b50 Reviewed-on: https://go-review.googlesource.com/c/go/+/278592 Trust: Cherry Zhang <[email protected]> Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Than McIntosh <[email protected]> (cherry picked from commit a318d56) Reviewed-on: https://go-review.googlesource.com/c/go/+/326711 Run-TryBot: Carlos Amedee <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Trust: Dmitri Shuralyov <[email protected]>
1 parent ab7f829 commit b4a2af2

File tree

1 file changed

+4
-4
lines changed
  • src/cmd/link/internal/ld

1 file changed

+4
-4
lines changed

src/cmd/link/internal/ld/lib.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ func (ctxt *Link) hostlink() {
15551555
}
15561556

15571557
const compressDWARF = "-Wl,--compress-debug-sections=zlib-gnu"
1558-
if ctxt.compressDWARF && linkerFlagSupported(argv[0], altLinker, compressDWARF) {
1558+
if ctxt.compressDWARF && linkerFlagSupported(ctxt.Arch, argv[0], altLinker, compressDWARF) {
15591559
argv = append(argv, compressDWARF)
15601560
}
15611561

@@ -1645,7 +1645,7 @@ func (ctxt *Link) hostlink() {
16451645
if ctxt.BuildMode == BuildModeExe && !ctxt.linkShared {
16461646
// GCC uses -no-pie, clang uses -nopie.
16471647
for _, nopie := range []string{"-no-pie", "-nopie"} {
1648-
if linkerFlagSupported(argv[0], altLinker, nopie) {
1648+
if linkerFlagSupported(ctxt.Arch, argv[0], altLinker, nopie) {
16491649
argv = append(argv, nopie)
16501650
break
16511651
}
@@ -1746,7 +1746,7 @@ func (ctxt *Link) hostlink() {
17461746

17471747
var createTrivialCOnce sync.Once
17481748

1749-
func linkerFlagSupported(linker, altLinker, flag string) bool {
1749+
func linkerFlagSupported(arch *sys.Arch, linker, altLinker, flag string) bool {
17501750
createTrivialCOnce.Do(func() {
17511751
src := filepath.Join(*flagTmpdir, "trivial.c")
17521752
if err := ioutil.WriteFile(src, []byte("int main() { return 0; }"), 0666); err != nil {
@@ -1780,7 +1780,7 @@ func linkerFlagSupported(linker, altLinker, flag string) bool {
17801780
"-target",
17811781
}
17821782

1783-
var flags []string
1783+
flags := hostlinkArchArgs(arch)
17841784
keep := false
17851785
skip := false
17861786
extldflags := strings.Fields(*flagExtldflags)

0 commit comments

Comments
 (0)