...

Package sym

import "cmd/link/internal/sym"
Overview
Index

Overview ▾

Index ▾

Constants
Variables
func ABIToVersion(abi obj.ABI) int
func RelocName(arch *sys.Arch, r objabi.RelocType) string
func VersionToABI(v int) (obj.ABI, bool)
type Attribute
    func (a Attribute) CgoExport() bool
    func (a Attribute) CgoExportDynamic() bool
    func (a Attribute) CgoExportStatic() bool
    func (a Attribute) Container() bool
    func (a Attribute) DuplicateOK() bool
    func (a Attribute) External() bool
    func (a Attribute) Local() bool
    func (a Attribute) MakeTypelink() bool
    func (a Attribute) NoSplit() bool
    func (a Attribute) NotInSymbolTable() bool
    func (a Attribute) OnList() bool
    func (a Attribute) Reachable() bool
    func (a Attribute) ReadOnly() bool
    func (a Attribute) ReflectMethod() bool
    func (a *Attribute) Set(flag Attribute, value bool)
    func (a Attribute) Shared() bool
    func (a Attribute) Special() bool
    func (a Attribute) StackCheck() bool
    func (a Attribute) SubSymbol() bool
    func (a Attribute) TopFrame() bool
    func (a Attribute) VisibilityHidden() bool
type Auto
type AuxSymbol
type FuncInfo
type InlinedCall
type Library
    func (l Library) String() string
type Pcdata
type Reloc
    func (r *Reloc) InitExt()
type RelocByOff
    func (x RelocByOff) Len() int
    func (x RelocByOff) Less(i, j int) bool
    func (x RelocByOff) Swap(i, j int)
type RelocVariant
type Section
type Segment
type SymKind
    func (i SymKind) String() string
type Symbol
    func SortSub(l *Symbol) *Symbol
    func (s *Symbol) AddAddr(arch *sys.Arch, t *Symbol) int64
    func (s *Symbol) AddAddrPlus(arch *sys.Arch, t *Symbol, add int64) int64
    func (s *Symbol) AddAddrPlus4(t *Symbol, add int64) int64
    func (s *Symbol) AddBytes(bytes []byte) int64
    func (s *Symbol) AddCURelativeAddrPlus(arch *sys.Arch, t *Symbol, add int64) int64
    func (s *Symbol) AddPCRelPlus(arch *sys.Arch, t *Symbol, add int64) int64
    func (s *Symbol) AddRel() *Reloc
    func (s *Symbol) AddSize(arch *sys.Arch, t *Symbol) int64
    func (s *Symbol) AddUint(arch *sys.Arch, v uint64) int64
    func (s *Symbol) AddUint16(arch *sys.Arch, v uint16) int64
    func (s *Symbol) AddUint32(arch *sys.Arch, v uint32) int64
    func (s *Symbol) AddUint64(arch *sys.Arch, v uint64) int64
    func (s *Symbol) AddUint8(v uint8) int64
    func (s *Symbol) AddUintXX(arch *sys.Arch, v uint64, wid int) int64
    func (s *Symbol) Dynimplib() string
    func (s *Symbol) Dynimpvers() string
    func (s *Symbol) ElfType() elf.SymType
    func (s *Symbol) ElfsymForReloc() int32
    func (s *Symbol) Extname() string
    func (s *Symbol) Got() int32
    func (s *Symbol) Grow(siz int64)
    func (s *Symbol) IsFileLocal() bool
    func (s *Symbol) Len() int64
    func (s *Symbol) Localentry() uint8
    func (s *Symbol) Plt() int32
    func (s *Symbol) ResetDyninfo()
    func (s *Symbol) SetAddr(arch *sys.Arch, off int64, t *Symbol) int64
    func (s *Symbol) SetAddrPlus(arch *sys.Arch, off int64, t *Symbol, add int64) int64
    func (s *Symbol) SetDynimplib(lib string)
    func (s *Symbol) SetDynimpvers(vers string)
    func (s *Symbol) SetElfType(val elf.SymType)
    func (s *Symbol) SetExtname(n string)
    func (s *Symbol) SetGot(val int32)
    func (s *Symbol) SetLocalentry(val uint8)
    func (s *Symbol) SetPlt(val int32)
    func (s *Symbol) SetUint(arch *sys.Arch, r int64, v uint64) int64
    func (s *Symbol) SetUint16(arch *sys.Arch, r int64, v uint16) int64
    func (s *Symbol) SetUint32(arch *sys.Arch, r int64, v uint32) int64
    func (s *Symbol) SetUint8(arch *sys.Arch, r int64, v uint8) int64
    func (s *Symbol) String() string
