Package obj

import "cmd/internal/obj"
Overview
Index

Overview ▾

Index ▾

Constants
Variables
func AlignmentPadding(pc int32, p *Prog, ctxt *Link, cursym *LSym) int
func AlignmentPaddingLength(pc int32, p *Prog, ctxt *Link) int
func Bool2int(b bool) int
func CConv(s uint8) string
func CConvARM(s uint8) string
func Dconv(p *Prog, a *Addr) string
func DconvWithABIDetail(p *Prog, a *Addr) string
func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc)
func MarkUnsafePoints(ctxt *Link, p0 *Prog, newprog ProgAlloc, isUnsafePoint, isRestartable func(*Prog) bool)
func Nopout(p *Prog)
func RLconv(list int64) string
func Rconv(reg int) string
func RegisterOpSuffix(arch string, cconv func(uint8) string)
func RegisterOpcode(lo As, Anames []string)
func RegisterRegister(lo, hi int, Rconv func(int) string)
func RegisterRegisterList(lo, hi int64, rlconv func(int64) string)
func RegisterSpecialOperands(lo, hi int64, rlconv func(int64) string)
func SPCconv(spc int64) string
func WriteDconv(w io.Writer, p *Prog, a *Addr)
func WriteObjFile(ctxt *Link, b *bio.Writer)
type ABI
    func ParseABI(abistr string) (ABI, bool)
    func (i ABI) String() string
type ABISet
    func ABISetOf(abi ABI) ABISet
    func (a *ABISet) Get(abi ABI) bool
    func (a *ABISet) Set(abi ABI, value bool)
    func (a ABISet) String() string
type Addr
    func (a *Addr) SetConst(v int64)
    func (a *Addr) SetTarget(t *Prog)
    func (a *Addr) Target() *Prog
    func (a *Addr) WriteNameTo(w io.Writer)
type AddrName
type AddrPos
type AddrType
    func (i AddrType) String() string
type As
    func (a As) String() string
type Attribute
    func (a *Attribute) ABI() ABI
    func (a *Attribute) ABIWrapper() bool
    func (a *Attribute) CFunc() bool
    func (a *Attribute) ContentAddressable() bool
    func (a *Attribute) DuplicateOK() bool
    func (a *Attribute) Indexed() bool
    func (a *Attribute) IsLinkname() bool
    func (a *Attribute) IsPcdata() bool
    func (a *Attribute) IsPkgInit() bool
    func (a *Attribute) Leaf() bool
    func (a *Attribute) Local() bool
    func (a *Attribute) MakeTypelink() bool
    func (a *Attribute) NeedCtxt() bool
    func (a *Attribute) NoFrame() bool
    func (a *Attribute) NoSplit() bool
    func (a *Attribute) OnList() bool
    func (a *Attribute) ReflectMethod() bool
    func (a *Attribute) Set(flag Attribute, value bool)
    func (a *Attribute) SetABI(abi ABI)
    func (a *Attribute) Static() bool
    func (a Attribute) String() string
    func (a *Attribute) UsedInIface() bool
    func (a *Attribute) WasInlined() bool
    func (a *Attribute) Wrapper() bool
type Auto
type BySymName
    func (s BySymName) Len() int
    func (s BySymName) Less(i, j int) bool
    func (s BySymName) Swap(i, j int)
type DwarfFixupTable
    func NewDwarfFixupTable(ctxt *Link) *DwarfFixupTable
    func (ft *DwarfFixupTable) AbsFuncDwarfSym(fnsym *LSym) *LSym
    func (ft *DwarfFixupTable) Finalize(myimportpath string, trace bool)
    func (ft *DwarfFixupTable) GetPrecursorFunc(s *LSym) Func
    func (ft *DwarfFixupTable) ReferenceChildDIE(s *LSym, ridx int, tgt *LSym, dclidx int, inlIndex int)
    func (ft *DwarfFixupTable) RegisterChildDIEOffsets(s *LSym, vars []*dwarf.Var, coffsets []int32)
    func (ft *DwarfFixupTable) SetPrecursorFunc(s *LSym, fn Func)
type FileInfo
type Func
type FuncInfo
    func (fi *FuncInfo) AddInlMark(p *Prog, id int32)
    func (fi *FuncInfo) AddSpill(s RegSpill)
    func (fi *FuncInfo) RecordAutoType(gotype *LSym)
    func (fi *FuncInfo) SpillRegisterArgs(last *Prog, pa ProgAlloc) *Prog
    func (fi *FuncInfo) UnspillRegisterArgs(last *Prog, pa ProgAlloc) *Prog
type InlMark
type InlTree
    func (tree *InlTree) Add(parent int, pos src.XPos, func_ *LSym, name string) int
    func (tree *InlTree) AllParents(inlIndex int, do func(InlinedCall))
    func (tree *InlTree) CallPos(inlIndex int) src.XPos
    func (tree *InlTree) InlinedFunction(inlIndex int) *LSym
    func (tree *InlTree) Parent(inlIndex int) int
type InlinedCall
type JumpTable
type LSym
    func (*LSym) CanBeAnSSAAux()
    func (*LSym) CanBeAnSSASym()
    func (s *LSym) File() *FileInfo
    func (s *LSym) Func() *FuncInfo
    func (s *LSym) Grow(lsiz int64)
    func (s *LSym) GrowCap(c int64)
    func (s *LSym) NewFileInfo() *FileInfo
    func (s *LSym) NewFuncInfo() *FuncInfo
    func (s *LSym) NewTypeInfo() *TypeInfo
    func (s *LSym) NewVarInfo() *VarInfo
    func (s *LSym) String() string
    func (s *LSym) TextAttrString() string
    func (s *LSym) VarInfo() *VarInfo
    func (s *LSym) WriteAddr(ctxt *Link, off int64, siz int, rsym *LSym, roff int64)
    func (s *LSym) WriteBytes(ctxt *Link, off int64, b []byte) int64
    func (s *LSym) WriteCURelativeAddr(ctxt *Link, off int64, rsym *LSym, roff int64)
    func (s *LSym) WriteFloat32(ctxt *Link, off int64, f float32)
    func (s *LSym) WriteFloat64(ctxt *Link, off int64, f float64)
    func (s *LSym) WriteInt(ctxt *Link, off int64, siz int, i int64)
    func (s *LSym) WriteOff(ctxt *Link, off int64, rsym *LSym, roff int64)
    func (s *LSym) WriteString(ctxt *Link, off int64, siz int, str string)
    func (s *LSym) WriteWeakAddr(ctxt *Link, off int64, siz int, rsym *LSym, roff int64)
    func (s *LSym) WriteWeakOff(ctxt *Link, off int64, rsym *LSym, roff int64)
