From dd66786029f9d53554dd78ab02a75ff448c051b4 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Wed, 18 Mar 2020 13:26:38 -0400 Subject: [PATCH] [dev.link] cmd/link: add loader.Sym equivalents to ArchSyms Populate ArchSyms with loader.Sym versions of important symbols, so as to be able to convert the code that uses ArchSyms to the new loader interfaces. Change-Id: If6766f7164642a9dc2e31fcf7f9280a6e95e5d23 Reviewed-on: https://go-review.googlesource.com/c/go/+/224383 Reviewed-by: Cherry Zhang Reviewed-by: Jeremy Faller Run-TryBot: Than McIntosh TryBot-Result: Gobot Gobot --- src/cmd/link/internal/ld/lib.go | 40 ++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 49af1c3b74..cc7b00fbfc 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -123,27 +123,51 @@ type ArchSyms struct { // Darwin symbols LinkEditGOT *sym.Symbol LinkEditPLT *sym.Symbol + + // ----- loader.Sym equivalents ----- + + TOC2 loader.Sym + DotTOC2 []loader.Sym // for each version + + GOT2 loader.Sym + PLT2 loader.Sym + GOTPLT2 loader.Sym + + Tlsg2 loader.Sym + + Dynamic2 loader.Sym + DynSym2 loader.Sym + DynStr2 loader.Sym } // setArchSyms sets up the ArchSyms structure, and must be called before // relocations are applied. func (ctxt *Link) setArchSyms() { - ctxt.GOT = ctxt.Syms.Lookup(".got", 0) - ctxt.PLT = ctxt.Syms.Lookup(".plt", 0) - ctxt.GOTPLT = ctxt.Syms.Lookup(".got.plt", 0) + ctxt.GOT2 = ctxt.loader.LookupOrCreateSym(".got", 0) + ctxt.GOT = ctxt.loader.Syms[ctxt.GOT2] + ctxt.PLT2 = ctxt.loader.LookupOrCreateSym(".plt", 0) + ctxt.PLT = ctxt.loader.Syms[ctxt.PLT2] + ctxt.GOTPLT2 = ctxt.loader.LookupOrCreateSym(".got.plt", 0) + ctxt.GOTPLT = ctxt.loader.Syms[ctxt.GOTPLT2] - ctxt.Dynamic = ctxt.Syms.Lookup(".dynamic", 0) - ctxt.DynSym = ctxt.Syms.Lookup(".dynsym", 0) - ctxt.DynStr = ctxt.Syms.Lookup(".dynstr", 0) + ctxt.Dynamic2 = ctxt.loader.LookupOrCreateSym(".dynamic", 0) + ctxt.Dynamic = ctxt.loader.Syms[ctxt.Dynamic2] + ctxt.DynSym2 = ctxt.loader.LookupOrCreateSym(".dynsym", 0) + ctxt.DynSym = ctxt.loader.Syms[ctxt.DynSym2] + ctxt.DynStr2 = ctxt.loader.LookupOrCreateSym(".dynstr", 0) + ctxt.DynStr = ctxt.loader.Syms[ctxt.DynStr2] if ctxt.IsAIX() { - ctxt.TOC = ctxt.Syms.Lookup("TOC", 0) + ctxt.TOC2 = ctxt.loader.LookupOrCreateSym("TOC", 0) + ctxt.TOC = ctxt.loader.Syms[ctxt.TOC2] ctxt.DotTOC = make([]*sym.Symbol, ctxt.Syms.MaxVersion()+1) + ctxt.DotTOC2 = make([]loader.Sym, ctxt.Syms.MaxVersion()+1) for i := 0; i <= ctxt.Syms.MaxVersion(); i++ { if i >= 2 && i < sym.SymVerStatic { // these versions are not used currently continue } - ctxt.DotTOC[i] = ctxt.Syms.Lookup(".TOC.", i) + ctxt.DotTOC2[i] = ctxt.loader.LookupOrCreateSym(".TOC.", i) + ctxt.DotTOC[i] = ctxt.loader.Syms[ctxt.DotTOC2[i]] } } if ctxt.IsElf() {