type Symbols
    func NewSymbols() *Symbols
    func (syms *Symbols) IncVersion() int
    func (syms *Symbols) Lookup(name string, v int) *Symbol
    func (syms *Symbols) Newsym(name string, v int) *Symbol
    func (syms *Symbols) ROLookup(name string, v int) *Symbol
    func (syms *Symbols) Rename(old, new string, v int, reachparent map[*Symbol]*Symbol)

Package files

attribute.go library.go reloc.go segment.go symbol.go symbols.go symkind.go symkind_string.go

Constants

const (
    SymVerABI0        = 0
    SymVerABIInternal = 1
    SymVerStatic      = 10 // Minimum version used by static (file-local) syms
)

Variables

var AbiSymKindToSymKind = [...]SymKind{
    Sxxx,
    STEXT,
    SRODATA,
    SNOPTRDATA,
    SDATA,
    SBSS,
    SNOPTRBSS,
    STLSBSS,
    SDWARFINFO,
    SDWARFRANGE,
    SDWARFLOC,
    SDWARFMISC,
    SABIALIAS,
}

AbiSymKindToSymKind maps values read from object files (which are of type cmd/internal/objabi.SymKind) to values of type SymKind.

var ReadOnly = []SymKind{
    STYPE,
    SSTRING,
    SGOSTRING,
    SGOFUNC,
    SGCBITS,
    SRODATA,
    SFUNCTAB,
}

ReadOnly are the symbol kinds that form read-only sections. In some cases, if they will require relocations, they are transformed into rel-ro sections using relROMap.

var RelROMap = map[SymKind]SymKind{
    STYPE:     STYPERELRO,
    SSTRING:   SSTRINGRELRO,
    SGOSTRING: SGOSTRINGRELRO,
    SGOFUNC:   SGOFUNCRELRO,
    SGCBITS:   SGCBITSRELRO,
    SRODATA:   SRODATARELRO,
    SFUNCTAB:  SFUNCTABRELRO,
}

RelROMap describes the transformation of read-only symbols to rel-ro symbols.

func ABIToVersion

func ABIToVersion(abi obj.ABI) int

func RelocName

func RelocName(arch *sys.Arch, r objabi.RelocType) string

func VersionToABI

func VersionToABI(v int) (obj.ABI, bool)

type Attribute

type Attribute int32

Attribute is a set of common symbol attributes.

