From 4ba39d6a58c910456337245663ac71a044d5d436 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Tue, 24 Mar 2020 12:55:14 -0400 Subject: [PATCH] [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 Reviewed-by: Than McIntosh --- src/cmd/link/internal/amd64/asm.go | 2 +- src/cmd/link/internal/arm/asm.go | 2 +- src/cmd/link/internal/arm64/asm.go | 2 +- src/cmd/link/internal/ld/data.go | 19 +++++++++++-------- src/cmd/link/internal/ld/lib.go | 2 +- src/cmd/link/internal/ld/xcoff.go | 8 ++------ src/cmd/link/internal/mips/asm.go | 2 +- src/cmd/link/internal/mips64/asm.go | 2 +- src/cmd/link/internal/ppc64/asm.go | 4 ++-- src/cmd/link/internal/riscv64/asm.go | 2 +- src/cmd/link/internal/s390x/asm.go | 2 +- src/cmd/link/internal/x86/asm.go | 2 +- 12 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/cmd/link/internal/amd64/asm.go b/src/cmd/link/internal/amd64/asm.go index 8065aa549d..7b925856cc 100644 --- a/src/cmd/link/internal/amd64/asm.go +++ b/src/cmd/link/internal/amd64/asm.go @@ -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 { diff --git a/src/cmd/link/internal/arm/asm.go b/src/cmd/link/internal/arm/asm.go index c7ec1e5678..a76f0db1de 100644 --- a/src/cmd/link/internal/arm/asm.go +++ b/src/cmd/link/internal/arm/asm.go @@ -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 { diff --git a/src/cmd/link/internal/arm64/asm.go b/src/cmd/link/internal/arm64/asm.go index 684326fc64..ddf5da8e8b 100644 --- a/src/cmd/link/internal/arm64/asm.go +++ b/src/cmd/link/internal/arm64/asm.go @@ -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 { diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 5682997b79..730aba2397 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -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) } diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index cc7b00fbfc..01dc31b4d8 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -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 diff --git a/src/cmd/link/internal/ld/xcoff.go b/src/cmd/link/internal/ld/xcoff.go index fc5d2358b8..5bdf863f14 100644 --- a/src/cmd/link/internal/ld/xcoff.go +++ b/src/cmd/link/internal/ld/xcoff.go @@ -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) diff --git a/src/cmd/link/internal/mips/asm.go b/src/cmd/link/internal/mips/asm.go index de2979eff7..44503a1348 100644 --- a/src/cmd/link/internal/mips/asm.go +++ b/src/cmd/link/internal/mips/asm.go @@ -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 } diff --git a/src/cmd/link/internal/mips64/asm.go b/src/cmd/link/internal/mips64/asm.go index b465d8a45f..2024c082e9 100644 --- a/src/cmd/link/internal/mips64/asm.go +++ b/src/cmd/link/internal/mips64/asm.go @@ -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 } diff --git a/src/cmd/link/internal/ppc64/asm.go b/src/cmd/link/internal/ppc64/asm.go index bc9c8d65a8..f12522a5dd 100644 --- a/src/cmd/link/internal/ppc64/asm.go +++ b/src/cmd/link/internal/ppc64/asm.go @@ -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 } diff --git a/src/cmd/link/internal/riscv64/asm.go b/src/cmd/link/internal/riscv64/asm.go index 585548d26a..6148f6c035 100644 --- a/src/cmd/link/internal/riscv64/asm.go +++ b/src/cmd/link/internal/riscv64/asm.go @@ -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 } diff --git a/src/cmd/link/internal/s390x/asm.go b/src/cmd/link/internal/s390x/asm.go index 35e248522a..b118a4db63 100644 --- a/src/cmd/link/internal/s390x/asm.go +++ b/src/cmd/link/internal/s390x/asm.go @@ -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() diff --git a/src/cmd/link/internal/x86/asm.go b/src/cmd/link/internal/x86/asm.go index c6570ea1a3..30ad08688c 100644 --- a/src/cmd/link/internal/x86/asm.go +++ b/src/cmd/link/internal/x86/asm.go @@ -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 {