1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:04:45 -07:00

[dev.link] cmd/link: add archrelocsym x86 support for loader

Change-Id: I34822e5610caf537d62203fb6e0023c382a1e60a
Reviewed-on: https://go-review.googlesource.com/c/go/+/230678
Run-TryBot: Jeremy Faller <jeremy@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Jeremy Faller 2020-04-28 17:28:52 -04:00
parent 76c6cce116
commit 09cd065875
5 changed files with 33 additions and 19 deletions

View File

@ -221,24 +221,23 @@ func relocsym(target *Target, ldr *loader.Loader, err *ErrorReporter, syms *Arch
var o int64 var o int64
switch rt { switch rt {
default: default:
panic("not implemented") switch siz {
//switch siz { default:
//default: err.Errorf(s, "bad reloc size %#x for %s", uint32(siz), ldr.SymName(rs))
// err.Errorf(s, "bad reloc size %#x for %s", uint32(siz), ldr.SymName(rs)) case 1:
//case 1: o = int64(P[off])
// o = int64(P[off]) case 2:
//case 2: o = int64(target.Arch.ByteOrder.Uint16(P[off:]))
// o = int64(target.Arch.ByteOrder.Uint16(P[off:])) case 4:
//case 4: o = int64(target.Arch.ByteOrder.Uint32(P[off:]))
// o = int64(target.Arch.ByteOrder.Uint32(P[off:])) case 8:
//case 8: o = int64(target.Arch.ByteOrder.Uint64(P[off:]))
// o = int64(target.Arch.ByteOrder.Uint64(P[off:])) }
//} if out, ok := thearch.Archreloc2(target, ldr, syms, &r, s, o); ok {
//if out, ok := thearch.Archreloc(ldr, target, syms, &r, s, o); ok { o = out
// o = out } else {
//} else { err.Errorf(s, "unknown reloc to %v: %d (%s)", ldr.SymName(rs), rt, sym.RelocName(target.Arch, rt))
// err.Errorf(s, "unknown reloc to %v: %d (%s)", ldr.SymName(rs), rt, sym.RelocName(target.Arch, rt)) }
//}
case objabi.R_TLS_LE: case objabi.R_TLS_LE:
//if target.IsExternal() && target.IsElf() { //if target.IsExternal() && target.IsElf() {
// r.Done = false // r.Done = false

View File

@ -246,6 +246,7 @@ type Arch struct {
// success/failure (a failing value indicates a fatal error). // success/failure (a failing value indicates a fatal error).
Archreloc func(target *Target, syms *ArchSyms, rel *sym.Reloc, sym *sym.Symbol, Archreloc func(target *Target, syms *ArchSyms, rel *sym.Reloc, sym *sym.Symbol,
offset int64) (relocatedOffset int64, success bool) offset int64) (relocatedOffset int64, success bool)
Archreloc2 func(*Target, *loader.Loader, *ArchSyms, *loader.Reloc2, loader.Sym, int64) (int64, bool)
// Archrelocvariant is a second arch-specific hook used for // Archrelocvariant is a second arch-specific hook used for
// relocation processing; it handles relocations where r.Type is // relocation processing; it handles relocations where r.Type is
// insufficient to describe the relocation (r.Variant != // insufficient to describe the relocation (r.Variant !=

View File

@ -326,7 +326,7 @@ func Main(arch *sys.Arch, theArch Arch) {
ctxt.loader.InitOutData() ctxt.loader.InitOutData()
thearch.Asmb(ctxt, ctxt.loader) thearch.Asmb(ctxt, ctxt.loader)
newreloc := ctxt.IsInternal() && ctxt.IsAMD64() newreloc := ctxt.IsInternal() && (ctxt.IsAMD64() || ctxt.Is386())
if newreloc { if newreloc {
bench.Start("reloc") bench.Start("reloc")
ctxt.reloc() ctxt.reloc()

View File

@ -435,6 +435,19 @@ func pereloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, secto
return true return true
} }
func archreloc2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r *loader.Reloc2, sym loader.Sym, val int64) (int64, bool) {
if target.IsExternal() {
return val, false
}
switch r.Type() {
case objabi.R_CONST:
return r.Add(), true
case objabi.R_GOTOFF:
return ldr.SymValue(r.Sym()) + r.Add() - ldr.SymValue(syms.GOT2), true
}
return val, false
}
func archreloc(target *ld.Target, syms *ld.ArchSyms, r *sym.Reloc, s *sym.Symbol, val int64) (int64, bool) { func archreloc(target *ld.Target, syms *ld.ArchSyms, r *sym.Reloc, s *sym.Symbol, val int64) (int64, bool) {
if target.IsExternal() { if target.IsExternal() {
return val, false return val, false

View File

@ -49,6 +49,7 @@ func Init() (*sys.Arch, ld.Arch) {
Adddynrel2: adddynrel2, Adddynrel2: adddynrel2,
Archinit: archinit, Archinit: archinit,
Archreloc: archreloc, Archreloc: archreloc,
Archreloc2: archreloc2,
Archrelocvariant: archrelocvariant, Archrelocvariant: archrelocvariant,
Asmb: asmb, Asmb: asmb,
Asmb2: asmb2, Asmb2: asmb2,