const (
    // AttrDuplicateOK marks a symbol that can be present in multiple object
    // files.
    AttrDuplicateOK Attribute = 1 << iota
    // AttrExternal marks function symbols loaded from host object files.
    AttrExternal
    // AttrNoSplit marks functions that cannot split the stack; the linker
    // cares because it checks that there are no call chains of nosplit
    // functions that require more than StackLimit bytes (see
    // lib.go:dostkcheck)
    AttrNoSplit
    // AttrReachable marks symbols that are transitively referenced from the
    // entry points. Unreachable symbols are not written to the output.
    AttrReachable
    // AttrCgoExportDynamic and AttrCgoExportStatic mark symbols referenced
    // by directives written by cgo (in response to //export directives in
    // the source).
    AttrCgoExportDynamic
    AttrCgoExportStatic
    // AttrSpecial marks symbols that do not have their address (i.e. Value)
    // computed by the usual mechanism of data.go:dodata() &
    // data.go:address().
    AttrSpecial
    // AttrStackCheck is used by dostkcheck to only check each NoSplit
    // function's stack usage once.
    AttrStackCheck
    // AttrNotInSymbolTable marks symbols that are not written to the symbol table.
    AttrNotInSymbolTable
    // AttrOnList marks 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.
    AttrOnList
    // AttrLocal marks symbols that are only visible within the module
    // (executable or shared library) being linked. Only relevant when
    // dynamically linking Go code.
    AttrLocal
    // AttrReflectMethod marks certain methods from the reflect package that
    // can be used to call arbitrary methods. If no symbol with this bit set
    // is marked as reachable, more dead code elimination can be done.
    AttrReflectMethod
    // AttrMakeTypelink Amarks types that should be added to the typelink
    // table. See typelinks.go:typelinks().
    AttrMakeTypelink
    // AttrShared marks symbols compiled with the -shared option.
    AttrShared
    // AttrVisibilityHidden symbols are 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.
    AttrVisibilityHidden
    // AttrSubSymbol mostly means that the symbol appears on the Sub list of some
    // other symbol.  Unfortunately, it's not 100% reliable; at least, it's not set
    // correctly for the .TOC. symbol in Link.dodata.  Usually the Outer field of the
    // symbol points to the symbol whose list it is on, but that it is not set for the
    // symbols added to .windynamic in initdynimport in pe.go.
    //
    // TODO(mwhudson): fix the inconsistencies noticed above.
    //
    // Sub lists are used when loading host objects (sections from the host object
    // become regular linker symbols and symbols go on the Sub list of their section)
    // and for constructing the global offset table when internally linking a dynamic
    // executable.
    //
    // TODO(mwhudson): perhaps a better name for this is AttrNonGoSymbol.
    AttrSubSymbol
    // AttrContainer is set on text symbols that are present as the .Outer for some
    // other symbol.
    AttrContainer
    // AttrTopFrame means that the function is an entry point and unwinders
    // should stop when they hit this function.
    AttrTopFrame
    // AttrReadOnly indicates whether the symbol's content (Symbol.P) is backed by
    // read-only memory.
    AttrReadOnly
)

func (Attribute) CgoExport

func (a Attribute) CgoExport() bool

func (Attribute) CgoExportDynamic

func (a Attribute) CgoExportDynamic() bool

func (Attribute) CgoExportStatic

func (a Attribute) CgoExportStatic() bool

func (Attribute) Container

func (a Attribute) Container() bool

func (Attribute) DuplicateOK

func (a Attribute) DuplicateOK() bool

func (Attribute) External

func (a Attribute) External() bool

func (Attribute) Local

func (a Attribute) Local() bool
func (a Attribute) MakeTypelink() bool

func (Attribute) NoSplit

func (a Attribute) NoSplit() bool

func (Attribute) NotInSymbolTable

func (a Attribute) NotInSymbolTable() bool

func (Attribute) OnList

func (a Attribute) OnList() bool

func (Attribute) Reachable

func (a Attribute) Reachable() bool

func (Attribute) ReadOnly

func (a Attribute) ReadOnly() bool

func (Attribute) ReflectMethod

func (a Attribute) ReflectMethod() bool

func (*Attribute) Set

func (a *Attribute) Set(flag Attribute, value bool)

func (Attribute) Shared

func (a Attribute) Shared() bool

func (Attribute) Special

func (a Attribute) Special() bool

func (Attribute) StackCheck

func (a Attribute) StackCheck() bool

func (Attribute) SubSymbol

func (a Attribute) SubSymbol() bool

func (Attribute) TopFrame

func (a Attribute) TopFrame() bool

func (Attribute) VisibilityHidden

func (a Attribute) VisibilityHidden() bool

type Auto

type Auto struct {
    Asym    *Symbol
    Gotype  *Symbol
    Aoffset int32
    Name    int16
}

type AuxSymbol

type AuxSymbol struct {
    // contains filtered or unexported fields
}

AuxSymbol contains less-frequently used sym.Symbol fields.