type Link
    func Linknew(arch *LinkArch) *Link
    func (ctxt *Link) AddImport(pkg string, fingerprint goobj.FingerprintType)
    func (ctxt *Link) AllPos(xpos src.XPos, do func(src.Pos))
    func (ctxt *Link) CanReuseProgs() bool
    func (ctxt *Link) Diag(format string, args ...interface{})
    func (ctxt *Link) DwarfAbstractFunc(curfn Func, s *LSym)
    func (ctxt *Link) DwarfGlobal(typename string, varSym *LSym)
    func (ctxt *Link) DwarfIntConst(name, typename string, val int64)
    func (ctxt *Link) EmitEntryLiveness(s *LSym, p *Prog, newprog ProgAlloc) *Prog
    func (ctxt *Link) EmitEntryStackMap(s *LSym, p *Prog, newprog ProgAlloc) *Prog
    func (ctxt *Link) EmitEntryUnsafePoint(s *LSym, p *Prog, newprog ProgAlloc) *Prog
    func (ctxt *Link) EndUnsafePoint(p *Prog, newprog ProgAlloc, oldval int64) *Prog
    func (ctxt *Link) Float32Sym(f float32) *LSym
    func (ctxt *Link) Float64Sym(f float64) *LSym
    func (ctxt *Link) GCLocalsSym(data []byte) *LSym
    func (ctxt *Link) Globl(s *LSym, size int64, flag int)
    func (ctxt *Link) GloblPos(s *LSym, size int64, flag int, pos src.XPos)
    func (ctxt *Link) InitTextSym(s *LSym, flag int, start src.XPos)
    func (ctxt *Link) InnermostPos(xpos src.XPos) src.Pos
    func (ctxt *Link) Int128Sym(hi, lo int64) *LSym
    func (ctxt *Link) Int32Sym(i int64) *LSym
    func (ctxt *Link) Int64Sym(i int64) *LSym
    func (ctxt *Link) Logf(format string, args ...interface{})
    func (ctxt *Link) Lookup(name string) *LSym
    func (ctxt *Link) LookupABI(name string, abi ABI) *LSym
    func (ctxt *Link) LookupABIInit(name string, abi ABI, init func(s *LSym)) *LSym
    func (ctxt *Link) LookupDerived(s *LSym, name string) *LSym
    func (ctxt *Link) LookupInit(name string, init func(s *LSym)) *LSym
    func (ctxt *Link) LookupStatic(name string) *LSym
    func (ctxt *Link) NewProg() *Prog
    func (ctxt *Link) NumberSyms()
    func (ctxt *Link) OutermostPos(xpos src.XPos) src.Pos
    func (ctxt *Link) StartUnsafePoint(p *Prog, newprog ProgAlloc) *Prog
type LinkArch
type OperandPos
type PCIter
    func NewPCIter(pcScale uint32) *PCIter
    func (it *PCIter) Init(p []byte)
    func (it *PCIter) Next()
type Pcln
type Plist
type Prog
    func Appendp(q *Prog, newprog ProgAlloc) *Prog
    func (p *Prog) AddRestDest(a Addr)
    func (p *Prog) AddRestSource(a Addr)
    func (p *Prog) AddRestSourceArgs(args []Addr)
    func (p *Prog) AddRestSourceConst(off int64)
    func (p *Prog) AddRestSourceReg(reg int16)
    func (p *Prog) From3Type() AddrType
    func (p *Prog) GetFrom3() *Addr
    func (p *Prog) GetTo2() *Addr
    func (p *Prog) InnermostFilename() string
    func (p *Prog) InnermostLine(w io.Writer)
    func (p *Prog) InnermostLineNumber() string
    func (p *Prog) InnermostLineNumberHTML() string
    func (p *Prog) InnermostString(w io.Writer)
    func (p *Prog) InstructionString() string
    func (p *Prog) Line() string
    func (p *Prog) String() string
    func (p *Prog) WriteInstructionString(w io.Writer)
type ProgAlloc
type RegSpill
type Reloc
    func Addrel(s *LSym) *Reloc
type TypeInfo
type VarInfo
type WasmField
type WasmFieldType
type WasmImport
    func (wi *WasmImport) CreateSym(ctxt *Link) *LSym

Package files

abi_string.go addrtype_string.go data.go dwarf.go go.go inl.go ld.go line.go link.go objfile.go pass.go pcln.go plist.go sym.go textflag.go util.go

Constants

Generate a sequence of opcodes that is as short as possible. See section 6.2.5

const (
    LINE_BASE   = -4
    LINE_RANGE  = 10
    PC_RANGE    = (255 - OPCODE_BASE) / LINE_RANGE
    OPCODE_BASE = 11
)

Each architecture is allotted a distinct subspace of opcode values for declaring its arch-specific opcodes. Within this subspace, the first arch-specific opcode should be at offset A_ARCHSPECIFIC.

Subspaces are aligned to a power of two so opcodes can be masked with AMask and used as compact array indices.

const (
    ABase386 = (1 + iota) << 11
    ABaseARM
    ABaseAMD64
    ABasePPC64
    ABaseARM64
    ABaseMIPS
    ABaseLoong64
    ABaseRISCV
    ABaseS390X
    ABaseWasm

    AllowedOpCodes = 1 << 11            // The number of opcodes available for any given architecture.
    AMask          = AllowedOpCodes - 1 // AND with this to use the opcode as an array index.
)
const (
    // Don't profile the marked routine.
    //
    // Deprecated: Not implemented, do not use.
    NOPROF = 1

    // It is ok for the linker to get multiple of these symbols. It will
    // pick one of the duplicates to use.
    DUPOK = 2

    // Don't insert stack check preamble.
    NOSPLIT = 4

    // Put this data in a read-only section.
    RODATA = 8

    // This data contains no pointers.
    NOPTR = 16

    // This is a wrapper function and should not count as
    // disabling 'recover' or appear in tracebacks by default.
    WRAPPER = 32

    // This function uses its incoming context register.
    NEEDCTXT = 64

    // When passed to objw.Global, causes Local to be set to true on the LSym it creates.
    LOCAL = 128

    // Allocate a word of thread local storage and store the offset from the
    // thread local base to the thread local storage in this variable.
    TLSBSS = 256

    // Do not insert instructions to allocate a stack frame for this function.
    // Only valid on functions that declare a frame size of 0.
    // TODO(mwhudson): only implemented for ppc64x at present.
    NOFRAME = 512

    // Function can call reflect.Type.Method or reflect.Type.MethodByName.
    REFLECTMETHOD = 1024

    // Function is the outermost frame of the call stack. Call stack unwinders
    // should stop at this function.
    TOPFRAME = 2048

    // Function is an ABI wrapper.
    ABIWRAPPER = 4096

    // Function is a compiler-generated package init function.
    PKGINIT = 8192
)

ARM scond byte

const (
    C_SCOND     = (1 << 4) - 1
    C_SBIT      = 1 << 4
    C_PBIT      = 1 << 5
    C_WBIT      = 1 << 6
    C_FBIT      = 1 << 7
    C_UBIT      = 1 << 7
    C_SCOND_XOR = 14
)
const (
    // Because of masking operations in the encodings, each register
    // space should start at 0 modulo some power of 2.
    RBase386     = 1 * 1024
    RBaseAMD64   = 2 * 1024
    RBaseARM     = 3 * 1024
    RBasePPC64   = 4 * 1024  // range [4k, 8k)
    RBaseARM64   = 8 * 1024  // range [8k, 13k)
    RBaseMIPS    = 13 * 1024 // range [13k, 14k)
    RBaseS390X   = 14 * 1024 // range [14k, 15k)
    RBaseRISCV   = 15 * 1024 // range [15k, 16k)
    RBaseWasm    = 16 * 1024
    RBaseLOONG64 = 17 * 1024
)

