@@ -254,6 +254,8 @@ type Loader struct {
254254 strictDupMsgs int // number of strict-dup warning/errors, when FlagStrictDups is enabled
255255
256256 elfsetstring elfsetstringFunc
257+
258+ SymLookup func (name string , ver int ) * sym.Symbol
257259}
258260
259261const (
@@ -1893,17 +1895,21 @@ func (l *Loader) PropagateSymbolChangesBackToLoader() {
18931895
18941896// PropagateLoaderChangesToSymbols is a temporary shim function that
18951897// takes a list of loader.Sym symbols and works to copy their contents
1896- // and attributes over to a corresponding sym.Symbol. See the
1897- // PropagateSymbolChangesBackToLoader header comment for more info.
1898+ // and attributes over to a corresponding sym.Symbol. The parameter
1899+ // anonVerReplacement specifies a version number for any new anonymous
1900+ // symbols encountered on the list, when creating sym.Symbols for them
1901+ // (or zero if we don't expect to encounter any new anon symbols). See
1902+ // the PropagateSymbolChangesBackToLoader header comment for more
1903+ // info.
18981904//
18991905// WARNING: this function is brittle and depends heavily on loader
19001906// implementation. A key problem with doing this is that as things
19011907// stand at the moment, some sym.Symbol contents/attributes are
1902- // populated only when converting from loader.Sym to sym.Symbol
1903- // in loadlibfull, meaning if we may wipe out some information
1904- // when copying back.
1908+ // populated only when converting from loader.Sym to sym.Symbol in
1909+ // loadlibfull, meaning we may wipe out some information when copying
1910+ // back.
19051911
1906- func (l * Loader ) PropagateLoaderChangesToSymbols (toconvert []Sym , syms * sym. Symbols ) []* sym.Symbol {
1912+ func (l * Loader ) PropagateLoaderChangesToSymbols (toconvert []Sym , anonVerReplacement int ) []* sym.Symbol {
19071913
19081914 result := []* sym.Symbol {}
19091915 relocfixup := []Sym {}
@@ -1922,14 +1928,16 @@ func (l *Loader) PropagateLoaderChangesToSymbols(toconvert []Sym, syms *sym.Symb
19221928 // sym.Symbols are created.
19231929
19241930 // First pass, symbol creation and symbol data fixup.
1925- anonVerReplacement := syms .IncVersion ()
19261931 rslice := []Reloc {}
19271932 for _ , cand := range toconvert {
19281933
19291934 sn := l .SymName (cand )
19301935 sv := l .SymVersion (cand )
19311936 st := l .SymType (cand )
19321937 if sv < 0 {
1938+ if anonVerReplacement == 0 {
1939+ panic ("expected valid anon version replacement" )
1940+ }
19331941 sv = anonVerReplacement
19341942 }
19351943
@@ -1951,7 +1959,7 @@ func (l *Loader) PropagateLoaderChangesToSymbols(toconvert []Sym, syms *sym.Symb
19511959 // or may not be in the name lookup map.
19521960 } else {
19531961 isnew = true
1954- s = syms . Lookup (sn , sv )
1962+ s = l . SymLookup (sn , sv )
19551963 }
19561964 }
19571965 result = append (result , s )
@@ -2046,7 +2054,7 @@ func (l *Loader) ExtractSymbols(syms *sym.Symbols, rp map[*sym.Symbol]*sym.Symbo
20462054 }
20472055
20482056 // Provide lookup functions for sym.Symbols.
2049- syms . Lookup = func (name string , ver int ) * sym.Symbol {
2057+ l . SymLookup = func (name string , ver int ) * sym.Symbol {
20502058 i := l .LookupOrCreateSym (name , ver )
20512059 if s := l .Syms [i ]; s != nil {
20522060 return s
@@ -2056,6 +2064,7 @@ func (l *Loader) ExtractSymbols(syms *sym.Symbols, rp map[*sym.Symbol]*sym.Symbo
20562064 syms .Allsym = append (syms .Allsym , s ) // XXX see above
20572065 return s
20582066 }
2067+ syms .Lookup = l .SymLookup
20592068 syms .ROLookup = func (name string , ver int ) * sym.Symbol {
20602069 i := l .Lookup (name , ver )
20612070 return l .Syms [i ]
0 commit comments