obj

package
v0.0.0-...-e03519e Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PCDATA_StackMapIndex       = 0
	FUNCDATA_ArgsPointerMaps   = 0
	FUNCDATA_LocalsPointerMaps = 1
	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.

View Source
const (
	NAME_NONE = 0 + 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
)
View Source
const (
	ABase386 = (1 + iota) << 10
	ABaseARM
	ABaseAMD64
	ABasePPC64
	ABaseARM64
	ABaseMIPS
	ABaseS390X

	AllowedOpCodes = 1 << 10            // The number of opcodes available for any given architecture.
	AMask          = AllowedOpCodes - 1 // AND with this to use the opcode as an array index.
)

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.

View Source
const (
	A_AUTO = 1 + iota
	A_PARAM
)

Auto.name

View Source
const (
	STACKSYSTEM = 0
	StackSystem = STACKSYSTEM
	StackBig    = 4096
	StackGuard  = 880*stackGuardMultiplier + StackSystem
	StackSmall  = 128
	StackLimit  = StackGuard - StackSystem - StackSmall
)
View Source
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'.
	WRAPPER = 32

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

	// When passed to ggloblsym, 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
)
View Source
const (
	KindBool = 1 + iota
	KindInt
	KindInt8
	KindInt16
	KindInt32
	KindInt64
	KindUint
	KindUint8
	KindUint16
	KindUint32
	KindUint64
	KindUintptr
	KindFloat32
	KindFloat64
	KindComplex64
	KindComplex128
	KindArray
	KindChan
	KindFunc
	KindInterface
	KindMap
	KindPtr
	KindSlice
	KindString
	KindStruct
	KindUnsafePointer
	KindDirectIface = 1 << 5
	KindGCProg      = 1 << 6
	KindNoPointers  = 1 << 7
	KindMask        = (1 << 5) - 1
)
View Source
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
)

ARM scond byte

View Source
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)
)
View Source
const (
	HistVersion = 1
)

symbol version, incremented each time a file is loaded. version==1 is reserved for savehist.

View Source
const (
	LOG = 5
)
View Source
const REG_NONE = 0
View Source
const (
	StackPreempt = -1314 // 0xfff...fade
)

Variables

View Source
var (
	Fieldtrack_enabled       int
	Preemptibleloops_enabled int
)
View Source
var (
	GOROOT  = envOr("GOROOT", defaultGOROOT)
	GOARCH  = envOr("GOARCH", defaultGOARCH)
	GOOS    = envOr("GOOS", defaultGOOS)
	GO386   = envOr("GO386", defaultGO386)
	GOARM   = goarm()
	Version = version
)
View Source
var Anames = []string{
	"XXX",
	"CALL",
	"DUFFCOPY",
	"DUFFZERO",
	"END",
	"FUNCDATA",
	"JMP",
	"NOP",
	"PCDATA",
	"RET",
	"TEXT",
	"TYPE",
	"UNDEF",
	"USEFIELD",
	"VARDEF",
	"VARKILL",
	"VARLIVE",
}

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.

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

Functions

func Bool2int

func Bool2int(b bool) int

func CConv

func CConv(s uint8) string

CConv formats ARM condition codes.

func Cputime

func Cputime() float64

func Dconv

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

func Expstring

func Expstring() string

func Flagcount

func Flagcount(name, usage string, val *int)

func Flagfn0

func Flagfn0(name, usage string, f func())

func Flagfn1

func Flagfn1(name, usage string, f func(string))

func Flagfn2

func Flagfn2(string, string, func(string, string))

func Flagint32

func Flagint32(name, usage string, val *int32)

func Flagint64

func Flagint64(name, usage string, val *int64)

func Flagparse

func Flagparse(usage func())

func Flagprint

func Flagprint(fd int)

func Flagstr

func Flagstr(name, usage string, val *string)

func Flushplist

func Flushplist(ctxt *Link)

func FlushplistNoFree

func FlushplistNoFree(ctxt *Link)

func Framepointer_enabled

func Framepointer_enabled(goos, goarch string) bool

func Getcallerpc

func Getcallerpc(interface{}) uintptr

func Getgoextlinkenabled

func Getgoextlinkenabled() string

func Linkprfile

func Linkprfile(ctxt *Link, line int)

func Linksymfmt

func Linksymfmt(s *LSym) string

func Mconv

func Mconv(a *Addr) string

func Nopout

func Nopout(p *Prog)

func Rconv

func Rconv(reg int) string

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 Setuintxx

func Setuintxx(ctxt *Link, s *LSym, off int64, v uint64, wid int64) int64

func WriteObjFile

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

func Writeobjdirect

func Writeobjdirect(ctxt *Link, b *bufio.Writer)

The Go and C compilers, and the assembler, call writeobj to write out a Go object file. The linker does not call this; the linker does not write out object files.

Types

type Addr

type Addr struct {
	Reg    int16
	Index  int16
	Scale  int16 // Sometimes holds a register.
	Type   AddrType
	Name   int8
	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{}

	Node interface{} // for use by compiler
}

An Addr is an argument to an instruction. The general forms and their encodings are:

sym±offset(symkind)(reg)(index*scale)
	Memory reference at address &sym(symkind) + offset + reg + index*scale.
	Any of sym(symkind), ±offset, (reg), (index*scale), and *scale can be omitted.
	If (reg) and *scale are both omitted, the resulting expression (index) is parsed as (reg).
	To force a parsing as index*scale, write (index*1).
	Encoding:
		type = TYPE_MEM
		name = symkind (NAME_AUTO, ...) or 0 (NAME_NONE)
		sym = sym
		offset = ±offset
		reg = reg (REG_*)
		index = index (REG_*)
		scale = scale (1, 2, 4, 8)

$<mem>
	Effective address of memory reference <mem>, defined above.
	Encoding: same as memory reference, but type = TYPE_ADDR.

$<±integer value>
	This is a special case of $<mem>, in which only ±offset is present.
	It has a separate type for easy recognition.
	Encoding:
		type = TYPE_CONST
		offset = ±integer value

*<mem>
	Indirect reference through memory reference <mem>, defined above.
	Only used on x86 for CALL/JMP *sym(SB), which calls/jumps to a function
	pointer stored in the data word sym(SB), not a function named sym(SB).
	Encoding: same as above, but type = TYPE_INDIR.

$*$<mem>
	No longer used.
	On machines with actual SB registers, $*$<mem> forced the
	instruction encoding to use a full 32-bit constant, never a
	reference relative to SB.

$<floating point literal>
	Floating point constant value.
	Encoding:
		type = TYPE_FCONST
		val = floating point value

$<string literal, up to 8 chars>
	String literal value (raw bytes used for DATA instruction).
	Encoding:
		type = TYPE_SCONST
		val = string

<register name>
	Any register: integer, floating point, control, segment, and so on.
	If looking for specific register kind, must check type and reg value range.
	Encoding:
		type = TYPE_REG
		reg = reg (REG_*)

x(PC)
	Encoding:
		type = TYPE_BRANCH
		val = Prog* reference OR ELSE offset = target pc (branch takes priority)

$±x-±y
	Final argument to TEXT, specifying local frame size x and argument size y.
	In this form, x and y are integer literals only, not arbitrary expressions.
	This avoids parsing ambiguities due to the use of - as a separator.
	The ± are optional.
	If the final argument to TEXT omits the -±y, the encoding should still
	use TYPE_TEXTSIZE (not TYPE_CONST), with u.argsize = ArgsSizeUnknown.
	Encoding:
		type = TYPE_TEXTSIZE
		offset = x
		val = int32(y)

reg<<shift, reg>>shift, reg->shift, reg@>shift
	Shifted register value, for ARM and ARM64.
	In this form, reg must be a register and shift can be a register or an integer constant.
	Encoding:
		type = TYPE_SHIFT
	On ARM:
		offset = (reg&15) | shifttype<<5 | count
		shifttype = 0, 1, 2, 3 for <<, >>, ->, @>
		count = (reg&15)<<8 | 1<<4 for a register shift count, (n&31)<<7 for an integer constant.
	On ARM64:
		offset = (reg&31)<<16 | shifttype<<22 | (count&63)<<10
		shifttype = 0, 1, 2 for <<, >>, ->

(reg, reg)
	A destination register pair. When used as the last argument of an instruction,
	this form makes clear that both registers are destinations.
	Encoding:
		type = TYPE_REGREG
		reg = first register
		offset = second register

[reg, reg, reg-reg]
	Register list for ARM.
	Encoding:
		type = TYPE_REGLIST
		offset = bit mask of registers in list; R0 is low bit.

reg, reg
	Register pair for ARM.
	TYPE_REGREG2

(reg+reg)
	Register pair for PPC64.
	Encoding:
		type = TYPE_MEM
		reg = first register
		index = second register
		scale = 1

type AddrType

type AddrType uint8
const (
	TYPE_NONE AddrType = 0

	TYPE_BRANCH AddrType = 5 + iota
	TYPE_TEXTSIZE
	TYPE_MEM
	TYPE_CONST
	TYPE_FCONST
	TYPE_SCONST
	TYPE_REG
	TYPE_ADDR
	TYPE_SHIFT
	TYPE_REGREG
	TYPE_REGREG2
	TYPE_INDIR
	TYPE_REGLIST
)

func (AddrType) String

func (i AddrType) String() string

type As

type As int16

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.

const (
	AXXX As = iota
	ACALL
	ADUFFCOPY
	ADUFFZERO
	AEND
	AFUNCDATA
	AJMP
	ANOP
	APCDATA
	ARET
	ATEXT
	ATYPE
	AUNDEF
	AUSEFIELD
	AVARDEF
	AVARKILL
	AVARLIVE
	A_ARCHSPECIFIC
)

These are the portable opcodes.

func (As) String

func (a As) String() string

type AsmBuf

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

AsmBuf is a simple buffer to assemble variable-length x86 instructions into.

func (*AsmBuf) Bytes

func (a *AsmBuf) Bytes() []byte

Bytes returns the contents of the buffer.

func (*AsmBuf) Insert

func (a *AsmBuf) Insert(i int, b byte)

Insert inserts b at offset i.

func (*AsmBuf) Last

func (a *AsmBuf) Last() byte

Last returns the byte at the end of the buffer.

func (*AsmBuf) Len

func (a *AsmBuf) Len() int

Len returns the length of the buffer.

func (*AsmBuf) Peek

func (a *AsmBuf) Peek(i int) byte

Peek returns the byte at offset i.

func (*AsmBuf) Put

func (a *AsmBuf) Put(b []byte)

Put copies b into the buffer.

func (*AsmBuf) Put1

func (a *AsmBuf) Put1(x byte)

Put1 appends one byte to the end of the buffer.

func (*AsmBuf) Put2

func (a *AsmBuf) Put2(x, y byte)

Put2 appends two bytes to the end of the buffer.

func (*AsmBuf) Put3

func (a *AsmBuf) Put3(x, y, z byte)

Put3 appends three bytes to the end of the buffer.

func (*AsmBuf) Put4

func (a *AsmBuf) Put4(x, y, z, w byte)

Put4 appends four bytes to the end of the buffer.

func (*AsmBuf) PutInt16

func (a *AsmBuf) PutInt16(v int16)

PutInt16 writes v into the buffer using little-endian encoding.

func (*AsmBuf) PutInt32

func (a *AsmBuf) PutInt32(v int32)

PutInt32 writes v into the buffer using little-endian encoding.

func (*AsmBuf) PutInt64

func (a *AsmBuf) PutInt64(v int64)

PutInt64 writes v into the buffer using little-endian encoding.

func (*AsmBuf) Reset

func (a *AsmBuf) Reset()

Reset empties the buffer.

type Attribute

type Attribute int16

Attribute is a set of symbol attributes.

const (
	AttrDuplicateOK Attribute = 1 << iota
	AttrCFunc
	AttrNoSplit
	AttrLeaf
	AttrSeenGlobl
	AttrOnList

	// 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
)

func (Attribute) CFunc

func (a Attribute) CFunc() bool

func (Attribute) DuplicateOK

func (a Attribute) DuplicateOK() bool

func (Attribute) Leaf

func (a Attribute) Leaf() bool

func (Attribute) Local

func (a Attribute) Local() bool
func (a Attribute) MakeTypelink() 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) SeenGlobl

func (a Attribute) SeenGlobl() bool

func (*Attribute) Set

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

type Auto

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

type HeadType

type HeadType uint8

HeadType is the executable header type.

const (
	Hunknown HeadType = iota
	Hdarwin
	Hdragonfly
	Hfreebsd
	Hlinux
	Hnacl
	Hnetbsd
	Hopenbsd
	Hplan9
	Hsolaris
	Hwindows
	Hwindowsgui
)

func (*HeadType) Set

func (h *HeadType) Set(s string) error

func (*HeadType) String

func (h *HeadType) String() string

type LSym

type LSym struct {
	Name    string
	Type    SymKind
	Version int16
	Attribute

	RefIdx int // Index of this symbol in the symbol reference list.
	Args   int32
	Locals int32
	Size   int64
	Gotype *LSym
	Autom  *Auto
	Text   *Prog
	Pcln   *Pcln
	P      []byte
	R      []Reloc
}

An LSym is the sort of symbol that is written to an object file.

func Linklookup

func Linklookup(ctxt *Link, name string, v int) *LSym

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) String

func (s *LSym) String() string

The compiler needs LSym to satisfy fmt.Stringer, because it stores an LSym in ssa.ExternSymbol.

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) 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) 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).

type LineHist

type LineHist struct {
	Top               *LineStack  // current top of stack
	Ranges            []LineRange // ranges for lookup
	Dir               string      // directory to qualify relative paths
	TrimPathPrefix    string      // remove leading TrimPath from recorded file names
	PrintFilenameOnly bool        // ignore path when pretty-printing a line; internal use only
	GOROOT            string      // current GOROOT
}

A LineHist records the history of the file input stack, which maps the virtual line number, an incrementing count of lines processed in any input file and typically named lineno, to a stack of file:line pairs showing the path of inclusions that led to that position. The first line directive (//line in Go, #line in assembly) is treated as pushing a new entry on the stack, so that errors can report both the actual and translated line number.

In typical use, the virtual lineno begins at 1, and file line numbers also begin at 1, but the only requirements placed upon the numbers by this code are:

  • calls to Push, Update, and Pop must be monotonically increasing in lineno
  • except as specified by those methods, virtual and file line number increase together, so that given (only) calls Push(10, "x.go", 1) and Pop(15), virtual line 12 corresponds to x.go line 3.

func (*LineHist) AbsFileLine

func (h *LineHist) AbsFileLine(lineno int) (file string, line int)

AbsFileLine returns the absolute file name and line number at the top of the stack for the given lineno.

func (*LineHist) At

func (h *LineHist) At(lineno int) *LineStack

At returns the input stack in effect at lineno.

func (*LineHist) FileLine

func (h *LineHist) FileLine(lineno int) (file string, line int)

FileLine returns the file name and line number at the top of the stack for the given lineno.

func (*LineHist) LineString

func (h *LineHist) LineString(lineno int) string

LineString returns a string giving the file and line number corresponding to lineno, for use in error messages.

func (*LineHist) Pop

func (h *LineHist) Pop(lineno int)

Pop records that at lineno the current file was popped from the input stack.

func (*LineHist) Push

func (h *LineHist) Push(lineno int, file string)

Push records that at that lineno a new file with the given name was pushed onto the input stack.

func (*LineHist) Update

func (h *LineHist) Update(lineno int, file string, line int)

Update records that at lineno the file name and line number were changed using a line directive (//line in Go, #line in assembly).

type LineRange

type LineRange struct {
	Start int        // starting lineno
	Stack *LineStack // top of stack for this range
}

The span of valid linenos in the recorded line history can be broken into a set of ranges, each with a particular stack. A LineRange records one such range.

type LineStack

type LineStack struct {
	Parent    *LineStack // parent in inclusion stack
	Lineno    int        // virtual line number where this entry takes effect
	File      string     // file name used to open source file, for error messages
	AbsFile   string     // absolute file name, for pcln tables
	FileLine  int        // line number in file at Lineno
	Directive bool
	Sym       *LSym // for linkgetline - TODO(rsc): remove
}

A LineStack is an entry in the recorded line history. Although the history at any given line number is a stack, the record for all line processed forms a tree, with common stack prefixes acting as parents.

type Link struct {
	Headtype      HeadType
	Arch          *LinkArch
	Debugasm      int32
	Debugvlog     int32
	Debugdivmod   int32
	Debugpcln     int32
	Flag_shared   bool
	Flag_dynlink  bool
	Flag_optimize bool
	Bso           *bufio.Writer
	Pathname      string
	Hash          map[SymVer]*LSym
	LineHist      LineHist
	Imports       []string
	Plists        []*Plist
	Sym_div       *LSym
	Sym_divu      *LSym
	Sym_mod       *LSym
	Sym_modu      *LSym
	Plan9privates *LSym
	Curp          *Prog
	Printp        *Prog
	Blitrl        *Prog
	Elitrl        *Prog
	Rexflag       int
	Vexflag       int
	Rep           int
	Repn          int
	Lock          int
	Asmode        int
	AsmBuf        AsmBuf // instruction buffer for x86
	Instoffset    int64
	Autosize      int32
	Armsize       int32
	Pc            int64
	DiagFunc      func(string, ...interface{})
	Mode          int
	Cursym        *LSym
	Version       int
	Errors        int

	Framepointer_enabled bool

	// state for writing objects
	Text []*LSym
	Data []*LSym
	// contains filtered or unexported fields
}

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

func Linknew

func Linknew(arch *LinkArch) *Link

func (*Link) AddImport

func (ctxt *Link) AddImport(pkg string)

AddImport adds a package to the list of imported packages.

func (*Link) Dconv

func (ctxt *Link) Dconv(a *Addr) string

func (*Link) Diag

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

func (*Link) FixedFrameSize

func (ctxt *Link) FixedFrameSize() int64

The smallest possible offset from the hardware stack pointer to a local variable on the stack. Architectures that use a link register save its value on the stack in the function prologue and so always have a pointer between the hardware stack pointer and the local variable area.

func (*Link) Globl

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

func (*Link) Line

func (ctxt *Link) Line(n int) string

func (*Link) Logf

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

func (*Link) NewProg

func (ctxt *Link) NewProg() *Prog

type LinkArch

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

LinkArch is the definition of a single architecture.

type Pcdata

type Pcdata struct {
	P []byte
}

type Pcln

type Pcln struct {
	Pcsp        Pcdata
	Pcfile      Pcdata
	Pcline      Pcdata
	Pcdata      []Pcdata
	Funcdata    []*LSym
	Funcdataoff []int64
	File        []*LSym
	Lastfile    *LSym
	Lastindex   int
}

type Plist

type Plist struct {
	Firstpc *Prog
}

func Linknewplist

func Linknewplist(ctxt *Link) *Plist

* start a new Prog list.

type Prog

type Prog struct {
	Ctxt   *Link       // linker context
	Link   *Prog       // next Prog in linked list
	From   Addr        // first source operand
	From3  *Addr       // third source operand (second is Reg below)
	To     Addr        // destination operand (second is RegTo2 below)
	Pcond  *Prog       // target of conditional jump
	Opt    interface{} // available to optimization passes to hold per-Prog state
	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
	Lineno int32       // line number 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       // condition bits for conditional instruction (e.g., on ARM)
	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
	Mode   int8        // for x86 back end: 32- or 64-bit mode
}

Prog describes a single machine instruction.

The general instruction form is:

As.Scond From, Reg, From3, To, RegTo2

where As is an opcode and the others are arguments: From, Reg, From3 are sources, and To, RegTo2 are 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.

Jump instructions use the Pcond field to point to the target instruction, 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 Lineno, an index into the line history (see LineHist). Every Prog has a Ctxt field that defines various context, including the current LineHist. Progs should be allocated using ctxt.NewProg(), not 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.

func Appendp

func Appendp(ctxt *Link, q *Prog) *Prog

func Brchain

func Brchain(ctxt *Link, p *Prog) *Prog

func Copyp

func Copyp(ctxt *Link, q *Prog) *Prog

func (*Prog) From3Offset

func (p *Prog) From3Offset() int64

From3Offset returns From3.Offset, or 0 when From3 is nil.

func (*Prog) From3Type

func (p *Prog) From3Type() AddrType

From3Type returns From3.Type, or TYPE_NONE when From3 is nil.

func (*Prog) Line

func (p *Prog) Line() string

func (*Prog) String

func (p *Prog) String() string

type Reloc

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

func Addrel

func Addrel(s *LSym) *Reloc

type RelocType

type RelocType int32
const (
	R_ADDR RelocType = 1 + iota
	// R_ADDRPOWER relocates a pair of "D-form" instructions (instructions with 16-bit
	// immediates in the low half of the instruction word), usually addis followed by
	// another add or a load, inserting the "high adjusted" 16 bits of the address of
	// the referenced symbol into the immediate field of the first instruction and the
	// low 16 bits into that of the second instruction.
	R_ADDRPOWER
	// R_ADDRARM64 relocates an adrp, add pair to compute the address of the
	// referenced symbol.
	R_ADDRARM64
	// R_ADDRMIPS (only used on mips/mips64) resolves to the low 16 bits of an external
	// address, by encoding it into the instruction.
	R_ADDRMIPS
	// R_ADDROFF resolves to a 32-bit offset from the beginning of the section
	// holding the data being relocated to the referenced symbol.
	R_ADDROFF
	// R_WEAKADDROFF resolves just like R_ADDROFF but is a weak relocation.
	// A weak relocation does not make the symbol it refers to reachable,
	// and is only honored by the linker if the symbol is in some other way
	// reachable.
	R_WEAKADDROFF
	R_SIZE
	R_CALL
	R_CALLARM
	R_CALLARM64
	R_CALLIND
	R_CALLPOWER
	// R_CALLMIPS (only used on mips64) resolves to non-PC-relative target address
	// of a CALL (JAL) instruction, by encoding the address into the instruction.
	R_CALLMIPS
	R_CONST
	R_PCREL
	// R_TLS_LE, used on 386, amd64, and ARM, resolves to the offset of the
	// thread-local symbol from the thread local base and is used to implement the
	// "local exec" model for tls access (r.Sym is not set on intel platforms but is
	// set to a TLS symbol -- runtime.tlsg -- in the linker when externally linking).
	R_TLS_LE
	// R_TLS_IE, used 386, amd64, and ARM resolves to the PC-relative offset to a GOT
	// slot containing the offset from the thread-local symbol from the thread local
	// base and is used to implemented the "initial exec" model for tls access (r.Sym
	// is not set on intel platforms but is set to a TLS symbol -- runtime.tlsg -- in
	// the linker when externally linking).
	R_TLS_IE
	R_GOTOFF
	R_PLT0
	R_PLT1
	R_PLT2
	R_USEFIELD
	// R_USETYPE resolves to an *rtype, but no relocation is created. The
	// linker uses this as a signal that the pointed-to type information
	// should be linked into the final binary, even if there are no other
	// direct references. (This is used for types reachable by reflection.)
	R_USETYPE
	// R_METHODOFF resolves to a 32-bit offset from the beginning of the section
	// holding the data being relocated to the referenced symbol.
	// It is a variant of R_ADDROFF used when linking from the uncommonType of a
	// *rtype, and may be set to zero by the linker if it determines the method
	// text is unreachable by the linked program.
	R_METHODOFF
	R_POWER_TOC
	R_GOTPCREL
	// R_JMPMIPS (only used on mips64) resolves to non-PC-relative target address
	// of a JMP instruction, by encoding the address into the instruction.
	// The stack nosplit check ignores this since it is not a function call.
	R_JMPMIPS
	// R_DWARFREF resolves to the offset of the symbol from its section.
	R_DWARFREF

	// Set a MOV[NZ] immediate field to bits [15:0] of the offset from the thread
	// local base to the thread local variable defined by the referenced (thread
	// local) symbol. Error if the offset does not fit into 16 bits.
	R_ARM64_TLS_LE

	// Relocates an ADRP; LD64 instruction sequence to load the offset between
	// the thread local base and the thread local variable defined by the
	// referenced (thread local) symbol from the GOT.
	R_ARM64_TLS_IE

	// R_ARM64_GOTPCREL relocates an adrp, ld64 pair to compute the address of the GOT
	// slot of the referenced symbol.
	R_ARM64_GOTPCREL

	// R_POWER_TLS_LE is used to implement the "local exec" model for tls
	// access. It resolves to the offset of the thread-local symbol from the
	// thread pointer (R13) and inserts this value into the low 16 bits of an
	// instruction word.
	R_POWER_TLS_LE

	// R_POWER_TLS_IE is used to implement the "initial exec" model for tls access. It
	// relocates a D-form, DS-form instruction sequence like R_ADDRPOWER_DS. It
	// inserts to the offset of GOT slot for the thread-local symbol from the TOC (the
	// GOT slot is filled by the dynamic linker with the offset of the thread-local
	// symbol from the thread pointer (R13)).
	R_POWER_TLS_IE

	// R_POWER_TLS marks an X-form instruction such as "MOVD 0(R13)(R31*1), g" as
	// accessing a particular thread-local symbol. It does not affect code generation
	// but is used by the system linker when relaxing "initial exec" model code to
	// "local exec" model code.
	R_POWER_TLS

	// R_ADDRPOWER_DS is similar to R_ADDRPOWER above, but assumes the second
	// instruction is a "DS-form" instruction, which has an immediate field occupying
	// bits [15:2] of the instruction word. Bits [15:2] of the address of the
	// relocated symbol are inserted into this field; it is an error if the last two
	// bits of the address are not 0.
	R_ADDRPOWER_DS

	// R_ADDRPOWER_PCREL relocates a D-form, DS-form instruction sequence like
	// R_ADDRPOWER_DS but inserts the offset of the GOT slot for the referenced symbol
	// from the TOC rather than the symbol's address.
	R_ADDRPOWER_GOT

	// R_ADDRPOWER_PCREL relocates two D-form instructions like R_ADDRPOWER, but
	// inserts the displacement from the place being relocated to the address of the
	// the relocated symbol instead of just its address.
	R_ADDRPOWER_PCREL

	// R_ADDRPOWER_TOCREL relocates two D-form instructions like R_ADDRPOWER, but
	// inserts the offset from the TOC to the address of the the relocated symbol
	// rather than the symbol's address.
	R_ADDRPOWER_TOCREL

	// R_ADDRPOWER_TOCREL relocates a D-form, DS-form instruction sequence like
	// R_ADDRPOWER_DS but inserts the offset from the TOC to the address of the the
	// relocated symbol rather than the symbol's address.
	R_ADDRPOWER_TOCREL_DS

	// R_PCRELDBL relocates s390x 2-byte aligned PC-relative addresses.
	// TODO(mundaym): remove once variants can be serialized - see issue 14218.
	R_PCRELDBL

	// R_ADDRMIPSU (only used on mips/mips64) resolves to the sign-adjusted "upper" 16
	// bits (bit 16-31) of an external address, by encoding it into the instruction.
	R_ADDRMIPSU
	// R_ADDRMIPSTLS (only used on mips64) resolves to the low 16 bits of a TLS
	// address (offset from thread pointer), by encoding it into the instruction.
	R_ADDRMIPSTLS
)

func (RelocType) IsDirectJump

func (r RelocType) IsDirectJump() bool

IsDirectJump returns whether r is a relocation for a direct jump. A direct jump is a CALL or JMP instruction that takes the target address as immediate. The address is embedded into the instruction, possibly with limited width. An indirect jump is a CALL or JMP instruction that takes the target address in register or memory.

func (RelocType) String

func (i RelocType) String() string

type SymKind

type SymKind int16

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.
	SELFSECT
	SMACHO
	SMACHOGOT
	SWINDOWS
	SELFGOT
	SNOPTRDATA
	SINITARR
	SDATA
	SBSS
	SNOPTRBSS
	STLSBSS
	SXREF
	SMACHOSYMSTR
	SMACHOSYMTAB
	SMACHOINDIRECTPLT
	SMACHOINDIRECTGOT
	SFILE
	SFILEPATH
	SCONST
	SDYNIMPORT
	SHOSTOBJ
	SDWARFSECT
	SDWARFINFO
	SSUB       = SymKind(1 << 8)
	SMASK      = SymKind(SSUB - 1)
	SHIDDEN    = SymKind(1 << 9)
	SCONTAINER = SymKind(1 << 10) // has a sub-symbol
)

Defined SymKind values.

TODO(rsc): Give idiomatic Go names. TODO(rsc): Reduce the number of symbol types in the object files.

func (SymKind) String

func (i SymKind) String() string

type SymVer

type SymVer struct {
	Name    string
	Version int // TODO: make int16 to match LSym.Version?
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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