1
0
mirror of https://github.com/golang/go synced 2024-11-17 23:14:49 -07:00

[dev.link] cmd/link: stream external relocations on MIPS (32/64)

Change-Id: I47fbeb3a49754395dceff51af371638fd43350ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/244097
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
Cherry Zhang 2020-07-21 19:14:18 -04:00
parent ea708dc94c
commit ed6b8af509
5 changed files with 61 additions and 28 deletions

View File

@ -184,5 +184,6 @@ func (t *Target) IsBigEndian() bool {
// Temporary helper.
func (t *Target) StreamExtRelocs() bool {
return (t.IsELF || t.IsDarwin()) && (t.IsAMD64() || t.Is386() || t.IsARM64())
return (t.IsELF || t.IsDarwin()) &&
(t.IsAMD64() || t.Is386() || t.IsARM64() || t.IsMIPS() || t.IsMIPS64())
}

View File

@ -100,19 +100,12 @@ func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loade
case objabi.R_ADDRMIPS, objabi.R_ADDRMIPSU:
// set up addend for eventual relocation via outer symbol.
rs, off := ld.FoldSubSymbolOffset(ldr, rs)
rr.Xadd = r.Add() + off
rst := ldr.SymType(rs)
if rst != sym.SHOSTOBJ && rst != sym.SDYNIMPORT && ldr.SymSect(rs) == nil {
ldr.Errorf(s, "missing section for %s", ldr.SymName(rs))
}
rr.Xsym = rs
return applyrel(target.Arch, ldr, r.Type(), r.Off(), s, val, rr.Xadd), 1, true
_, off := ld.FoldSubSymbolOffset(ldr, rs)
xadd := r.Add() + off
return applyrel(target.Arch, ldr, r.Type(), r.Off(), s, val, xadd), 1, true
case objabi.R_ADDRMIPSTLS, objabi.R_CALLMIPS, objabi.R_JMPMIPS:
rr.Xsym = rs
rr.Xadd = r.Add()
return applyrel(target.Arch, ldr, r.Type(), r.Off(), s, val, rr.Xadd), 1, true
return applyrel(target.Arch, ldr, r.Type(), r.Off(), s, val, r.Add()), 1, true
}
}
@ -150,3 +143,26 @@ func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loade
func archrelocvariant(*ld.Target, *loader.Loader, loader.Reloc2, sym.RelocVariant, loader.Sym, int64) int64 {
return -1
}
func extreloc(target *ld.Target, ldr *loader.Loader, r loader.Reloc2, s loader.Sym) (loader.ExtReloc, bool) {
rs := ldr.ResolveABIAlias(r.Sym())
var rr loader.ExtReloc
switch r.Type() {
case objabi.R_ADDRMIPS, objabi.R_ADDRMIPSU:
// set up addend for eventual relocation via outer symbol.
rs, off := ld.FoldSubSymbolOffset(ldr, rs)
rr.Xadd = r.Add() + off
rst := ldr.SymType(rs)
if rst != sym.SHOSTOBJ && rst != sym.SDYNIMPORT && ldr.SymSect(rs) == nil {
ldr.Errorf(s, "missing section for %s", ldr.SymName(rs))
}
rr.Xsym = rs
return rr, true
case objabi.R_ADDRMIPSTLS, objabi.R_CALLMIPS, objabi.R_JMPMIPS:
rr.Xsym = rs
rr.Xadd = r.Add()
return rr, true
}
return rr, false
}

View File

@ -52,6 +52,7 @@ func Init() (*sys.Arch, ld.Arch) {
Archinit: archinit,
Archreloc: archreloc,
Archrelocvariant: archrelocvariant,
Extreloc: extreloc,
Elfreloc1: elfreloc1,
ElfrelocSize: 8,
Elfsetupplt: elfsetupplt,

View File

@ -95,36 +95,24 @@ func machoreloc1(*sys.Arch, *ld.OutBuf, *loader.Loader, loader.Sym, loader.ExtRe
}
func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loader.Reloc2, rr *loader.ExtReloc, s loader.Sym, val int64) (o int64, nExtReloc int, ok bool) {
rs := r.Sym()
rs = ldr.ResolveABIAlias(rs)
if target.IsExternal() {
switch r.Type() {
default:
return val, 0, false
case objabi.R_ADDRMIPS,
objabi.R_ADDRMIPSU:
// set up addend for eventual relocation via outer symbol.
rs, off := ld.FoldSubSymbolOffset(ldr, rs)
rr.Xadd = r.Add() + off
rst := ldr.SymType(rs)
if rst != sym.SHOSTOBJ && rst != sym.SDYNIMPORT && ldr.SymSect(rs) == nil {
ldr.Errorf(s, "missing section for %s", ldr.SymName(rs))
}
rr.Xsym = rs
return val, 1, true
case objabi.R_ADDRMIPSTLS,
objabi.R_ADDRMIPSU,
objabi.R_ADDRMIPSTLS,
objabi.R_CALLMIPS,
objabi.R_JMPMIPS:
rr.Xsym = rs
rr.Xadd = r.Add()
return val, 1, true
}
}
const isOk = true
const noExtReloc = 0
rs := r.Sym()
rs = ldr.ResolveABIAlias(rs)
switch r.Type() {
case objabi.R_ADDRMIPS,
objabi.R_ADDRMIPSU:
@ -153,3 +141,29 @@ func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loade
func archrelocvariant(*ld.Target, *loader.Loader, loader.Reloc2, sym.RelocVariant, loader.Sym, int64) int64 {
return -1
}
func extreloc(target *ld.Target, ldr *loader.Loader, r loader.Reloc2, s loader.Sym) (loader.ExtReloc, bool) {
rs := ldr.ResolveABIAlias(r.Sym())
var rr loader.ExtReloc
switch r.Type() {
case objabi.R_ADDRMIPS,
objabi.R_ADDRMIPSU:
// set up addend for eventual relocation via outer symbol.
rs, off := ld.FoldSubSymbolOffset(ldr, rs)
rr.Xadd = r.Add() + off
rst := ldr.SymType(rs)
if rst != sym.SHOSTOBJ && rst != sym.SDYNIMPORT && ldr.SymSect(rs) == nil {
ldr.Errorf(s, "missing section for %s", ldr.SymName(rs))
}
rr.Xsym = rs
return rr, true
case objabi.R_ADDRMIPSTLS,
objabi.R_CALLMIPS,
objabi.R_JMPMIPS:
rr.Xsym = rs
rr.Xadd = r.Add()
return rr, true
}
return rr, false
}

View File

@ -51,6 +51,7 @@ func Init() (*sys.Arch, ld.Arch) {
Archinit: archinit,
Archreloc: archreloc,
Archrelocvariant: archrelocvariant,
Extreloc: extreloc,
Elfreloc1: elfreloc1,
ElfrelocSize: 24,
Elfsetupplt: elfsetupplt,