Each architecture is allotted a distinct subspace: [Lo, Hi) for declaring its arch-specific register list numbers.

const (
    RegListARMLo = 0
    RegListARMHi = 1 << 16

    // arm64 uses the 60th bit to differentiate from other archs
    RegListARM64Lo = 1 << 60
    RegListARM64Hi = 1<<61 - 1

    // x86 uses the 61th bit to differentiate from other archs
    RegListX86Lo = 1 << 61
    RegListX86Hi = 1<<62 - 1
)
const (
    LOG = 5
)
const REG_NONE = 0

StaticNamePref is the prefix the front end applies to static temporary variables. When turned into LSyms, these can be tagged as static so as to avoid inserting them into the linker's name lookup tables.

const StaticNamePref = ".stmp_"
const UnlinkablePkg = "<unlinkable>" // invalid package path, used when compiled without -p flag

Variables

var Anames = []string{
    "XXX",
    "CALL",
    "DUFFCOPY",
    "DUFFZERO",
    "END",
    "FUNCDATA",
    "JMP",
    "NOP",
    "PCALIGN",
    "PCALIGNMAX",
    "PCDATA",
    "RET",
    "GETCALLERPC",
    "TEXT",
    "UNDEF",
}

func AlignmentPadding

func AlignmentPadding(pc int32, p *Prog, ctxt *Link, cursym *LSym) int

AlignmentPadding bytes to add to align code as requested. Alignment is restricted to powers of 2 between 8 and 2048 inclusive.

pc_: current offset in function, in bytes p: a PCALIGN or PCALIGNMAX prog ctxt: the context, for current function cursym: current function being assembled returns number of bytes of padding needed, updates minimum alignment for the function.

func AlignmentPaddingLength

func AlignmentPaddingLength(pc int32, p *Prog, ctxt *Link) int

AlignmentPaddingLength is the number of bytes to add to align code as requested. Alignment is restricted to powers of 2 between 8 and 2048 inclusive. This only computes the length and does not update the (missing parameter) current function's own required alignment.

pc: current offset in function, in bytes p: a PCALIGN or PCALIGNMAX prog ctxt: the context, for current function returns number of bytes of padding needed,

func Bool2int

func Bool2int(b bool) int

func CConv

func CConv(s uint8) string

CConv formats opcode suffix bits (Prog.Scond).

func CConvARM

func CConvARM(s uint8) string

CConvARM formats ARM opcode suffix bits (mostly condition codes).

func Dconv

func Dconv(p *Prog, a *Addr) string

Dconv accepts an argument 'a' within a prog 'p' and returns a string with a formatted version of the argument.

func DconvWithABIDetail

func DconvWithABIDetail(p *Prog, a *Addr) string

DconvWithABIDetail accepts an argument 'a' within a prog 'p' and returns a string with a formatted version of the argument, in which text symbols are rendered with explicit ABI selectors.

func Flushplist

func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc)

func MarkUnsafePoints

func MarkUnsafePoints(ctxt *Link, p0 *Prog, newprog ProgAlloc, isUnsafePoint, isRestartable func(*Prog) bool)

MarkUnsafePoints inserts PCDATAs to mark nonpreemptible and restartable instruction sequences, based on isUnsafePoint and isRestartable predicate. p0 is the start of the instruction stream. isUnsafePoint(p) returns true if p is not safe for async preemption. isRestartable(p) returns true if we can restart at the start of p (this Prog) upon async preemption. (Currently multi-Prog restartable sequence is not supported.) isRestartable can be nil. In this case it is treated as always returning false. If isUnsafePoint(p) and isRestartable(p) are both true, it is treated as an unsafe point.

func Nopout

func Nopout(p *Prog)

func RLconv

func RLconv(list int64) string

func Rconv

func Rconv(reg int) string

func RegisterOpSuffix

func RegisterOpSuffix(arch string, cconv func(uint8) string)

RegisterOpSuffix assigns cconv function for formatting opcode suffixes when compiling for GOARCH=arch.

cconv is never called with 0 argument.

func RegisterOpcode

func RegisterOpcode(lo As, Anames []string)

RegisterOpcode binds a list of instruction names to a given instruction number range.

func RegisterRegister

func RegisterRegister(lo, hi int, Rconv func(int) string)

RegisterRegister binds a pretty-printer (Rconv) for register numbers to a given register number range. Lo is inclusive, hi exclusive (valid registers are lo through hi-1).

func RegisterRegisterList

func RegisterRegisterList(lo, hi int64, rlconv func(int64) string)

RegisterRegisterList binds a pretty-printer (RLconv) for register list numbers to a given register list number range. Lo is inclusive, hi exclusive (valid register list are lo through hi-1).

func RegisterSpecialOperands

func RegisterSpecialOperands(lo, hi int64, rlconv func(int64) string)

RegisterSpecialOperands binds a pretty-printer (SPCconv) for special operand numbers to a given special operand number range. Lo is inclusive, hi is exclusive (valid special operands are lo through hi-1).

func SPCconv

func SPCconv(spc int64) string

SPCconv returns the string representation of the special operand spc.

func WriteDconv

func WriteDconv(w io.Writer, p *Prog, a *Addr)

WriteDconv accepts an argument 'a' within a prog 'p' and writes a formatted version of the arg to the writer.

func WriteObjFile

func WriteObjFile(ctxt *Link, b *bio.Writer)

Entry point of writing new object file.

type ABI

ABI is the calling convention of a text symbol.

type ABI uint8
const (
    // ABI0 is the stable stack-based ABI. It's important that the
    // value of this is "0": we can't distinguish between
    // references to data and ABI0 text symbols in assembly code,
    // and hence this doesn't distinguish between symbols without
    // an ABI and text symbols with ABI0.
    ABI0 ABI = iota

    // ABIInternal is the internal ABI that may change between Go
    // versions. All Go functions use the internal ABI and the
    // compiler generates wrappers for calls to and from other
    // ABIs.
    ABIInternal

    ABICount
)

func ParseABI

func ParseABI(abistr string) (ABI, bool)

ParseABI converts from a string representation in 'abistr' to the corresponding ABI value. Second return value is TRUE if the abi string is recognized, FALSE otherwise.

func (ABI) String

func (i ABI) String() string

type ABISet

ABISet is a bit set of ABI values.

type ABISet uint8
const (
    // ABISetCallable is the set of all ABIs any function could
    // potentially be called using.
    ABISetCallable ABISet = (1 << ABI0) | (1 << ABIInternal)
)

func ABISetOf

func ABISetOf(abi ABI) ABISet

func (*ABISet) Get

func (a *ABISet) Get(abi ABI) bool

func (*ABISet) Set

func (a *ABISet) Set(abi ABI, value bool)

func (ABISet) String

func (a ABISet) String() string

type Addr

type Addr struct {
    Reg    int16
    Index  int16
    Scale  int16 // Sometimes holds a register.
    Type   AddrType
    Name   AddrName
    Class  int8
    Offset int64
    Sym    *LSym

    // argument value:
    //	for TYPE_SCONST, a string
    //	for TYPE_FCONST, a float64
    //	for TYPE_BRANCH, a *Prog (optional)
    //	for TYPE_TEXTSIZE, an int32 (optional)
    Val interface{}
}

