Documentation ¶
Index ¶
- Constants
- Variables
- func Aconv(a int) string
- func Bgetc(b *Biobuf) int
- func Bgetrune(b *Biobuf) int
- func Blinelen(b *Biobuf) int
- func Boffset(b *Biobuf) int64
- func Bool2int(b bool) int
- func Bputc(b *Biobuf, c byte)
- func Brdline(b *Biobuf, delim int) string
- func Brdstr(b *Biobuf, delim int, cut int) string
- func Bread(b *Biobuf, p []byte) int
- func Bseek(b *Biobuf, offset int64, whence int) int64
- func Bterm(b *Biobuf) error
- func Bungetrune(b *Biobuf)
- func Bwritestring(b *Biobuf, p string) (int, error)
- func CConv(s uint8) string
- func Cputime() float64
- func Dconv(p *Prog, a *Addr) string
- func Expstring() string
- func Flagcount(name, usage string, val *int)
- func Flagfn0(name, usage string, f func())
- func Flagfn1(name, usage string, f func(string))
- func Flagfn2(string, string, func(string, string))
- func Flagint32(name, usage string, val *int32)
- func Flagint64(name, usage string, val *int64)
- func Flagparse(usage func())
- func Flagprint(fd int)
- func Flagstr(name, usage string, val *string)
- func Getcallerpc(interface{}) uintptr
- func Getgo386() string
- func Getgoarch() string
- func Getgoarm() int32
- func Getgoextlinkenabled() string
- func Getgoos() string
- func Getgoroot() string
- func Getgoversion() string
- func Headstr(v int) string
- func Linkprfile(ctxt *Link, line int)
- func Linksymfmt(s *LSym) string
- func Mconv(a *Addr) string
- func Nocache(p *Prog)
- func Nopout(p *Prog)
- func Rconv(reg int) string
- func RegisterOpcode(lo int, Anames []string)
- func RegisterRegister(lo, hi int, Rconv func(int) string)
- func Setuintxx(ctxt *Link, s *LSym, off int64, v uint64, wid int64) int64
- func Symgrow(ctxt *Link, s *LSym, lsiz int64)
- func Writeobjdirect(ctxt *Link, b *Biobuf)
- type Addr
- type Auto
- type Biobuf
- type LSym
- type LineHist
- func (h *LineHist) AbsFileLine(lineno int) (file string, line int)
- func (h *LineHist) At(lineno int) *LineStack
- func (h *LineHist) FileLine(lineno int) (file string, line int)
- func (h *LineHist) LineString(lineno int) string
- func (h *LineHist) Pop(lineno int)
- func (h *LineHist) Push(lineno int, file string)
- func (h *LineHist) Update(lineno int, file string, line int)
- type LineRange
- type LineStack
- type Link
- type LinkArch
- type Pcdata
- type Pciter
- type Pcln
- type Plist
- type Prog
- type ProgInfo
- type Reloc
- type SymVer
Constants ¶
const ( FmtWidth = 1 << iota FmtLeft FmtSharp FmtSign FmtUnsigned FmtShort FmtLong FmtComma FmtByte )
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.
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 )
const ( TYPE_BRANCH = 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 )
const ( AXXX = 0 + iota ACALL ACHECKNIL ADATA ADUFFCOPY ADUFFZERO AEND AFUNCDATA AGLOBL AJMP ANOP APCDATA ARET ATEXT ATYPE AUNDEF AUSEFIELD AVARDEF AVARKILL A_ARCHSPECIFIC )
Prog.as opcodes. These are the portable opcodes, common to all architectures. Each architecture defines many more arch-specific opcodes, with values starting at A_ARCHSPECIFIC. Each architecture adds an offset to this so each machine has distinct space for its instructions. The offset is a power of two so it can be masked to return to origin zero. See the definitions of ABase386 etc.
const ( Sxxx = iota STEXT SELFRXSECT STYPE SSTRING SGOSTRING SGOFUNC SGCBITS SRODATA SFUNCTAB // 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 STYPELINK SSYMTAB SPCLNTAB SELFROSECT SMACHOPLT SELFSECT SMACHO SMACHOGOT SWINDOWS SELFGOT SNOPTRDATA SINITARR SDATA SBSS SNOPTRBSS STLSBSS SXREF SMACHOSYMSTR SMACHOSYMTAB SMACHOINDIRECTPLT SMACHOINDIRECTGOT SFILE SFILEPATH SCONST SDYNIMPORT SHOSTOBJ SSUB = 1 << 8 SMASK = SSUB - 1 SHIDDEN = 1 << 9 SCONTAINER = 1 << 10 // has a sub-symbol )
LSym.type
const ( R_ADDR = 1 + iota R_ADDRPOWER R_ADDRARM64 R_SIZE R_CALL R_CALLARM R_CALLARM64 R_CALLIND R_CALLPOWER R_CONST R_PCREL // R_TLS (only used on arm currently, and not on android and darwin where tlsg is // a regular variable) resolves to data needed to access the thread-local g. It is // interpreted differently depending on toolchain flags to implement either the // "local exec" or "inital exec" model for tls access. // TODO(mwhudson): change to use R_TLS_LE or R_TLS_IE as appropriate, not having // R_TLS do double duty. R_TLS // R_TLS_LE (only used on 386 and amd64 currently) resolves to the offset of the // thread-local g from the thread local base and is used to implement the "local // exec" model for tls access (r.Sym is not set by the compiler for this case but // is set to Tlsg in the linker when externally linking). R_TLS_LE // R_TLS_IE (only used on 386 and amd64 currently) resolves to the PC-relative // offset to a GOT slot containing the offset the thread-local g from the thread // local base and is used to implemented the "initial exec" model for tls access // (r.Sym is not set by the compiler for this case but is set to Tlsg in the // linker when externally linking). R_TLS_IE R_GOTOFF R_PLT0 R_PLT1 R_PLT2 R_USEFIELD R_POWER_TOC R_GOTPCREL )
Reloc.type
const ( A_AUTO = 1 + iota A_PARAM )
Auto.name
const ( Hunknown = 0 + iota Hdarwin Hdragonfly Helf Hfreebsd Hlinux Hnacl Hnetbsd Hopenbsd Hplan9 Hsolaris Hwindows )
executable header types
const ( STACKSYSTEM = 0 StackSystem = STACKSYSTEM StackBig = 4096 StackGuard = 640*stackGuardMultiplier + StackSystem StackSmall = 128 StackLimit = StackGuard - StackSystem - StackSmall )
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 )
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 )
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
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, 12k) )
const ( ABase386 = (1 + iota) << 12 ABaseARM ABaseAMD64 ABasePPC64 ABaseARM64 AMask = 1<<12 - 1 // AND with this to use the opcode as an array index. )
const Beof = -1
const (
HistVersion = 1
)
symbol version, incremented each time a file is loaded. version==1 is reserved for savehist.
const (
LOG = 5
)
const REG_NONE = 0
const (
StackPreempt = -1314 // 0xfff...fade
)
const (
TYPE_NONE = 0
)
Variables ¶
var ( Framepointer_enabled int Fieldtrack_enabled int )
var Anames = []string{
"XXX",
"CALL",
"CHECKNIL",
"DATA",
"DUFFCOPY",
"DUFFZERO",
"END",
"FUNCDATA",
"GLOBL",
"JMP",
"NOP",
"PCDATA",
"RET",
"TEXT",
"TYPE",
"UNDEF",
"USEFIELD",
"VARDEF",
"VARKILL",
}
Functions ¶
func Bungetrune ¶
func Bungetrune(b *Biobuf)
func Getcallerpc ¶
func Getcallerpc(interface{}) uintptr
func Getgoextlinkenabled ¶
func Getgoextlinkenabled() string
func Getgoversion ¶
func Getgoversion() string
func Linkprfile ¶
func Linksymfmt ¶
func RegisterOpcode ¶
RegisterOpcode binds a list of instruction names to a given instruction number range.
func RegisterRegister ¶
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 Writeobjdirect ¶
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 { Type int16 Reg int16 Index int16 Scale int16 // Sometimes holds a register. Name int8 Class int8 Etype uint8 Offset int64 Width int64 Sym *LSym Gotype *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. In this form, reg must be a register and shift can be a register or an integer constant. Encoding: type = TYPE_SHIFT 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. (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 LSym ¶
type LSym struct { Name string Type int16 Version int16 Dupok uint8 Cfunc uint8 Nosplit uint8 Leaf uint8 Seenglobl uint8 Onlist uint8 // 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). Local bool Args int32 Locals int32 Value int64 Size int64 Next *LSym Gotype *LSym Autom *Auto Text *Prog Etext *Prog Pcln *Pcln P []byte R []Reloc }
An LSym is the sort of symbol that is written to an object file.
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 GOROOT string // current GOROOT GOROOT_FINAL string // target 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 ¶
AbsFileLine returns the absolute file name and line number at the top of the stack for the given lineno.
func (*LineHist) FileLine ¶
FileLine returns the file name and line number at the top of the stack for the given lineno.
func (*LineHist) LineString ¶
LineString returns a string giving the file and line number corresponding to lineno, for use in error messages.
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 ¶
type Link struct { Goarm int32 Headtype int Arch *LinkArch Debugasm int32 Debugvlog int32 Debugdivmod int32 Debugpcln int32 Flag_dynlink bool Bso *Biobuf Pathname string Windows int32 Goroot string Goroot_final string Enforce_data_order int32 Hash map[SymVer]*LSym LineHist LineHist Imports []string Plist *Plist Plast *Plist Sym_div *LSym Sym_divu *LSym Sym_mod *LSym Sym_modu *LSym Tlsg *LSym Plan9privates *LSym Curp *Prog Printp *Prog Blitrl *Prog Elitrl *Prog Rexflag int Rep int Repn int Lock int Asmode int Andptr []byte And [100]uint8 Instoffset int64 Autosize int32 Armsize int32 Pc int64 Diag func(string, ...interface{}) Mode int Cursym *LSym Version int Textp *LSym Etextp *LSym }
Link holds the context for writing object code from a compiler to be linker input or for reading that input into the linker.
type LinkArch ¶
type LinkArch struct { ByteOrder binary.ByteOrder Name string Thechar int Preprocess func(*Link, *LSym) Assemble func(*Link, *LSym) Follow func(*Link, *LSym) Progedit func(*Link, *Prog) UnaryDst map[int]bool // Instruction takes one operand, a destination. Minlc int Ptrsize int Regsize int }
LinkArch is the definition of a single architecture.
type Pciter ¶
type Pciter struct {
// contains filtered or unexported fields
}
Pcdata iterator.
for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) }
type Prog ¶
type Prog struct { Ctxt *Link Link *Prog From Addr From3 *Addr // optional To Addr Opt interface{} Forwd *Prog Pcond *Prog Rel *Prog // Source of forward jumps on x86; pcrel on arm Pc int64 Lineno int32 Spadj int32 As int16 Reg int16 RegTo2 int16 // 2nd register output operand Mark uint16 Optab uint16 Scond uint8 Back uint8 Ft uint8 Tt uint8 Isize uint8 Mode int8 Info ProgInfo }
TODO(rsc): Describe prog. TODO(rsc): Describe TEXT/GLOBL flag in from3, DATA width in from3.
func (*Prog) From3Offset ¶
From3Offset returns From3.Offset, or 0 when From3 is nil.
type ProgInfo ¶
type ProgInfo struct { Flags uint32 // flag bits Reguse uint64 // registers implicitly used by this instruction Regset uint64 // registers implicitly set by this instruction Regindex uint64 // registers used by addressing mode // contains filtered or unexported fields }
ProgInfo holds information about the instruction for use by clients such as the compiler. The exact meaning of this data is up to the client and is not interpreted by the cmd/internal/obj/... packages.