Skip to content

Commit 5ccf9f4

Browse files
committed
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.
1 parent 83bfed9 commit 5ccf9f4

File tree

1 file changed

+7
-12
lines changed
  • src/cmd/link/internal/ld

1 file changed

+7
-12
lines changed

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,25 +1390,20 @@ func (ctxt *Link) hostlink() {
13901390
}
13911391

13921392
if ctxt.Arch.InFamily(sys.ARM, sys.ARM64) && buildcfg.GOOS == "linux" {
1393-
// On ARM, the GNU linker will generate COPY relocations
1394-
// even with -znocopyreloc set.
1393+
// On ARM, older versions of the GNU linker will generate
1394+
// COPY relocations even with -znocopyreloc set.
13951395
// https://sourceware.org/bugzilla/show_bug.cgi?id=19962
13961396
//
1397-
// On ARM64, the GNU linker will fail instead of
1398-
// generating COPY relocations.
1397+
// On ARM64, older versions of the GNU linker will fail
1398+
// instead of generating COPY relocations.
13991399
//
1400-
// In both cases, switch to gold.
1401-
altLinker = "gold"
1402-
1403-
// If gold is not installed, gcc will silently switch
1404-
// back to ld.bfd. So we parse the version information
1405-
// and provide a useful error if gold is missing.
1400+
// In both cases, switch to gold if gold is available.
14061401
name, args := flagExtld[0], flagExtld[1:]
14071402
args = append(args, "-fuse-ld=gold", "-Wl,--version")
14081403
cmd := exec.Command(name, args...)
14091404
if out, err := cmd.CombinedOutput(); err == nil {
1410-
if !bytes.Contains(out, []byte("GNU gold")) {
1411-
log.Fatalf("ARM external linker must be gold (issue #15696), but is not: %s", out)
1405+
if bytes.Contains(out, []byte("GNU gold")) {
1406+
altLinker = "gold"
14121407
}
14131408
}
14141409
}

0 commit comments

Comments
 (0)