func (*Addr) SetConst

func (a *Addr) SetConst(v int64)

func (*Addr) SetTarget

func (a *Addr) SetTarget(t *Prog)

func (*Addr) Target

func (a *Addr) Target() *Prog

func (*Addr) WriteNameTo

func (a *Addr) WriteNameTo(w io.Writer)

type AddrName

type AddrName int8
const (
    NAME_NONE AddrName = iota
    NAME_EXTERN
    NAME_STATIC
    NAME_AUTO
    NAME_PARAM
    // A reference to name@GOT(SB) is a reference to the entry in the global offset
    // table for 'name'.
    NAME_GOTREF
    // Indicates that this is a reference to a TOC anchor.
    NAME_TOCREF
)

type AddrPos

AddrPos indicates whether the operand is the source or the destination.

type AddrPos struct {
    Addr
    Pos OperandPos
}

type AddrType

type AddrType uint8
const (
    TYPE_NONE AddrType = iota
    TYPE_BRANCH
    TYPE_TEXTSIZE
    TYPE_MEM
    TYPE_CONST
    TYPE_FCONST
    TYPE_SCONST
    TYPE_REG
    TYPE_ADDR
    TYPE_SHIFT
    TYPE_REGREG
    TYPE_REGREG2
    TYPE_INDIR
    TYPE_REGLIST
    TYPE_SPECIAL
)

func (AddrType) String

func (i AddrType) String() string

type As

An As denotes an assembler opcode. There are some portable opcodes, declared here in package obj, that are common to all architectures. However, the majority of opcodes are arch-specific and are declared in their respective architecture's subpackage.

type As int16

These are the portable opcodes.

const (
    AXXX As = iota
    ACALL
    ADUFFCOPY
    ADUFFZERO
    AEND
    AFUNCDATA
    AJMP
    ANOP
    APCALIGN
    APCALIGNMAX // currently x86, amd64 and arm64
    APCDATA
    ARET
    AGETCALLERPC
    ATEXT
    AUNDEF
    A_ARCHSPECIFIC
)

func (As) String

func (a As) String() string

type Attribute

Attribute is a set of symbol attributes.

type Attribute uint32
const (
    AttrDuplicateOK Attribute = 1 << iota
    AttrCFunc
    AttrNoSplit
    AttrLeaf
    AttrWrapper
    AttrNeedCtxt
    AttrNoFrame
    AttrOnList
    AttrStatic

    // MakeTypelink means that the type should have an entry in the typelink table.
    AttrMakeTypelink

    // ReflectMethod means the function may call reflect.Type.Method or
    // reflect.Type.MethodByName. Matching is imprecise (as reflect.Type
    // can be used through a custom interface), so ReflectMethod may be
    // set in some cases when the reflect package is not called.
    //
    // Used by the linker to determine what methods can be pruned.
    AttrReflectMethod

    // Local means make the symbol local even when compiling Go code to reference Go
    // symbols in other shared libraries, as in this mode symbols are global by
    // default. "local" here means in the sense of the dynamic linker, i.e. not
    // visible outside of the module (shared library or executable) that contains its
    // definition. (When not compiling to support Go shared libraries, all symbols are
    // local in this sense unless there is a cgo_export_* directive).
    AttrLocal

    // For function symbols; indicates that the specified function was the
    // target of an inline during compilation
    AttrWasInlined

    // Indexed indicates this symbol has been assigned with an index (when using the
    // new object file format).
    AttrIndexed

    // Only applied on type descriptor symbols, UsedInIface indicates this type is
    // converted to an interface.
    //
    // Used by the linker to determine what methods can be pruned.
    AttrUsedInIface

    // ContentAddressable indicates this is a content-addressable symbol.
    AttrContentAddressable

    // ABI wrapper is set for compiler-generated text symbols that
    // convert between ABI0 and ABIInternal calling conventions.
    AttrABIWrapper

    // IsPcdata indicates this is a pcdata symbol.
    AttrPcdata

    // PkgInit indicates this is a compiler-generated package init func.
    AttrPkgInit

    // Linkname indicates this is a go:linkname'd symbol.
    AttrLinkname
)

func (*Attribute) ABI

func (a *Attribute) ABI() ABI

func (*Attribute) ABIWrapper

func (a *Attribute) ABIWrapper() bool

func (*Attribute) CFunc

func (a *Attribute) CFunc() bool

func (*Attribute) ContentAddressable

func (a *Attribute) ContentAddressable() bool

func (*Attribute) DuplicateOK

func (a *Attribute) DuplicateOK() bool

func (*Attribute) Indexed

func (a *Attribute) Indexed() bool

func (*Attribute) IsLinkname

func (a *Attribute) IsLinkname() bool

func (*Attribute) IsPcdata

func (a *Attribute) IsPcdata() bool

func (*Attribute) IsPkgInit

func (a *Attribute) IsPkgInit() bool

func (*Attribute) Leaf

func (a *Attribute) Leaf() bool

func (*Attribute) Local

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

func (*Attribute) NeedCtxt

func (a *Attribute) NeedCtxt() bool

func (*Attribute) NoFrame

func (a *Attribute) NoFrame() bool

func (*Attribute) NoSplit

func (a *Attribute) NoSplit() bool

func (*Attribute) OnList

func (a *Attribute) OnList() bool

func (*Attribute) ReflectMethod

func (a *Attribute) ReflectMethod() bool

func (*Attribute) Set

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

func (*Attribute) SetABI

func (a *Attribute) SetABI(abi ABI)

func (*Attribute) Static

func (a *Attribute) Static() bool

func (Attribute) String

func (a Attribute) String() string

String formats a for printing in as part of a TEXT prog.

func (*Attribute) UsedInIface

func (a *Attribute) UsedInIface() bool

func (*Attribute) WasInlined

func (a *Attribute) WasInlined() bool

func (*Attribute) Wrapper

func (a *Attribute) Wrapper() bool

type Auto

type Auto struct {
    Asym    *LSym
    Aoffset int32
    Name    AddrName
    Gotype  *LSym
}

type BySymName

type BySymName []*LSym

func (BySymName) Len

func (s BySymName) Len() int

func (BySymName) Less

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

func (BySymName) Swap

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

type DwarfFixupTable

This table is designed to aid in the creation of references between DWARF subprogram DIEs.

In most cases when one DWARF DIE has to refer to another DWARF DIE, the target of the reference has an LSym, which makes it easy to use the existing relocation mechanism. For DWARF inlined routine DIEs, however, the subprogram DIE has to refer to a child parameter/variable DIE of the abstract subprogram. This child DIE doesn't have an LSym, and also of interest is the fact that when DWARF generation is happening for inlined function F within caller G, it's possible that DWARF generation hasn't happened yet for F, so there is no way to know the offset of a child DIE within F's abstract function. Making matters more complex, each inlined instance of F may refer to a subset of the original F's variables (depending on what happens with optimization, some vars may be eliminated).

