Commit a3c92c9d authored by David Crawshaw's avatar David Crawshaw

cmd/link: use gold when dynamic linking on arm64

The GNU linker follows the letter of -znocopyreloc by refusing to
generate COPY relocations on arm64. Unfortunately it generates an
error instead of finding another way. The gold linker works, so
switch to it.

Fixes linux/arm64 build.

Change-Id: I1f7119d999c8f9f1f2d0c1e06b6462cea9c02a71
Reviewed-on: https://go-review.googlesource.com/22185
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 0db2bf23
......@@ -329,21 +329,21 @@ func readNotes(f *elf.File) ([]*note, error) {
return notes, nil
}
func dynStrings(path string, flag elf.DynTag) []string {
func dynStrings(t *testing.T, path string, flag elf.DynTag) []string {
f, err := elf.Open(path)
defer f.Close()
if err != nil {
log.Fatal("elf.Open failed: ", err)
t.Fatalf("elf.Open(%q) failed: %v", path, err)
}
dynstrings, err := f.DynString(flag)
if err != nil {
log.Fatal("dynstring failed: ", err)
t.Fatalf("DynString(%s) failed on %s: %v", flag, path, err)
}
return dynstrings
}
func AssertIsLinkedToRegexp(t *testing.T, path string, re *regexp.Regexp) {
for _, dynstring := range dynStrings(path, elf.DT_NEEDED) {
for _, dynstring := range dynStrings(t, path, elf.DT_NEEDED) {
if re.MatchString(dynstring) {
return
}
......@@ -357,7 +357,7 @@ func AssertIsLinkedTo(t *testing.T, path, lib string) {
func AssertHasRPath(t *testing.T, path, dir string) {
for _, tag := range []elf.DynTag{elf.DT_RPATH, elf.DT_RUNPATH} {
for _, dynstring := range dynStrings(path, tag) {
for _, dynstring := range dynStrings(t, path, tag) {
for _, rpath := range strings.Split(dynstring, ":") {
if filepath.Clean(rpath) == filepath.Clean(dir) {
return
......
......@@ -1123,10 +1123,15 @@ func hostlink() {
// from the beginning of the section (like STYPE).
argv = append(argv, "-Wl,-znocopyreloc")
if SysArch.Family == sys.ARM {
// The GNU linker will generate COPY relocations on ARM
// even with -znocopyreloc set. Switch to gold.
if SysArch.InFamily(sys.ARM, sys.ARM64) {
// On ARM, 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.
//
// In both cases, switch to gold.
argv = append(argv, "-fuse-ld=gold")
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment