From abac923832997eaf3668e364d36a1d7732ee3c5b Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Wed, 22 Apr 2020 00:00:03 -0400 Subject: [PATCH] [dev.link] cmd/link, cmd/oldlink: remove more darwin/386 and darwin/arm code Updates #37610, #37611. Change-Id: I0a497af03e24ddea40ed3e342f3a9362bf21ac0c Reviewed-on: https://go-review.googlesource.com/c/go/+/229323 Run-TryBot: Cherry Zhang Reviewed-by: Austin Clements --- src/cmd/link/internal/arm/asm.go | 82 +---------------------------- src/cmd/link/internal/ld/data.go | 10 +--- src/cmd/link/internal/x86/asm.go | 48 +---------------- src/cmd/oldlink/internal/arm/asm.go | 82 +---------------------------- src/cmd/oldlink/internal/ld/data.go | 10 +--- src/cmd/oldlink/internal/x86/asm.go | 48 +---------------- 6 files changed, 6 insertions(+), 274 deletions(-) diff --git a/src/cmd/link/internal/arm/asm.go b/src/cmd/link/internal/arm/asm.go index e9eea5ce2c9ec1..446691f31856ea 100644 --- a/src/cmd/link/internal/arm/asm.go +++ b/src/cmd/link/internal/arm/asm.go @@ -314,87 +314,7 @@ func elfsetupplt(ctxt *ld.Link, plt, got *loader.SymbolBuilder, dynamic loader.S } func machoreloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool { - var v uint32 - - rs := r.Xsym - - if r.Type == objabi.R_PCREL { - if rs.Type == sym.SHOSTOBJ { - ld.Errorf(s, "pc-relative relocation of external symbol is not supported") - return false - } - if r.Siz != 4 { - return false - } - - // emit a pair of "scattered" relocations that - // resolve to the difference of section addresses of - // the symbol and the instruction - // this value is added to the field being relocated - o1 := uint32(sectoff) - o1 |= 1 << 31 // scattered bit - o1 |= ld.MACHO_ARM_RELOC_SECTDIFF << 24 - o1 |= 2 << 28 // size = 4 - - o2 := uint32(0) - o2 |= 1 << 31 // scattered bit - o2 |= ld.MACHO_ARM_RELOC_PAIR << 24 - o2 |= 2 << 28 // size = 4 - - out.Write32(o1) - out.Write32(uint32(ld.Symaddr(rs))) - out.Write32(o2) - out.Write32(uint32(s.Value + int64(r.Off))) - return true - } - - if rs.Type == sym.SHOSTOBJ || r.Type == objabi.R_CALLARM { - if rs.Dynid < 0 { - ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Type, rs.Type) - return false - } - - v = uint32(rs.Dynid) - v |= 1 << 27 // external relocation - } else { - v = uint32(rs.Sect.Extnum) - if v == 0 { - ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type) - return false - } - } - - switch r.Type { - default: - return false - - case objabi.R_ADDR: - v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28 - - case objabi.R_CALLARM: - v |= 1 << 24 // pc-relative bit - v |= ld.MACHO_ARM_RELOC_BR24 << 28 - } - - switch r.Siz { - default: - return false - case 1: - v |= 0 << 25 - - case 2: - v |= 1 << 25 - - case 4: - v |= 2 << 25 - - case 8: - v |= 3 << 25 - } - - out.Write32(uint32(sectoff)) - out.Write32(v) - return true + return false } func pereloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool { diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 6569c155c6c9fb..46fc6ec304c7ac 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -465,14 +465,9 @@ func relocsym(target *Target, ldr *loader.Loader, err *ErrorReporter, syms *Arch } else if target.IsDarwin() { if r.Type == objabi.R_CALL { if target.IsExternal() && rs.Type == sym.SDYNIMPORT { - switch target.Arch.Family { - case sys.AMD64: + if target.IsAMD64() { // AMD64 dynamic relocations are relative to the end of the relocation. o += int64(r.Siz) - case sys.I386: - // I386 dynamic relocations are relative to the start of the section. - o -= int64(r.Off) // offset in symbol - o -= int64(s.Value - int64(s.Sect.Vaddr)) // offset of symbol in section } } else { if rs.Type != sym.SHOSTOBJ { @@ -480,9 +475,6 @@ func relocsym(target *Target, ldr *loader.Loader, err *ErrorReporter, syms *Arch } o -= int64(r.Off) // relative to section offset, not symbol } - } else if target.IsARM() { - // see ../arm/asm.go:/machoreloc1 - o += Symaddr(rs) - s.Value - int64(r.Off) } else { o += int64(r.Siz) } diff --git a/src/cmd/link/internal/x86/asm.go b/src/cmd/link/internal/x86/asm.go index 7dcdda0fa80d45..650fe12f94a91b 100644 --- a/src/cmd/link/internal/x86/asm.go +++ b/src/cmd/link/internal/x86/asm.go @@ -372,53 +372,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool { } func machoreloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool { - var v uint32 - - rs := r.Xsym - - if rs.Type == sym.SHOSTOBJ || r.Type == objabi.R_CALL { - if rs.Dynid < 0 { - ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Type, rs.Type) - return false - } - - v = uint32(rs.Dynid) - v |= 1 << 27 // external relocation - } else { - v = uint32(rs.Sect.Extnum) - if v == 0 { - ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type) - return false - } - } - - switch r.Type { - default: - return false - case objabi.R_ADDR: - v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28 - case objabi.R_CALL, - objabi.R_PCREL: - v |= 1 << 24 // pc-relative bit - v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28 - } - - switch r.Siz { - default: - return false - case 1: - v |= 0 << 25 - case 2: - v |= 1 << 25 - case 4: - v |= 2 << 25 - case 8: - v |= 3 << 25 - } - - out.Write32(uint32(sectoff)) - out.Write32(v) - return true + return false } func pereloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool { diff --git a/src/cmd/oldlink/internal/arm/asm.go b/src/cmd/oldlink/internal/arm/asm.go index a2a0879c5b0331..de6173569ae851 100644 --- a/src/cmd/oldlink/internal/arm/asm.go +++ b/src/cmd/oldlink/internal/arm/asm.go @@ -328,87 +328,7 @@ func elfsetupplt(ctxt *ld.Link) { } func machoreloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool { - var v uint32 - - rs := r.Xsym - - if r.Type == objabi.R_PCREL { - if rs.Type == sym.SHOSTOBJ { - ld.Errorf(s, "pc-relative relocation of external symbol is not supported") - return false - } - if r.Siz != 4 { - return false - } - - // emit a pair of "scattered" relocations that - // resolve to the difference of section addresses of - // the symbol and the instruction - // this value is added to the field being relocated - o1 := uint32(sectoff) - o1 |= 1 << 31 // scattered bit - o1 |= ld.MACHO_ARM_RELOC_SECTDIFF << 24 - o1 |= 2 << 28 // size = 4 - - o2 := uint32(0) - o2 |= 1 << 31 // scattered bit - o2 |= ld.MACHO_ARM_RELOC_PAIR << 24 - o2 |= 2 << 28 // size = 4 - - out.Write32(o1) - out.Write32(uint32(ld.Symaddr(rs))) - out.Write32(o2) - out.Write32(uint32(s.Value + int64(r.Off))) - return true - } - - if rs.Type == sym.SHOSTOBJ || r.Type == objabi.R_CALLARM { - if rs.Dynid < 0 { - ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Type, rs.Type) - return false - } - - v = uint32(rs.Dynid) - v |= 1 << 27 // external relocation - } else { - v = uint32(rs.Sect.Extnum) - if v == 0 { - ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type) - return false - } - } - - switch r.Type { - default: - return false - - case objabi.R_ADDR: - v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28 - - case objabi.R_CALLARM: - v |= 1 << 24 // pc-relative bit - v |= ld.MACHO_ARM_RELOC_BR24 << 28 - } - - switch r.Siz { - default: - return false - case 1: - v |= 0 << 25 - - case 2: - v |= 1 << 25 - - case 4: - v |= 2 << 25 - - case 8: - v |= 3 << 25 - } - - out.Write32(uint32(sectoff)) - out.Write32(v) - return true + return false } func pereloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool { diff --git a/src/cmd/oldlink/internal/ld/data.go b/src/cmd/oldlink/internal/ld/data.go index 13f412ccd85baf..ba4a74156be458 100644 --- a/src/cmd/oldlink/internal/ld/data.go +++ b/src/cmd/oldlink/internal/ld/data.go @@ -455,14 +455,9 @@ func relocsym(ctxt *Link, s *sym.Symbol) { } else if ctxt.HeadType == objabi.Hdarwin { if r.Type == objabi.R_CALL { if ctxt.LinkMode == LinkExternal && rs.Type == sym.SDYNIMPORT { - switch ctxt.Arch.Family { - case sys.AMD64: + if ctxt.Arch.Family == sys.AMD64 { // AMD64 dynamic relocations are relative to the end of the relocation. o += int64(r.Siz) - case sys.I386: - // I386 dynamic relocations are relative to the start of the section. - o -= int64(r.Off) // offset in symbol - o -= int64(s.Value - int64(s.Sect.Vaddr)) // offset of symbol in section } } else { if rs.Type != sym.SHOSTOBJ { @@ -470,9 +465,6 @@ func relocsym(ctxt *Link, s *sym.Symbol) { } o -= int64(r.Off) // relative to section offset, not symbol } - } else if ctxt.Arch.Family == sys.ARM { - // see ../arm/asm.go:/machoreloc1 - o += Symaddr(rs) - s.Value - int64(r.Off) } else { o += int64(r.Siz) } diff --git a/src/cmd/oldlink/internal/x86/asm.go b/src/cmd/oldlink/internal/x86/asm.go index 34668063dae5ff..e8e52f671fbd41 100644 --- a/src/cmd/oldlink/internal/x86/asm.go +++ b/src/cmd/oldlink/internal/x86/asm.go @@ -410,53 +410,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool { } func machoreloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool { - var v uint32 - - rs := r.Xsym - - if rs.Type == sym.SHOSTOBJ || r.Type == objabi.R_CALL { - if rs.Dynid < 0 { - ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Type, rs.Type) - return false - } - - v = uint32(rs.Dynid) - v |= 1 << 27 // external relocation - } else { - v = uint32(rs.Sect.Extnum) - if v == 0 { - ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type) - return false - } - } - - switch r.Type { - default: - return false - case objabi.R_ADDR: - v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28 - case objabi.R_CALL, - objabi.R_PCREL: - v |= 1 << 24 // pc-relative bit - v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28 - } - - switch r.Siz { - default: - return false - case 1: - v |= 0 << 25 - case 2: - v |= 1 << 25 - case 4: - v |= 2 << 25 - case 8: - v |= 3 << 25 - } - - out.Write32(uint32(sectoff)) - out.Write32(v) - return true + return false } func pereloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool {