abi

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// RAX, RBX, RCX, RDI, RSI, R8, R9, R10, R11.
	IntArgRegs = 9

	// X0 -> X14.
	FloatArgRegs = 15

	// We use SSE2 registers which support 64-bit float operations.
	EffectiveFloatRegSize = 8
)
View Source
const (
	MapBucketCountBits = 3 // log2 of number of elements in a bucket.
	MapBucketCount     = 1 << MapBucketCountBits
	MapMaxKeyBytes     = 128 // Must fit in a uint8.
	MapMaxElemBytes    = 128 // Must fit in a uint8.
)

Map constants common to several packages runtime/runtime-gdb.py:MapTypePrinter contains its own copy

View Source
const (
	// StackNosplitBase is the base maximum number of bytes that a chain of
	// NOSPLIT functions can use.
	//
	// This value must be multiplied by the stack guard multiplier, so do not
	// use it directly. See runtime/stack.go:stackNosplit and
	// cmd/internal/objabi/stack.go:StackNosplit.
	StackNosplitBase = 800

	// After a stack split check the SP is allowed to be StackSmall bytes below
	// the stack guard.
	//
	// Functions that need frames <= StackSmall can perform the stack check
	// using a single comparison directly between the stack guard and the SP
	// because we ensure that StackSmall bytes of stack space are available
	// beyond the stack guard.
	StackSmall = 128

	// Functions that need frames <= StackBig can assume that neither
	// SP-framesize nor stackGuard-StackSmall will underflow, and thus use a
	// more efficient check. In order to ensure this, StackBig must be <= the
	// size of the unmapped space at zero.
	StackBig = 4096
)
View Source
const (
	PCDATA_UnsafePoint   = 0
	PCDATA_StackMapIndex = 1
	PCDATA_InlTreeIndex  = 2
	PCDATA_ArgLiveIndex  = 3

	FUNCDATA_ArgsPointerMaps    = 0
	FUNCDATA_LocalsPointerMaps  = 1
	FUNCDATA_StackObjects       = 2
	FUNCDATA_InlTree            = 3
	FUNCDATA_OpenCodedDeferInfo = 4
	FUNCDATA_ArgInfo            = 5
	FUNCDATA_ArgLiveInfo        = 6
	FUNCDATA_WrapInfo           = 7
)

IDs for PCDATA and FUNCDATA tables in Go binaries.

These must agree with ../../../runtime/funcdata.h.

View Source
const (
	UnsafePointSafe   = -1 // Safe for async preemption
	UnsafePointUnsafe = -2 // Unsafe for async preemption

	// UnsafePointRestart1(2) apply on a sequence of instructions, within
	// which if an async preemption happens, we should back off the PC
	// to the start of the sequence when resuming.
	// We need two so we can distinguish the start/end of the sequence
	// in case that two sequences are next to each other.
	UnsafePointRestart1 = -3
	UnsafePointRestart2 = -4

	// Like UnsafePointRestart1, but back to function entry if async preempted.
	UnsafePointRestartAtEntry = -5
)

Special values for the PCDATA_UnsafePoint table.

View Source
const (
	// TODO (khr, drchase) why aren't these in TFlag?  Investigate, fix if possible.
	KindDirectIface = 1 << 5
	KindGCProg      = 1 << 6 // Type.gc points to GC program
	KindMask        = (1 << 5) - 1
)
View Source
const ArgsSizeUnknown = -0x80000000

ArgsSizeUnknown is set in Func.argsize to mark all functions whose argument size is unknown (C vararg functions, and assembly code without an explicit specification). This value is generated by the compiler, assembler, or linker.

Variables

This section is empty.

Functions

func CommonSize

func CommonSize(ptrSize int) int

CommonSize returns sizeof(Type) for a compilation target with a given ptrSize

func FuncPCABI0

func FuncPCABI0(f interface{}) uintptr

FuncPCABI0 returns the entry PC of the function f, which must be a direct reference of a function defined as ABI0. Otherwise it is a compile-time error.

Implemented as a compile intrinsic.

func FuncPCABIInternal

func FuncPCABIInternal(f interface{}) uintptr

FuncPCABIInternal returns the entry PC of the function f. If f is a direct reference of a function, it must be defined as ABIInternal. Otherwise it is a compile-time error. If f is not a direct reference of a defined function, it assumes that f is a func value. Otherwise the behavior is undefined.

Implemented as a compile intrinsic.

func GetItab

func GetItab(inter *InterfaceType, typ *Type) (*Itab, GetItabResult)

func IMethodSize

func IMethodSize(ptrSize int) int

IMethodSize returns sizeof(IMethod) for a compilation target with a given ptrSize

