|
| 1 | +This is https://github.com/golang/go/pull/49748 backported for Go 1.17. |
| 2 | + |
| 3 | +--- a/src/cmd/link/internal/ld/lib.go |
| 4 | ++++ b/src/cmd/link/internal/ld/lib.go |
| 5 | +@@ -1388,23 +1388,18 @@ func (ctxt *Link) hostlink() { |
| 6 | + } |
| 7 | + |
| 8 | + if ctxt.Arch.InFamily(sys.ARM, sys.ARM64) && buildcfg.GOOS == "linux" { |
| 9 | +- // On ARM, the GNU linker will generate COPY relocations |
| 10 | +- // even with -znocopyreloc set. |
| 11 | ++ // On ARM, older versions of the GNU linker will generate |
| 12 | ++ // COPY relocations even with -znocopyreloc set. |
| 13 | + // https://sourceware.org/bugzilla/show_bug.cgi?id=19962 |
| 14 | + // |
| 15 | +- // On ARM64, the GNU linker will fail instead of |
| 16 | +- // generating COPY relocations. |
| 17 | ++ // On ARM64, older versions of the GNU linker will fail |
| 18 | ++ // instead of generating COPY relocations. |
| 19 | + // |
| 20 | +- // In both cases, switch to gold. |
| 21 | +- altLinker = "gold" |
| 22 | +- |
| 23 | +- // If gold is not installed, gcc will silently switch |
| 24 | +- // back to ld.bfd. So we parse the version information |
| 25 | +- // and provide a useful error if gold is missing. |
| 26 | ++ // In both cases, switch to gold if gold is available. |
| 27 | + cmd := exec.Command(*flagExtld, "-fuse-ld=gold", "-Wl,--version") |
| 28 | + if out, err := cmd.CombinedOutput(); err == nil { |
| 29 | +- if !bytes.Contains(out, []byte("GNU gold")) { |
| 30 | +- log.Fatalf("ARM external linker must be gold (issue #15696), but is not: %s", out) |
| 31 | ++ if bytes.Contains(out, []byte("GNU gold")) { |
| 32 | ++ altLinker = "gold" |
| 33 | + } |
| 34 | + } |
| 35 | + } |
0 commit comments