[dev.link] cmd/link: convert Asmb2 path to loader APIs for Elf/AMD64

This patch converts the linker's Asmb2 phase to use loader APIs
for AMD64 (other architectures to be converted in a subsequent
patch).

Change-Id: I5a9aa9b03769cabc1a22b982f48fd113213d7bcf
Reviewed-on: https://go-review.googlesource.com/c/go/+/233338
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Than McIntosh 2020-05-07 10:06:28 -04:00
parent 88a12a99b4
commit 25e9417b98
11 changed files with 1004 additions and 160 deletions

View file

@ -2662,46 +2662,32 @@ func (ctxt *Link) xdefine2(p string, t sym.SymKind, v int64) {
s.SetLocal(true)
}
func datoff(s *sym.Symbol, addr int64) int64 {
func datoff(ldr *loader.Loader, s loader.Sym, addr int64) int64 {
if uint64(addr) >= Segdata.Vaddr {
return int64(uint64(addr) - Segdata.Vaddr + Segdata.Fileoff)
}
if uint64(addr) >= Segtext.Vaddr {
return int64(uint64(addr) - Segtext.Vaddr + Segtext.Fileoff)
}
Errorf(s, "invalid datoff %#x", addr)
ldr.Errorf(s, "invalid datoff %#x", addr)
return 0
}
func Entryvalue(ctxt *Link) int64 {
a := *flagEntrySymbol
if a[0] >= '0' && a[0] <= '9' {
return atolwhex(a)
}
s := ctxt.Syms.Lookup(a, 0)
if s.Type == 0 {
return *FlagTextAddr
}
if ctxt.HeadType != objabi.Haix && s.Type != sym.STEXT {
Errorf(s, "entry not text")
}
return s.Value
}
func Entryvalue2(ctxt *Link) int64 {
a := *flagEntrySymbol
if a[0] >= '0' && a[0] <= '9' {
return atolwhex(a)
}
s := ctxt.loader.Lookup(a, 0)
typ := ctxt.loader.SymType(s)
if typ == 0 {
ldr := ctxt.loader
s := ldr.Lookup(a, 0)
st := ldr.SymType(s)
if st == 0 {
return *FlagTextAddr
}
if ctxt.HeadType != objabi.Haix && typ != sym.STEXT {
ctxt.Errorf(s, "entry not text")
if !ctxt.IsAIX() && st != sym.STEXT {
ldr.Errorf(s, "entry not text")
}
return ctxt.loader.SymValue(s)
return ldr.SymValue(s)
}
func (ctxt *Link) callgraph() {
@ -2799,6 +2785,7 @@ func addToTextp(ctxt *Link) {
}
func (ctxt *Link) loadlibfull(symGroupType []sym.SymKind, needReloc, needExtReloc bool) {
// Load full symbol contents, resolve indexed references.
ctxt.loader.LoadFull(ctxt.Arch, ctxt.Syms, needReloc, needExtReloc)
@ -2891,14 +2878,14 @@ func symPkg(ctxt *Link, s *sym.Symbol) string {
return ctxt.loader.SymPkg(loader.Sym(s.SymIdx))
}
func ElfSymForReloc(ctxt *Link, s *sym.Symbol) int32 {
func ElfSymForReloc2(ctxt *Link, s loader.Sym) int32 {
// If putelfsym created a local version of this symbol, use that in all
// relocations.
les := ctxt.loader.SymLocalElfSym(loader.Sym(s.SymIdx))
les := ctxt.loader.SymLocalElfSym(s)
if les != 0 {
return les
} else {
return ctxt.loader.SymElfSym(loader.Sym(s.SymIdx))
return ctxt.loader.SymElfSym(s)
}
}