From 286d744246a84b3a19093db6e7f24a823aac50bb Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Thu, 17 Oct 2019 01:11:23 -0400 Subject: [PATCH] [dev.link] cmd/compile: pass index through when re-exporting When we re-export an imported symbol that has an index, we should pass the index through. Currently, if the symbol is not referenced in the generated machine code, it does not get assigned a package index, and the exporter will not export its symbol index. Let the exporter handle this case -- if the symbol has a symbol index but not a package index, still export its symbol index. This is safe as referenced-by-name symbols always have their package indices set to a special value. This should reduce the number of referenced-by-name symbols, and also make the export data more stable, less dependent on codegen details. Change-Id: Ic515a002ae84226e7fdbe68a53496c051b7badcc Reviewed-on: https://go-review.googlesource.com/c/go/+/201719 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Than McIntosh --- src/cmd/compile/internal/gc/iexport.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/gc/iexport.go b/src/cmd/compile/internal/gc/iexport.go index 9125f67586..259b70a69f 100644 --- a/src/cmd/compile/internal/gc/iexport.go +++ b/src/cmd/compile/internal/gc/iexport.go @@ -993,9 +993,14 @@ func (w *exportWriter) linkname(s *types.Sym) { func (w *exportWriter) symIdx(s *types.Sym) { if Ctxt.Flag_newobj { lsym := s.Linksym() - if lsym.PkgIdx > goobj2.PkgIdxSelf || lsym.PkgIdx == goobj2.PkgIdxInvalid || s.Linkname != "" { + if lsym.PkgIdx > goobj2.PkgIdxSelf || (lsym.PkgIdx == goobj2.PkgIdxInvalid && !lsym.Indexed()) || s.Linkname != "" { + // Don't export index for non-package symbols, linkname'd symbols, + // and symbols without an index. They can only be referenced by + // name. w.int64(-1) } else { + // For a defined symbol, export its index. + // For re-exporting an imported symbol, pass its index through. w.int64(int64(lsym.SymIdx)) } } -- 2.48.1