podman
771 строка · 24.3 Кб
1// Derived from Inferno utils/6l/l.h and related files.
2// https://bitbucket.org/inferno-os/inferno-os/src/master/utils/6l/l.h
3//
4// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
5// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
6// Portions Copyright © 1997-1999 Vita Nuova Limited
7// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
8// Portions Copyright © 2004,2006 Bruce Ellis
9// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
10// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
11// Portions Copyright © 2009 The Go Authors. All rights reserved.
12//
13// Permission is hereby granted, free of charge, to any person obtaining a copy
14// of this software and associated documentation files (the "Software"), to deal
15// in the Software without restriction, including without limitation the rights
16// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17// copies of the Software, and to permit persons to whom the Software is
18// furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included in
21// all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29// THE SOFTWARE.
30
31package obj
32
33import (
34"bufio"
35"github.com/twitchyliquid64/golang-asm/dwarf"
36"github.com/twitchyliquid64/golang-asm/goobj"
37"github.com/twitchyliquid64/golang-asm/objabi"
38"github.com/twitchyliquid64/golang-asm/src"
39"github.com/twitchyliquid64/golang-asm/sys"
40"fmt"
41"sync"
42)
43
44// An Addr is an argument to an instruction.
45// The general forms and their encodings are:
46//
47// sym±offset(symkind)(reg)(index*scale)
48// Memory reference at address &sym(symkind) + offset + reg + index*scale.
49// Any of sym(symkind), ±offset, (reg), (index*scale), and *scale can be omitted.
50// If (reg) and *scale are both omitted, the resulting expression (index) is parsed as (reg).
51// To force a parsing as index*scale, write (index*1).
52// Encoding:
53// type = TYPE_MEM
54// name = symkind (NAME_AUTO, ...) or 0 (NAME_NONE)
55// sym = sym
56// offset = ±offset
57// reg = reg (REG_*)
58// index = index (REG_*)
59// scale = scale (1, 2, 4, 8)
60//
61// $<mem>
62// Effective address of memory reference <mem>, defined above.
63// Encoding: same as memory reference, but type = TYPE_ADDR.
64//
65// $<±integer value>
66// This is a special case of $<mem>, in which only ±offset is present.
67// It has a separate type for easy recognition.
68// Encoding:
69// type = TYPE_CONST
70// offset = ±integer value
71//
72// *<mem>
73// Indirect reference through memory reference <mem>, defined above.
74// Only used on x86 for CALL/JMP *sym(SB), which calls/jumps to a function
75// pointer stored in the data word sym(SB), not a function named sym(SB).
76// Encoding: same as above, but type = TYPE_INDIR.
77//
78// $*$<mem>
79// No longer used.
80// On machines with actual SB registers, $*$<mem> forced the
81// instruction encoding to use a full 32-bit constant, never a
82// reference relative to SB.
83//
84// $<floating point literal>
85// Floating point constant value.
86// Encoding:
87// type = TYPE_FCONST
88// val = floating point value
89//
90// $<string literal, up to 8 chars>
91// String literal value (raw bytes used for DATA instruction).
92// Encoding:
93// type = TYPE_SCONST
94// val = string
95//
96// <register name>
97// Any register: integer, floating point, control, segment, and so on.
98// If looking for specific register kind, must check type and reg value range.
99// Encoding:
100// type = TYPE_REG
101// reg = reg (REG_*)
102//
103// x(PC)
104// Encoding:
105// type = TYPE_BRANCH
106// val = Prog* reference OR ELSE offset = target pc (branch takes priority)
107//
108// $±x-±y
109// Final argument to TEXT, specifying local frame size x and argument size y.
110// In this form, x and y are integer literals only, not arbitrary expressions.
111// This avoids parsing ambiguities due to the use of - as a separator.
112// The ± are optional.
113// If the final argument to TEXT omits the -±y, the encoding should still
114// use TYPE_TEXTSIZE (not TYPE_CONST), with u.argsize = ArgsSizeUnknown.
115// Encoding:
116// type = TYPE_TEXTSIZE
117// offset = x
118// val = int32(y)
119//
120// reg<<shift, reg>>shift, reg->shift, reg@>shift
121// Shifted register value, for ARM and ARM64.
122// In this form, reg must be a register and shift can be a register or an integer constant.
123// Encoding:
124// type = TYPE_SHIFT
125// On ARM:
126// offset = (reg&15) | shifttype<<5 | count
127// shifttype = 0, 1, 2, 3 for <<, >>, ->, @>
128// count = (reg&15)<<8 | 1<<4 for a register shift count, (n&31)<<7 for an integer constant.
129// On ARM64:
130// offset = (reg&31)<<16 | shifttype<<22 | (count&63)<<10
131// shifttype = 0, 1, 2 for <<, >>, ->
132//
133// (reg, reg)
134// A destination register pair. When used as the last argument of an instruction,
135// this form makes clear that both registers are destinations.
136// Encoding:
137// type = TYPE_REGREG
138// reg = first register
139// offset = second register
140//
141// [reg, reg, reg-reg]
142// Register list for ARM, ARM64, 386/AMD64.
143// Encoding:
144// type = TYPE_REGLIST
145// On ARM:
146// offset = bit mask of registers in list; R0 is low bit.
147// On ARM64:
148// offset = register count (Q:size) | arrangement (opcode) | first register
149// On 386/AMD64:
150// reg = range low register
151// offset = 2 packed registers + kind tag (see x86.EncodeRegisterRange)
152//
153// reg, reg
154// Register pair for ARM.
155// TYPE_REGREG2
156//
157// (reg+reg)
158// Register pair for PPC64.
159// Encoding:
160// type = TYPE_MEM
161// reg = first register
162// index = second register
163// scale = 1
164//
165// reg.[US]XT[BHWX]
166// Register extension for ARM64
167// Encoding:
168// type = TYPE_REG
169// reg = REG_[US]XT[BHWX] + register + shift amount
170// offset = ((reg&31) << 16) | (exttype << 13) | (amount<<10)
171//
172// reg.<T>
173// Register arrangement for ARM64 SIMD register
174// e.g.: V1.S4, V2.S2, V7.D2, V2.H4, V6.B16
175// Encoding:
176// type = TYPE_REG
177// reg = REG_ARNG + register + arrangement
178//
179// reg.<T>[index]
180// Register element for ARM64
181// Encoding:
182// type = TYPE_REG
183// reg = REG_ELEM + register + arrangement
184// index = element index
185
186type Addr struct {
187Reg int16
188Index int16
189Scale int16 // Sometimes holds a register.
190Type AddrType
191Name AddrName
192Class int8
193Offset int64
194Sym *LSym
195
196// argument value:
197// for TYPE_SCONST, a string
198// for TYPE_FCONST, a float64
199// for TYPE_BRANCH, a *Prog (optional)
200// for TYPE_TEXTSIZE, an int32 (optional)
201Val interface{}
202}
203
204type AddrName int8
205
206const (
207NAME_NONE AddrName = iota
208NAME_EXTERN
209NAME_STATIC
210NAME_AUTO
211NAME_PARAM
212// A reference to name@GOT(SB) is a reference to the entry in the global offset
213// table for 'name'.
214NAME_GOTREF
215// Indicates that this is a reference to a TOC anchor.
216NAME_TOCREF
217)
218
219//go:generate stringer -type AddrType
220
221type AddrType uint8
222
223const (
224TYPE_NONE AddrType = iota
225TYPE_BRANCH
226TYPE_TEXTSIZE
227TYPE_MEM
228TYPE_CONST
229TYPE_FCONST
230TYPE_SCONST
231TYPE_REG
232TYPE_ADDR
233TYPE_SHIFT
234TYPE_REGREG
235TYPE_REGREG2
236TYPE_INDIR
237TYPE_REGLIST
238)
239
240func (a *Addr) Target() *Prog {
241if a.Type == TYPE_BRANCH && a.Val != nil {
242return a.Val.(*Prog)
243}
244return nil
245}
246func (a *Addr) SetTarget(t *Prog) {
247if a.Type != TYPE_BRANCH {
248panic("setting branch target when type is not TYPE_BRANCH")
249}
250a.Val = t
251}
252
253// Prog describes a single machine instruction.
254//
255// The general instruction form is:
256//
257// (1) As.Scond From [, ...RestArgs], To
258// (2) As.Scond From, Reg [, ...RestArgs], To, RegTo2
259//
260// where As is an opcode and the others are arguments:
261// From, Reg are sources, and To, RegTo2 are destinations.
262// RestArgs can hold additional sources and destinations.
263// Usually, not all arguments are present.
264// For example, MOVL R1, R2 encodes using only As=MOVL, From=R1, To=R2.
265// The Scond field holds additional condition bits for systems (like arm)
266// that have generalized conditional execution.
267// (2) form is present for compatibility with older code,
268// to avoid too much changes in a single swing.
269// (1) scheme is enough to express any kind of operand combination.
270//
271// Jump instructions use the To.Val field to point to the target *Prog,
272// which must be in the same linked list as the jump instruction.
273//
274// The Progs for a given function are arranged in a list linked through the Link field.
275//
276// Each Prog is charged to a specific source line in the debug information,
277// specified by Pos.Line().
278// Every Prog has a Ctxt field that defines its context.
279// For performance reasons, Progs usually are usually bulk allocated, cached, and reused;
280// those bulk allocators should always be used, rather than new(Prog).
281//
282// The other fields not yet mentioned are for use by the back ends and should
283// be left zeroed by creators of Prog lists.
284type Prog struct {
285Ctxt *Link // linker context
286Link *Prog // next Prog in linked list
287From Addr // first source operand
288RestArgs []Addr // can pack any operands that not fit into {Prog.From, Prog.To}
289To Addr // destination operand (second is RegTo2 below)
290Pool *Prog // constant pool entry, for arm,arm64 back ends
291Forwd *Prog // for x86 back end
292Rel *Prog // for x86, arm back ends
293Pc int64 // for back ends or assembler: virtual or actual program counter, depending on phase
294Pos src.XPos // source position of this instruction
295Spadj int32 // effect of instruction on stack pointer (increment or decrement amount)
296As As // assembler opcode
297Reg int16 // 2nd source operand
298RegTo2 int16 // 2nd destination operand
299Mark uint16 // bitmask of arch-specific items
300Optab uint16 // arch-specific opcode index
301Scond uint8 // bits that describe instruction suffixes (e.g. ARM conditions)
302Back uint8 // for x86 back end: backwards branch state
303Ft uint8 // for x86 back end: type index of Prog.From
304Tt uint8 // for x86 back end: type index of Prog.To
305Isize uint8 // for x86 back end: size of the instruction in bytes
306}
307
308// From3Type returns p.GetFrom3().Type, or TYPE_NONE when
309// p.GetFrom3() returns nil.
310//
311// Deprecated: for the same reasons as Prog.GetFrom3.
312func (p *Prog) From3Type() AddrType {
313if p.RestArgs == nil {
314return TYPE_NONE
315}
316return p.RestArgs[0].Type
317}
318
319// GetFrom3 returns second source operand (the first is Prog.From).
320// In combination with Prog.From and Prog.To it makes common 3 operand
321// case easier to use.
322//
323// Should be used only when RestArgs is set with SetFrom3.
324//
325// Deprecated: better use RestArgs directly or define backend-specific getters.
326// Introduced to simplify transition to []Addr.
327// Usage of this is discouraged due to fragility and lack of guarantees.
328func (p *Prog) GetFrom3() *Addr {
329if p.RestArgs == nil {
330return nil
331}
332return &p.RestArgs[0]
333}
334
335// SetFrom3 assigns []Addr{a} to p.RestArgs.
336// In pair with Prog.GetFrom3 it can help in emulation of Prog.From3.
337//
338// Deprecated: for the same reasons as Prog.GetFrom3.
339func (p *Prog) SetFrom3(a Addr) {
340p.RestArgs = []Addr{a}
341}
342
343// An As denotes an assembler opcode.
344// There are some portable opcodes, declared here in package obj,
345// that are common to all architectures.
346// However, the majority of opcodes are arch-specific
347// and are declared in their respective architecture's subpackage.
348type As int16
349
350// These are the portable opcodes.
351const (
352AXXX As = iota
353ACALL
354ADUFFCOPY
355ADUFFZERO
356AEND
357AFUNCDATA
358AJMP
359ANOP
360APCALIGN
361APCDATA
362ARET
363AGETCALLERPC
364ATEXT
365AUNDEF
366A_ARCHSPECIFIC
367)
368
369// Each architecture is allotted a distinct subspace of opcode values
370// for declaring its arch-specific opcodes.
371// Within this subspace, the first arch-specific opcode should be
372// at offset A_ARCHSPECIFIC.
373//
374// Subspaces are aligned to a power of two so opcodes can be masked
375// with AMask and used as compact array indices.
376const (
377ABase386 = (1 + iota) << 11
378ABaseARM
379ABaseAMD64
380ABasePPC64
381ABaseARM64
382ABaseMIPS
383ABaseRISCV
384ABaseS390X
385ABaseWasm
386
387AllowedOpCodes = 1 << 11 // The number of opcodes available for any given architecture.
388AMask = AllowedOpCodes - 1 // AND with this to use the opcode as an array index.
389)
390
391// An LSym is the sort of symbol that is written to an object file.
392// It represents Go symbols in a flat pkg+"."+name namespace.
393type LSym struct {
394Name string
395Type objabi.SymKind
396Attribute
397
398RefIdx int // Index of this symbol in the symbol reference list.
399Size int64
400Gotype *LSym
401P []byte
402R []Reloc
403
404Func *FuncInfo
405
406Pkg string
407PkgIdx int32
408SymIdx int32 // TODO: replace RefIdx
409}
410
411// A FuncInfo contains extra fields for STEXT symbols.
412type FuncInfo struct {
413Args int32
414Locals int32
415Align int32
416FuncID objabi.FuncID
417Text *Prog
418Autot map[*LSym]struct{}
419Pcln Pcln
420InlMarks []InlMark
421
422dwarfInfoSym *LSym
423dwarfLocSym *LSym
424dwarfRangesSym *LSym
425dwarfAbsFnSym *LSym
426dwarfDebugLinesSym *LSym
427
428GCArgs *LSym
429GCLocals *LSym
430GCRegs *LSym // Only if !go115ReduceLiveness
431StackObjects *LSym
432OpenCodedDeferInfo *LSym
433
434FuncInfoSym *LSym
435}
436
437type InlMark struct {
438// When unwinding from an instruction in an inlined body, mark
439// where we should unwind to.
440// id records the global inlining id of the inlined body.
441// p records the location of an instruction in the parent (inliner) frame.
442p *Prog
443id int32
444}
445
446// Mark p as the instruction to set as the pc when
447// "unwinding" the inlining global frame id. Usually it should be
448// instruction with a file:line at the callsite, and occur
449// just before the body of the inlined function.
450func (fi *FuncInfo) AddInlMark(p *Prog, id int32) {
451fi.InlMarks = append(fi.InlMarks, InlMark{p: p, id: id})
452}
453
454// Record the type symbol for an auto variable so that the linker
455// an emit DWARF type information for the type.
456func (fi *FuncInfo) RecordAutoType(gotype *LSym) {
457if fi.Autot == nil {
458fi.Autot = make(map[*LSym]struct{})
459}
460fi.Autot[gotype] = struct{}{}
461}
462
463//go:generate stringer -type ABI
464
465// ABI is the calling convention of a text symbol.
466type ABI uint8
467
468const (
469// ABI0 is the stable stack-based ABI. It's important that the
470// value of this is "0": we can't distinguish between
471// references to data and ABI0 text symbols in assembly code,
472// and hence this doesn't distinguish between symbols without
473// an ABI and text symbols with ABI0.
474ABI0 ABI = iota
475
476// ABIInternal is the internal ABI that may change between Go
477// versions. All Go functions use the internal ABI and the
478// compiler generates wrappers for calls to and from other
479// ABIs.
480ABIInternal
481
482ABICount
483)
484
485// Attribute is a set of symbol attributes.
486type Attribute uint32
487
488const (
489AttrDuplicateOK Attribute = 1 << iota
490AttrCFunc
491AttrNoSplit
492AttrLeaf
493AttrWrapper
494AttrNeedCtxt
495AttrNoFrame
496AttrOnList
497AttrStatic
498
499// MakeTypelink means that the type should have an entry in the typelink table.
500AttrMakeTypelink
501
502// ReflectMethod means the function may call reflect.Type.Method or
503// reflect.Type.MethodByName. Matching is imprecise (as reflect.Type
504// can be used through a custom interface), so ReflectMethod may be
505// set in some cases when the reflect package is not called.
506//
507// Used by the linker to determine what methods can be pruned.
508AttrReflectMethod
509
510// Local means make the symbol local even when compiling Go code to reference Go
511// symbols in other shared libraries, as in this mode symbols are global by
512// default. "local" here means in the sense of the dynamic linker, i.e. not
513// visible outside of the module (shared library or executable) that contains its
514// definition. (When not compiling to support Go shared libraries, all symbols are
515// local in this sense unless there is a cgo_export_* directive).
516AttrLocal
517
518// For function symbols; indicates that the specified function was the
519// target of an inline during compilation
520AttrWasInlined
521
522// TopFrame means that this function is an entry point and unwinders should not
523// keep unwinding beyond this frame.
524AttrTopFrame
525
526// Indexed indicates this symbol has been assigned with an index (when using the
527// new object file format).
528AttrIndexed
529
530// Only applied on type descriptor symbols, UsedInIface indicates this type is
531// converted to an interface.
532//
533// Used by the linker to determine what methods can be pruned.
534AttrUsedInIface
535
536// ContentAddressable indicates this is a content-addressable symbol.
537AttrContentAddressable
538
539// attrABIBase is the value at which the ABI is encoded in
540// Attribute. This must be last; all bits after this are
541// assumed to be an ABI value.
542//
543// MUST BE LAST since all bits above this comprise the ABI.
544attrABIBase
545)
546
547func (a Attribute) DuplicateOK() bool { return a&AttrDuplicateOK != 0 }
548func (a Attribute) MakeTypelink() bool { return a&AttrMakeTypelink != 0 }
549func (a Attribute) CFunc() bool { return a&AttrCFunc != 0 }
550func (a Attribute) NoSplit() bool { return a&AttrNoSplit != 0 }
551func (a Attribute) Leaf() bool { return a&AttrLeaf != 0 }
552func (a Attribute) OnList() bool { return a&AttrOnList != 0 }
553func (a Attribute) ReflectMethod() bool { return a&AttrReflectMethod != 0 }
554func (a Attribute) Local() bool { return a&AttrLocal != 0 }
555func (a Attribute) Wrapper() bool { return a&AttrWrapper != 0 }
556func (a Attribute) NeedCtxt() bool { return a&AttrNeedCtxt != 0 }
557func (a Attribute) NoFrame() bool { return a&AttrNoFrame != 0 }
558func (a Attribute) Static() bool { return a&AttrStatic != 0 }
559func (a Attribute) WasInlined() bool { return a&AttrWasInlined != 0 }
560func (a Attribute) TopFrame() bool { return a&AttrTopFrame != 0 }
561func (a Attribute) Indexed() bool { return a&AttrIndexed != 0 }
562func (a Attribute) UsedInIface() bool { return a&AttrUsedInIface != 0 }
563func (a Attribute) ContentAddressable() bool { return a&AttrContentAddressable != 0 }
564
565func (a *Attribute) Set(flag Attribute, value bool) {
566if value {
567*a |= flag
568} else {
569*a &^= flag
570}
571}
572
573func (a Attribute) ABI() ABI { return ABI(a / attrABIBase) }
574func (a *Attribute) SetABI(abi ABI) {
575const mask = 1 // Only one ABI bit for now.
576*a = (*a &^ (mask * attrABIBase)) | Attribute(abi)*attrABIBase
577}
578
579var textAttrStrings = [...]struct {
580bit Attribute
581s string
582}{
583{bit: AttrDuplicateOK, s: "DUPOK"},
584{bit: AttrMakeTypelink, s: ""},
585{bit: AttrCFunc, s: "CFUNC"},
586{bit: AttrNoSplit, s: "NOSPLIT"},
587{bit: AttrLeaf, s: "LEAF"},
588{bit: AttrOnList, s: ""},
589{bit: AttrReflectMethod, s: "REFLECTMETHOD"},
590{bit: AttrLocal, s: "LOCAL"},
591{bit: AttrWrapper, s: "WRAPPER"},
592{bit: AttrNeedCtxt, s: "NEEDCTXT"},
593{bit: AttrNoFrame, s: "NOFRAME"},
594{bit: AttrStatic, s: "STATIC"},
595{bit: AttrWasInlined, s: ""},
596{bit: AttrTopFrame, s: "TOPFRAME"},
597{bit: AttrIndexed, s: ""},
598{bit: AttrContentAddressable, s: ""},
599}
600
601// TextAttrString formats a for printing in as part of a TEXT prog.
602func (a Attribute) TextAttrString() string {
603var s string
604for _, x := range textAttrStrings {
605if a&x.bit != 0 {
606if x.s != "" {
607s += x.s + "|"
608}
609a &^= x.bit
610}
611}
612switch a.ABI() {
613case ABI0:
614case ABIInternal:
615s += "ABIInternal|"
616a.SetABI(0) // Clear ABI so we don't print below.
617}
618if a != 0 {
619s += fmt.Sprintf("UnknownAttribute(%d)|", a)
620}
621// Chop off trailing |, if present.
622if len(s) > 0 {
623s = s[:len(s)-1]
624}
625return s
626}
627
628func (s *LSym) String() string {
629return s.Name
630}
631
632// The compiler needs *LSym to be assignable to cmd/compile/internal/ssa.Sym.
633func (s *LSym) CanBeAnSSASym() {
634}
635
636type Pcln struct {
637Pcsp Pcdata
638Pcfile Pcdata
639Pcline Pcdata
640Pcinline Pcdata
641Pcdata []Pcdata
642Funcdata []*LSym
643Funcdataoff []int64
644UsedFiles map[goobj.CUFileIndex]struct{} // file indices used while generating pcfile
645InlTree InlTree // per-function inlining tree extracted from the global tree
646}
647
648type Reloc struct {
649Off int32
650Siz uint8
651Type objabi.RelocType
652Add int64
653Sym *LSym
654}
655
656type Auto struct {
657Asym *LSym
658Aoffset int32
659Name AddrName
660Gotype *LSym
661}
662
663type Pcdata struct {
664P []byte
665}
666
667// Link holds the context for writing object code from a compiler
668// to be linker input or for reading that input into the linker.
669type Link struct {
670Headtype objabi.HeadType
671Arch *LinkArch
672Debugasm int
673Debugvlog bool
674Debugpcln string
675Flag_shared bool
676Flag_dynlink bool
677Flag_linkshared bool
678Flag_optimize bool
679Flag_locationlists bool
680Retpoline bool // emit use of retpoline stubs for indirect jmp/call
681Bso *bufio.Writer
682Pathname string
683Pkgpath string // the current package's import path, "" if unknown
684hashmu sync.Mutex // protects hash, funchash
685hash map[string]*LSym // name -> sym mapping
686funchash map[string]*LSym // name -> sym mapping for ABIInternal syms
687statichash map[string]*LSym // name -> sym mapping for static syms
688PosTable src.PosTable
689InlTree InlTree // global inlining tree used by gc/inl.go
690DwFixups *DwarfFixupTable
691Imports []goobj.ImportedPkg
692DiagFunc func(string, ...interface{})
693DiagFlush func()
694DebugInfo func(fn *LSym, info *LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCalls) // if non-nil, curfn is a *gc.Node
695GenAbstractFunc func(fn *LSym)
696Errors int
697
698InParallel bool // parallel backend phase in effect
699UseBASEntries bool // use Base Address Selection Entries in location lists and PC ranges
700IsAsm bool // is the source assembly language, which may contain surprising idioms (e.g., call tables)
701
702// state for writing objects
703Text []*LSym
704Data []*LSym
705
706// ABIAliases are text symbols that should be aliased to all
707// ABIs. These symbols may only be referenced and not defined
708// by this object, since the need for an alias may appear in a
709// different object than the definition. Hence, this
710// information can't be carried in the symbol definition.
711//
712// TODO(austin): Replace this with ABI wrappers once the ABIs
713// actually diverge.
714ABIAliases []*LSym
715
716// Constant symbols (e.g. $i64.*) are data symbols created late
717// in the concurrent phase. To ensure a deterministic order, we
718// add them to a separate list, sort at the end, and append it
719// to Data.
720constSyms []*LSym
721
722// pkgIdx maps package path to index. The index is used for
723// symbol reference in the object file.
724pkgIdx map[string]int32
725
726defs []*LSym // list of defined symbols in the current package
727hashed64defs []*LSym // list of defined short (64-bit or less) hashed (content-addressable) symbols
728hasheddefs []*LSym // list of defined hashed (content-addressable) symbols
729nonpkgdefs []*LSym // list of defined non-package symbols
730nonpkgrefs []*LSym // list of referenced non-package symbols
731
732Fingerprint goobj.FingerprintType // fingerprint of symbol indices, to catch index mismatch
733}
734
735func (ctxt *Link) Diag(format string, args ...interface{}) {
736ctxt.Errors++
737ctxt.DiagFunc(format, args...)
738}
739
740func (ctxt *Link) Logf(format string, args ...interface{}) {
741fmt.Fprintf(ctxt.Bso, format, args...)
742ctxt.Bso.Flush()
743}
744
745// The smallest possible offset from the hardware stack pointer to a local
746// variable on the stack. Architectures that use a link register save its value
747// on the stack in the function prologue and so always have a pointer between
748// the hardware stack pointer and the local variable area.
749func (ctxt *Link) FixedFrameSize() int64 {
750switch ctxt.Arch.Family {
751case sys.AMD64, sys.I386, sys.Wasm:
752return 0
753case sys.PPC64:
754// PIC code on ppc64le requires 32 bytes of stack, and it's easier to
755// just use that much stack always on ppc64x.
756return int64(4 * ctxt.Arch.PtrSize)
757default:
758return int64(ctxt.Arch.PtrSize)
759}
760}
761
762// LinkArch is the definition of a single architecture.
763type LinkArch struct {
764*sys.Arch
765Init func(*Link)
766Preprocess func(*Link, *LSym, ProgAlloc)
767Assemble func(*Link, *LSym, ProgAlloc)
768Progedit func(*Link, *Prog, ProgAlloc)
769UnaryDst map[As]bool // Instruction takes one operand, a destination.
770DWARFRegisters map[int16]int16
771}
772