loader

Imports

Imports #

"bytes"
"cmd/internal/bio"
"cmd/internal/goobj"
"cmd/internal/obj"
"cmd/internal/objabi"
"cmd/internal/sys"
"cmd/link/internal/sym"
"debug/elf"
"fmt"
"internal/abi"
"io"
"log"
"math/bits"
"os"
"sort"
"strings"
"cmd/internal/goobj"
"cmd/internal/objabi"
"cmd/internal/sys"
"cmd/link/internal/sym"
"cmp"
"slices"

Constants & Variables

FlagCheckLinkname const #

const FlagCheckLinkname

FlagStrictDups const #

Loader.flags

const FlagStrictDups = *ast.BinaryExpr

_ var #

var _ = fmt.Print

blockedLinknames var #

A list of blocked linknames. Some linknames are allowed only in specific packages. This maps symbol names to allowed packages. If a name is not in this map, it is allowed iff the definition has a linkname (push). If a name is in this map, it is allowed only in listed packages, even if it has a linknamed definition.

var blockedLinknames = map[string][]string{...}

extObj const #

objidx

const extObj

goObjStart const #

objidx

const goObjStart

hashed64Def const #

const hashed64Def

hashedDef const #

const hashedDef

nilObj const #

objidx

const nilObj = iota

nonPkgDef const #

const nonPkgDef

nonPkgRef const #

const nonPkgRef

pkgDef const #

const pkgDef = iota

Type Aliases

Bitmap type #

type Bitmap []uint32

Sym type #

Sym encapsulates a global symbol index, used to identify a specific Go symbol. The 0-valued Sym is corresponds to an invalid symbol.

type Sym sym.LoaderSym

bySymValue type #

type bySymValue []symWithVal

Structs

Aux struct #

Aux holds a "handle" to access an aux symbol record from an object file.

type Aux struct {
*goobj.Aux
r *oReader
l *Loader
}

ErrorReporter struct #

ErrorReporter is a helper class for reporting errors.

type ErrorReporter struct {
ldr *Loader
AfterErrorAction func()
}

ExtReloc struct #

ExtReloc contains the payload for an external relocation.

type ExtReloc struct {
Xsym Sym
Xadd int64
Type objabi.RelocType
Size uint8
}

FuncInfo struct #

FuncInfo provides hooks to access goobj.FuncInfo in the objects.

type FuncInfo struct {
l *Loader
r *oReader
data []byte
lengths goobj.FuncInfoLengths
}

InlTreeNode struct #

type InlTreeNode struct {
Parent int32
File goobj.CUFileIndex
Line int32
Func Sym
ParentPC int32
}

Loader struct #

A Loader loads new object files and resolves indexed symbol references. Notes on the layout of global symbol index space: - Go object files are read before host object files; each Go object read adds its defined package symbols to the global index space. Nonpackage symbols are not yet added. - In loader.LoadNonpkgSyms, add non-package defined symbols and references in all object files to the global index space. - Host object file loading happens; the host object loader does a name/version lookup for each symbol it finds; this can wind up extending the external symbol index space range. The host object loader stores symbol payloads in loader.payloads using SymbolBuilder. - Each symbol gets a unique global index. For duplicated and overwriting/overwritten symbols, the second (or later) appearance of the symbol gets the same global index as the first appearance.

type Loader struct {
objs []*oReader
extStart Sym
builtinSyms []Sym
objSyms []objSym
symsByName [2]map[string]Sym
extStaticSyms map[nameVer]Sym
extReader *oReader
payloadBatch []extSymPayload
payloads []*extSymPayload
values []int64
sects []*sym.Section
symSects []uint16
align []uint8
deferReturnTramp map[Sym]bool
objByPkg map[string]uint32
anonVersion int
attrReachable Bitmap
attrOnList Bitmap
attrLocal Bitmap
attrNotInSymbolTable Bitmap
attrUsedInIface Bitmap
attrSpecial Bitmap
attrVisibilityHidden Bitmap
attrDuplicateOK Bitmap
attrShared Bitmap
attrExternal Bitmap
generatedSyms Bitmap
attrReadOnly map[Sym]bool
attrCgoExportDynamic map[Sym]struct{...}
attrCgoExportStatic map[Sym]struct{...}
outer []Sym
sub map[Sym]Sym
dynimplib map[Sym]string
dynimpvers map[Sym]string
localentry map[Sym]uint8
extname map[Sym]string
elfType map[Sym]elf.SymType
elfSym map[Sym]int32
localElfSym map[Sym]int32
symPkg map[Sym]string
plt map[Sym]int32
got map[Sym]int32
dynid map[Sym]int32
relocVariant map[relocId]sym.RelocVariant
Reachparent []Sym
CgoExports map[string]Sym
WasmExports []Sym
sizeFixups []symAndSize
flags uint32
strictDupMsgs int
errorReporter *ErrorReporter
npkgsyms int
nhashedsyms int
}

Reloc struct #

Reloc holds a "handle" to access a relocation record from an object file.

type Reloc struct {
*goobj.Reloc
r *oReader
l *Loader
}

Relocs struct #

Relocs encapsulates the set of relocations on a given symbol; an instance of this type is returned by the Loader Relocs() method.

type Relocs struct {
rs []goobj.Reloc
li uint32
r *oReader
l *Loader
}

SymbolBuilder struct #

SymbolBuilder is a helper designed to help with the construction of new symbol contents.

type SymbolBuilder struct {
*extSymPayload
symIdx Sym
l *Loader
}

extSymPayload struct #

extSymPayload holds the payload (data + relocations) for linker-synthesized external symbols (note that symbol value is stored in a separate slice).

type extSymPayload struct {
name string
size int64
ver int
kind sym.SymKind
objidx uint32
relocs []goobj.Reloc
data []byte
auxs []goobj.Aux
}

linknameVarRef struct #

type linknameVarRef struct {
pkg string
name string
sym Sym
}

loadState struct #

Holds the loader along with temporary states for loading symbols.

type loadState struct {
l *Loader
hashed64Syms map[uint64]symAndSize
hashedSyms map[goobj.HashType]symAndSize
linknameVarRefs []linknameVarRef
}

nameVer struct #

type nameVer struct {
name string
v int
}

oReader struct #

oReader is a wrapper type of obj.Reader, along with some extra information.

type oReader struct {
*goobj.Reader
unit *sym.CompilationUnit
version int
pkgprefix string
syms []Sym
pkg []uint32
ndef int
nhashed64def int
nhasheddef int
objidx uint32
}

objSym struct #

objSym represents a symbol in an object file. It is a tuple of the object and the symbol's local index. For external symbols, objidx is the index of l.extReader (extObj), s is its index into the payload array. {0, 0} represents the nil symbol.

type objSym struct {
objidx uint32
s uint32
}

relocId struct #

relocId is essentially a tuple identifying the Rth relocation of symbol S.

type relocId struct {
sym Sym
ridx int
}

symAndSize struct #

type symAndSize struct {
sym Sym
size uint32
}

symWithVal struct #

type symWithVal struct {
s Sym
v int64
}

Functions

AddAddr method #

func (sb *SymbolBuilder) AddAddr(arch *sys.Arch, tgt Sym) int64

AddAddrPlus method #

func (sb *SymbolBuilder) AddAddrPlus(arch *sys.Arch, tgt Sym, add int64) int64

AddAddrPlus4 method #

func (sb *SymbolBuilder) AddAddrPlus4(arch *sys.Arch, tgt Sym, add int64) int64

AddBytes method #

func (sb *SymbolBuilder) AddBytes(data []byte)

AddCStringAt method #

AddCStringAt adds str plus a null terminating byte.

func (sb *SymbolBuilder) AddCStringAt(off int64, str string) int64

AddCURelativeAddrPlus method #

func (sb *SymbolBuilder) AddCURelativeAddrPlus(arch *sys.Arch, tgt Sym, add int64) int64

AddCgoExport method #

