Skip to content

cmd/link: use gold on ARM/ARM64 only if gold is available #49748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/cmd/link/internal/ld/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -1390,25 +1390,20 @@ func (ctxt *Link) hostlink() {
}

if ctxt.Arch.InFamily(sys.ARM, sys.ARM64) && buildcfg.GOOS == "linux" {
// On ARM, the GNU linker will generate COPY relocations
// even with -znocopyreloc set.
// On ARM, older versions of the GNU linker will generate
// COPY relocations even with -znocopyreloc set.
// https://sourceware.org/bugzilla/show_bug.cgi?id=19962
//
// On ARM64, the GNU linker will fail instead of
// generating COPY relocations.
// On ARM64, older versions of the GNU linker will fail
// instead of generating COPY relocations.
//
// In both cases, switch to gold.
altLinker = "gold"

// If gold is not installed, gcc will silently switch
// 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.
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)
if bytes.Contains(out, []byte("GNU gold")) {
altLinker = "gold"
}
}
}
Expand Down