func KindOff

func KindOff(ptrSize int) int

KindOff returns the offset of Type.Kind_ for a compilation target with a given ptrSize

func PtrBytesOff

func PtrBytesOff(ptrSize int) int

PtrBytes returns the offset of Type.PtrBytes for a compilation target with a given ptrSize

func SizeOff

func SizeOff(ptrSize int) int

SizeOff returns the offset of Type.Size_ for a compilation target with a given ptrSize

func StructFieldSize

func StructFieldSize(ptrSize int) int

StructFieldSize returns sizeof(StructField) for a compilation target with a given ptrSize

func TFlagOff

func TFlagOff(ptrSize int) int

TFlagOff returns the offset of Type.TFlag for a compilation target with a given ptrSize

func UncommonSize

func UncommonSize() uint64

UncommonSize returns sizeof(UncommonType). This currently does not depend on ptrSize. This exported function is in an internal package, so it may change to depend on ptrSize in the future.

Types

type ArrayType

type ArrayType struct {
	Type
	Elem  *Type // array element type
	Slice *Type // slice type
	Len   uintptr
}

ArrayType represents a fixed array type.

NOTE: The type name has to be ArrayType, as expected by dwarf See ${GOROOT}/src/cmd/link/internal/ld/dwarf.go#func:dwarfGenerateDebugInfo

type BitVector

type BitVector struct {
	N        int32 // # of bits
	ByteData *uint8
}

Information from the compiler about the layout of stack frames. Note: this type must agree with reflect.bitVector.

type ChanDir

type ChanDir int
const (
	ChanDirRecv    ChanDir = 1 << iota                 // <-chan
	ChanDirSend                                        // chan<-
	ChanDirBoth            = ChanDirRecv | ChanDirSend // chan
	ChanDirInvalid ChanDir = 0
)

type ChanType

type ChanType struct {
	Type
	Elem *Type
	Dir  ChanDir
}

ChanType represents a channel type

NOTE: The type name has to be ChanType, as expected by dwarf See ${GOROOT}/src/cmd/link/internal/ld/dwarf.go#func:dwarfGenerateDebugInfo

type Func

type Func struct {
	DeferReturn uint32 // offset of start of a deferreturn call instruction from entry, if any.

	PCSP   uint32
	PCFile uint32
	PCLn   uint32

	StartLine int32  // line number of start of function (func keyword/TEXT directive)
	FuncID    FuncID // set for certain special runtime functions
	Flag      FuncFlag
	// contains filtered or unexported fields
}

Layout of in-memory per-function information prepared by linker See https://golang.org/s/go12symtab. Keep in sync with linker (../cmd/link/internal/ld/pcln.go:/pclntab) and with package debug/gosym and with symtab.go in package runtime.

see $GOROOT/src/runtime/runtime2.go#type:_func

func (*Func) IsInlined

func (f *Func) IsInlined() bool

IsInlined reports whether f should be re-interpreted as a *funcinl.

type FuncFlag

type FuncFlag uint8

A FuncFlag records bits about a function, passed to the runtime.

const (
	// FuncFlagTopFrame indicates a function that appears at the top of its stack.
	// The traceback routine stop at such a function and consider that a
	// successful, complete traversal of the stack.
	// Examples of TopFrame functions include goexit, which appears
	// at the top of a user goroutine stack, and mstart, which appears
	// at the top of a system goroutine stack.
	FuncFlagTopFrame FuncFlag = 1 << iota

	// FuncFlagSPWrite indicates a function that writes an arbitrary value to SP
	// (any write other than adding or subtracting a constant amount).
	// The traceback routines cannot encode such changes into the
	// pcsp tables, so the function traceback cannot safely unwind past
	// SPWrite functions. Stopping at an SPWrite function is considered
	// to be an incomplete unwinding of the stack. In certain contexts
	// (in particular garbage collector stack scans) that is a fatal error.
	FuncFlagSPWrite

	// FuncFlagAsm indicates that a function was implemented in assembly.
	FuncFlagAsm
)

type FuncID

type FuncID uint8

A FuncID identifies particular functions that need to be treated specially by the runtime. Note that in some situations involving plugins, there may be multiple copies of a particular special runtime function.

const (
	FuncIDNormal FuncID = iota // not a special function
	FuncID_abort
	FuncID_asmcgocall
	FuncID_asyncPreempt
	FuncID_cgocallback
	FuncID_debugCallV2
	FuncID_gcBgMarkWorker
	FuncID_goexit
	FuncID_gogo
	FuncID_gopanic
	FuncID_handleAsyncEvent
	FuncID_mcall
	FuncID_morestack
	FuncID_mstart
	FuncID_panicwrap
	FuncID_rt0_go
	FuncID_runfinq
	FuncID_runtime_main
	FuncID_sigpanic
	FuncID_systemstack
	FuncID_systemstack_switch
	FuncIDWrapper // any autogenerated code (hash/eq algorithms, method wrappers, etc.)
)

