return target
}
-// PropagateSymbolChangesBackToLoader is a temporary shim function
-// that copies over a given sym.Symbol into the equivalent representation
-// in the loader world. The intent is to enable converting a given
-// linker phase/pass from dealing with sym.Symbol's to a modernized
-// pass that works with loader.Sym, in cases where the "loader.Sym
-// wavefront" has not yet reached the pass in question. For such work
-// the recipe is to first call PropagateSymbolChangesBackToLoader(),
-// then exexute the pass working with the loader, then call
-// PropagateLoaderChangesToSymbols to copy the changes made by the
-// pass back to the sym.Symbol world.
-func (l *Loader) PropagateSymbolChangesBackToLoader() {
-
- // For the moment we only copy symbol values, and we don't touch
- // any new sym.Symbols created since loadlibfull() was run. This
- // seems to be what's needed for DWARF gen.
- for i := Sym(1); i < Sym(len(l.objSyms)); i++ {
- s := l.Syms[i]
- if s != nil {
- if s.Value != l.SymValue(i) {
- l.SetSymValue(i, s.Value)
- }
- }
- }
-}
-
-// PropagateLoaderChangesToSymbols is a temporary shim function that
-// takes a list of loader.Sym symbols and works to copy their contents
-// and attributes over to a corresponding sym.Symbol. The parameter
-// anonVerReplacement specifies a version number for any new anonymous
-// symbols encountered on the list, when creating sym.Symbols for them
-// (or zero if we don't expect to encounter any new anon symbols). See
-// the PropagateSymbolChangesBackToLoader header comment for more
-// info.
-//
-// WARNING: this function is brittle and depends heavily on loader
-// implementation. A key problem with doing this is that as things
-// stand at the moment, some sym.Symbol contents/attributes are
-// populated only when converting from loader.Sym to sym.Symbol in
-// loadlibfull, meaning we may wipe out some information when copying
-// back.
-
-func (l *Loader) PropagateLoaderChangesToSymbols(toconvert []Sym, anonVerReplacement int) []*sym.Symbol {
-
- result := []*sym.Symbol{}
- relocfixup := []Sym{}
-
- // Note: this loop needs to allow for the possibility that we may
- // see "new" symbols on the 'toconvert' list that come from object
- // files (for example, DWARF location lists), as opposed to just
- // newly manufactured symbols (ex: DWARF section symbols such as
- // ".debug_info"). This means that we have to be careful not to
- // stomp on sym.Symbol attributes/content that was set up in
- // in loadlibfull().
-
- // Also note that in order for the relocation fixup to work, we
- // have to do this in two passes -- one pass to create the symbols,
- // and then a second fix up the relocations once all necessary
- // sym.Symbols are created.
-
- // First pass, symbol creation and symbol data fixup.
- for _, cand := range toconvert {
-
- sn := l.SymName(cand)
- sv := l.SymVersion(cand)
- st := l.SymType(cand)
- if sv < 0 {
- if anonVerReplacement == 0 {
- panic("expected valid anon version replacement")
- }
- sv = anonVerReplacement
- }
-
- s := l.Syms[cand]
-
- isnew := false
- if sn == "" {
- // Don't install anonymous symbols in the lookup tab.
- if s == nil {
- s = l.allocSym(sn, sv)
- l.installSym(cand, s)
- }
- isnew = true
- } else {
- if s != nil {
- // Already have a symbol for this -- it must be
- // something that was previously processed by
- // loadObjFull. Note that the symbol in question may
- // or may not be in the name lookup map.
- } else {
- isnew = true
- s = l.SymLookup(sn, sv)
- }
- }
- result = append(result, s)
-
- // Always copy these from new to old.
- s.Value = l.SymValue(cand)
- s.Type = st
-
- // If the data for a symbol has increased in size, make sure
- // we bring the new content across.
- relfix := isnew
- if isnew || len(l.Data(cand)) > len(s.P) {
- s.P = l.Data(cand)
- s.Size = int64(len(s.P))
- relfix = true
- }
-
- // For 'new' symbols, copy other content.
- if relfix {
- relocfixup = append(relocfixup, cand)
- }
-
- // If new symbol, call a helper to migrate attributes.
- // Otherwise touch only not-in-symbol-table, since there are
- // some attrs that are only set up at the point where we
- // convert loader.Sym to sym.Symbol.
- if isnew {
- l.migrateAttributes(cand, s)
- } else {
- if l.AttrNotInSymbolTable(cand) {
- s.Attr.Set(sym.AttrNotInSymbolTable, true)
- }
- }
- }
-
- // Second pass to fix up relocations.
- for _, cand := range relocfixup {
- s := l.Syms[cand]
- relocs := l.Relocs(cand)
- if len(s.R) != relocs.Count() {
- s.R = make([]sym.Reloc, relocs.Count())
- }
- l.convertRelocations(cand, &relocs, s, true)
- }
-
- return result
-}
-
// ExtractSymbols grabs the symbols out of the loader for work that hasn't been
// ported to the new symbol type.
func (l *Loader) ExtractSymbols(syms *sym.Symbols) {