type FuncInfo

type FuncInfo struct {
    Args        int32
    Locals      int32
    Autom       []Auto
    Pcsp        Pcdata
    Pcfile      Pcdata
    Pcline      Pcdata
    Pcinline    Pcdata
    Pcdata      []Pcdata
    Funcdata    []*Symbol
    Funcdataoff []int64
    File        []*Symbol
    InlTree     []InlinedCall
}

type InlinedCall

type InlinedCall struct {
    Parent   int32   // index of parent in InlTree
    File     *Symbol // file of the inlined call
    Line     int32   // line number of the inlined call
    Func     *Symbol // function that was inlined
    ParentPC int32   // PC of the instruction just before the inlined body (offset from function start)
}

InlinedCall is a node in a local inlining tree (FuncInfo.InlTree).

type Library

type Library struct {
    Objref        string
    Srcref        string
    File          string
    Pkg           string
    Shlib         string
    Hash          string
    ImportStrings []string
    Imports       []*Library
    Textp         []*Symbol // text symbols defined in this library
    DupTextSyms   []*Symbol // dupok text symbols defined in this library
    Main          bool
    Safe          bool
}

func (Library) String

func (l Library) String() string

type Pcdata

type Pcdata struct {
    P []byte
}

type Reloc

type Reloc struct {
    Off  int32            // offset to rewrite
    Siz  uint8            // number of bytes to rewrite, 1, 2, or 4
    Done bool             // set to true when relocation is complete
    Type objabi.RelocType // the relocation type
    Add  int64            // addend
    Sym  *Symbol          // symbol the relocation addresses
    // contains filtered or unexported fields
}

Reloc is a relocation.

The typical Reloc rewrites part of a symbol at offset Off to address Sym. A Reloc is stored in a slice on the Symbol it rewrites.

Relocations are generated by the compiler as the type cmd/internal/obj.Reloc, which is encoded into the object file wire format and decoded by the linker into this type. A separate type is used to hold linker-specific state about the relocation.

Some relocations are created by cmd/link.

func (*Reloc) InitExt

func (r *Reloc) InitExt()

type RelocByOff

type RelocByOff []Reloc

RelocByOff implements sort.Interface for sorting relocations by offset.

func (RelocByOff) Len

func (x RelocByOff) Len() int

func (RelocByOff) Less

func (x RelocByOff) Less(i, j int) bool

func (RelocByOff) Swap

func (x RelocByOff) Swap(i, j int)

type RelocVariant

type RelocVariant uint8

RelocVariant is a linker-internal variation on a relocation.

const (
    RV_NONE RelocVariant = iota
    RV_POWER_LO
    RV_POWER_HI
    RV_POWER_HA
    RV_POWER_DS

    // RV_390_DBL is a s390x-specific relocation variant that indicates that
    // the value to be placed into the relocatable field should first be
    // divided by 2.
    RV_390_DBL

    RV_CHECK_OVERFLOW RelocVariant = 1 << 7
    RV_TYPE_MASK      RelocVariant = RV_CHECK_OVERFLOW - 1
)

type Section

type Section struct {
    Rwx     uint8
    Extnum  int16
    Align   int32
    Name    string
    Vaddr   uint64
    Length  uint64
    Seg     *Segment
    Elfsect interface{} // an *ld.ElfShdr
    Reloff  uint64
    Rellen  uint64
}

type Segment

type Segment struct {
    Rwx      uint8  // permission as usual unix bits (5 = r-x etc)
    Vaddr    uint64 // virtual address
    Length   uint64 // length in memory
    Fileoff  uint64 // file offset
    Filelen  uint64 // length on disk
    Sections []*Section
}

type SymKind

type SymKind uint8

A SymKind describes the kind of memory represented by a symbol.

