github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/link/internal/loader/loader.go (about)

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package loader
     6  
     7  import (
     8  	"github.com/shogo82148/std/cmd/internal/bio"
     9  	"github.com/shogo82148/std/cmd/internal/goobj"
    10  	"github.com/shogo82148/std/cmd/internal/objabi"
    11  	"github.com/shogo82148/std/cmd/internal/sys"
    12  	"github.com/shogo82148/std/cmd/link/internal/sym"
    13  	"github.com/shogo82148/std/debug/elf"
    14  	"github.com/shogo82148/std/fmt"
    15  	"github.com/shogo82148/std/internal/abi"
    16  )
    17  
    18  var _ = fmt.Print
    19  
    20  // Sym encapsulates a global symbol index, used to identify a specific
    21  // Go symbol. The 0-valued Sym is corresponds to an invalid symbol.
    22  type Sym = sym.LoaderSym
    23  
    24  // Relocs encapsulates the set of relocations on a given symbol; an
    25  // instance of this type is returned by the Loader Relocs() method.
    26  type Relocs struct {
    27  	rs []goobj.Reloc
    28  
    29  	li uint32
    30  	r  *oReader
    31  	l  *Loader
    32  }
    33  
    34  // ExtReloc contains the payload for an external relocation.
    35  type ExtReloc struct {
    36  	Xsym Sym
    37  	Xadd int64
    38  	Type objabi.RelocType
    39  	Size uint8
    40  }
    41  
    42  // Reloc holds a "handle" to access a relocation record from an
    43  // object file.
    44  type Reloc struct {
    45  	*goobj.Reloc
    46  	r *oReader
    47  	l *Loader
    48  }
    49  
    50  func (rel Reloc) Type() objabi.RelocType
    51  func (rel Reloc) Weak() bool
    52  func (rel Reloc) SetType(t objabi.RelocType)
    53  func (rel Reloc) Sym() Sym
    54  func (rel Reloc) SetSym(s Sym)
    55  func (rel Reloc) IsMarker() bool
    56  
    57  // Aux holds a "handle" to access an aux symbol record from an
    58  // object file.
    59  type Aux struct {
    60  	*goobj.Aux
    61  	r *oReader
    62  	l *Loader
    63  }
    64  
    65  func (a Aux) Sym() Sym
    66  
    67  type Bitmap []uint32
    68  
    69  // set the i-th bit.
    70  func (bm Bitmap) Set(i Sym)
    71  
    72  // unset the i-th bit.
    73  func (bm Bitmap) Unset(i Sym)
    74  
    75  // whether the i-th bit is set.
    76  func (bm Bitmap) Has(i Sym) bool
    77  
    78  // return current length of bitmap in bits.
    79  func (bm Bitmap) Len() int
    80  
    81  // return the number of bits set.
    82  func (bm Bitmap) Count() int
    83  
    84  func MakeBitmap(n int) Bitmap
    85  
    86  // A Loader loads new object files and resolves indexed symbol references.
    87  //
    88  // Notes on the layout of global symbol index space:
    89  //
    90  //   - Go object files are read before host object files; each Go object
    91  //     read adds its defined package symbols to the global index space.
    92  //     Nonpackage symbols are not yet added.
    93  //
    94  //   - In loader.LoadNonpkgSyms, add non-package defined symbols and
    95  //     references in all object files to the global index space.
    96  //
    97  //   - Host object file loading happens; the host object loader does a
    98  //     name/version lookup for each symbol it finds; this can wind up
    99  //     extending the external symbol index space range. The host object
   100  //     loader stores symbol payloads in loader.payloads using SymbolBuilder.
   101  //
   102  //   - Each symbol gets a unique global index. For duplicated and
   103  //     overwriting/overwritten symbols, the second (or later) appearance
   104  //     of the symbol gets the same global index as the first appearance.
   105  type Loader struct {
   106  	objs        []*oReader
   107  	extStart    Sym
   108  	builtinSyms []Sym
   109  
   110  	objSyms []objSym
   111  
   112  	symsByName    [2]map[string]Sym
   113  	extStaticSyms map[nameVer]Sym
   114  
   115  	extReader    *oReader
   116  	payloadBatch []extSymPayload
   117  	payloads     []*extSymPayload
   118  	values       []int64
   119  
   120  	sects    []*sym.Section
   121  	symSects []uint16
   122  
   123  	align []uint8
   124  
   125  	deferReturnTramp map[Sym]bool
   126  
   127  	objByPkg map[string]uint32
   128  
   129  	anonVersion int
   130  
   131  	// Bitmaps and other side structures used to store data used to store
   132  	// symbol flags/attributes; these are to be accessed via the
   133  	// corresponding loader "AttrXXX" and "SetAttrXXX" methods. Please
   134  	// visit the comments on these methods for more details on the
   135  	// semantics / interpretation of the specific flags or attribute.
   136  	attrReachable        Bitmap
   137  	attrOnList           Bitmap
   138  	attrLocal            Bitmap
   139  	attrNotInSymbolTable Bitmap
   140  	attrUsedInIface      Bitmap
   141  	attrSpecial          Bitmap
   142  	attrVisibilityHidden Bitmap
   143  	attrDuplicateOK      Bitmap
   144  	attrShared           Bitmap
   145  	attrExternal         Bitmap
   146  	generatedSyms        Bitmap
   147  
   148  	attrReadOnly         map[Sym]bool
   149  	attrCgoExportDynamic map[Sym]struct{}
   150  	attrCgoExportStatic  map[Sym]struct{}
   151  
   152  	// Outer and Sub relations for symbols.
   153  	outer []Sym
   154  	sub   map[Sym]Sym
   155  
   156  	dynimplib   map[Sym]string
   157  	dynimpvers  map[Sym]string
   158  	localentry  map[Sym]uint8
   159  	extname     map[Sym]string
   160  	elfType     map[Sym]elf.SymType
   161  	elfSym      map[Sym]int32
   162  	localElfSym map[Sym]int32
   163  	symPkg      map[Sym]string
   164  	plt         map[Sym]int32
   165  	got         map[Sym]int32
   166  	dynid       map[Sym]int32
   167  
   168  	relocVariant map[relocId]sym.RelocVariant
   169  
   170  	// Used to implement field tracking; created during deadcode if
   171  	// field tracking is enabled. Reachparent[K] contains the index of
   172  	// the symbol that triggered the marking of symbol K as live.
   173  	Reachparent []Sym
   174  
   175  	// CgoExports records cgo-exported symbols by SymName.
   176  	CgoExports map[string]Sym
   177  
   178  	flags uint32
   179  
   180  	strictDupMsgs int
   181  
   182  	errorReporter *ErrorReporter
   183  
   184  	npkgsyms    int
   185  	nhashedsyms int
   186  }
   187  
   188  const (
   189  	// Loader.flags
   190  	FlagStrictDups = 1 << iota
   191  )
   192  
   193  func NewLoader(flags uint32, reporter *ErrorReporter) *Loader
   194  
   195  // LookupOrCreateSym looks up the symbol with the specified name/version,
   196  // returning its Sym index if found. If the lookup fails, a new external
   197  // Sym will be created, entered into the lookup tables, and returned.
   198  func (l *Loader) LookupOrCreateSym(name string, ver int) Sym
   199  
   200  // AddCgoExport records a cgo-exported symbol in l.CgoExports.
   201  // This table is used to identify the correct Go symbol ABI to use
   202  // to resolve references from host objects (which don't have ABIs).
   203  func (l *Loader) AddCgoExport(s Sym)
   204  
   205  // LookupOrCreateCgoExport is like LookupOrCreateSym, but if ver
   206  // indicates a global symbol, it uses the CgoExport table to determine
   207  // the appropriate symbol version (ABI) to use. ver must be either 0
   208  // or a static symbol version.
   209  func (l *Loader) LookupOrCreateCgoExport(name string, ver int) Sym
   210  
   211  func (l *Loader) IsExternal(i Sym) bool
   212  
   213  // Look up a symbol by name, return global index, or 0 if not found.
   214  // This is more like Syms.ROLookup than Lookup -- it doesn't create
   215  // new symbol.
   216  func (l *Loader) Lookup(name string, ver int) Sym
   217  
   218  func (l *Loader) NStrictDupMsgs() int
   219  
   220  // Number of total symbols.
   221  func (l *Loader) NSym() int
   222  
   223  // Number of defined Go symbols.
   224  func (l *Loader) NDef() int
   225  
   226  // Number of reachable symbols.
   227  func (l *Loader) NReachableSym() int
   228  
   229  // Returns the name of the i-th symbol.
   230  func (l *Loader) SymName(i Sym) string
   231  
   232  // Returns the version of the i-th symbol.
   233  func (l *Loader) SymVersion(i Sym) int
   234  
   235  func (l *Loader) IsFileLocal(i Sym) bool
   236  
   237  // IsFromAssembly returns true if this symbol is derived from an
   238  // object file generated by the Go assembler.
   239  func (l *Loader) IsFromAssembly(i Sym) bool
   240  
   241  // Returns the type of the i-th symbol.
   242  func (l *Loader) SymType(i Sym) sym.SymKind
   243  
   244  // Returns the attributes of the i-th symbol.
   245  func (l *Loader) SymAttr(i Sym) uint8
   246  
   247  // Returns the size of the i-th symbol.
   248  func (l *Loader) SymSize(i Sym) int64
   249  
   250  // AttrReachable returns true for symbols that are transitively
   251  // referenced from the entry points. Unreachable symbols are not
   252  // written to the output.
   253  func (l *Loader) AttrReachable(i Sym) bool
   254  
   255  // SetAttrReachable sets the reachability property for a symbol (see
   256  // AttrReachable).
   257  func (l *Loader) SetAttrReachable(i Sym, v bool)
   258  
   259  // AttrOnList returns true for symbols that are on some list (such as
   260  // the list of all text symbols, or one of the lists of data symbols)
   261  // and is consulted to avoid bugs where a symbol is put on a list
   262  // twice.
   263  func (l *Loader) AttrOnList(i Sym) bool
   264  
   265  // SetAttrOnList sets the "on list" property for a symbol (see
   266  // AttrOnList).
   267  func (l *Loader) SetAttrOnList(i Sym, v bool)
   268  
   269  // AttrLocal returns true for symbols that are only visible within the
   270  // module (executable or shared library) being linked. This attribute
   271  // is applied to thunks and certain other linker-generated symbols.
   272  func (l *Loader) AttrLocal(i Sym) bool
   273  
   274  // SetAttrLocal the "local" property for a symbol (see AttrLocal above).
   275  func (l *Loader) SetAttrLocal(i Sym, v bool)
   276  
   277  // AttrUsedInIface returns true for a type symbol that is used in
   278  // an interface.
   279  func (l *Loader) AttrUsedInIface(i Sym) bool
   280  
   281  func (l *Loader) SetAttrUsedInIface(i Sym, v bool)
   282  
   283  // SymAddr checks that a symbol is reachable, and returns its value.
   284  func (l *Loader) SymAddr(i Sym) int64
   285  
   286  // AttrNotInSymbolTable returns true for symbols that should not be
   287  // added to the symbol table of the final generated load module.
   288  func (l *Loader) AttrNotInSymbolTable(i Sym) bool
   289  
   290  // SetAttrNotInSymbolTable the "not in symtab" property for a symbol
   291  // (see AttrNotInSymbolTable above).
   292  func (l *Loader) SetAttrNotInSymbolTable(i Sym, v bool)
   293  
   294  // AttrVisibilityHidden symbols returns true for ELF symbols with
   295  // visibility set to STV_HIDDEN. They become local symbols in
   296  // the final executable. Only relevant when internally linking
   297  // on an ELF platform.
   298  func (l *Loader) AttrVisibilityHidden(i Sym) bool
   299  
   300  // SetAttrVisibilityHidden sets the "hidden visibility" property for a
   301  // symbol (see AttrVisibilityHidden).
   302  func (l *Loader) SetAttrVisibilityHidden(i Sym, v bool)
   303  
   304  // AttrDuplicateOK returns true for a symbol that can be present in
   305  // multiple object files.
   306  func (l *Loader) AttrDuplicateOK(i Sym) bool
   307  
   308  // SetAttrDuplicateOK sets the "duplicate OK" property for an external
   309  // symbol (see AttrDuplicateOK).
   310  func (l *Loader) SetAttrDuplicateOK(i Sym, v bool)
   311  
   312  // AttrShared returns true for symbols compiled with the -shared option.
   313  func (l *Loader) AttrShared(i Sym) bool
   314  
   315  // SetAttrShared sets the "shared" property for an external
   316  // symbol (see AttrShared).
   317  func (l *Loader) SetAttrShared(i Sym, v bool)
   318  
   319  // AttrExternal returns true for function symbols loaded from host
   320  // object files.
   321  func (l *Loader) AttrExternal(i Sym) bool
   322  
   323  // SetAttrExternal sets the "external" property for a host object
   324  // symbol (see AttrExternal).
   325  func (l *Loader) SetAttrExternal(i Sym, v bool)
   326  
   327  // AttrSpecial returns true for a symbols that do not have their
   328  // address (i.e. Value) computed by the usual mechanism of
   329  // data.go:dodata() & data.go:address().
   330  func (l *Loader) AttrSpecial(i Sym) bool
   331  
   332  // SetAttrSpecial sets the "special" property for a symbol (see
   333  // AttrSpecial).
   334  func (l *Loader) SetAttrSpecial(i Sym, v bool)
   335  
   336  // AttrCgoExportDynamic returns true for a symbol that has been
   337  // specially marked via the "cgo_export_dynamic" compiler directive
   338  // written by cgo (in response to //export directives in the source).
   339  func (l *Loader) AttrCgoExportDynamic(i Sym) bool
   340  
   341  // SetAttrCgoExportDynamic sets the "cgo_export_dynamic" for a symbol
   342  // (see AttrCgoExportDynamic).
   343  func (l *Loader) SetAttrCgoExportDynamic(i Sym, v bool)
   344  
   345  // ForAllCgoExportDynamic calls f for every symbol that has been
   346  // marked with the "cgo_export_dynamic" compiler directive.
   347  func (l *Loader) ForAllCgoExportDynamic(f func(Sym))
   348  
   349  // AttrCgoExportStatic returns true for a symbol that has been
   350  // specially marked via the "cgo_export_static" directive
   351  // written by cgo.
   352  func (l *Loader) AttrCgoExportStatic(i Sym) bool
   353  
   354  // SetAttrCgoExportStatic sets the "cgo_export_static" for a symbol
   355  // (see AttrCgoExportStatic).
   356  func (l *Loader) SetAttrCgoExportStatic(i Sym, v bool)
   357  
   358  // IsGeneratedSym returns true if a symbol's been previously marked as a
   359  // generator symbol through the SetIsGeneratedSym. The functions for generator
   360  // symbols are kept in the Link context.
   361  func (l *Loader) IsGeneratedSym(i Sym) bool
   362  
   363  // SetIsGeneratedSym marks symbols as generated symbols. Data shouldn't be
   364  // stored in generated symbols, and a function is registered and called for
   365  // each of these symbols.
   366  func (l *Loader) SetIsGeneratedSym(i Sym, v bool)
   367  
   368  func (l *Loader) AttrCgoExport(i Sym) bool
   369  
   370  // AttrReadOnly returns true for a symbol whose underlying data
   371  // is stored via a read-only mmap.
   372  func (l *Loader) AttrReadOnly(i Sym) bool
   373  
   374  // SetAttrReadOnly sets the "data is read only" property for a symbol
   375  // (see AttrReadOnly).
   376  func (l *Loader) SetAttrReadOnly(i Sym, v bool)
   377  
   378  func (l *Loader) AttrSubSymbol(i Sym) bool
   379  
   380  // Returns whether the i-th symbol has ReflectMethod attribute set.
   381  func (l *Loader) IsReflectMethod(i Sym) bool
   382  
   383  // Returns whether the i-th symbol is nosplit.
   384  func (l *Loader) IsNoSplit(i Sym) bool
   385  
   386  // Returns whether this is a Go type symbol.
   387  func (l *Loader) IsGoType(i Sym) bool
   388  
   389  // Returns whether this symbol should be included in typelink.
   390  func (l *Loader) IsTypelink(i Sym) bool
   391  
   392  // Returns whether this symbol is an itab symbol.
   393  func (l *Loader) IsItab(i Sym) bool
   394  
   395  // Returns whether this symbol is a dictionary symbol.
   396  func (l *Loader) IsDict(i Sym) bool
   397  
   398  // Returns whether this symbol is a compiler-generated package init func.
   399  func (l *Loader) IsPkgInit(i Sym) bool
   400  
   401  // Return whether this is a trampoline of a deferreturn call.
   402  func (l *Loader) IsDeferReturnTramp(i Sym) bool
   403  
   404  // Set that i is a trampoline of a deferreturn call.
   405  func (l *Loader) SetIsDeferReturnTramp(i Sym, v bool)
   406  
   407  // SymValue returns the value of the i-th symbol. i is global index.
   408  func (l *Loader) SymValue(i Sym) int64
   409  
   410  // SetSymValue sets the value of the i-th symbol. i is global index.
   411  func (l *Loader) SetSymValue(i Sym, val int64)
   412  
   413  // AddToSymValue adds to the value of the i-th symbol. i is the global index.
   414  func (l *Loader) AddToSymValue(i Sym, val int64)
   415  
   416  // Returns the symbol content of the i-th symbol. i is global index.
   417  func (l *Loader) Data(i Sym) []byte
   418  
   419  // Returns the symbol content of the i-th symbol as a string. i is global index.
   420  func (l *Loader) DataString(i Sym) string
   421  
   422  // FreeData clears the symbol data of an external symbol, allowing the memory
   423  // to be freed earlier. No-op for non-external symbols.
   424  // i is global index.
   425  func (l *Loader) FreeData(i Sym)
   426  
   427  // SymAlign returns the alignment for a symbol.
   428  func (l *Loader) SymAlign(i Sym) int32
   429  
   430  // SetSymAlign sets the alignment for a symbol.
   431  func (l *Loader) SetSymAlign(i Sym, align int32)
   432  
   433  // SymSect returns the section of the i-th symbol. i is global index.
   434  func (l *Loader) SymSect(i Sym) *sym.Section
   435  
   436  // SetSymSect sets the section of the i-th symbol. i is global index.
   437  func (l *Loader) SetSymSect(i Sym, sect *sym.Section)
   438  
   439  // NewSection creates a new (output) section.
   440  func (l *Loader) NewSection() *sym.Section
   441  
   442  // SymDynimplib returns the "dynimplib" attribute for the specified
   443  // symbol, making up a portion of the info for a symbol specified
   444  // on a "cgo_import_dynamic" compiler directive.
   445  func (l *Loader) SymDynimplib(i Sym) string
   446  
   447  // SetSymDynimplib sets the "dynimplib" attribute for a symbol.
   448  func (l *Loader) SetSymDynimplib(i Sym, value string)
   449  
   450  // SymDynimpvers returns the "dynimpvers" attribute for the specified
   451  // symbol, making up a portion of the info for a symbol specified
   452  // on a "cgo_import_dynamic" compiler directive.
   453  func (l *Loader) SymDynimpvers(i Sym) string
   454  
   455  // SetSymDynimpvers sets the "dynimpvers" attribute for a symbol.
   456  func (l *Loader) SetSymDynimpvers(i Sym, value string)
   457  
   458  // SymExtname returns the "extname" value for the specified
   459  // symbol.
   460  func (l *Loader) SymExtname(i Sym) string
   461  
   462  // SetSymExtname sets the  "extname" attribute for a symbol.
   463  func (l *Loader) SetSymExtname(i Sym, value string)
   464  
   465  // SymElfType returns the previously recorded ELF type for a symbol
   466  // (used only for symbols read from shared libraries by ldshlibsyms).
   467  // It is not set for symbols defined by the packages being linked or
   468  // by symbols read by ldelf (and so is left as elf.STT_NOTYPE).
   469  func (l *Loader) SymElfType(i Sym) elf.SymType
   470  
   471  // SetSymElfType sets the elf type attribute for a symbol.
   472  func (l *Loader) SetSymElfType(i Sym, et elf.SymType)
   473  
   474  // SymElfSym returns the ELF symbol index for a given loader
   475  // symbol, assigned during ELF symtab generation.
   476  func (l *Loader) SymElfSym(i Sym) int32
   477  
   478  // SetSymElfSym sets the elf symbol index for a symbol.
   479  func (l *Loader) SetSymElfSym(i Sym, es int32)
   480  
   481  // SymLocalElfSym returns the "local" ELF symbol index for a given loader
   482  // symbol, assigned during ELF symtab generation.
   483  func (l *Loader) SymLocalElfSym(i Sym) int32
   484  
   485  // SetSymLocalElfSym sets the "local" elf symbol index for a symbol.
   486  func (l *Loader) SetSymLocalElfSym(i Sym, es int32)
   487  
   488  // SymPlt returns the PLT offset of symbol s.
   489  func (l *Loader) SymPlt(s Sym) int32
   490  
   491  // SetPlt sets the PLT offset of symbol i.
   492  func (l *Loader) SetPlt(i Sym, v int32)
   493  
   494  // SymGot returns the GOT offset of symbol s.
   495  func (l *Loader) SymGot(s Sym) int32
   496  
   497  // SetGot sets the GOT offset of symbol i.
   498  func (l *Loader) SetGot(i Sym, v int32)
   499  
   500  // SymDynid returns the "dynid" property for the specified symbol.
   501  func (l *Loader) SymDynid(i Sym) int32
   502  
   503  // SetSymDynid sets the "dynid" property for a symbol.
   504  func (l *Loader) SetSymDynid(i Sym, val int32)
   505  
   506  // DynidSyms returns the set of symbols for which dynID is set to an
   507  // interesting (non-default) value. This is expected to be a fairly
   508  // small set.
   509  func (l *Loader) DynidSyms() []Sym
   510  
   511  // SymGoType returns the 'Gotype' property for a given symbol (set by
   512  // the Go compiler for variable symbols). This version relies on
   513  // reading aux symbols for the target sym -- it could be that a faster
   514  // approach would be to check for gotype during preload and copy the
   515  // results in to a map (might want to try this at some point and see
   516  // if it helps speed things up).
   517  func (l *Loader) SymGoType(i Sym) Sym
   518  
   519  // SymUnit returns the compilation unit for a given symbol (which will
   520  // typically be nil for external or linker-manufactured symbols).
   521  func (l *Loader) SymUnit(i Sym) *sym.CompilationUnit
   522  
   523  // SymPkg returns the package where the symbol came from (for
   524  // regular compiler-generated Go symbols), but in the case of
   525  // building with "-linkshared" (when a symbol is read from a
   526  // shared library), will hold the library name.
   527  // NOTE: this corresponds to sym.Symbol.File field.
   528  func (l *Loader) SymPkg(i Sym) string
   529  
   530  // SetSymPkg sets the package/library for a symbol. This is
   531  // needed mainly for external symbols, specifically those imported
   532  // from shared libraries.
   533  func (l *Loader) SetSymPkg(i Sym, pkg string)
   534  
   535  // SymLocalentry returns an offset in bytes of the "local entry" of a symbol.
   536  //
   537  // On PPC64, a value of 1 indicates the symbol does not use or preserve a TOC
   538  // pointer in R2, nor does it have a distinct local entry.
   539  func (l *Loader) SymLocalentry(i Sym) uint8
   540  
   541  // SetSymLocalentry sets the "local entry" offset attribute for a symbol.
   542  func (l *Loader) SetSymLocalentry(i Sym, value uint8)
   543  
   544  // Returns the number of aux symbols given a global index.
   545  func (l *Loader) NAux(i Sym) int
   546  
   547  // Returns the "handle" to the j-th aux symbol of the i-th symbol.
   548  func (l *Loader) Aux(i Sym, j int) Aux
   549  
   550  // WasmImportSym returns the auxiliary WebAssembly import symbol associated with
   551  // a given function symbol. The aux sym only exists for Go function stubs that
   552  // have been annotated with the //go:wasmimport directive.  The aux sym
   553  // contains the information necessary for the linker to add a WebAssembly
   554  // import statement.
   555  // (https://webassembly.github.io/spec/core/syntax/modules.html#imports)
   556  func (l *Loader) WasmImportSym(fnSymIdx Sym) (Sym, bool)
   557  
   558  // SEHUnwindSym returns the auxiliary SEH unwind symbol associated with
   559  // a given function symbol.
   560  func (l *Loader) SEHUnwindSym(fnSymIdx Sym) Sym
   561  
   562  // GetFuncDwarfAuxSyms collects and returns the auxiliary DWARF
   563  // symbols associated with a given function symbol.  Prior to the
   564  // introduction of the loader, this was done purely using name
   565  // lookups, e.f. for function with name XYZ we would then look up
   566  // go.info.XYZ, etc.
   567  func (l *Loader) GetFuncDwarfAuxSyms(fnSymIdx Sym) (auxDwarfInfo, auxDwarfLoc, auxDwarfRanges, auxDwarfLines Sym)
   568  
   569  func (l *Loader) GetVarDwarfAuxSym(i Sym) Sym
   570  
   571  // AddInteriorSym sets up 'interior' as an interior symbol of
   572  // container/payload symbol 'container'. An interior symbol does not
   573  // itself have data, but gives a name to a subrange of the data in its
   574  // container symbol. The container itself may or may not have a name.
   575  // This method is intended primarily for use in the host object
   576  // loaders, to capture the semantics of symbols and sections in an
   577  // object file. When reading a host object file, we'll typically
   578  // encounter a static section symbol (ex: ".text") containing content
   579  // for a collection of functions, then a series of ELF (or macho, etc)
   580  // symbol table entries each of which points into a sub-section
   581  // (offset and length) of its corresponding container symbol. Within
   582  // the go linker we create a loader.Sym for the container (which is
   583  // expected to have the actual content/payload) and then a set of
   584  // interior loader.Sym's that point into a portion of the container.
   585  func (l *Loader) AddInteriorSym(container Sym, interior Sym)
   586  
   587  // OuterSym gets the outer/container symbol.
   588  func (l *Loader) OuterSym(i Sym) Sym
   589  
   590  // SubSym gets the subsymbol for host object loaded symbols.
   591  func (l *Loader) SubSym(i Sym) Sym
   592  
   593  // SetCarrierSym declares that 'c' is the carrier or container symbol
   594  // for 's'. Carrier symbols are used in the linker to as a container
   595  // for a collection of sub-symbols where the content of the
   596  // sub-symbols is effectively concatenated to form the content of the
   597  // carrier. The carrier is given a name in the output symbol table
   598  // while the sub-symbol names are not. For example, the Go compiler
   599  // emits named string symbols (type SGOSTRING) when compiling a
   600  // package; after being deduplicated, these symbols are collected into
   601  // a single unit by assigning them a new carrier symbol named
   602  // "go:string.*" (which appears in the final symbol table for the
   603  // output load module).
   604  func (l *Loader) SetCarrierSym(s Sym, c Sym)
   605  
   606  // Initialize Reachable bitmap and its siblings for running deadcode pass.
   607  func (l *Loader) InitReachable()
   608  
   609  // SortSub walks through the sub-symbols for 's' and sorts them
   610  // in place by increasing value. Return value is the new
   611  // sub symbol for the specified outer symbol.
   612  func (l *Loader) SortSub(s Sym) Sym
   613  
   614  // SortSyms sorts a list of symbols by their value.
   615  func (l *Loader) SortSyms(ss []Sym)
   616  
   617  func (relocs *Relocs) Count() int
   618  
   619  // At returns the j-th reloc for a global symbol.
   620  func (relocs *Relocs) At(j int) Reloc
   621  
   622  // Relocs returns a Relocs object for the given global sym.
   623  func (l *Loader) Relocs(i Sym) Relocs
   624  
   625  func (l *Loader) Pcsp(i Sym) Sym
   626  
   627  // Returns all aux symbols of per-PC data for symbol i.
   628  // tmp is a scratch space for the pcdata slice.
   629  func (l *Loader) PcdataAuxs(i Sym, tmp []Sym) (pcsp, pcfile, pcline, pcinline Sym, pcdata []Sym)
   630  
   631  // Returns the number of pcdata for symbol i.
   632  func (l *Loader) NumPcdata(i Sym) int
   633  
   634  // Returns all funcdata symbols of symbol i.
   635  // tmp is a scratch space.
   636  func (l *Loader) Funcdata(i Sym, tmp []Sym) []Sym
   637  
   638  // Returns the number of funcdata for symbol i.
   639  func (l *Loader) NumFuncdata(i Sym) int
   640  
   641  // FuncInfo provides hooks to access goobj.FuncInfo in the objects.
   642  type FuncInfo struct {
   643  	l       *Loader
   644  	r       *oReader
   645  	data    []byte
   646  	lengths goobj.FuncInfoLengths
   647  }
   648  
   649  func (fi *FuncInfo) Valid() bool
   650  
   651  func (fi *FuncInfo) Args() int
   652  
   653  func (fi *FuncInfo) Locals() int
   654  
   655  func (fi *FuncInfo) FuncID() abi.FuncID
   656  
   657  func (fi *FuncInfo) FuncFlag() abi.FuncFlag
   658  
   659  func (fi *FuncInfo) StartLine() int32
   660  
   661  // Preload has to be called prior to invoking the various methods
   662  // below related to pcdata, funcdataoff, files, and inltree nodes.
   663  func (fi *FuncInfo) Preload()
   664  
   665  func (fi *FuncInfo) NumFile() uint32
   666  
   667  func (fi *FuncInfo) File(k int) goobj.CUFileIndex
   668  
   669  // TopFrame returns true if the function associated with this FuncInfo
   670  // is an entry point, meaning that unwinders should stop when they hit
   671  // this function.
   672  func (fi *FuncInfo) TopFrame() bool
   673  
   674  type InlTreeNode struct {
   675  	Parent   int32
   676  	File     goobj.CUFileIndex
   677  	Line     int32
   678  	Func     Sym
   679  	ParentPC int32
   680  }
   681  
   682  func (fi *FuncInfo) NumInlTree() uint32
   683  
   684  func (fi *FuncInfo) InlTree(k int) InlTreeNode
   685  
   686  func (l *Loader) FuncInfo(i Sym) FuncInfo
   687  
   688  // Preload a package: adds autolib.
   689  // Does not add defined package or non-packaged symbols to the symbol table.
   690  // These are done in LoadSyms.
   691  // Does not read symbol data.
   692  // Returns the fingerprint of the object.
   693  func (l *Loader) Preload(localSymVersion int, f *bio.Reader, lib *sym.Library, unit *sym.CompilationUnit, length int64) goobj.FingerprintType
   694  
   695  // Add syms, hashed (content-addressable) symbols, non-package symbols, and
   696  // references to external symbols (which are always named).
   697  func (l *Loader) LoadSyms(arch *sys.Arch)
   698  
   699  // TopLevelSym tests a symbol (by name and kind) to determine whether
   700  // the symbol first class sym (participating in the link) or is an
   701  // anonymous aux or sub-symbol containing some sub-part or payload of
   702  // another symbol.
   703  func (l *Loader) TopLevelSym(s Sym) bool
   704  
   705  // Copy the payload of symbol src to dst. Both src and dst must be external
   706  // symbols.
   707  // The intended use case is that when building/linking against a shared library,
   708  // where we do symbol name mangling, the Go object file may have reference to
   709  // the original symbol name whereas the shared library provides a symbol with
   710  // the mangled name. When we do mangling, we copy payload of mangled to original.
   711  func (l *Loader) CopySym(src, dst Sym)
   712  
   713  // CreateExtSym creates a new external symbol with the specified name
   714  // without adding it to any lookup tables, returning a Sym index for it.
   715  func (l *Loader) CreateExtSym(name string, ver int) Sym
   716  
   717  // CreateStaticSym creates a new static symbol with the specified name
   718  // without adding it to any lookup tables, returning a Sym index for it.
   719  func (l *Loader) CreateStaticSym(name string) Sym
   720  
   721  func (l *Loader) FreeSym(i Sym)
   722  
   723  // SetRelocVariant sets the 'variant' property of a relocation on
   724  // some specific symbol.
   725  func (l *Loader) SetRelocVariant(s Sym, ri int, v sym.RelocVariant)
   726  
   727  // RelocVariant returns the 'variant' property of a relocation on
   728  // some specific symbol.
   729  func (l *Loader) RelocVariant(s Sym, ri int) sym.RelocVariant
   730  
   731  // UndefinedRelocTargets iterates through the global symbol index
   732  // space, looking for symbols with relocations targeting undefined
   733  // references. The linker's loadlib method uses this to determine if
   734  // there are unresolved references to functions in system libraries
   735  // (for example, libgcc.a), presumably due to CGO code. Return value
   736  // is a pair of lists of loader.Sym's. First list corresponds to the
   737  // corresponding to the undefined symbols themselves, the second list
   738  // is the symbol that is making a reference to the undef. The "limit"
   739  // param controls the maximum number of results returned; if "limit"
   740  // is -1, then all undefs are returned.
   741  func (l *Loader) UndefinedRelocTargets(limit int) ([]Sym, []Sym)
   742  
   743  // AssignTextSymbolOrder populates the Textp slices within each
   744  // library and compilation unit, insuring that packages are laid down
   745  // in dependency order (internal first, then everything else). Return value
   746  // is a slice of all text syms.
   747  func (l *Loader) AssignTextSymbolOrder(libs []*sym.Library, intlibs []bool, extsyms []Sym) []Sym
   748  
   749  // ErrorReporter is a helper class for reporting errors.
   750  type ErrorReporter struct {
   751  	ldr              *Loader
   752  	AfterErrorAction func()
   753  }
   754  
   755  // Errorf method logs an error message.
   756  //
   757  // After each error, the error actions function will be invoked; this
   758  // will either terminate the link immediately (if -h option given)
   759  // or it will keep a count and exit if more than 20 errors have been printed.
   760  //
   761  // Logging an error means that on exit cmd/link will delete any
   762  // output file and return a non-zero error code.
   763  func (reporter *ErrorReporter) Errorf(s Sym, format string, args ...interface{})
   764  
   765  // GetErrorReporter returns the loader's associated error reporter.
   766  func (l *Loader) GetErrorReporter() *ErrorReporter
   767  
   768  // Errorf method logs an error message. See ErrorReporter.Errorf for details.
   769  func (l *Loader) Errorf(s Sym, format string, args ...interface{})
   770  
   771  // Symbol statistics.
   772  func (l *Loader) Stat() string
   773  
   774  // For debugging.
   775  func (l *Loader) Dump()