type FuncInfo

type FuncInfo struct {
	*Func
	Datap *ModuleData
}

func FindFunc

func FindFunc(pc uintptr) FuncInfo

FindFunc looks up function metadata for a PC.

It is nosplit because it's part of the isgoexception implementation.

func (FuncInfo) Entry

func (f FuncInfo) Entry() uintptr

Entry returns the entry PC for f.

func (FuncInfo) Name

func (f FuncInfo) Name() string

Name is something like "main.(*T).F".

func (FuncInfo) Valid

func (f FuncInfo) Valid() bool

type FuncInl

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

Pseudo-Func that is returned for PCs that occur in inlined code. A *Func can be either a *_func or a *FuncInl, and they are distinguished by the first uintptr.

TODO(austin): Can we merge this with inlinedCall?

type FuncTab

type FuncTab struct {
	Entryoff uint32 // relative to runtime.text
	Funcoff  uint32
}

type FuncType

type FuncType struct {
	Type
	InCount  uint16
	OutCount uint16 // top bit is set if last input parameter is ...
}

funcType represents a function type.

A *Type for each in and out parameter is stored in an array that directly follows the funcType (and possibly its uncommonType). So a function type with one method, one input, and one output is:

struct {
	funcType
	uncommonType
	[2]*rtype    // [0] is in, [1] is out
}

NOTE: The type name has to be `FuncType`, as expected by dwarf See ${GOROOT}/src/cmd/link/internal/ld/dwarf.go#func:dwarfGenerateDebugInfo

func (*FuncType) In

func (t *FuncType) In(i int) *Type

func (*FuncType) InSlice

func (t *FuncType) InSlice() []*Type

func (*FuncType) IsVariadic

func (t *FuncType) IsVariadic() bool

func (*FuncType) NumIn

func (t *FuncType) NumIn() int

func (*FuncType) NumOut

func (t *FuncType) NumOut() int

func (*FuncType) Out

func (t *FuncType) Out(i int) *Type

func (*FuncType) OutSlice

func (t *FuncType) OutSlice() []*Type

type FuncVal

type FuncVal struct {
	Fn uintptr
}

type GetItabResult

type GetItabResult uint8
const (
	GetItabResult_OK GetItabResult = iota
	GetItabResult_UncommonType
	GetItabResult_
)

type Imethod

type Imethod struct {
	Name NameOff // name of method
	Typ  TypeOff // .(*FuncType) underneath
}

Imethod represents a method on an interface type

NOTE: The type name has to be `Imethod`, as expected by dwarf See ${GOROOT}/src/cmd/link/internal/ld/dwarf.go#func:dwarfGenerateDebugInfo

type InitTask

type InitTask struct {
	State uint32 // 0 = uninitialized, 1 = in progress, 2 = done
	NFns  uint32
	// contains filtered or unexported fields
}

An InitTask represents the set of initializations that need to be done for a package. Keep in sync with ../../test/noinit.go:InitTask

see $GOROOT/src/runtime/proc.go#type:initTask

func (*InitTask) Nth

func (tsk *InitTask) Nth(i uint32) func()

Nth returns the i-th init() function in the InitTask.

i MUST be in range [0, tsk.NFns).

type IntArgRegBitmap

type IntArgRegBitmap [(IntArgRegs + 7) / 8]uint8

IntArgRegBitmap is a bitmap large enough to hold one bit per integer argument/return register.

func (*IntArgRegBitmap) Get

func (b *IntArgRegBitmap) Get(i int) bool

Get returns whether the i'th bit of the bitmap is set.

nosplit because it's called in extremely sensitive contexts, like on the reflectcall return path.

func (*IntArgRegBitmap) Set

func (b *IntArgRegBitmap) Set(i int)

Set sets the i'th bit of the bitmap to 1.

type InterfaceType

type InterfaceType struct {
	Type
	PkgPath Name      // import path
	Methods []Imethod // sorted by hash
}

NOTE: The type name has to be `InterfaceType`, as expected by dwarf See ${GOROOT}/src/cmd/link/internal/ld/dwarf.go#func:dwarfGenerateDebugInfo

func (*InterfaceType) NumMethod

func (t *InterfaceType) NumMethod() int

NumMethod returns the number of interface methods in the type's method set.

type Itab

type Itab struct {
	Inter *InterfaceType
	Type  *Type
	Hash  uint32 // copy of _type.hash. Used for type switches.

	// actual length of Fun = len(.Inter.Methods)
	// fun[0]==0 means _type does not implement inter.
	Fun [1]uintptr
	// contains filtered or unexported fields
}

layout of Itab known to compilers allocated in non-garbage-collected memory Needs to be in sync with ../cmd/compile/internal/reflectdata/reflect.go:/^func.WriteTabs.

func (*Itab) FuncPCs

func (m *Itab) FuncPCs() []unsafe.Pointer

func (*Itab) Init

func (m *Itab) Init() string

init fills in the m.fun array with all the code pointers for the m.inter/m._type pair. If the type does not implement the interface, it sets m.fun[0] to 0 and returns the name of an interface function that is missing. It is ok to call this multiple times on the same m, even concurrently.

type Kind

type Kind uint

A Kind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind.

const (
	KindInvalid Kind = iota
	KindBool
	KindInt
	KindInt8
	KindInt16
	KindInt32
	KindInt64
	KindUint
	KindUint8
	KindUint16
	KindUint32
	KindUint64
	KindUintptr
	KindFloat32
	KindFloat64
	KindComplex64
	KindComplex128
	KindArray
	KindChan
	KindKindFunc
	KindInterface
	KindMap
	KindPointer
	KindSlice
	KindString
	KindStruct
	KindUnsafePointer
)

type MapType

type MapType struct {
	Type
	Key    *Type
	Elem   *Type
	Bucket *Type // internal type representing a hash bucket
	// function for hashing keys (ptr to key, seed) -> hash
	Hasher     func(unsafe.Pointer, uintptr) uintptr
	KeySize    uint8  // size of key slot
	ValueSize  uint8  // size of elem slot
	BucketSize uint16 // size of bucket
	Flags      uint32
}

NOTE: The type name has to be `MapType`, as expected by dwarf See ${GOROOT}/src/cmd/link/internal/ld/dwarf.go#func:dwarfGenerateDebugInfo

func (*MapType) HashMightPanic

func (mt *MapType) HashMightPanic() bool

func (*MapType) IndirectElem

func (mt *MapType) IndirectElem() bool

func (*MapType) IndirectKey

func (mt *MapType) IndirectKey() bool

Note: flag values must match those used in the TMAP case in ../cmd/compile/internal/reflectdata/reflect.go:writeType.

func (*MapType) NeedKeyUpdate

func (mt *MapType) NeedKeyUpdate() bool

func (*MapType) ReflexiveKey

func (mt *MapType) ReflexiveKey() bool

type Method

type Method struct {
	Name NameOff // name of method
	Mtyp TypeOff // method type (without receiver)
	Ifn  TextOff // fn used in interface call (one-word receiver)
	Tfn  TextOff // fn used for normal method call
}

Method on non-interface type

type ModuleData

type ModuleData struct {
	PCHeader     *PCHeader
	FuncNameTab  []byte
	CuTab        []uint32
	FileTab      []byte
	PCTab        []byte
	PCLnTable    []byte
	FTab         []FuncTab
	FindFuncTab  uintptr
	MinPC, MaxPC uintptr

	Text, Etext           uintptr
	NOPTRdata, ENOPTRdata uintptr
	Data, Edata           uintptr
	Bss, Ebss             uintptr
	NOPTRbss, ENOPTRbss   uintptr
	CovCtrs, ECovCtrs     uintptr // since go1.20
	End, GCdata, GCbss    uintptr
	Types, ETypes         uintptr
	ROData                uintptr
	GoFunc                uintptr // go.func.*

	TextSectMap []TextSect

	// .Types + .TypeLinks[i] = uintptr(unsafe.Pointer(*Type))
	//
	// The linker will leave a table of all the typelinks for
	// types in the binary, so the runtime can find them.
	//
	// When buildmode=shared, all types are in typelinks so the
	// runtime can deduplicate type pointers.
	//
	// Ref: ${GOROOT}/src/cmd/compile/internal/reflectdata/reflect.go#func:writeType
	TypeLinks []int32 // offsets from types
	ITabLinks []*Itab

	PTab []PTabEntry

	PluginPath string
	PkgHashes  []ModuleHash

	// This slice records the initializing tasks that need to be
	// done to start up the program. It is built by the linker.
	InitTasks []*InitTask // since go1.21

	ModuleName   string
	ModuleHashes []ModuleHash

	HasMain uint8 // 1 if module contains the main function, 0 otherwise

	GCdataMask, GCbssMask BitVector

	TypeMap map[TypeOff]*Type // offset to *_rtype in previous module

	Bad bool // module failed to load and should be ignored

	Next *ModuleData
	// contains filtered or unexported fields
}