const (
    Sxxx SymKind = iota
    STEXT
    SELFRXSECT

    // Read-only sections.
    STYPE
    SSTRING
    SGOSTRING
    SGOFUNC
    SGCBITS
    SRODATA
    SFUNCTAB

    SELFROSECT
    SMACHOPLT

    // Read-only sections with relocations.
    //
    // Types STYPE-SFUNCTAB above are written to the .rodata section by default.
    // When linking a shared object, some conceptually "read only" types need to
    // be written to by relocations and putting them in a section called
    // ".rodata" interacts poorly with the system linkers. The GNU linkers
    // support this situation by arranging for sections of the name
    // ".data.rel.ro.XXX" to be mprotected read only by the dynamic linker after
    // relocations have applied, so when the Go linker is creating a shared
    // object it checks all objects of the above types and bumps any object that
    // has a relocation to it to the corresponding type below, which are then
    // written to sections with appropriate magic names.
    STYPERELRO
    SSTRINGRELRO
    SGOSTRINGRELRO
    SGOFUNCRELRO
    SGCBITSRELRO
    SRODATARELRO
    SFUNCTABRELRO

    // Part of .data.rel.ro if it exists, otherwise part of .rodata.
    STYPELINK
    SITABLINK
    SSYMTAB
    SPCLNTAB

    // Writable sections.
    SFirstWritable
    SBUILDINFO
    SELFSECT
    SMACHO
    SMACHOGOT
    SWINDOWS
    SELFGOT
    SNOPTRDATA
    SINITARR
    SDATA
    SXCOFFTOC
    SBSS
    SNOPTRBSS
    STLSBSS
    SXREF
    SMACHOSYMSTR
    SMACHOSYMTAB
    SMACHOINDIRECTPLT
    SMACHOINDIRECTGOT
    SFILEPATH
    SCONST
    SDYNIMPORT
    SHOSTOBJ

    // Sections for debugging information
    SDWARFSECT
    SDWARFINFO
    SDWARFRANGE
    SDWARFLOC
    SDWARFMISC // Not really a section; informs/affects other DWARF section generation

    // ABI aliases (these never appear in the output)
    SABIALIAS
)

Defined SymKind values.

TODO(rsc): Give idiomatic Go names. go:generate stringer -type=SymKind

func (SymKind) String

func (i SymKind) String() string

type Symbol

type Symbol struct {
    Name        string
    Type        SymKind
    Version     int16
    Attr        Attribute
    Dynid       int32
    Align       int32
    Elfsym      int32
    LocalElfsym int32
    Value       int64
    Size        int64
    Sub         *Symbol
    Outer       *Symbol
    Gotype      *Symbol
    File        string // actually package!

    Sect     *Section
    FuncInfo *FuncInfo
    Lib      *Library // Package defining this symbol
    // P contains the raw symbol data.
    P []byte
    R []Reloc
    // contains filtered or unexported fields
}

Symbol is an entry in the symbol table.

func SortSub

func SortSub(l *Symbol) *Symbol

SortSub sorts a linked-list (by Sub) of *Symbol by Value. Used for sub-symbols when loading host objects (see e.g. ldelf.go).

func (*Symbol) AddAddr

func (s *Symbol) AddAddr(arch *sys.Arch, t *Symbol) int64

func (*Symbol) AddAddrPlus

func (s *Symbol) AddAddrPlus(arch *sys.Arch, t *Symbol, add int64) int64

func (*Symbol) AddAddrPlus4

func (s *Symbol) AddAddrPlus4(t *Symbol, add int64) int64

func (*Symbol) AddBytes

func (s *Symbol) AddBytes(bytes []byte) int64

func (*Symbol) AddCURelativeAddrPlus

func (s *Symbol) AddCURelativeAddrPlus(arch *sys.Arch, t *Symbol, add int64) int64

func (*Symbol) AddPCRelPlus

func (s *Symbol) AddPCRelPlus(arch *sys.Arch, t *Symbol, add int64) int64

func (*Symbol) AddRel

func (s *Symbol) AddRel() *Reloc

func (*Symbol) AddSize

func (s *Symbol) AddSize(arch *sys.Arch, t *Symbol) int64

func (*Symbol) AddUint

