-This is https://github.com/golang/go/pull/49748 backported for Go 1.17.
+From 5ccf9f47bf4f5ba53e0ab7338a7fd4626714cfb2 Mon Sep 17 00:00:00 2001
+From: Jeffery To <jeffery.to@gmail.com>
+Date: Tue, 23 Nov 2021 15:05:37 +0800
+Subject: [PATCH] cmd/link: use gold on ARM/ARM64 only if gold is available
+
+COPY relocation handling on ARM/ARM64 has been fixed in recent versions
+of the GNU linker. This switches to gold only if gold is available.
+
+Fixes #22040.
+---
+ src/cmd/link/internal/ld/lib.go | 19 +++++++------------
+ 1 file changed, 7 insertions(+), 12 deletions(-)
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
-@@ -1388,23 +1388,18 @@ func (ctxt *Link) hostlink() {
+@@ -1502,25 +1502,20 @@ func (ctxt *Link) hostlink() {
}
if ctxt.Arch.InFamily(sys.ARM, sys.ARM64) && buildcfg.GOOS == "linux" {
- // back to ld.bfd. So we parse the version information
- // and provide a useful error if gold is missing.
+ // In both cases, switch to gold if gold is available.
- cmd := exec.Command(*flagExtld, "-fuse-ld=gold", "-Wl,--version")
+ name, args := flagExtld[0], flagExtld[1:]
+ args = append(args, "-fuse-ld=gold", "-Wl,--version")
+ cmd := exec.Command(name, args...)
if out, err := cmd.CombinedOutput(); err == nil {
- if !bytes.Contains(out, []byte("GNU gold")) {
- log.Fatalf("ARM external linker must be gold (issue #15696), but is not: %s", out)