AddCgoExport records a cgo-exported symbol in l.CgoExports. This table is used to identify the correct Go symbol ABI to use to resolve references from host objects (which don't have ABIs).

func (l *Loader) AddCgoExport(s Sym)

AddInteriorSym method #

AddInteriorSym sets up 'interior' as an interior symbol of container/payload symbol 'container'. An interior symbol does not itself have data, but gives a name to a subrange of the data in its container symbol. The container itself may or may not have a name. This method is intended primarily for use in the host object loaders, to capture the semantics of symbols and sections in an object file. When reading a host object file, we'll typically encounter a static section symbol (ex: ".text") containing content for a collection of functions, then a series of ELF (or macho, etc) symbol table entries each of which points into a sub-section (offset and length) of its corresponding container symbol. Within the go linker we create a loader.Sym for the container (which is expected to have the actual content/payload) and then a set of interior loader.Sym's that point into a portion of the container.

func (l *Loader) AddInteriorSym(container Sym, interior Sym)

AddInteriorSym method #

func (sb *SymbolBuilder) AddInteriorSym(sub Sym)

AddPCRelPlus method #

func (sb *SymbolBuilder) AddPCRelPlus(arch *sys.Arch, tgt Sym, add int64) int64

AddPEImageRelativeAddrPlus method #

func (sb *SymbolBuilder) AddPEImageRelativeAddrPlus(arch *sys.Arch, tgt Sym, add int64) int64

AddRel method #

Add a relocation with given type, return its handle and index (to set other fields).

func (sb *SymbolBuilder) AddRel(typ objabi.RelocType) (Reloc, int)

AddRelocs method #

Add n relocations, return a handle to the relocations.

func (sb *SymbolBuilder) AddRelocs(n int) Relocs

AddSize method #

func (sb *SymbolBuilder) AddSize(arch *sys.Arch, tgt Sym) int64

AddStringAt method #

func (sb *SymbolBuilder) AddStringAt(off int64, str string) int64

AddSymRef method #

Add a symbol reference (relocation) with given type, addend, and size (the most generic form).

func (sb *SymbolBuilder) AddSymRef(arch *sys.Arch, tgt Sym, add int64, typ objabi.RelocType, rsize int) int64

AddToSymValue method #

AddToSymValue adds to the value of the i-th symbol. i is the global index.

func (l *Loader) AddToSymValue(i Sym, val int64)

AddUint method #

func (sb *SymbolBuilder) AddUint(arch *sys.Arch, v uint64) int64

AddUint16 method #

func (sb *SymbolBuilder) AddUint16(arch *sys.Arch, v uint16) int64

AddUint32 method #

func (sb *SymbolBuilder) AddUint32(arch *sys.Arch, v uint32) int64

AddUint64 method #

func (sb *SymbolBuilder) AddUint64(arch *sys.Arch, v uint64) int64

AddUint8 method #

func (sb *SymbolBuilder) AddUint8(v uint8) int64

AddUintXX method #

func (sb *SymbolBuilder) AddUintXX(arch *sys.Arch, v uint64, wid int) int64

AddUleb method #

func (sb *SymbolBuilder) AddUleb(v uint64)

Addstring method #

func (sb *SymbolBuilder) Addstring(str string) int64

Align method #

func (sb *SymbolBuilder) Align() int32

Args method #

func (fi *FuncInfo) Args() int

AssignTextSymbolOrder method #

AssignTextSymbolOrder populates the Textp slices within each library and compilation unit, insuring that packages are laid down in dependency order (internal first, then everything else). Return value is a slice of all text syms.

func (l *Loader) AssignTextSymbolOrder(libs []*sym.Library, intlibs []bool, extsyms []Sym) []Sym

At method #

At returns the j-th reloc for a global symbol.

func (relocs *Relocs) At(j int) Reloc

AttrCgoExport method #

func (l *Loader) AttrCgoExport(i Sym) bool

AttrCgoExportDynamic method #

AttrCgoExportDynamic returns true for a symbol that has been specially marked via the "cgo_export_dynamic" compiler directive written by cgo (in response to //export directives in the source).

func (l *Loader) AttrCgoExportDynamic(i Sym) bool

AttrCgoExportStatic method #

AttrCgoExportStatic returns true for a symbol that has been specially marked via the "cgo_export_static" directive written by cgo.

func (l *Loader) AttrCgoExportStatic(i Sym) bool

AttrDuplicateOK method #

AttrDuplicateOK returns true for a symbol that can be present in multiple object files.

func (l *Loader) AttrDuplicateOK(i Sym) bool

AttrExternal method #

AttrExternal returns true for function symbols loaded from host object files.

func (l *Loader) AttrExternal(i Sym) bool

AttrLocal method #

AttrLocal returns true for symbols that are only visible within the module (executable or shared library) being linked. This attribute is applied to thunks and certain other linker-generated symbols.

func (l *Loader) AttrLocal(i Sym) bool

AttrNotInSymbolTable method #

AttrNotInSymbolTable returns true for symbols that should not be added to the symbol table of the final generated load module.

func (l *Loader) AttrNotInSymbolTable(i Sym) bool

AttrOnList method #

AttrOnList returns true for symbols that are on some list (such as the list of all text symbols, or one of the lists of data symbols) and is consulted to avoid bugs where a symbol is put on a list twice.

func (l *Loader) AttrOnList(i Sym) bool

AttrReachable method #

AttrReachable returns true for symbols that are transitively referenced from the entry points. Unreachable symbols are not written to the output.

func (l *Loader) AttrReachable(i Sym) bool

AttrReadOnly method #

AttrReadOnly returns true for a symbol whose underlying data is stored via a read-only mmap.

func (l *Loader) AttrReadOnly(i Sym) bool

AttrShared method #

AttrShared returns true for symbols compiled with the -shared option.

func (l *Loader) AttrShared(i Sym) bool

AttrSpecial method #

AttrSpecial returns true for a symbols that do not have their address (i.e. Value) computed by the usual mechanism of data.go:dodata() & data.go:address().

func (l *Loader) AttrSpecial(i Sym) bool

AttrSubSymbol method #

func (l *Loader) AttrSubSymbol(i Sym) bool

AttrUsedInIface method #

AttrUsedInIface returns true for a type symbol that is used in an interface.

func (l *Loader) AttrUsedInIface(i Sym) bool

AttrVisibilityHidden method #

AttrVisibilityHidden symbols returns true for ELF symbols with visibility set to STV_HIDDEN. They become local symbols in the final executable. Only relevant when internally linking on an ELF platform.

func (l *Loader) AttrVisibilityHidden(i Sym) bool

Aux method #

Returns the "handle" to the j-th aux symbol of the i-th symbol.

func (l *Loader) Aux(i Sym, j int) Aux

CgoExportDynamic method #

func (sb *SymbolBuilder) CgoExportDynamic() bool

CopySym method #

Copy the payload of symbol src to dst. Both src and dst must be external symbols. The intended use case is that when building/linking against a shared library, where we do symbol name mangling, the Go object file may have reference to the original symbol name whereas the shared library provides a symbol with the mangled name. When we do mangling, we copy payload of mangled to original.

func (l *Loader) CopySym(src Sym, dst Sym)

Count method #

func (relocs *Relocs) Count() int

Count method #

return the number of bits set.

func (bm Bitmap) Count() int

CreateExtSym method #

CreateExtSym creates a new external symbol with the specified name without adding it to any lookup tables, returning a Sym index for it.

func (l *Loader) CreateExtSym(name string, ver int) Sym

CreateStaticSym method #

CreateStaticSym creates a new static symbol with the specified name without adding it to any lookup tables, returning a Sym index for it.

func (l *Loader) CreateStaticSym(name string) Sym

CreateSymForUpdate method #

CreateSymForUpdate creates a symbol with given name and version, returns a CreateSymForUpdate for update. If the symbol already exists, it will update in-place.

func (l *Loader) CreateSymForUpdate(name string, version int) *SymbolBuilder

Data method #

func (sb *SymbolBuilder) Data() []byte

Data method #

Returns the symbol content of the i-th symbol. i is global index.

func (l *Loader) Data(i Sym) []byte

DataString method #

Returns the symbol content of the i-th symbol as a string. i is global index.

func (l *Loader) DataString(i Sym) string

Dump method #

For debugging.

func (l *Loader) Dump()

DuplicateOK method #

func (sb *SymbolBuilder) DuplicateOK() bool

DynidSyms method #

DynidSyms returns the set of symbols for which dynID is set to an interesting (non-default) value. This is expected to be a fairly small set.

func (l *Loader) DynidSyms() []Sym

Dynimplib method #

func (sb *SymbolBuilder) Dynimplib() string

Dynimpvers method #

func (sb *SymbolBuilder) Dynimpvers() string

Errorf method #

Errorf method logs an error message. See ErrorReporter.Errorf for details.

func (l *Loader) Errorf(s Sym, format string, args ...interface{})

Errorf method #

Errorf method logs an error message. After each error, the error actions function will be invoked; this will either terminate the link immediately (if -h option given) or it will keep a count and exit if more than 20 errors have been printed. Logging an error means that on exit cmd/link will delete any output file and return a non-zero error code.

func (reporter *ErrorReporter) Errorf(s Sym, format string, args ...interface{})

External method #

func (sb *SymbolBuilder) External() bool

Extname method #

func (sb *SymbolBuilder) Extname() string

File method #

func (fi *FuncInfo) File(k int) goobj.CUFileIndex

ForAllCgoExportDynamic method #

ForAllCgoExportDynamic calls f for every symbol that has been marked with the "cgo_export_dynamic" compiler directive.

func (l *Loader) ForAllCgoExportDynamic(f func(Sym))

FreeData method #

FreeData clears the symbol data of an external symbol, allowing the memory to be freed earlier. No-op for non-external symbols. i is global index.

func (l *Loader) FreeData(i Sym)

FreeSym method #

func (l *Loader) FreeSym(i Sym)

FuncFlag method #

func (fi *FuncInfo) FuncFlag() abi.FuncFlag

FuncID method #

func (fi *FuncInfo) FuncID() abi.FuncID

FuncInfo method #

func (l *Loader) FuncInfo(i Sym) FuncInfo

Funcdata method #

Returns all funcdata symbols of symbol i. tmp is a scratch space.

func (l *Loader) Funcdata(i Sym, tmp []Sym) []Sym

GenAddAddrPlusFunc function #

GenAddAddrPlusFunc returns a function to be called when capturing a function symbol's address. In later stages of the link (when address assignment is done) when doing internal linking and targeting an executable, we can just emit the address of a function directly instead of generating a relocation. Clients can call this function (setting 'internalExec' based on build mode and target) and then invoke the returned function in roughly the same way that loader.*SymbolBuilder.AddAddrPlus would be used.

func GenAddAddrPlusFunc(internalExec bool) (func(s *SymbolBuilder, arch *sys.Arch, tgt Sym, add int64) int64)

GetErrorReporter method #

GetErrorReporter returns the loader's associated error reporter.

func (l *Loader) GetErrorReporter() *ErrorReporter

GetFuncDwarfAuxSyms method #

GetFuncDwarfAuxSyms collects and returns the auxiliary DWARF symbols associated with a given function symbol. Prior to the introduction of the loader, this was done purely using name lookups, e.f. for function with name XYZ we would then look up go.info.XYZ, etc.

func (l *Loader) GetFuncDwarfAuxSyms(fnSymIdx Sym) (auxDwarfInfo Sym, auxDwarfLoc Sym, auxDwarfRanges Sym, auxDwarfLines Sym)

GetVarDwarfAuxSym method #

func (l *Loader) GetVarDwarfAuxSym(i Sym) Sym

GoType method #

func (sb *SymbolBuilder) GoType() Sym

Grow method #

func (ms *extSymPayload) Grow(siz int64)

Has method #

whether the i-th bit is set.

func (bm Bitmap) Has(i Sym) bool

InitReachable method #

Initialize Reachable bitmap and its siblings for running deadcode pass.

func (l *Loader) InitReachable()

InlTree method #

func (fi *FuncInfo) InlTree(k int) InlTreeNode

IsDeferReturnTramp method #

Return whether this is a trampoline of a deferreturn call.

func (l *Loader) IsDeferReturnTramp(i Sym) bool

IsDict method #

Returns whether this symbol is a dictionary symbol.

func (l *Loader) IsDict(i Sym) bool

IsExternal method #

func (l *Loader) IsExternal(i Sym) bool

IsFileLocal method #

func (l *Loader) IsFileLocal(i Sym) bool

IsFromAssembly method #

IsFromAssembly returns true if this symbol is derived from an object file generated by the Go assembler.

func (l *Loader) IsFromAssembly(i Sym) bool

IsGeneratedSym method #

IsGeneratedSym returns true if a symbol's been previously marked as a generator symbol through the SetIsGeneratedSym. The functions for generator symbols are kept in the Link context.

func (l *Loader) IsGeneratedSym(i Sym) bool

IsGoType method #

Returns whether this is a Go type symbol.

func (l *Loader) IsGoType(i Sym) bool

IsItab method #

Returns whether this symbol is an itab symbol.

func (l *Loader) IsItab(i Sym) bool

IsMarker method #

func (rel Reloc) IsMarker() bool

IsNoSplit method #

Returns whether the i-th symbol is nosplit.

func (l *Loader) IsNoSplit(i Sym) bool

IsPkgInit method #

Returns whether this symbol is a compiler-generated package init func.

func (l *Loader) IsPkgInit(i Sym) bool

IsReflectMethod method #

Returns whether the i-th symbol has ReflectMethod attribute set.

func (l *Loader) IsReflectMethod(i Sym) bool

Len method #

func (s bySymValue) Len() int

Len method #

return current length of bitmap in bits.

func (bm Bitmap) Len() int

Less method #

func (s bySymValue) Less(i int, j int) bool

LoadSyms method #

Add syms, hashed (content-addressable) symbols, non-package symbols, and references to external symbols (which are always named).

func (l *Loader) LoadSyms(arch *sys.Arch)

Localentry method #

func (sb *SymbolBuilder) Localentry() uint8

Locals method #

func (fi *FuncInfo) Locals() int

Lookup method #

Look up a symbol by name, return global index, or 0 if not found. This is more like Syms.ROLookup than Lookup -- it doesn't create new symbol.

func (l *Loader) Lookup(name string, ver int) Sym

LookupOrCreateCgoExport method #

LookupOrCreateCgoExport is like LookupOrCreateSym, but if ver indicates a global symbol, it uses the CgoExport table to determine the appropriate symbol version (ABI) to use. ver must be either 0 or a static symbol version.

func (l *Loader) LookupOrCreateCgoExport(name string, ver int) Sym

LookupOrCreateSym method #

LookupOrCreateSym looks up the symbol with the specified name/version, returning its Sym index if found. If the lookup fails, a new external Sym will be created, entered into the lookup tables, and returned.

func (l *Loader) LookupOrCreateSym(name string, ver int) Sym

MakeBitmap function #

func MakeBitmap(n int) Bitmap

MakeSymbolBuilder method #

MakeSymbolBuilder creates a symbol builder for use in constructing an entirely new symbol.

func (l *Loader) MakeSymbolBuilder(name string) *SymbolBuilder

MakeSymbolUpdater method #

MakeSymbolUpdater creates a symbol builder helper for an existing symbol 'symIdx'. If 'symIdx' is not an external symbol, then create a clone of it (copy name, properties, etc) fix things up so that the lookup tables and caches point to the new version, not the old version.

func (l *Loader) MakeSymbolUpdater(symIdx Sym) *SymbolBuilder

MakeWritable method #

func (sb *SymbolBuilder) MakeWritable()

NAlldef method #

Total number of defined symbols (package symbols, hashed symbols, and non-package symbols).

func (r *oReader) NAlldef() int

NAux method #

Returns the number of aux symbols given a global index.

func (l *Loader) NAux(i Sym) int

NDef method #

Number of defined Go symbols.

func (l *Loader) NDef() int

NReachableSym method #

Number of reachable symbols.

func (l *Loader) NReachableSym() int

NStrictDupMsgs method #

func (l *Loader) NStrictDupMsgs() int

NSym method #

Number of total symbols.

func (l *Loader) NSym() int

Name method #

func (sb *SymbolBuilder) Name() string

NewLoader function #

func NewLoader(flags uint32, reporter *ErrorReporter) *Loader

NewSection method #

NewSection creates a new (output) section.

func (l *Loader) NewSection() *sym.Section

NumFile method #

func (fi *FuncInfo) NumFile() uint32

NumFuncdata method #

Returns the number of funcdata for symbol i.

func (l *Loader) NumFuncdata(i Sym) int

NumInlTree method #

func (fi *FuncInfo) NumInlTree() uint32

NumPcdata method #

Returns the number of pcdata for symbol i.

func (l *Loader) NumPcdata(i Sym) int

OnList method #

func (sb *SymbolBuilder) OnList() bool

Outer method #

func (sb *SymbolBuilder) Outer() Sym

OuterSym method #

OuterSym gets the outer/container symbol.

func (l *Loader) OuterSym(i Sym) Sym

PcdataAuxs method #

Returns all aux symbols of per-PC data for symbol i. tmp is a scratch space for the pcdata slice.

func (l *Loader) PcdataAuxs(i Sym, tmp []Sym) (pcsp Sym, pcfile Sym, pcline Sym, pcinline Sym, pcdata []Sym)

Pcsp method #

func (l *Loader) Pcsp(i Sym) Sym

Preload method #

Preload has to be called prior to invoking the various methods below related to pcdata, funcdataoff, files, and inltree nodes.

func (fi *FuncInfo) Preload()

Preload method #

Preload a package: adds autolib. Does not add defined package or non-packaged symbols to the symbol table. These are done in LoadSyms. Does not read symbol data. Returns the fingerprint of the object.

func (l *Loader) Preload(localSymVersion int, f *bio.Reader, lib *sym.Library, unit *sym.CompilationUnit, length int64) goobj.FingerprintType

Reachable method #

func (sb *SymbolBuilder) Reachable() bool

ReadOnly method #

func (sb *SymbolBuilder) ReadOnly() bool

RelocVariant method #

RelocVariant returns the 'variant' property of a relocation on some specific symbol.

func (l *Loader) RelocVariant(s Sym, ri int) sym.RelocVariant

Relocs method #

Relocs returns a Relocs object for the given global sym.

func (l *Loader) Relocs(i Sym) Relocs

Relocs method #

func (sb *SymbolBuilder) Relocs() Relocs

ResetRelocs method #

ResetRelocs removes all relocations on this symbol.

func (sb *SymbolBuilder) ResetRelocs()

SEHUnwindSym method #

SEHUnwindSym returns the auxiliary SEH unwind symbol associated with a given function symbol.

func (l *Loader) SEHUnwindSym(fnSymIdx Sym) Sym

Sect method #

func (sb *SymbolBuilder) Sect() *sym.Section

Set method #

set the i-th bit.

func (bm Bitmap) Set(i Sym)

SetAddr method #

func (sb *SymbolBuilder) SetAddr(arch *sys.Arch, off int64, tgt Sym) int64

SetAddrPlus method #

func (sb *SymbolBuilder) SetAddrPlus(arch *sys.Arch, off int64, tgt Sym, add int64) int64

SetAlign method #

func (sb *SymbolBuilder) SetAlign(align int32)

SetAttrCgoExportDynamic method #

SetAttrCgoExportDynamic sets the "cgo_export_dynamic" for a symbol (see AttrCgoExportDynamic).

func (l *Loader) SetAttrCgoExportDynamic(i Sym, v bool)

SetAttrCgoExportStatic method #

SetAttrCgoExportStatic sets the "cgo_export_static" for a symbol (see AttrCgoExportStatic).

func (l *Loader) SetAttrCgoExportStatic(i Sym, v bool)

SetAttrDuplicateOK method #

SetAttrDuplicateOK sets the "duplicate OK" property for an external symbol (see AttrDuplicateOK).

func (l *Loader) SetAttrDuplicateOK(i Sym, v bool)

SetAttrExternal method #

SetAttrExternal sets the "external" property for a host object symbol (see AttrExternal).

func (l *Loader) SetAttrExternal(i Sym, v bool)

SetAttrLocal method #

SetAttrLocal the "local" property for a symbol (see AttrLocal above).

func (l *Loader) SetAttrLocal(i Sym, v bool)

SetAttrNotInSymbolTable method #

SetAttrNotInSymbolTable the "not in symtab" property for a symbol (see AttrNotInSymbolTable above).

func (l *Loader) SetAttrNotInSymbolTable(i Sym, v bool)

SetAttrOnList method #

SetAttrOnList sets the "on list" property for a symbol (see AttrOnList).

func (l *Loader) SetAttrOnList(i Sym, v bool)

SetAttrReachable method #

SetAttrReachable sets the reachability property for a symbol (see AttrReachable).

func (l *Loader) SetAttrReachable(i Sym, v bool)

SetAttrReadOnly method #

SetAttrReadOnly sets the "data is read only" property for a symbol (see AttrReadOnly).

func (l *Loader) SetAttrReadOnly(i Sym, v bool)

SetAttrShared method #

SetAttrShared sets the "shared" property for an external symbol (see AttrShared).

func (l *Loader) SetAttrShared(i Sym, v bool)

SetAttrSpecial method #

SetAttrSpecial sets the "special" property for a symbol (see AttrSpecial).

func (l *Loader) SetAttrSpecial(i Sym, v bool)

SetAttrUsedInIface method #

func (l *Loader) SetAttrUsedInIface(i Sym, v bool)

SetAttrVisibilityHidden method #

SetAttrVisibilityHidden sets the "hidden visibility" property for a symbol (see AttrVisibilityHidden).

func (l *Loader) SetAttrVisibilityHidden(i Sym, v bool)

SetBytesAt method #

func (sb *SymbolBuilder) SetBytesAt(off int64, b []byte) int64

SetCarrierSym method #

SetCarrierSym declares that 'c' is the carrier or container symbol for 's'. Carrier symbols are used in the linker to as a container for a collection of sub-symbols where the content of the sub-symbols is effectively concatenated to form the content of the carrier. The carrier is given a name in the output symbol table while the sub-symbol names are not. For example, the Go compiler emits named string symbols (type SGOSTRING) when compiling a package; after being deduplicated, these symbols are collected into a single unit by assigning them a new carrier symbol named "go:string.*" (which appears in the final symbol table for the output load module).

func (l *Loader) SetCarrierSym(s Sym, c Sym)

SetData method #

func (sb *SymbolBuilder) SetData(data []byte)

SetDuplicateOK method #

func (sb *SymbolBuilder) SetDuplicateOK(v bool)

SetDynimplib method #

func (sb *SymbolBuilder) SetDynimplib(value string)

SetDynimpvers method #

func (sb *SymbolBuilder) SetDynimpvers(value string)

SetExternal method #

func (sb *SymbolBuilder) SetExternal(v bool)

SetExtname method #

func (sb *SymbolBuilder) SetExtname(value string)

SetGot method #

func (sb *SymbolBuilder) SetGot(value int32)

SetGot method #

SetGot sets the GOT offset of symbol i.

func (l *Loader) SetGot(i Sym, v int32)

SetIsDeferReturnTramp method #

Set that i is a trampoline of a deferreturn call.

func (l *Loader) SetIsDeferReturnTramp(i Sym, v bool)

SetIsGeneratedSym method #

SetIsGeneratedSym marks symbols as generated symbols. Data shouldn't be stored in generated symbols, and a function is registered and called for each of these symbols.

func (l *Loader) SetIsGeneratedSym(i Sym, v bool)

SetLocal method #

func (sb *SymbolBuilder) SetLocal(value bool)

SetLocalentry method #

func (sb *SymbolBuilder) SetLocalentry(value uint8)

SetNotInSymbolTable method #

func (sb *SymbolBuilder) SetNotInSymbolTable(value bool)

SetOnList method #

func (sb *SymbolBuilder) SetOnList(v bool)

SetPlt method #

func (sb *SymbolBuilder) SetPlt(value int32)

SetPlt method #

SetPlt sets the PLT offset of symbol i.

func (l *Loader) SetPlt(i Sym, v int32)

SetReachable method #

func (sb *SymbolBuilder) SetReachable(v bool)

SetReadOnly method #

func (sb *SymbolBuilder) SetReadOnly(v bool)

SetRelocAdd method #

SetRelocAdd sets the addend of the 'i'-th relocation on this sym to 'a'

func (sb *SymbolBuilder) SetRelocAdd(i int, a int64)

SetRelocSym method #

SetRelocSym sets the target sym of the 'i'-th relocation on this sym to 's'

func (sb *SymbolBuilder) SetRelocSym(i int, tgt Sym)

SetRelocType method #

SetRelocType sets the type of the 'i'-th relocation on this sym to 't'

func (sb *SymbolBuilder) SetRelocType(i int, t objabi.RelocType)

SetRelocVariant method #

SetRelocVariant sets the 'variant' property of a relocation on some specific symbol.

func (l *Loader) SetRelocVariant(s Sym, ri int, v sym.RelocVariant)

SetSect method #

func (sb *SymbolBuilder) SetSect(sect *sym.Section)

SetSize method #

func (sb *SymbolBuilder) SetSize(size int64)

SetSpecial method #

func (sb *SymbolBuilder) SetSpecial(value bool)

SetSym method #

func (rel Reloc) SetSym(s Sym)

SetSymAlign method #

SetSymAlign sets the alignment for a symbol.

func (l *Loader) SetSymAlign(i Sym, align int32)

SetSymDynid method #

SetSymDynid sets the "dynid" property for a symbol.

func (l *Loader) SetSymDynid(i Sym, val int32)

SetSymDynimplib method #

SetSymDynimplib sets the "dynimplib" attribute for a symbol.

func (l *Loader) SetSymDynimplib(i Sym, value string)

SetSymDynimpvers method #

SetSymDynimpvers sets the "dynimpvers" attribute for a symbol.

func (l *Loader) SetSymDynimpvers(i Sym, value string)

SetSymElfSym method #

SetSymElfSym sets the elf symbol index for a symbol.

func (l *Loader) SetSymElfSym(i Sym, es int32)

SetSymElfType method #

SetSymElfType sets the elf type attribute for a symbol.

func (l *Loader) SetSymElfType(i Sym, et elf.SymType)

SetSymExtname method #

SetSymExtname sets the "extname" attribute for a symbol.

func (l *Loader) SetSymExtname(i Sym, value string)

SetSymLocalElfSym method #

SetSymLocalElfSym sets the "local" elf symbol index for a symbol.

func (l *Loader) SetSymLocalElfSym(i Sym, es int32)

SetSymLocalentry method #

SetSymLocalentry sets the "local entry" offset attribute for a symbol.

func (l *Loader) SetSymLocalentry(i Sym, value uint8)

SetSymPkg method #

SetSymPkg sets the package/library for a symbol. This is needed mainly for external symbols, specifically those imported from shared libraries.

func (l *Loader) SetSymPkg(i Sym, pkg string)

SetSymSect method #

SetSymSect sets the section of the i-th symbol. i is global index.

func (l *Loader) SetSymSect(i Sym, sect *sym.Section)

SetSymValue method #

SetSymValue sets the value of the i-th symbol. i is global index.

func (l *Loader) SetSymValue(i Sym, val int64)

SetType method #

func (sb *SymbolBuilder) SetType(kind sym.SymKind)

SetType method #

func (rel Reloc) SetType(t objabi.RelocType)

SetUint method #

func (sb *SymbolBuilder) SetUint(arch *sys.Arch, r int64, v uint64) int64

SetUint16 method #

func (sb *SymbolBuilder) SetUint16(arch *sys.Arch, r int64, v uint16) int64

SetUint32 method #

func (sb *SymbolBuilder) SetUint32(arch *sys.Arch, r int64, v uint32) int64

SetUint8 method #

func (sb *SymbolBuilder) SetUint8(arch *sys.Arch, r int64, v uint8) int64

SetUintptr method #

func (sb *SymbolBuilder) SetUintptr(arch *sys.Arch, r int64, v uintptr) int64

SetValue method #

func (sb *SymbolBuilder) SetValue(v int64)

SetVisibilityHidden method #

func (sb *SymbolBuilder) SetVisibilityHidden(value bool)

Size method #

func (sb *SymbolBuilder) Size() int64

SortRelocs method #

SortRelocs Sort relocations by offset.

func (sb *SymbolBuilder) SortRelocs()

SortSub method #

SortSub walks through the sub-symbols for 's' and sorts them in place by increasing value. Return value is the new sub symbol for the specified outer symbol.

func (l *Loader) SortSub(s Sym) Sym

SortSub method #

func (sb *SymbolBuilder) SortSub()

SortSyms method #

SortSyms sorts a list of symbols by their value.

func (l *Loader) SortSyms(ss []Sym)

StartLine method #

func (fi *FuncInfo) StartLine() int32

Stat method #

Symbol statistics.

func (l *Loader) Stat() string

Sub method #

func (sb *SymbolBuilder) Sub() Sym

SubSym method #

SubSym gets the subsymbol for host object loaded symbols.

func (l *Loader) SubSym(i Sym) Sym

SubSym method #

func (sb *SymbolBuilder) SubSym() Sym

Swap method #

func (s bySymValue) Swap(i int, j int)

Sym method #

func (rel Reloc) Sym() Sym

Sym method #

func (a Aux) Sym() Sym

Sym method #

func (sb *SymbolBuilder) Sym() Sym

SymAddr method #

SymAddr checks that a symbol is reachable, and returns its value.

func (l *Loader) SymAddr(i Sym) int64

SymAlign method #

SymAlign returns the alignment for a symbol.

func (l *Loader) SymAlign(i Sym) int32

SymAttr method #

Returns the attributes of the i-th symbol.

func (l *Loader) SymAttr(i Sym) uint8

SymDynid method #

SymDynid returns the "dynid" property for the specified symbol.

func (l *Loader) SymDynid(i Sym) int32

SymDynimplib method #

SymDynimplib returns the "dynimplib" attribute for the specified symbol, making up a portion of the info for a symbol specified on a "cgo_import_dynamic" compiler directive.

func (l *Loader) SymDynimplib(i Sym) string

SymDynimpvers method #

SymDynimpvers returns the "dynimpvers" attribute for the specified symbol, making up a portion of the info for a symbol specified on a "cgo_import_dynamic" compiler directive.

func (l *Loader) SymDynimpvers(i Sym) string

SymElfSym method #

SymElfSym returns the ELF symbol index for a given loader symbol, assigned during ELF symtab generation.

func (l *Loader) SymElfSym(i Sym) int32

SymElfType method #

SymElfType returns the previously recorded ELF type for a symbol (used only for symbols read from shared libraries by ldshlibsyms). It is not set for symbols defined by the packages being linked or by symbols read by ldelf (and so is left as elf.STT_NOTYPE).

func (l *Loader) SymElfType(i Sym) elf.SymType

SymExtname method #

SymExtname returns the "extname" value for the specified symbol.

func (l *Loader) SymExtname(i Sym) string

SymGoType method #

SymGoType returns the 'Gotype' property for a given symbol (set by the Go compiler for variable symbols). This version relies on reading aux symbols for the target sym -- it could be that a faster approach would be to check for gotype during preload and copy the results in to a map (might want to try this at some point and see if it helps speed things up).

func (l *Loader) SymGoType(i Sym) Sym

SymGot method #

SymGot returns the GOT offset of symbol s.

func (l *Loader) SymGot(s Sym) int32

SymLocalElfSym method #

SymLocalElfSym returns the "local" ELF symbol index for a given loader symbol, assigned during ELF symtab generation.

func (l *Loader) SymLocalElfSym(i Sym) int32

SymLocalentry method #

SymLocalentry returns an offset in bytes of the "local entry" of a symbol. On PPC64, a value of 1 indicates the symbol does not use or preserve a TOC pointer in R2, nor does it have a distinct local entry.

func (l *Loader) SymLocalentry(i Sym) uint8

SymName method #

Returns the name of the i-th symbol.

func (l *Loader) SymName(i Sym) string

SymPkg method #

SymPkg returns the package where the symbol came from (for regular compiler-generated Go symbols), but in the case of building with "-linkshared" (when a symbol is read from a shared library), will hold the library name. NOTE: this corresponds to sym.Symbol.File field.

func (l *Loader) SymPkg(i Sym) string

SymPlt method #

SymPlt returns the PLT offset of symbol s.

func (l *Loader) SymPlt(s Sym) int32

SymSect method #

SymSect returns the section of the i-th symbol. i is global index.

func (l *Loader) SymSect(i Sym) *sym.Section

SymSize method #

Returns the size of the i-th symbol.

func (l *Loader) SymSize(i Sym) int64

SymType method #

Returns the type of the i-th symbol.

func (l *Loader) SymType(i Sym) sym.SymKind

SymUnit method #

SymUnit returns the compilation unit for a given symbol (which will typically be nil for external or linker-manufactured symbols).

func (l *Loader) SymUnit(i Sym) *sym.CompilationUnit

SymValue method #

SymValue returns the value of the i-th symbol. i is global index.

func (l *Loader) SymValue(i Sym) int64

SymVersion method #

Returns the version of the i-th symbol.

func (l *Loader) SymVersion(i Sym) int

TopFrame method #

TopFrame returns true if the function associated with this FuncInfo is an entry point, meaning that unwinders should stop when they hit this function.

func (fi *FuncInfo) TopFrame() bool

TopLevelSym method #

TopLevelSym tests a symbol (by name and kind) to determine whether the symbol first class sym (participating in the link) or is an anonymous aux or sub-symbol containing some sub-part or payload of another symbol.

func (l *Loader) TopLevelSym(s Sym) bool

Type method #

func (rel Reloc) Type() objabi.RelocType

Type method #

func (sb *SymbolBuilder) Type() sym.SymKind

UndefinedRelocTargets method #

UndefinedRelocTargets iterates through the global symbol index space, looking for symbols with relocations targeting undefined references. The linker's loadlib method uses this to determine if there are unresolved references to functions in system libraries (for example, libgcc.a), presumably due to CGO code. Return value is a pair of lists of loader.Sym's. First list corresponds to the corresponding to the undefined symbols themselves, the second list is the symbol that is making a reference to the undef. The "limit" param controls the maximum number of results returned; if "limit" is -1, then all undefs are returned.

func (l *Loader) UndefinedRelocTargets(limit int) ([]Sym, []Sym)

Unset method #

unset the i-th bit.

func (bm Bitmap) Unset(i Sym)

Valid method #

func (fi *FuncInfo) Valid() bool

Value method #

func (sb *SymbolBuilder) Value() int64

Version method #

func (sb *SymbolBuilder) Version() int

VisibilityHidden method #

func (sb *SymbolBuilder) VisibilityHidden() bool

WasmImportSym method #

WasmImportSym returns the auxiliary WebAssembly import symbol associated with a given function symbol. The aux sym only exists for Go function stubs that have been annotated with the //go:wasmimport directive. The aux sym contains the information necessary for the linker to add a WebAssembly import statement. (https://webassembly.github.io/spec/core/syntax/modules.html#imports)

func (l *Loader) WasmImportSym(fnSymIdx Sym) Sym

WasmTypeSym method #

func (l *Loader) WasmTypeSym(s Sym) Sym

Weak method #

func (rel Reloc) Weak() bool

abiToVer function #

func abiToVer(abi uint16, localSymVersion int) int

addObj method #

Add object file r

func (l *Loader) addObj(pkg string, r *oReader)

addSym method #

Add a symbol from an object file, return the global index. If the symbol already exist, it returns the index of that symbol.

func (st *loadState) addSym(name string, ver int, r *oReader, li uint32, kind int, osym *goobj.Sym) Sym

addSymRef method #

func (sb *SymbolBuilder) addSymRef(tgt Sym, add int64, typ objabi.RelocType, rsize int) int64

allocPayload method #

allocPayload allocates a new payload.

func (l *Loader) allocPayload() *extSymPayload

aux1 method #

Returns a specific aux symbol of type t for symbol i.

func (l *Loader) aux1(i Sym, t uint8) Sym

auxs method #

func (l *Loader) auxs(i Sym) (*oReader, []goobj.Aux)

checkLinkname method #

check if a linkname reference to symbol s from pkg is allowed

func (l *Loader) checkLinkname(pkg string, name string, s Sym)

checkdup method #

Check that duplicate symbols have same contents.

func (l *Loader) checkdup(name string, r *oReader, li uint32, dup Sym)

cloneToExternal method #

cloneToExternal takes the existing object file symbol (symIdx) and creates a new external symbol payload that is a clone with respect to name, version, type, relocations, etc. The idea here is that if the linker decides it wants to update the contents of a symbol originally discovered as part of an object file, it's easier to do this if we make the updates to an external symbol payload.

func (l *Loader) cloneToExternal(symIdx Sym) *extSymPayload

extIndex method #

For external symbol, return its index in the payloads array. XXX result is actually not a global index. We (ab)use the Sym type so we don't need conversion for accessing bitmaps.

func (l *Loader) extIndex(i Sym) Sym

getPayload method #

getPayload returns a pointer to the extSymPayload struct for an external symbol if the symbol has a payload. Will panic if the symbol in question is bogus (zero or not an external sym).

func (l *Loader) getPayload(i Sym) *extSymPayload

growAttrBitmaps method #

Insure that reachable bitmap and its siblings have enough size.

func (l *Loader) growAttrBitmaps(reqLen int)

growBitmap function #

growBitmap insures that the specified bitmap has enough capacity, reallocating (doubling the size) if needed.

func growBitmap(reqLen int, b Bitmap) Bitmap

growExtAttrBitmaps method #

func (l *Loader) growExtAttrBitmaps()

growOuter method #

growOuter grows the slice used to store outer symbol.

func (l *Loader) growOuter(reqLen int)

growValues method #

growValues grows the slice used to store symbol values.

func (l *Loader) growValues(reqLen int)

isExtReader method #

func (l *Loader) isExtReader(r *oReader) bool

loadObjRefs function #

func loadObjRefs(l *Loader, r *oReader, arch *sys.Arch)

newExtSym method #

newExtSym creates a new external sym with the specified name/version.

func (l *Loader) newExtSym(name string, ver int) Sym

newPayload method #

Get a new payload for external symbol, return its index in the payloads array.

func (l *Loader) newPayload(name string, ver int) int

preloadSyms method #

Preload symbols of given kind from an object.

func (st *loadState) preloadSyms(r *oReader, kind int)

relocs method #

relocs returns a Relocs object given a local sym index and reader.

func (l *Loader) relocs(r *oReader, li uint32) Relocs

reportMissingBuiltin method #

reportMissingBuiltin issues an error in the case where we have a relocation against a runtime builtin whose definition is not found when the runtime package is built. The canonical example is "runtime.racefuncenter" -- currently if you do something like go build -gcflags=-race myprogram.go the compiler will insert calls to the builtin runtime.racefuncenter, but the version of the runtime used for linkage won't actually contain definitions of that symbol. See issue #42396 for details. As currently implemented, this is a fatal error. This has drawbacks in that if there are multiple missing builtins, the error will only cite the first one. On the plus side, terminating the link here has advantages in that we won't run the risk of panics or crashes later on in the linker due to R_CALL relocations with 0-valued target symbols.

func (l *Loader) reportMissingBuiltin(bsym int, reflib string)

resolve method #

Resolve a local symbol reference. Return global index.

func (l *Loader) resolve(r *oReader, s goobj.SymRef) Sym

setUintXX method #

func (sb *SymbolBuilder) setUintXX(arch *sys.Arch, off int64, v uint64, wid int64) int64

toGlobal method #

Convert a local index to a global index.

func (l *Loader) toGlobal(r *oReader, i uint32) Sym

toLocal method #

Convert a global index to a local index.

func (l *Loader) toLocal(i Sym) (*oReader, uint32)

topLevelSym function #

topLevelSym tests a symbol name and kind to determine whether the symbol first class sym (participating in the link) or is an anonymous aux or sub-symbol containing some sub-part or payload of another symbol.

func topLevelSym(sname string, skind sym.SymKind) bool

Generated with Arrow