The fixup table below helps overcome this hurdle. At the point where a parameter/variable reference is made (via a call to "ReferenceChildDIE"), a fixup record is generate that records the relocation that is targeting that child variable. At a later point when the abstract function DIE is emitted, there will be a call to "RegisterChildDIEOffsets", at which point the offsets needed to apply fixups are captured. Finally, once the parallel portion of the compilation is done, fixups can actually be applied during the "Finalize" method (this can't be done during the parallel portion of the compile due to the possibility of data races).

This table is also used to record the "precursor" function node for each function that is the target of an inline -- child DIE references have to be made with respect to the original pre-optimization version of the function (to allow for the fact that each inlined body may be optimized differently).

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

func NewDwarfFixupTable

func NewDwarfFixupTable(ctxt *Link) *DwarfFixupTable

func (*DwarfFixupTable) AbsFuncDwarfSym

func (ft *DwarfFixupTable) AbsFuncDwarfSym(fnsym *LSym) *LSym

return the LSym corresponding to the 'abstract subprogram' DWARF info entry for a function.

func (*DwarfFixupTable) Finalize

func (ft *DwarfFixupTable) Finalize(myimportpath string, trace bool)

Called after all functions have been compiled; the main job of this function is to identify cases where there are outstanding fixups. This scenario crops up when we have references to variables of an inlined routine, but that routine is defined in some other package. This helper walks through and locate these fixups, then invokes a helper to create an abstract subprogram DIE for each one.

func (*DwarfFixupTable) GetPrecursorFunc

func (ft *DwarfFixupTable) GetPrecursorFunc(s *LSym) Func

func (*DwarfFixupTable) ReferenceChildDIE

func (ft *DwarfFixupTable) ReferenceChildDIE(s *LSym, ridx int, tgt *LSym, dclidx int, inlIndex int)

Make a note of a child DIE reference: relocation 'ridx' within symbol 's' is targeting child 'c' of DIE with symbol 'tgt'.

func (*DwarfFixupTable) RegisterChildDIEOffsets

func (ft *DwarfFixupTable) RegisterChildDIEOffsets(s *LSym, vars []*dwarf.Var, coffsets []int32)

Called once DWARF generation is complete for a given abstract function, whose children might have been referenced via a call above. Stores the offsets for any child DIEs (vars, params) so that they can be consumed later in on DwarfFixupTable.Finalize, which applies any outstanding fixups.

func (*DwarfFixupTable) SetPrecursorFunc

func (ft *DwarfFixupTable) SetPrecursorFunc(s *LSym, fn Func)

type FileInfo

A FileInfo contains extra fields for SDATA symbols backed by files. (If LSym.Extra is a *FileInfo, LSym.P == nil.)

type FileInfo struct {
    Name string // name of file to read into object file
    Size int64  // length of file
}

type Func

A Func represents a Go function. If non-nil, it must be a *ir.Func.

type Func interface {
    Pos() src.XPos
}

type FuncInfo

A FuncInfo contains extra fields for STEXT symbols.

type FuncInfo struct {
    Args      int32
    Locals    int32
    Align     int32
    FuncID    abi.FuncID
    FuncFlag  abi.FuncFlag
    StartLine int32
    Text      *Prog
    Autot     map[*LSym]struct{}
    Pcln      Pcln
    InlMarks  []InlMark

    GCArgs             *LSym
    GCLocals           *LSym
    StackObjects       *LSym
    OpenCodedDeferInfo *LSym
    ArgInfo            *LSym // argument info for traceback
    ArgLiveInfo        *LSym // argument liveness info for traceback
    WrapInfo           *LSym // for wrapper, info of wrapped function
    JumpTables         []JumpTable

    FuncInfoSym   *LSym
    WasmImportSym *LSym
    WasmImport    *WasmImport
    // contains filtered or unexported fields
}

func (*FuncInfo) AddInlMark

func (fi *FuncInfo) AddInlMark(p *Prog, id int32)

Mark p as the instruction to set as the pc when "unwinding" the inlining global frame id. Usually it should be instruction with a file:line at the callsite, and occur just before the body of the inlined function.

func (*FuncInfo) AddSpill

func (fi *FuncInfo) AddSpill(s RegSpill)

AddSpill appends a spill record to the list for FuncInfo fi

func (*FuncInfo) RecordAutoType

func (fi *FuncInfo) RecordAutoType(gotype *LSym)

Record the type symbol for an auto variable so that the linker an emit DWARF type information for the type.

func (*FuncInfo) SpillRegisterArgs

func (fi *FuncInfo) SpillRegisterArgs(last *Prog, pa ProgAlloc) *Prog

SpillRegisterArgs emits the code to spill register args into whatever locations the spill records specify.

func (*FuncInfo) UnspillRegisterArgs

func (fi *FuncInfo) UnspillRegisterArgs(last *Prog, pa ProgAlloc) *Prog

UnspillRegisterArgs emits the code to restore register args from whatever locations the spill records specify.

type InlMark

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

type InlTree

InlTree is a collection of inlined calls. The Parent field of an InlinedCall is the index of another InlinedCall in InlTree.

The compiler maintains a global inlining tree and adds a node to it every time a function is inlined. For example, suppose f() calls g() and g has two calls to h(), and that f, g, and h are inlineable:

 1 func main() {
 2     f()
 3 }
 4 func f() {
 5     g()
 6 }
 7 func g() {
 8     h()
 9     h()
10 }
11 func h() {
12     println("H")
13 }

Assuming the global tree starts empty, inlining will produce the following tree:

[]InlinedCall{
  {Parent: -1, Func: "f", Pos: <line 2>},
  {Parent:  0, Func: "g", Pos: <line 5>},
  {Parent:  1, Func: "h", Pos: <line 8>},
  {Parent:  1, Func: "h", Pos: <line 9>},
}

The nodes of h inlined into main will have inlining indexes 2 and 3.

Eventually, the compiler extracts a per-function inlining tree from the global inlining tree (see pcln.go).

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

func (*InlTree) Add

func (tree *InlTree) Add(parent int, pos src.XPos, func_ *LSym, name string) int

Add adds a new call to the tree, returning its index.

func (*InlTree) AllParents

func (tree *InlTree) AllParents(inlIndex int, do func(InlinedCall))

AllParents invokes do on each InlinedCall in the inlining call stack, from outermost to innermost.

That is, if inlIndex corresponds to f inlining g inlining h, AllParents invokes do with the call for inlining g into f, and then inlining h into g.

func (*InlTree) CallPos

func (tree *InlTree) CallPos(inlIndex int) src.XPos

func (*InlTree) InlinedFunction

func (tree *InlTree) InlinedFunction(inlIndex int) *LSym

func (*InlTree) Parent

func (tree *InlTree) Parent(inlIndex int) int

type InlinedCall

InlinedCall is a node in an InlTree.

type InlinedCall struct {
    Parent   int      // index of the parent in the InlTree or < 0 if outermost call
    Pos      src.XPos // position of the inlined call
    Func     *LSym    // function that was inlined
    Name     string   // bare name of the function (w/o package prefix)
    ParentPC int32    // PC of instruction just before inlined body. Only valid in local trees.
}

type JumpTable

JumpTable represents a table used for implementing multi-way computed branching, used typically for implementing switches. Sym is the table itself, and Targets is a list of target instructions to go to for the computed branch index.

type JumpTable struct {
    Sym     *LSym
    Targets []*Prog
}

type LSym

An LSym is the sort of symbol that is written to an object file. It represents Go symbols in a flat pkg+"."+name namespace.

type LSym struct {
    Name string
    Type objabi.SymKind
    Attribute

    Size   int64
    Gotype *LSym
    P      []byte
    R      []Reloc

    Extra *interface{} // *FuncInfo, *VarInfo, *FileInfo, or *TypeInfo, if present

    Pkg    string
    PkgIdx int32
    SymIdx int32
}

func (*LSym) CanBeAnSSAAux

func (*LSym) CanBeAnSSAAux()

func (*LSym) CanBeAnSSASym

func (*LSym) CanBeAnSSASym()

The compiler needs *LSym to be assignable to cmd/compile/internal/ssa.Sym.

func (*LSym) File

func (s *LSym) File() *FileInfo

File returns the *FileInfo associated with s, or else nil.

func (*LSym) Func

func (s *LSym) Func() *FuncInfo

Func returns the *FuncInfo associated with s, or else nil.

func (*LSym) Grow

func (s *LSym) Grow(lsiz int64)

Grow increases the length of s.P to lsiz.

func (*LSym) GrowCap

func (s *LSym) GrowCap(c int64)

GrowCap increases the capacity of s.P to c.

func (*LSym) NewFileInfo

func (s *LSym) NewFileInfo() *FileInfo

NewFileInfo allocates and returns a FileInfo for LSym.

func (*LSym) NewFuncInfo

func (s *LSym) NewFuncInfo() *FuncInfo

NewFuncInfo allocates and returns a FuncInfo for LSym.

func (*LSym) NewTypeInfo

func (s *LSym) NewTypeInfo() *TypeInfo

func (*LSym) NewVarInfo

func (s *LSym) NewVarInfo() *VarInfo

NewVarInfo allocates and returns a VarInfo for LSym.

func (*LSym) String

func (s *LSym) String() string

func (*LSym) TextAttrString

func (s *LSym) TextAttrString() string

TextAttrString formats the symbol attributes for printing in as part of a TEXT prog.

func (*LSym) VarInfo

func (s *LSym) VarInfo() *VarInfo

VarInfo returns the *VarInfo associated with s, or else nil.

func (*LSym) WriteAddr

func (s *LSym) WriteAddr(ctxt *Link, off int64, siz int, rsym *LSym, roff int64)

WriteAddr writes an address of size siz into s at offset off. rsym and roff specify the relocation for the address.

func (*LSym) WriteBytes

func (s *LSym) WriteBytes(ctxt *Link, off int64, b []byte) int64

WriteBytes writes a slice of bytes into s at offset off.

func (*LSym) WriteCURelativeAddr

func (s *LSym) WriteCURelativeAddr(ctxt *Link, off int64, rsym *LSym, roff int64)

WriteCURelativeAddr writes a pointer-sized address into s at offset off. rsym and roff specify the relocation for the address which will be resolved by the linker to an offset from the DW_AT_low_pc attribute of the DWARF Compile Unit of rsym.

func (*LSym) WriteFloat32

func (s *LSym) WriteFloat32(ctxt *Link, off int64, f float32)

WriteFloat32 writes f into s at offset off.

func (*LSym) WriteFloat64

func (s *LSym) WriteFloat64(ctxt *Link, off int64, f float64)

WriteFloat64 writes f into s at offset off.

func (*LSym) WriteInt

func (s *LSym) WriteInt(ctxt *Link, off int64, siz int, i int64)

WriteInt writes an integer i of size siz into s at offset off.

func (*LSym) WriteOff

func (s *LSym) WriteOff(ctxt *Link, off int64, rsym *LSym, roff int64)

WriteOff writes a 4 byte offset to rsym+roff into s at offset off. After linking the 4 bytes stored at s+off will be rsym+roff-(start of section that s is in).

func (*LSym) WriteString

func (s *LSym) WriteString(ctxt *Link, off int64, siz int, str string)

WriteString writes a string of size siz into s at offset off.

func (*LSym) WriteWeakAddr

func (s *LSym) WriteWeakAddr(ctxt *Link, off int64, siz int, rsym *LSym, roff int64)

WriteWeakAddr writes an address of size siz into s at offset off. rsym and roff specify the relocation for the address. This is a weak reference.

func (*LSym) WriteWeakOff

func (s *LSym) WriteWeakOff(ctxt *Link, off int64, rsym *LSym, roff int64)

WriteWeakOff writes a weak 4 byte offset to rsym+roff into s at offset off. After linking the 4 bytes stored at s+off will be rsym+roff-(start of section that s is in).

Link holds the context for writing object code from a compiler to be linker input or for reading that input into the linker.

type Link struct {
    Headtype           objabi.HeadType
    Arch               *LinkArch
    Debugasm           int
    Debugvlog          bool
    Debugpcln          string
    Flag_shared        bool
    Flag_dynlink       bool
    Flag_linkshared    bool
    Flag_optimize      bool
    Flag_locationlists bool
    Flag_noRefName     bool   // do not include referenced symbol names in object file
    Retpoline          bool   // emit use of retpoline stubs for indirect jmp/call
    Flag_maymorestack  string // If not "", call this function before stack checks
    Bso                *bufio.Writer
    Pathname           string
    Pkgpath            string // the current package's import path

    PosTable        src.PosTable
    InlTree         InlTree // global inlining tree used by gc/inl.go
    DwFixups        *DwarfFixupTable
    Imports         []goobj.ImportedPkg
    DiagFunc        func(string, ...interface{})
    DiagFlush       func()
    DebugInfo       func(fn *LSym, info *LSym, curfn Func) ([]dwarf.Scope, dwarf.InlCalls)
    GenAbstractFunc func(fn *LSym)
    Errors          int

    InParallel    bool // parallel backend phase in effect
    UseBASEntries bool // use Base Address Selection Entries in location lists and PC ranges
    IsAsm         bool // is the source assembly language, which may contain surprising idioms (e.g., call tables)
    Std           bool // is standard library package

    // state for writing objects
    Text []*LSym
    Data []*LSym

    // Windows SEH symbols are also data symbols that can be created
    // concurrently.
    SEHSyms []*LSym

    Fingerprint goobj.FingerprintType // fingerprint of symbol indices, to catch index mismatch
    // contains filtered or unexported fields
}

func Linknew

func Linknew(arch *LinkArch) *Link

func (*Link) AddImport

func (ctxt *Link) AddImport(pkg string, fingerprint goobj.FingerprintType)

AddImport adds a package to the list of imported packages.

func (*Link) AllPos

func (ctxt *Link) AllPos(xpos src.XPos, do func(src.Pos))

AllPos invokes do with every position in the inlining call stack for xpos, from outermost to innermost. That is, xpos corresponds to f inlining g inlining h, AllPos invokes do with the position in f, then the position in g, then the position in h.

func (*Link) CanReuseProgs

func (ctxt *Link) CanReuseProgs() bool

func (*Link) Diag

func (ctxt *Link) Diag(format string, args ...interface{})

func (*Link) DwarfAbstractFunc

func (ctxt *Link) DwarfAbstractFunc(curfn Func, s *LSym)

func (*Link) DwarfGlobal

func (ctxt *Link) DwarfGlobal(typename string, varSym *LSym)

DwarfGlobal creates a link symbol containing a DWARF entry for a global variable.

func (*Link) DwarfIntConst

func (ctxt *Link) DwarfIntConst(name, typename string, val int64)

DwarfIntConst creates a link symbol for an integer constant with the given name, type and value.

func (*Link) EmitEntryLiveness

func (ctxt *Link) EmitEntryLiveness(s *LSym, p *Prog, newprog ProgAlloc) *Prog

EmitEntryLiveness generates PCDATA Progs after p to switch to the liveness map active at the entry of function s. It returns the last Prog generated.

func (*Link) EmitEntryStackMap

func (ctxt *Link) EmitEntryStackMap(s *LSym, p *Prog, newprog ProgAlloc) *Prog

Similar to EmitEntryLiveness, but just emit stack map.

func (*Link) EmitEntryUnsafePoint

func (ctxt *Link) EmitEntryUnsafePoint(s *LSym, p *Prog, newprog ProgAlloc) *Prog

Similar to EmitEntryLiveness, but just emit unsafe point map.

func (*Link) EndUnsafePoint

func (ctxt *Link) EndUnsafePoint(p *Prog, newprog ProgAlloc, oldval int64) *Prog

EndUnsafePoint generates PCDATA Progs after p to mark the end of an unsafe point, restoring the register map index to oldval. The unsafe point ends right after p. It returns the last Prog generated.

func (*Link) Float32Sym

func (ctxt *Link) Float32Sym(f float32) *LSym

func (*Link) Float64Sym

func (ctxt *Link) Float64Sym(f float64) *LSym

func (*Link) GCLocalsSym

func (ctxt *Link) GCLocalsSym(data []byte) *LSym

GCLocalsSym generates a content-addressable sym containing data.

func (*Link) Globl

func (ctxt *Link) Globl(s *LSym, size int64, flag int)

func (*Link) GloblPos

func (ctxt *Link) GloblPos(s *LSym, size int64, flag int, pos src.XPos)

func (*Link) InitTextSym

func (ctxt *Link) InitTextSym(s *LSym, flag int, start src.XPos)

func (*Link) InnermostPos

func (ctxt *Link) InnermostPos(xpos src.XPos) src.Pos

InnermostPos returns the innermost position corresponding to xpos, that is, the code that is inlined and that inlines nothing else. In the example for InlTree above, the code for println within h would have an innermost position with line number 12, whether h was not inlined, inlined into g, g-then-f, or g-then-f-then-main. This corresponds to what someone debugging main, f, g, or h might expect to see while single-stepping.

func (*Link) Int128Sym

func (ctxt *Link) Int128Sym(hi, lo int64) *LSym

func (*Link) Int32Sym

func (ctxt *Link) Int32Sym(i int64) *LSym

func (*Link) Int64Sym

func (ctxt *Link) Int64Sym(i int64) *LSym

func (*Link) Logf

func (ctxt *Link) Logf(format string, args ...interface{})

func (*Link) Lookup

func (ctxt *Link) Lookup(name string) *LSym

Lookup looks up the symbol with name name. If it does not exist, it creates it.

func (*Link) LookupABI

func (ctxt *Link) LookupABI(name string, abi ABI) *LSym

LookupABI looks up a symbol with the given ABI. If it does not exist, it creates it.

func (*Link) LookupABIInit

func (ctxt *Link) LookupABIInit(name string, abi ABI, init func(s *LSym)) *LSym

LookupABIInit looks up a symbol with the given ABI. If it does not exist, it creates it and passes it to init for one-time initialization.

func (*Link) LookupDerived

func (ctxt *Link) LookupDerived(s *LSym, name string) *LSym

LookupDerived looks up or creates the symbol with name derived from symbol s. The resulting symbol will be static iff s is.

func (*Link) LookupInit

func (ctxt *Link) LookupInit(name string, init func(s *LSym)) *LSym

LookupInit looks up the symbol with name name. If it does not exist, it creates it and passes it to init for one-time initialization.

func (*Link) LookupStatic

func (ctxt *Link) LookupStatic(name string) *LSym

LookupStatic looks up the static symbol with name name. If it does not exist, it creates it.

func (*Link) NewProg

func (ctxt *Link) NewProg() *Prog

func (*Link) NumberSyms

func (ctxt *Link) NumberSyms()

Assign index to symbols. asm is set to true if this is called by the assembler (i.e. not the compiler), in which case all the symbols are non-package (for now).

func (*Link) OutermostPos

func (ctxt *Link) OutermostPos(xpos src.XPos) src.Pos

OutermostPos returns the outermost position corresponding to xpos, which is where xpos was ultimately inlined to. In the example for InlTree, main() contains inlined AST nodes from h(), but the outermost position for those nodes is line 2.

func (*Link) StartUnsafePoint

func (ctxt *Link) StartUnsafePoint(p *Prog, newprog ProgAlloc) *Prog

StartUnsafePoint generates PCDATA Progs after p to mark the beginning of an unsafe point. The unsafe point starts immediately after p. It returns the last Prog generated.

type LinkArch

LinkArch is the definition of a single architecture.

type LinkArch struct {
    *sys.Arch
    Init           func(*Link)
    ErrorCheck     func(*Link, *LSym)
    Preprocess     func(*Link, *LSym, ProgAlloc)
    Assemble       func(*Link, *LSym, ProgAlloc)
    Progedit       func(*Link, *Prog, ProgAlloc)
    SEH            func(*Link, *LSym) *LSym
    UnaryDst       map[As]bool // Instruction takes one operand, a destination.
    DWARFRegisters map[int16]int16
}

type OperandPos

type OperandPos int8
const (
    Source OperandPos = iota
    Destination
)

type PCIter

PCIter iterates over encoded pcdata tables.

type PCIter struct {
    PC      uint32
    NextPC  uint32
    PCScale uint32
    Value   int32

    Done bool
    // contains filtered or unexported fields
}

func NewPCIter

func NewPCIter(pcScale uint32) *PCIter

NewPCIter creates a PCIter with a scale factor for the PC step size.

func (*PCIter) Init

func (it *PCIter) Init(p []byte)

init prepares it to iterate over p, and advances it to the first pc.

func (*PCIter) Next

func (it *PCIter) Next()

Next advances it to the Next pc.

type Pcln

type Pcln struct {
    // Aux symbols for pcln
    Pcsp      *LSym
    Pcfile    *LSym
    Pcline    *LSym
    Pcinline  *LSym
    Pcdata    []*LSym
    Funcdata  []*LSym
    UsedFiles map[goobj.CUFileIndex]struct{} // file indices used while generating pcfile
    InlTree   InlTree                        // per-function inlining tree extracted from the global tree
}

type Plist

type Plist struct {
    Firstpc *Prog
    Curfn   Func
}

type Prog

Prog describes a single machine instruction.

The general instruction form is:

(1) As.Scond From [, ...RestArgs], To
(2) As.Scond From, Reg [, ...RestArgs], To, RegTo2

where As is an opcode and the others are arguments: From, Reg are sources, and To, RegTo2 are destinations. RestArgs can hold additional sources and destinations. Usually, not all arguments are present. For example, MOVL R1, R2 encodes using only As=MOVL, From=R1, To=R2. The Scond field holds additional condition bits for systems (like arm) that have generalized conditional execution. (2) form is present for compatibility with older code, to avoid too much changes in a single swing. (1) scheme is enough to express any kind of operand combination.

Jump instructions use the To.Val field to point to the target *Prog, which must be in the same linked list as the jump instruction.

The Progs for a given function are arranged in a list linked through the Link field.

Each Prog is charged to a specific source line in the debug information, specified by Pos.Line(). Every Prog has a Ctxt field that defines its context. For performance reasons, Progs are usually bulk allocated, cached, and reused; those bulk allocators should always be used, rather than new(Prog).

The other fields not yet mentioned are for use by the back ends and should be left zeroed by creators of Prog lists.

type Prog struct {
    Ctxt     *Link     // linker context
    Link     *Prog     // next Prog in linked list
    From     Addr      // first source operand
    RestArgs []AddrPos // can pack any operands that not fit into {Prog.From, Prog.To}, same kinds of operands are saved in order
    To       Addr      // destination operand (second is RegTo2 below)
    Pool     *Prog     // constant pool entry, for arm,arm64 back ends
    Forwd    *Prog     // for x86 back end
    Rel      *Prog     // for x86, arm back ends
    Pc       int64     // for back ends or assembler: virtual or actual program counter, depending on phase
    Pos      src.XPos  // source position of this instruction
    Spadj    int32     // effect of instruction on stack pointer (increment or decrement amount)
    As       As        // assembler opcode
    Reg      int16     // 2nd source operand
    RegTo2   int16     // 2nd destination operand
    Mark     uint16    // bitmask of arch-specific items
    Optab    uint16    // arch-specific opcode index
    Scond    uint8     // bits that describe instruction suffixes (e.g. ARM conditions, RISCV Rounding Mode)
    Back     uint8     // for x86 back end: backwards branch state
    Ft       uint8     // for x86 back end: type index of Prog.From
    Tt       uint8     // for x86 back end: type index of Prog.To
    Isize    uint8     // for x86 back end: size of the instruction in bytes
}

func Appendp

func Appendp(q *Prog, newprog ProgAlloc) *Prog

func (*Prog) AddRestDest

func (p *Prog) AddRestDest(a Addr)

AddRestDest assigns []Args{{a, Destination}} to p.RestArgs when the second destination operand does not fit into prog.RegTo2.

func (*Prog) AddRestSource

func (p *Prog) AddRestSource(a Addr)

AddRestSource assigns []Args{{a, Source}} to p.RestArgs.

func (*Prog) AddRestSourceArgs

func (p *Prog) AddRestSourceArgs(args []Addr)

AddRestSourceArgs assigns more than one source operands to p.RestArgs.

func (*Prog) AddRestSourceConst

func (p *Prog) AddRestSourceConst(off int64)

AddRestSourceConst calls p.AddRestSource with a const Addr containing off.

func (*Prog) AddRestSourceReg

func (p *Prog) AddRestSourceReg(reg int16)

AddRestSourceReg calls p.AddRestSource with a register Addr containing reg.

func (*Prog) From3Type

func (p *Prog) From3Type() AddrType

From3Type returns p.GetFrom3().Type, or TYPE_NONE when p.GetFrom3() returns nil.

func (*Prog) GetFrom3

func (p *Prog) GetFrom3() *Addr

GetFrom3 returns second source operand (the first is Prog.From). The same kinds of operands are saved in order so GetFrom3 actually return the first source operand in p.RestArgs. In combination with Prog.From and Prog.To it makes common 3 operand case easier to use.

func (*Prog) GetTo2

func (p *Prog) GetTo2() *Addr

GetTo2 returns the second destination operand. The same kinds of operands are saved in order so GetTo2 actually return the first destination operand in Prog.RestArgs[]

func (*Prog) InnermostFilename

func (p *Prog) InnermostFilename() string

InnermostFilename returns a string containing the innermost (in inlining) filename at p's position

func (*Prog) InnermostLine

func (p *Prog) InnermostLine(w io.Writer)

func (*Prog) InnermostLineNumber

func (p *Prog) InnermostLineNumber() string

InnermostLineNumber returns a string containing the line number for the innermost inlined function (if any inlining) at p's position

func (*Prog) InnermostLineNumberHTML

func (p *Prog) InnermostLineNumberHTML() string

InnermostLineNumberHTML returns a string containing the line number for the innermost inlined function (if any inlining) at p's position

func (*Prog) InnermostString

func (p *Prog) InnermostString(w io.Writer)

func (*Prog) InstructionString

func (p *Prog) InstructionString() string

InstructionString returns a string representation of the instruction without preceding program counter or file and line number.

func (*Prog) Line

func (p *Prog) Line() string

Line returns a string containing the filename and line number for p

func (*Prog) String

func (p *Prog) String() string

func (*Prog) WriteInstructionString

func (p *Prog) WriteInstructionString(w io.Writer)

WriteInstructionString writes a string representation of the instruction without preceding program counter or file and line number.

type ProgAlloc

ProgAlloc is a function that allocates Progs. It is used to provide access to cached/bulk-allocated Progs to the assemblers.

type ProgAlloc func() *Prog

type RegSpill

RegSpill provides spill/fill information for a register-resident argument to a function. These need spilling/filling in the safepoint/stackgrowth case. At the time of fill/spill, the offset must be adjusted by the architecture-dependent adjustment to hardware SP that occurs in a call instruction. E.g., for AMD64, at Offset+8 because the return address was pushed.

type RegSpill struct {
    Addr           Addr
    Reg            int16
    Spill, Unspill As
}

type Reloc

type Reloc struct {
    Off  int32
    Siz  uint8
    Type objabi.RelocType
    Add  int64
    Sym  *LSym
}

func Addrel

func Addrel(s *LSym) *Reloc

type TypeInfo

A TypeInfo contains information for a symbol that contains a runtime._type.

type TypeInfo struct {
    Type interface{} // a *cmd/compile/internal/types.Type
}

type VarInfo

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

type WasmField

type WasmField struct {
    Type WasmFieldType
    // Offset holds the frame-pointer-relative locations for Go's stack-based
    // ABI. This is used by the src/cmd/internal/wasm package to map WASM
    // import parameters to the Go stack in a wrapper function.
    Offset int64
}

type WasmFieldType

type WasmFieldType byte
const (
    WasmI32 WasmFieldType = iota
    WasmI64
    WasmF32
    WasmF64
    WasmPtr
)

type WasmImport

WasmImport represents a WebAssembly (WASM) imported function with parameters and results translated into WASM types based on the Go function declaration.

type WasmImport struct {
    // Module holds the WASM module name specified by the //go:wasmimport
    // directive.
    Module string
    // Name holds the WASM imported function name specified by the
    // //go:wasmimport directive.
    Name string
    // Params holds the imported function parameter fields.
    Params []WasmField
    // Results holds the imported function result fields.
    Results []WasmField
}

func (*WasmImport) CreateSym

func (wi *WasmImport) CreateSym(ctxt *Link) *LSym