ModuleData records information about the layout of the executable image. It is written by the linker. Any changes here must be matched changes to the code in cmd/link/internal/ld/symtab.go:symtab. moduledata is stored in statically allocated non-pointer memory; none of the pointers here are visible to the garbage collector.

See $GOROOT/src/runtime/symtab.go#type:moduledata

type ModuleHash

type ModuleHash struct {
	ModuleName   string
	LinktimeHash string
	RuntimeHash  *string
}

A ModuleHash is used to compare the ABI of a new module or a package in a new module with the loaded program.

For each shared library a module links against, the linker creates an entry in the moduledata.modulehashes slice containing the name of the module, the abi hash seen at link time and a pointer to the runtime abi hash. These are checked in moduledataverify1 below.

For each loaded plugin, the pkghashes slice has a ModuleHash of the newly loaded package that can be used to check the plugin's version of a package against any previously loaded version of the package. This is done in plugin.lastmoduleinit.

type ModuleIter

type ModuleIter uintptr

ModuleIter is an iterator for active modules.

func (*ModuleIter) Nth

func (iter *ModuleIter) Nth(i int) (md *ModuleData, ok bool)

type Name

type Name struct {
	Bytes *byte
}

Name is an encoded type Name with optional extra data.

The first byte is a bit field containing:

1<<0 the name is exported
1<<1 tag data follows the name
1<<2 pkgPath nameOff follows the name and tag
1<<3 the name is of an embedded (a.k.a. anonymous) field

Following that, there is a varint-encoded length of the name, followed by the name itself.

If tag data is present, it also has a varint-encoded length followed by the tag itself.

If the import path follows, then 4 bytes at the end of the data form a nameOff. The import path is only set for concrete methods that are defined in a different package than their type.

If a name starts with "*", then the exported bit represents whether the pointed to type is exported.

Note: this encoding must match here and in:

cmd/compile/internal/reflectdata/reflect.go
cmd/link/internal/ld/decodesym.go

func NewName

func NewName(n, tag string, exported, embedded bool) Name

func (Name) Data

func (n Name) Data(off int) *byte

Data does pointer arithmetic on n's Bytes, and that arithmetic is asserted to be safe because the runtime made the call (other packages use DataChecked)

func (Name) DataChecked

func (n Name) DataChecked(off int, whySafe string) *byte

DataChecked does pointer arithmetic on n's Bytes, and that arithmetic is asserted to be safe for the reason in whySafe (which can appear in a backtrace, etc.)

func (Name) HasTag

func (n Name) HasTag() bool

HasTag returns true iff there is tag data following this name

func (Name) IsBlank

func (n Name) IsBlank() bool

IsBlank indicates whether n is "_".

func (Name) IsEmbedded

func (n Name) IsEmbedded() bool

IsEmbedded returns true iff n is embedded (an anonymous field).

func (Name) IsExported

func (n Name) IsExported() bool

IsExported returns "is n exported?"

func (Name) Name

func (n Name) Name() string

Name returns the name string for n, or empty if there is none.

func (Name) ReadVarint

func (n Name) ReadVarint(off int) (int, int)

ReadVarint parses a varint as encoded by encoding/binary. It returns the number of encoded bytes and the encoded value.

func (Name) Tag

func (n Name) Tag() string

Tag returns the tag string for n, or empty if there is none.

type NameOff

type NameOff int32

NameOff is the offset to a name from moduledata.types. See resolveNameOff in runtime.

type Offset

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

Offset is for computing offsets of type data structures at compile/link time; the target platform may not be the host platform. Its state includes the current offset, necessary alignment for the sequence of types, and the size of pointers and alignment of slices, interfaces, and strings (this is for tearing- resistant access to these types, if/when that is supported).

func CommonOffset

func CommonOffset(ptrSize int, twoWordAlignSlices bool) Offset

CommonOffset returns the Offset to the data after the common portion of type data structures.

func InitializedOffset

func InitializedOffset(off int, align uint8, ptrSize uint8, twoWordAlignSlices bool) Offset

InitializedOffset returns a new Offset with specified offset, alignment, pointer size, and slice alignment.

func NewOffset

func NewOffset(ptrSize uint8, twoWordAlignSlices bool) Offset

NewOffset returns a new Offset with offset 0 and alignment 1.

func (Offset) Align

func (o Offset) Align(a uint8) Offset

Align returns the offset obtained by aligning offset to a multiple of a. a must be a power of two.

func (Offset) D8

func (o Offset) D8() Offset

D8 returns the offset obtained by appending an 8-bit field to o.