func (s *Symbol) AddUint(arch *sys.Arch, v uint64) int64

func (*Symbol) AddUint16

func (s *Symbol) AddUint16(arch *sys.Arch, v uint16) int64

func (*Symbol) AddUint32

func (s *Symbol) AddUint32(arch *sys.Arch, v uint32) int64

func (*Symbol) AddUint64

func (s *Symbol) AddUint64(arch *sys.Arch, v uint64) int64

func (*Symbol) AddUint8

func (s *Symbol) AddUint8(v uint8) int64

func (*Symbol) AddUintXX

func (s *Symbol) AddUintXX(arch *sys.Arch, v uint64, wid int) int64

func (*Symbol) Dynimplib

func (s *Symbol) Dynimplib() string

func (*Symbol) Dynimpvers

func (s *Symbol) Dynimpvers() string

func (*Symbol) ElfType

func (s *Symbol) ElfType() elf.SymType

func (*Symbol) ElfsymForReloc

func (s *Symbol) ElfsymForReloc() int32

func (*Symbol) Extname

func (s *Symbol) Extname() string

func (*Symbol) Got

func (s *Symbol) Got() int32

func (*Symbol) Grow

func (s *Symbol) Grow(siz int64)

func (*Symbol) IsFileLocal

func (s *Symbol) IsFileLocal() bool

func (*Symbol) Len

func (s *Symbol) Len() int64

func (*Symbol) Localentry

func (s *Symbol) Localentry() uint8

func (*Symbol) Plt

func (s *Symbol) Plt() int32

func (*Symbol) ResetDyninfo

func (s *Symbol) ResetDyninfo()

func (*Symbol) SetAddr

func (s *Symbol) SetAddr(arch *sys.Arch, off int64, t *Symbol) int64

func (*Symbol) SetAddrPlus

func (s *Symbol) SetAddrPlus(arch *sys.Arch, off int64, t *Symbol, add int64) int64

func (*Symbol) SetDynimplib

func (s *Symbol) SetDynimplib(lib string)

func (*Symbol) SetDynimpvers

func (s *Symbol) SetDynimpvers(vers string)

func (*Symbol) SetElfType

func (s *Symbol) SetElfType(val elf.SymType)

func (*Symbol) SetExtname

func (s *Symbol) SetExtname(n string)

func (*Symbol) SetGot

func (s *Symbol) SetGot(val int32)

func (*Symbol) SetLocalentry

func (s *Symbol) SetLocalentry(val uint8)

func (*Symbol) SetPlt

func (s *Symbol) SetPlt(val int32)

func (*Symbol) SetUint

func (s *Symbol) SetUint(arch *sys.Arch, r int64, v uint64) int64

func (*Symbol) SetUint16

func (s *Symbol) SetUint16(arch *sys.Arch, r int64, v uint16) int64

func (*Symbol) SetUint32

func (s *Symbol) SetUint32(arch *sys.Arch, r int64, v uint32) int64

func (*Symbol) SetUint8

func (s *Symbol) SetUint8(arch *sys.Arch, r int64, v uint8) int64

func (*Symbol) String

func (s *Symbol) String() string

type Symbols

type Symbols struct {
    Allsym []*Symbol
    // contains filtered or unexported fields
}

func NewSymbols

func NewSymbols() *Symbols

func (*Symbols) IncVersion

func (syms *Symbols) IncVersion() int

Allocate a new version (i.e. symbol namespace).

func (*Symbols) Lookup

func (syms *Symbols) Lookup(name string, v int) *Symbol

Look up the symbol with the given name and version, creating the symbol if it is not found.

func (*Symbols) Newsym

func (syms *Symbols) Newsym(name string, v int) *Symbol

func (*Symbols) ROLookup

func (syms *Symbols) ROLookup(name string, v int) *Symbol

Look up the symbol with the given name and version, returning nil if it is not found.

func (*Symbols) Rename

func (syms *Symbols) Rename(old, new string, v int, reachparent map[*Symbol]*Symbol)

Rename renames a symbol.