mirror of
https://github.com/golang/go
synced 2024-11-05 14:46:11 -07:00
[dev.link] cmd/link: use new-style Reloc accessors in loadmacho
Change-Id: I890bd8b297fc5612000131fac7c45f5c623ab908 Reviewed-on: https://go-review.googlesource.com/c/go/+/227764 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
9669c3f361
commit
37cc5cd769
@ -14,7 +14,6 @@ import (
|
|||||||
"cmd/link/internal/sym"
|
"cmd/link/internal/sym"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -700,10 +699,16 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
|||||||
if sect.rel == nil {
|
if sect.rel == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
r := make([]loader.Reloc, sect.nreloc)
|
|
||||||
rpi := 0
|
sb := l.MakeSymbolUpdater(sect.sym)
|
||||||
for j := uint32(0); j < sect.nreloc; j++ {
|
for j := uint32(0); j < sect.nreloc; j++ {
|
||||||
rp := &r[rpi]
|
var (
|
||||||
|
rOff int32
|
||||||
|
rSize uint8
|
||||||
|
rAdd int64
|
||||||
|
rType objabi.RelocType
|
||||||
|
rSym loader.Sym
|
||||||
|
)
|
||||||
rel := §.rel[j]
|
rel := §.rel[j]
|
||||||
if rel.scattered != 0 {
|
if rel.scattered != 0 {
|
||||||
// mach-o only uses scattered relocation on 32-bit platforms,
|
// mach-o only uses scattered relocation on 32-bit platforms,
|
||||||
@ -711,11 +716,11 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
|||||||
return errorf("%v: unexpected scattered relocation", s)
|
return errorf("%v: unexpected scattered relocation", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
rp.Size = rel.length
|
rSize = rel.length
|
||||||
rp.Type = objabi.MachoRelocOffset + (objabi.RelocType(rel.type_) << 1) + objabi.RelocType(rel.pcrel)
|
rType = objabi.MachoRelocOffset + (objabi.RelocType(rel.type_) << 1) + objabi.RelocType(rel.pcrel)
|
||||||
rp.Off = int32(rel.addr)
|
rOff = int32(rel.addr)
|
||||||
|
|
||||||
// Handle X86_64_RELOC_SIGNED referencing a section (rel->extrn == 0).
|
// Handle X86_64_RELOC_SIGNED referencing a section (rel.extrn == 0).
|
||||||
p := l.Data(s)
|
p := l.Data(s)
|
||||||
if arch.Family == sys.AMD64 && rel.extrn == 0 && rel.type_ == MACHO_X86_64_RELOC_SIGNED {
|
if arch.Family == sys.AMD64 && rel.extrn == 0 && rel.type_ == MACHO_X86_64_RELOC_SIGNED {
|
||||||
// Calculate the addend as the offset into the section.
|
// Calculate the addend as the offset into the section.
|
||||||
@ -735,16 +740,16 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
|||||||
// [For future reference, see Darwin's /usr/include/mach-o/x86_64/reloc.h]
|
// [For future reference, see Darwin's /usr/include/mach-o/x86_64/reloc.h]
|
||||||
secaddr := c.seg.sect[rel.symnum-1].addr
|
secaddr := c.seg.sect[rel.symnum-1].addr
|
||||||
|
|
||||||
rp.Add = int64(uint64(int64(int32(e.Uint32(p[rp.Off:])))+int64(rp.Off)+4) - secaddr)
|
rAdd = int64(uint64(int64(int32(e.Uint32(p[rOff:])))+int64(rOff)+4) - secaddr)
|
||||||
} else {
|
} else {
|
||||||
rp.Add = int64(int32(e.Uint32(p[rp.Off:])))
|
rAdd = int64(int32(e.Uint32(p[rOff:])))
|
||||||
}
|
}
|
||||||
|
|
||||||
// An unsigned internal relocation has a value offset
|
// An unsigned internal relocation has a value offset
|
||||||
// by the section address.
|
// by the section address.
|
||||||
if arch.Family == sys.AMD64 && rel.extrn == 0 && rel.type_ == MACHO_X86_64_RELOC_UNSIGNED {
|
if arch.Family == sys.AMD64 && rel.extrn == 0 && rel.type_ == MACHO_X86_64_RELOC_UNSIGNED {
|
||||||
secaddr := c.seg.sect[rel.symnum-1].addr
|
secaddr := c.seg.sect[rel.symnum-1].addr
|
||||||
rp.Add -= int64(secaddr)
|
rAdd -= int64(secaddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rel.extrn == 0 {
|
if rel.extrn == 0 {
|
||||||
@ -752,8 +757,8 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
|||||||
return errorf("invalid relocation: section reference out of range %d vs %d", rel.symnum, c.seg.nsect)
|
return errorf("invalid relocation: section reference out of range %d vs %d", rel.symnum, c.seg.nsect)
|
||||||
}
|
}
|
||||||
|
|
||||||
rp.Sym = c.seg.sect[rel.symnum-1].sym
|
rSym = c.seg.sect[rel.symnum-1].sym
|
||||||
if rp.Sym == 0 {
|
if rSym == 0 {
|
||||||
return errorf("invalid relocation: %s", c.seg.sect[rel.symnum-1].name)
|
return errorf("invalid relocation: %s", c.seg.sect[rel.symnum-1].name)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -761,15 +766,17 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
|||||||
return errorf("invalid relocation: symbol reference out of range")
|
return errorf("invalid relocation: symbol reference out of range")
|
||||||
}
|
}
|
||||||
|
|
||||||
rp.Sym = symtab.sym[rel.symnum].sym
|
rSym = symtab.sym[rel.symnum].sym
|
||||||
}
|
}
|
||||||
|
|
||||||
rpi++
|
r, _ := sb.AddRel(rType)
|
||||||
|
r.SetOff(rOff)
|
||||||
|
r.SetSiz(rSize)
|
||||||
|
r.SetSym(rSym)
|
||||||
|
r.SetAdd(rAdd)
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(loader.RelocByOff(r[:rpi]))
|
sb.SortRelocs()
|
||||||
sb := l.MakeSymbolUpdater(sect.sym)
|
|
||||||
sb.SetRelocs(r[:rpi])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return textp, nil
|
return textp, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user