func (Offset) D16

func (o Offset) D16() Offset

D16 returns the offset obtained by appending a 16-bit field to o.

func (Offset) D32

func (o Offset) D32() Offset

D32 returns the offset obtained by appending a 32-bit field to o.

func (Offset) D64

func (o Offset) D64() Offset

D64 returns the offset obtained by appending a 64-bit field to o.

func (Offset) Interface

func (o Offset) Interface() Offset

Interface returns the offset obtained by appending an interface field to o.

func (Offset) Offset

func (o Offset) Offset() uint64

Offset returns the struct-aligned offset (size) of o. This is at least as large as the current internal offset; it may be larger.

func (Offset) P

func (o Offset) P() Offset

D64 returns the offset obtained by appending a pointer field to o.

func (Offset) PlusUncommon

func (o Offset) PlusUncommon() Offset

func (Offset) Slice

func (o Offset) Slice() Offset

Slice returns the offset obtained by appending a slice field to o.

func (Offset) String

func (o Offset) String() Offset

String returns the offset obtained by appending a string field to o.

type PCHeader

type PCHeader struct {
	// 0xfffffff1 (go1.20), 0xfffffff0 (go1.18) 0xfffffffa (go1.16) 0xfffffffb (go1.2)
	Magic uint32

	MinLC          uint8   // min instruction size
	PtrSize        uint8   // size of a ptr in bytes
	NFunc          int     // number of functions in the module
	NFiles         uint    // number of entries in the file tab
	TextStart      uintptr // base for function entry PC offsets in this module, equal to moduledata.text
	FuncNameOffset uintptr // offset to the funcnametab variable from pcHeader
	CuOffset       uintptr // offset to the cutab variable from pcHeader
	FileTabOffset  uintptr // offset to the filetab variable from pcHeader
	PCTabOffset    uintptr // offset to the pctab variable from pcHeader
	PCLnOffset     uintptr // offset to the pclntab variable from pcHeader
	// contains filtered or unexported fields
}

PCHeader holds data used by the pclntab lookups.

type PTabEntry

type PTabEntry struct {
	Name NameOff
	Type TypeOff
}

A PTabEntry is generated by the compiler for each exported function and global variable in the main package of a plugin. It is used to initialize the plugin module's symbol map.

type PointerType added in v0.2.1

type PointerType = PtrType

type PtrType

type PtrType struct {
	Type
	Elem *Type // pointer element (pointed at) type
}

NOTE: The type name has to be `PtrType`, as expected by dwarf See ${GOROOT}/src/cmd/link/internal/ld/dwarf.go#func:dwarfGenerateDebugInfo

type RegArgs

type RegArgs struct {
	// Values in these slots should be precisely the bit-by-bit
	// representation of how they would appear in a register.
	//
	// This means that on big endian arches, integer values should
	// be in the top bits of the slot. Floats are usually just
	// directly represented, but some architectures treat narrow
	// width floating point values specially (e.g. they're promoted
	// first, or they need to be NaN-boxed).
	Ints   [IntArgRegs]uintptr  // untyped integer registers
	Floats [FloatArgRegs]uint64 // untyped float registers

	// Ptrs is a space that duplicates Ints but with pointer type,
	// used to make pointers passed or returned  in registers
	// visible to the GC by making the type unsafe.Pointer.
	Ptrs [IntArgRegs]unsafe.Pointer

	// ReturnIsPtr is a bitmap that indicates which registers
	// contain or will contain pointers on the return path from
	// a reflectcall. The i'th bit indicates whether the i'th
	// register contains or will contain a valid Go pointer.
	ReturnIsPtr IntArgRegBitmap
}

RegArgs is a struct that has space for each argument and return value register on the current architecture.

Assembly code knows the layout of the first two fields of RegArgs.

RegArgs also contains additional space to hold pointers when it may not be safe to keep them only in the integer register space otherwise.

func (*RegArgs) Dump

func (r *RegArgs) Dump()

func (*RegArgs) IntRegArgAddr

func (r *RegArgs) IntRegArgAddr(reg int, argSize uintptr) unsafe.Pointer

IntRegArgAddr returns a pointer inside of r.Ints[reg] that is appropriately offset for an argument of size argSize.

argSize must be non-zero, fit in a register, and a power-of-two.

This method is a helper for dealing with the endianness of different CPU architectures, since sub-word-sized arguments in big endian architectures need to be "aligned" to the upper edge of the register to be interpreted by the CPU correctly.

type SliceType

type SliceType struct {
	Type
	Elem *Type // slice element type
}

