1
0
mirror of https://github.com/golang/go synced 2024-11-17 15:44:40 -07:00

[dev.link] cmd/link: pass loader to relocation functions

It is needed in Xcoffadddynrel. And it will be needed once we
move more things to new style (the sym.Symbol parameters will
also need to change).

Change-Id: Ie12683f9b44e21f1e6ea711bf2f4c5c32282e5b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/225203
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2020-03-24 12:55:14 -04:00
parent b1a19f3cc7
commit 4ba39d6a58
12 changed files with 24 additions and 25 deletions

View File

@ -107,7 +107,7 @@ func makeWritable(s *sym.Symbol) {
}
}
func adddynrel(target *ld.Target, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
targ := r.Sym
switch r.Type {

View File

@ -116,7 +116,7 @@ func braddoff(a int32, b int32) int32 {
return int32((uint32(a))&0xff000000 | 0x00ffffff&uint32(a+b))
}
func adddynrel(target *ld.Target, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
targ := r.Sym
switch r.Type {

View File

@ -92,7 +92,7 @@ func gentext(ctxt *ld.Link) {
initarray_entry.AddAddr(ctxt.Arch, initfunc)
}
func adddynrel(target *ld.Target, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
targ := r.Sym
switch r.Type {

View File

@ -129,7 +129,7 @@ func trampoline(ctxt *Link, s *sym.Symbol) {
// to avoid introducing unnecessary allocations in the main loop.
// TODO: This function is called in parallel. When the Loader wavefront
// reaches here, calls into the loader need to be parallel as well.
func relocsym(target *Target, err *ErrorReporter, lookup LookupFn, syms *ArchSyms, s *sym.Symbol) {
func relocsym(target *Target, ldr *loader.Loader, err *ErrorReporter, lookup LookupFn, syms *ArchSyms, s *sym.Symbol) {
if len(s.R) == 0 {
return
}
@ -337,7 +337,7 @@ func relocsym(target *Target, err *ErrorReporter, lookup LookupFn, syms *ArchSym
// symbol which isn't in .data. However, as .text has the
// same address once loaded, this is possible.
if s.Sect.Seg == &Segdata {
Xcoffadddynrel(target, s, r)
Xcoffadddynrel(target, ldr, s, r)
}
}
@ -575,25 +575,26 @@ func relocsym(target *Target, err *ErrorReporter, lookup LookupFn, syms *ArchSym
func (ctxt *Link) reloc() {
var wg sync.WaitGroup
target := &ctxt.Target
ldr := ctxt.loader
reporter := &ctxt.ErrorReporter
lookup := ctxt.Syms.ROLookup
syms := &ctxt.ArchSyms
wg.Add(3)
go func() {
for _, s := range ctxt.Textp {
relocsym(target, reporter, lookup, syms, s)
relocsym(target, ldr, reporter, lookup, syms, s)
}
wg.Done()
}()
go func() {
for _, s := range ctxt.datap {
relocsym(target, reporter, lookup, syms, s)
relocsym(target, ldr, reporter, lookup, syms, s)
}
wg.Done()
}()
go func() {
for _, s := range dwarfp {
relocsym(target, reporter, lookup, syms, s)
relocsym(target, ldr, reporter, lookup, syms, s)
}
wg.Done()
}()
@ -666,6 +667,7 @@ func (ctxt *Link) windynrelocsyms() {
func dynrelocsym(ctxt *Link, s *sym.Symbol) {
target := &ctxt.Target
ldr := ctxt.loader
syms := &ctxt.ArchSyms
for ri := range s.R {
r := &s.R[ri]
@ -673,7 +675,7 @@ func dynrelocsym(ctxt *Link, s *sym.Symbol) {
// It's expected that some relocations will be done
// later by relocsym (R_TLS_LE, R_ADDROFF), so
// don't worry if Adddynrel returns false.
thearch.Adddynrel(target, syms, s, r)
thearch.Adddynrel(target, ldr, syms, s, r)
continue
}
@ -681,7 +683,7 @@ func dynrelocsym(ctxt *Link, s *sym.Symbol) {
if r.Sym != nil && !r.Sym.Attr.Reachable() {
Errorf(s, "dynamic relocation to unreachable symbol %s", r.Sym.Name)
}
if !thearch.Adddynrel(target, syms, s, r) {
if !thearch.Adddynrel(target, ldr, syms, s, r) {
Errorf(s, "unsupported dynamic relocation for symbol %s (type=%d (%s) stype=%d (%s))", r.Sym.Name, r.Type, sym.RelocName(ctxt.Arch, r.Type), r.Sym.Type, r.Sym.Type)
}
}
@ -2488,6 +2490,7 @@ func compressSyms(ctxt *Link, syms []*sym.Symbol) []byte {
log.Fatalf("NewWriterLevel failed: %s", err)
}
target := &ctxt.Target
ldr := ctxt.loader
reporter := &ctxt.ErrorReporter
lookup := ctxt.Syms.ROLookup
archSyms := &ctxt.ArchSyms
@ -2502,7 +2505,7 @@ func compressSyms(ctxt *Link, syms []*sym.Symbol) []byte {
// TODO: This function call needs to be parallelized when the loader wavefront gets here.
s.Attr.Set(sym.AttrReadOnly, false)
}
relocsym(target, reporter, lookup, archSyms, s)
relocsym(target, ldr, reporter, lookup, archSyms, s)
if _, err := z.Write(s.P); err != nil {
log.Fatalf("compression failed: %s", err)
}

View File

@ -195,7 +195,7 @@ type Arch struct {
Openbsddynld string
Dragonflydynld string
Solarisdynld string
Adddynrel func(*Target, *ArchSyms, *sym.Symbol, *sym.Reloc) bool
Adddynrel func(*Target, *loader.Loader, *ArchSyms, *sym.Symbol, *sym.Reloc) bool
Archinit func(*Link)
// Archreloc is an arch-specific hook that assists in
// relocation processing (invoked by 'relocsym'); it handles

View File

@ -416,8 +416,6 @@ type xcoffFile struct {
dynLibraries map[string]int // Dynamic libraries in .loader section. The integer represents its import file number (- 1)
loaderSymbols []*xcoffLoaderSymbol // symbols inside .loader symbol table
loaderReloc []*xcoffLoaderReloc // Reloc that must be made inside loader
ldr *loader.Loader // XXX keep a reference here for now, as it is needed in Xcoffadddynrel. will clean up in the next CL.
}
// Var used by XCOFF Generation algorithms
@ -1108,7 +1106,7 @@ func (f *xcoffFile) adddynimpsym(ctxt *Link, s loader.Sym) {
// Xcoffadddynrel adds a dynamic relocation in a XCOFF file.
// This relocation will be made by the loader.
func Xcoffadddynrel(target *Target, s *sym.Symbol, r *sym.Reloc) bool {
func Xcoffadddynrel(target *Target, ldr *loader.Loader, s *sym.Symbol, r *sym.Reloc) bool {
if target.IsExternal() {
return true
}
@ -1130,7 +1128,7 @@ func Xcoffadddynrel(target *Target, s *sym.Symbol, r *sym.Reloc) bool {
if s.Type == sym.SXCOFFTOC && r.Sym.Type == sym.SDYNIMPORT {
// Imported symbol relocation
for i, dynsym := range xfile.loaderSymbols {
if xfile.ldr.Syms[dynsym.sym].Name == r.Sym.Name {
if ldr.Syms[dynsym.sym].Name == r.Sym.Name {
xldr.symndx = int32(i + 3) // +3 because of 3 section symbols
break
}
@ -1190,8 +1188,6 @@ func (ctxt *Link) doxcoff() {
xfile.genDynSym(ctxt)
xfile.ldr = ldr // XXX
for s := loader.Sym(1); s < loader.Sym(ldr.NSym()); s++ {
if strings.HasPrefix(ldr.SymName(s), "TOC.") {
sb := ldr.MakeSymbolUpdater(s)

View File

@ -45,7 +45,7 @@ func gentext(ctxt *ld.Link) {
return
}
func adddynrel(target *ld.Target, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
log.Fatalf("adddynrel not implemented")
return false
}

View File

@ -43,7 +43,7 @@ import (
func gentext(ctxt *ld.Link) {}
func adddynrel(target *ld.Target, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
log.Fatalf("adddynrel not implemented")
return false
}

View File

@ -263,11 +263,11 @@ func gencallstub(ctxt *ld.Link, abicase int, stub *sym.Symbol, targ *sym.Symbol)
stub.AddUint32(ctxt.Arch, 0x4e800420) // bctr
}
func adddynrel(target *ld.Target, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
if target.IsElf() {
return addelfdynrel(target, syms, s, r)
} else if target.IsAIX() {
return ld.Xcoffadddynrel(target, s, r)
return ld.Xcoffadddynrel(target, ldr, s, r)
}
return false
}

View File

@ -22,7 +22,7 @@ func adddynrela(target *ld.Target, syms *ld.ArchSyms, rel *sym.Symbol, s *sym.Sy
log.Fatalf("adddynrela not implemented")
}
func adddynrel(target *ld.Target, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
log.Fatalf("adddynrel not implemented")
return false
}

View File

@ -105,7 +105,7 @@ func gentext(ctxt *ld.Link) {
initarray_entry.AddAddr(ctxt.Arch, initfunc)
}
func adddynrel(target *ld.Target, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
targ := r.Sym
r.InitExt()

View File

@ -168,7 +168,7 @@ func gentext(ctxt *ld.Link) {
initarray_entry.AddAddr(ctxt.Arch, initfunc)
}
func adddynrel(target *ld.Target, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s *sym.Symbol, r *sym.Reloc) bool {
targ := r.Sym
switch r.Type {