Merge pull request #17303 from CarlosDerSeher/feature_bt_agent
[feed/packages.git] / lang / golang / golang / patches / 001-cmd-link-use-gold-on-ARM-ARM64-only-if-gold-is-available.patch
1 From 5ccf9f47bf4f5ba53e0ab7338a7fd4626714cfb2 Mon Sep 17 00:00:00 2001
2 From: Jeffery To <jeffery.to@gmail.com>
3 Date: Tue, 23 Nov 2021 15:05:37 +0800
4 Subject: [PATCH] cmd/link: use gold on ARM/ARM64 only if gold is available
5
6 COPY relocation handling on ARM/ARM64 has been fixed in recent versions
7 of the GNU linker. This switches to gold only if gold is available.
8
9 Fixes #22040.
10 ---
11 src/cmd/link/internal/ld/lib.go | 19 +++++++------------
12 1 file changed, 7 insertions(+), 12 deletions(-)
13
14 --- a/src/cmd/link/internal/ld/lib.go
15 +++ b/src/cmd/link/internal/ld/lib.go
16 @@ -1393,25 +1393,20 @@ func (ctxt *Link) hostlink() {
17 }
18
19 if ctxt.Arch.InFamily(sys.ARM, sys.ARM64) && buildcfg.GOOS == "linux" {
20 - // On ARM, the GNU linker will generate COPY relocations
21 - // even with -znocopyreloc set.
22 + // On ARM, older versions of the GNU linker will generate
23 + // COPY relocations even with -znocopyreloc set.
24 // https://sourceware.org/bugzilla/show_bug.cgi?id=19962
25 //
26 - // On ARM64, the GNU linker will fail instead of
27 - // generating COPY relocations.
28 + // On ARM64, older versions of the GNU linker will fail
29 + // instead of generating COPY relocations.
30 //
31 - // In both cases, switch to gold.
32 - altLinker = "gold"
33 -
34 - // If gold is not installed, gcc will silently switch
35 - // back to ld.bfd. So we parse the version information
36 - // and provide a useful error if gold is missing.
37 + // In both cases, switch to gold if gold is available.
38 name, args := flagExtld[0], flagExtld[1:]
39 args = append(args, "-fuse-ld=gold", "-Wl,--version")
40 cmd := exec.Command(name, args...)
41 if out, err := cmd.CombinedOutput(); err == nil {
42 - if !bytes.Contains(out, []byte("GNU gold")) {
43 - log.Fatalf("ARM external linker must be gold (issue #15696), but is not: %s", out)
44 + if bytes.Contains(out, []byte("GNU gold")) {
45 + altLinker = "gold"
46 }
47 }
48 }