NOTE: The type name has to be `SliceType`, as expected by dwarf See ${GOROOT}/src/cmd/link/internal/ld/dwarf.go#func:dwarfGenerateDebugInfo

type StructField

type StructField struct {
	Name   Name    // name is always non-empty
	Typ    *Type   // type of field
	Offset uintptr // byte offset of field
}

func (*StructField) Embedded

func (f *StructField) Embedded() bool

type StructType

type StructType struct {
	Type
	PkgPath Name
	Fields  []StructField
}

NOTE: The type name has to be `StructType`, as expected by dwarf See ${GOROOT}/src/cmd/link/internal/ld/dwarf.go#func:dwarfGenerateDebugInfo

type TFlag

type TFlag uint8

TFlag is used by a Type to signal what extra type information is available in the memory directly following the Type value.

const (
	// TFlagUncommon means that there is a data with a type, UncommonType,
	// just beyond the shared-per-type common data.  That is, the data
	// for struct types will store their UncommonType at one offset, the
	// data for interface types will store their UncommonType at a different
	// offset.  UncommonType is always accessed via a pointer that is computed
	// using trust-us-we-are-the-implementors pointer arithmetic.
	//
	// For example, if t.Kind() == Struct and t.tflag&TFlagUncommon != 0,
	// then t has UncommonType data and it can be accessed as:
	//
	//	type structTypeUncommon struct {
	//		structType
	//		u UncommonType
	//	}
	//	u := &(*structTypeUncommon)(unsafe.Pointer(t)).u
	TFlagUncommon TFlag = 1 << 0

	// TFlagExtraStar means the name in the str field has an
	// extraneous '*' prefix. This is because for most types T in
	// a program, the type *T also exists and reusing the str data
	// saves binary size.
	TFlagExtraStar TFlag = 1 << 1

	// TFlagNamed means the type has a name.
	TFlagNamed TFlag = 1 << 2

	// TFlagRegularMemory means that equal and hash functions can treat
	// this type as a single region of t.size bytes.
	TFlagRegularMemory TFlag = 1 << 3
)

type TextOff

type TextOff int32

TextOff is an offset from the top of a text section. See (rtype).textOff in runtime.

type TextSect

type TextSect struct {
	VAddr    uintptr // prelinked section vaddr
	End      uintptr // vaddr + section length
	BaseAddr uintptr // relocated section address
}

Mapping information for secondary text sections

type Type

type Type struct {
	Size_       uintptr
	PtrBytes    uintptr // number of (prefix) bytes in the type that can contain pointers
	Hash        uint32  // hash of type; avoids computation in hash tables
	TFlag       TFlag   // extra type information flags
	Align_      uint8   // alignment of variable with this type
	FieldAlign_ uint8   // alignment of struct field with this type
	Kind_       uint8   // enumeration for C
	// function for comparing objects of this type
	// (ptr to object A, ptr to object B) -> ==?
	Equal func(unsafe.Pointer, unsafe.Pointer) bool
	// GCData stores the GC type data for the garbage collector.
	// If the KindGCProg bit is set in kind, GCData is a GC program.
	// Otherwise it is a ptrmask bitmap. See mbitmap.go for details.
	GCData    *byte
	Str       NameOff // string form
	PtrToThis TypeOff // type for pointer to this type, may be zero
}

Type is the runtime representation of a Go type.

Type is also referenced implicitly (in the form of expressions involving constants and arch.PtrSize) in cmd/compile/internal/reflectdata/reflect.go and cmd/link/internal/ld/decodesym.go (e.g. data[2*arch.PtrSize+4] references the TFlag field) unsafe.OffsetOf(Type{}.TFlag) cannot be used directly in those places because it varies with cross compilation and experiments.

NOTE: The type name has to be Type, as expected by dwarf See ${GOROOT}/src/cmd/link/internal/ld/dwarf.go#func:dwarfGenerateDebugInfo

func (*Type) Align

func (t *Type) Align() int

Align returns the alignment of data with type t.

func (*Type) ArrayType

func (t *Type) ArrayType() *ArrayType

ArrayType returns t cast to a *ArrayType, or nil if its tag does not match.

func (*Type) ArrayTypeUnsafe

func (t *Type) ArrayTypeUnsafe() *ArrayType

func (*Type) ChanDir

func (t *Type) ChanDir() ChanDir

ChanDir returns the direction of t if t is a channel type, otherwise InvalidDir (0).

func (*Type) ChanType

func (t *Type) ChanType() *ChanType

ChanType returns t cast to a *ChanType, or nil if its tag does not match.

func (*Type) ChanTypeUnsafe

func (t *Type) ChanTypeUnsafe() *ChanType

func (*Type) Common

func (t *Type) Common() *Type

