From 49e94f19f0e0575fc14f6f83e5586762b263b864 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Mon, 6 Jan 2020 20:37:50 -0500 Subject: [PATCH] [dev.link] cmd/link: propagate gotype symbol info in cloneToExternal This patch fixes a problem with the loader's cloneToExternal method, specifically that the new external clone created did not get the proper Gotype value from its orginal symbol. Change-Id: I9978140d285104d407bf55649fb6ed94959933f2 Reviewed-on: https://go-review.googlesource.com/c/go/+/213639 Run-TryBot: Than McIntosh TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/link/internal/loader/loader.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index 7899a23caf..2cf4dd02ce 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -225,6 +225,7 @@ type extSymPayload struct { size int64 ver int kind sym.SymKind + gotype Sym // Gotype (0 if not present) relocs []Reloc data []byte } @@ -1524,6 +1525,9 @@ func (l *Loader) LoadFull(arch *sys.Arch, syms *sym.Symbols) { s.Type = pp.kind s.Size = pp.size s.Value = l.SymValue(i) + if pp.gotype != 0 { + s.Gotype = l.Syms[pp.gotype] + } // Copy relocations batch := l.relocBatch @@ -1823,6 +1827,20 @@ func (l *Loader) cloneToExternal(symIdx Sym) Sym { } } + // If we're overriding a data symbol, collect the associated + // Gotype, so as to propagate it to the new symbol. + naux := r.NAux(li) + for j := 0; j < naux; j++ { + a := goobj2.Aux{} + a.Read(r.Reader, r.AuxOff(li, j)) + switch a.Type { + case goobj2.AuxGotype: + pp.gotype = l.resolve(r, a.Sym) + default: + log.Fatalf("internal error: cloneToExternal applied to %s symbol %s with non-gotype aux data %d", skind.String(), sname, a.Type) + } + } + // Fix up the lookup tables if the symbol in question was // present in the lookup tables. At the moment it only makes // sense to do this sort of clone/update for symbols that are -- 2.48.1