Skip to content

Commit

Permalink
[dev.link] cmd/link, cmd/oldlink: remove more darwin/386 and darwin/a…
Browse files Browse the repository at this point in the history
…rm code

Updates golang#37610, golang#37611.

Change-Id: I0a497af03e24ddea40ed3e342f3a9362bf21ac0c
Reviewed-on: https://go-review.googlesource.com/c/go/+/229323
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Austin Clements <austin@google.com>
  • Loading branch information
cherrymui authored and xujianhai666 committed May 21, 2020
1 parent bdb3189 commit abac923
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 274 deletions.
82 changes: 1 addition & 81 deletions src/cmd/link/internal/arm/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 1 addition & 9 deletions src/cmd/link/internal/ld/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,24 +465,16 @@ 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 {
o += int64(uint64(Symaddr(rs)) - rs.Sect.Vaddr)
}
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)
}
Expand Down
48 changes: 1 addition & 47 deletions src/cmd/link/internal/x86/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
82 changes: 1 addition & 81 deletions src/cmd/oldlink/internal/arm/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 1 addition & 9 deletions src/cmd/oldlink/internal/ld/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,24 +455,16 @@ 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 {
o += int64(uint64(Symaddr(rs)) - rs.Sect.Vaddr)
}
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)
}
Expand Down
48 changes: 1 addition & 47 deletions src/cmd/oldlink/internal/x86/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit abac923

Please sign in to comment.