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: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 0db2bf23
...@@ -329,21 +329,21 @@ func readNotes(f *elf.File) ([]*note, error) { ...@@ -329,21 +329,21 @@ func readNotes(f *elf.File) ([]*note, error) {
return notes, nil 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) f, err := elf.Open(path)
defer f.Close() defer f.Close()
if err != nil { if err != nil {
log.Fatal("elf.Open failed: ", err) t.Fatalf("elf.Open(%q) failed: %v", path, err)
} }
dynstrings, err := f.DynString(flag) dynstrings, err := f.DynString(flag)
if err != nil { if err != nil {
log.Fatal("dynstring failed: ", err) t.Fatalf("DynString(%s) failed on %s: %v", flag, path, err)
} }
return dynstrings return dynstrings
} }
func AssertIsLinkedToRegexp(t *testing.T, path string, re *regexp.Regexp) { 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) { if re.MatchString(dynstring) {
return return
} }
...@@ -357,7 +357,7 @@ func AssertIsLinkedTo(t *testing.T, path, lib string) { ...@@ -357,7 +357,7 @@ func AssertIsLinkedTo(t *testing.T, path, lib string) {
func AssertHasRPath(t *testing.T, path, dir string) { func AssertHasRPath(t *testing.T, path, dir string) {
for _, tag := range []elf.DynTag{elf.DT_RPATH, elf.DT_RUNPATH} { 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, ":") { for _, rpath := range strings.Split(dynstring, ":") {
if filepath.Clean(rpath) == filepath.Clean(dir) { if filepath.Clean(rpath) == filepath.Clean(dir) {
return return
......
...@@ -1123,10 +1123,15 @@ func hostlink() { ...@@ -1123,10 +1123,15 @@ func hostlink() {
// from the beginning of the section (like STYPE). // from the beginning of the section (like STYPE).
argv = append(argv, "-Wl,-znocopyreloc") argv = append(argv, "-Wl,-znocopyreloc")
if SysArch.Family == sys.ARM { if SysArch.InFamily(sys.ARM, sys.ARM64) {
// The GNU linker will generate COPY relocations on ARM // On ARM, the GNU linker will generate COPY relocations
// even with -znocopyreloc set. Switch to gold. // even with -znocopyreloc set.
// https://sourceware.org/bugzilla/show_bug.cgi?id=19962 // 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") 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