func (*Type) Elem

func (t *Type) Elem() *Type

Elem returns the element type for t if t is an array, channel, map, pointer, or slice, otherwise nil.

func (*Type) ExportedMethods

func (t *Type) ExportedMethods() []Method

func (*Type) FieldAlign

func (t *Type) FieldAlign() int

func (*Type) FuncType

func (t *Type) FuncType() *FuncType

FuncType returns t cast to a *FuncType, or nil if its tag does not match.

func (*Type) FuncTypeUnsafe

func (t *Type) FuncTypeUnsafe() *FuncType

func (*Type) GcSlice

func (t *Type) GcSlice(begin, end uintptr) []byte

func (*Type) HasName

func (t *Type) HasName() bool

func (*Type) IfaceIndir

func (t *Type) IfaceIndir() bool

IfaceIndir reports whether t is stored indirectly in an interface value.

func (*Type) InterfaceType

func (t *Type) InterfaceType() *InterfaceType

InterfaceType returns t cast to a *InterfaceType, or nil if its tag does not match.

func (*Type) InterfaceTypeUnsafe

func (t *Type) InterfaceTypeUnsafe() *InterfaceType

func (*Type) IsDirectIface

func (t *Type) IsDirectIface() bool

IsDirectIface reports whether t is stored directly in an interface value.

To find out what types stores value directly as iface.Data, See ${GOROOT}/src/cmd/internal/types/type.go#func:IsDirectIface

As of go1.21, following types return true:

  • pointer types whose elem type doesn't have mark.NotInHeap
  • chan, map, func, unsafe.Pointer
  • struct/array of 1 field/elem of above types

func (*Type) Key

func (t *Type) Key() *Type

func (*Type) Kind

func (t *Type) Kind() Kind

func (*Type) Len

func (t *Type) Len() int

Len returns the length of t if t is an array type, otherwise 0

func (*Type) MapType

func (t *Type) MapType() *MapType

MapType returns t cast to a *MapType, or nil if its tag does not match.

func (*Type) MapTypeUnsafe

func (t *Type) MapTypeUnsafe() *MapType

func (*Type) Name

func (t *Type) Name() string

func (*Type) NameOff

func (t *Type) NameOff(off NameOff) Name

func (*Type) NumMethod

func (t *Type) NumMethod() int

func (*Type) PkgPath

func (t *Type) PkgPath() string

PkgPath returns the path of the package where t was defined, if available. This is not the same as the reflect package's PkgPath method, in that it returns the package path for struct and interface types, not just named types.

func (*Type) PointerType

func (t *Type) PointerType() *PointerType

PointerType returns t cast to a *InterfaceType, or nil if its tag does not match.

func (*Type) PointerTypeUnsafe

func (t *Type) PointerTypeUnsafe() *PointerType

func (*Type) Pointers

func (t *Type) Pointers() bool

func (*Type) Size

func (t *Type) Size() uintptr

Size returns the size of data with type t.

func (*Type) SliceType

func (t *Type) SliceType() *SliceType

SliceType returns t cast to a *SliceType, or nil if its tag does not match.

func (*Type) SliceTypeUnsafe

func (t *Type) SliceTypeUnsafe() *SliceType

func (*Type) String

func (t *Type) String() string

func (*Type) StructType

func (t *Type) StructType() *StructType

StructType returns t cast to a *StructType, or nil if its tag does not match.

func (*Type) StructTypeUnsafe

func (t *Type) StructTypeUnsafe() *StructType

func (*Type) TextOff

func (t *Type) TextOff(off TextOff) unsafe.Pointer

func (*Type) TypeOff

func (t *Type) TypeOff(off TypeOff) *Type

func (*Type) Uncommon

func (t *Type) Uncommon() *UncommonType

Uncommon returns a pointer to T's "uncommon" data if there is any, otherwise nil

type TypeOff

type TypeOff int32

TypeOff is the offset to a type from moduledata.types. See resolveTypeOff in runtime.

type UncommonType

type UncommonType struct {
	PkgPath NameOff // import path; empty for built-in types like int, string
	Mcount  uint16  // number of methods
	Xcount  uint16  // number of exported methods
	Moff    uint32  // offset from this uncommontype to [mcount]Method
	// contains filtered or unexported fields
}

UncommonType is present only for defined types or types with methods (if T is a defined type, the uncommonTypes for T and *T have methods). Using a pointer to this struct reduces the overall size required to describe a non-defined type with no methods.

func (*UncommonType) ExportedMethods

func (t *UncommonType) ExportedMethods() []Method

func (*UncommonType) Methods

func (t *UncommonType) Methods() []Method

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL