github.com/corona10/go@v0.0.0-20180224231303-7a218942be57/src/cmd/internal/obj/link.go (about)

     1  // Derived from Inferno utils/6l/l.h and related files.
     2  // https://bitbucket.org/inferno-os/inferno-os/src/default/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  
    31  package obj
    32  
    33  import (
    34  	"bufio"
    35  	"cmd/internal/dwarf"
    36  	"cmd/internal/objabi"
    37  	"cmd/internal/src"
    38  	"cmd/internal/sys"
    39  	"fmt"
    40  	"sync"
    41  )
    42  
    43  // An Addr is an argument to an instruction.
    44  // The general forms and their encodings are:
    45  //
    46  //	sym±offset(symkind)(reg)(index*scale)
    47  //		Memory reference at address &sym(symkind) + offset + reg + index*scale.
    48  //		Any of sym(symkind), ±offset, (reg), (index*scale), and *scale can be omitted.
    49  //		If (reg) and *scale are both omitted, the resulting expression (index) is parsed as (reg).
    50  //		To force a parsing as index*scale, write (index*1).
    51  //		Encoding:
    52  //			type = TYPE_MEM
    53  //			name = symkind (NAME_AUTO, ...) or 0 (NAME_NONE)
    54  //			sym = sym
    55  //			offset = ±offset
    56  //			reg = reg (REG_*)
    57  //			index = index (REG_*)
    58  //			scale = scale (1, 2, 4, 8)
    59  //
    60  //	$<mem>
    61  //		Effective address of memory reference <mem>, defined above.
    62  //		Encoding: same as memory reference, but type = TYPE_ADDR.
    63  //
    64  //	$<±integer value>
    65  //		This is a special case of $<mem>, in which only ±offset is present.
    66  //		It has a separate type for easy recognition.
    67  //		Encoding:
    68  //			type = TYPE_CONST
    69  //			offset = ±integer value
    70  //
    71  //	*<mem>
    72  //		Indirect reference through memory reference <mem>, defined above.
    73  //		Only used on x86 for CALL/JMP *sym(SB), which calls/jumps to a function
    74  //		pointer stored in the data word sym(SB), not a function named sym(SB).
    75  //		Encoding: same as above, but type = TYPE_INDIR.
    76  //
    77  //	$*$<mem>
    78  //		No longer used.
    79  //		On machines with actual SB registers, $*$<mem> forced the
    80  //		instruction encoding to use a full 32-bit constant, never a
    81  //		reference relative to SB.
    82  //
    83  //	$<floating point literal>
    84  //		Floating point constant value.
    85  //		Encoding:
    86  //			type = TYPE_FCONST
    87  //			val = floating point value
    88  //
    89  //	$<string literal, up to 8 chars>
    90  //		String literal value (raw bytes used for DATA instruction).
    91  //		Encoding:
    92  //			type = TYPE_SCONST
    93  //			val = string
    94  //
    95  //	<register name>
    96  //		Any register: integer, floating point, control, segment, and so on.
    97  //		If looking for specific register kind, must check type and reg value range.
    98  //		Encoding:
    99  //			type = TYPE_REG
   100  //			reg = reg (REG_*)
   101  //
   102  //	x(PC)
   103  //		Encoding:
   104  //			type = TYPE_BRANCH
   105  //			val = Prog* reference OR ELSE offset = target pc (branch takes priority)
   106  //
   107  //	$±x-±y
   108  //		Final argument to TEXT, specifying local frame size x and argument size y.
   109  //		In this form, x and y are integer literals only, not arbitrary expressions.
   110  //		This avoids parsing ambiguities due to the use of - as a separator.
   111  //		The ± are optional.
   112  //		If the final argument to TEXT omits the -±y, the encoding should still
   113  //		use TYPE_TEXTSIZE (not TYPE_CONST), with u.argsize = ArgsSizeUnknown.
   114  //		Encoding:
   115  //			type = TYPE_TEXTSIZE
   116  //			offset = x
   117  //			val = int32(y)
   118  //
   119  //	reg<<shift, reg>>shift, reg->shift, reg@>shift
   120  //		Shifted register value, for ARM and ARM64.
   121  //		In this form, reg must be a register and shift can be a register or an integer constant.
   122  //		Encoding:
   123  //			type = TYPE_SHIFT
   124  //		On ARM:
   125  //			offset = (reg&15) | shifttype<<5 | count
   126  //			shifttype = 0, 1, 2, 3 for <<, >>, ->, @>
   127  //			count = (reg&15)<<8 | 1<<4 for a register shift count, (n&31)<<7 for an integer constant.
   128  //		On ARM64:
   129  //			offset = (reg&31)<<16 | shifttype<<22 | (count&63)<<10
   130  //			shifttype = 0, 1, 2 for <<, >>, ->
   131  //
   132  //	(reg, reg)
   133  //		A destination register pair. When used as the last argument of an instruction,
   134  //		this form makes clear that both registers are destinations.
   135  //		Encoding:
   136  //			type = TYPE_REGREG
   137  //			reg = first register
   138  //			offset = second register
   139  //
   140  //	[reg, reg, reg-reg]
   141  //		Register list for ARM and ARM64.
   142  //		Encoding:
   143  //			type = TYPE_REGLIST
   144  //		On ARM:
   145  //			offset = bit mask of registers in list; R0 is low bit.
   146  //		On ARM64:
   147  //			offset = register count (Q:size) | arrangement (opcode) | first register
   148  //
   149  //	reg, reg
   150  //		Register pair for ARM.
   151  //		TYPE_REGREG2
   152  //
   153  //	(reg+reg)
   154  //		Register pair for PPC64.
   155  //		Encoding:
   156  //			type = TYPE_MEM
   157  //			reg = first register
   158  //			index = second register
   159  //			scale = 1
   160  //
   161  //	reg.[US]XT[BHWX]
   162  //		Register extension for ARM64
   163  //		Encoding:
   164  //			type = TYPE_REG
   165  //			reg = REG_[US]XT[BHWX] + register + shift amount
   166  //			offset = ((reg&31) << 16) | (exttype << 13) | (amount<<10)
   167  //
   168  //	reg.<T>
   169  //		Register arrangement for ARM64 SIMD register
   170  //		e.g.: V1.S4, V2.S2, V7.D2, V2.H4, V6.B16
   171  //		Encoding:
   172  //			type = TYPE_REG
   173  //			reg = REG_ARNG + register + arrangement
   174  //
   175  //	reg.<T>[index]
   176  //		Register element for ARM64
   177  //		Encoding:
   178  //			type = TYPE_REG
   179  //			reg = REG_ELEM + register + arrangement
   180  //			index = element index
   181  
   182  type Addr struct {
   183  	Reg    int16
   184  	Index  int16
   185  	Scale  int16 // Sometimes holds a register.
   186  	Type   AddrType
   187  	Name   AddrName
   188  	Class  int8
   189  	Offset int64
   190  	Sym    *LSym
   191  
   192  	// argument value:
   193  	//	for TYPE_SCONST, a string
   194  	//	for TYPE_FCONST, a float64
   195  	//	for TYPE_BRANCH, a *Prog (optional)
   196  	//	for TYPE_TEXTSIZE, an int32 (optional)
   197  	Val interface{}
   198  }
   199  
   200  type AddrName int8
   201  
   202  const (
   203  	NAME_NONE AddrName = iota
   204  	NAME_EXTERN
   205  	NAME_STATIC
   206  	NAME_AUTO
   207  	NAME_PARAM
   208  	// A reference to name@GOT(SB) is a reference to the entry in the global offset
   209  	// table for 'name'.
   210  	NAME_GOTREF
   211  	// Indicates auto that was optimized away, but whose type
   212  	// we want to preserve in the DWARF debug info.
   213  	NAME_DELETED_AUTO
   214  )
   215  
   216  type AddrType uint8
   217  
   218  const (
   219  	TYPE_NONE AddrType = iota
   220  	TYPE_BRANCH
   221  	TYPE_TEXTSIZE
   222  	TYPE_MEM
   223  	TYPE_CONST
   224  	TYPE_FCONST
   225  	TYPE_SCONST
   226  	TYPE_REG
   227  	TYPE_ADDR
   228  	TYPE_SHIFT
   229  	TYPE_REGREG
   230  	TYPE_REGREG2
   231  	TYPE_INDIR
   232  	TYPE_REGLIST
   233  )
   234  
   235  // Prog describes a single machine instruction.
   236  //
   237  // The general instruction form is:
   238  //
   239  //	(1) As.Scond From [, ...RestArgs], To
   240  //	(2) As.Scond From, Reg [, ...RestArgs], To, RegTo2
   241  //
   242  // where As is an opcode and the others are arguments:
   243  // From, Reg are sources, and To, RegTo2 are destinations.
   244  // RestArgs can hold additional sources and destinations.
   245  // Usually, not all arguments are present.
   246  // For example, MOVL R1, R2 encodes using only As=MOVL, From=R1, To=R2.
   247  // The Scond field holds additional condition bits for systems (like arm)
   248  // that have generalized conditional execution.
   249  // (2) form is present for compatibility with older code,
   250  // to avoid too much changes in a single swing.
   251  // (1) scheme is enough to express any kind of operand combination.
   252  //
   253  // Jump instructions use the Pcond field to point to the target instruction,
   254  // which must be in the same linked list as the jump instruction.
   255  //
   256  // The Progs for a given function are arranged in a list linked through the Link field.
   257  //
   258  // Each Prog is charged to a specific source line in the debug information,
   259  // specified by Pos.Line().
   260  // Every Prog has a Ctxt field that defines its context.
   261  // For performance reasons, Progs usually are usually bulk allocated, cached, and reused;
   262  // those bulk allocators should always be used, rather than new(Prog).
   263  //
   264  // The other fields not yet mentioned are for use by the back ends and should
   265  // be left zeroed by creators of Prog lists.
   266  type Prog struct {
   267  	Ctxt     *Link    // linker context
   268  	Link     *Prog    // next Prog in linked list
   269  	From     Addr     // first source operand
   270  	RestArgs []Addr   // can pack any operands that not fit into {Prog.From, Prog.To}
   271  	To       Addr     // destination operand (second is RegTo2 below)
   272  	Pcond    *Prog    // target of conditional jump
   273  	Forwd    *Prog    // for x86 back end
   274  	Rel      *Prog    // for x86, arm back ends
   275  	Pc       int64    // for back ends or assembler: virtual or actual program counter, depending on phase
   276  	Pos      src.XPos // source position of this instruction
   277  	Spadj    int32    // effect of instruction on stack pointer (increment or decrement amount)
   278  	As       As       // assembler opcode
   279  	Reg      int16    // 2nd source operand
   280  	RegTo2   int16    // 2nd destination operand
   281  	Mark     uint16   // bitmask of arch-specific items
   282  	Optab    uint16   // arch-specific opcode index
   283  	Scond    uint8    // condition bits for conditional instruction (e.g., on ARM)
   284  	Back     uint8    // for x86 back end: backwards branch state
   285  	Ft       uint8    // for x86 back end: type index of Prog.From
   286  	Tt       uint8    // for x86 back end: type index of Prog.To
   287  	Isize    uint8    // for x86 back end: size of the instruction in bytes
   288  }
   289  
   290  // From3Type returns p.GetFrom3().Type, or TYPE_NONE when
   291  // p.GetFrom3() returns nil.
   292  //
   293  // Deprecated: for the same reasons as Prog.GetFrom3.
   294  func (p *Prog) From3Type() AddrType {
   295  	if p.RestArgs == nil {
   296  		return TYPE_NONE
   297  	}
   298  	return p.RestArgs[0].Type
   299  }
   300  
   301  // GetFrom3 returns second source operand (the first is Prog.From).
   302  // In combination with Prog.From and Prog.To it makes common 3 operand
   303  // case easier to use.
   304  //
   305  // Should be used only when RestArgs is set with SetFrom3.
   306  //
   307  // Deprecated: better use RestArgs directly or define backend-specific getters.
   308  // Introduced to simplify transition to []Addr.
   309  // Usage of this is discouraged due to fragility and lack of guarantees.
   310  func (p *Prog) GetFrom3() *Addr {
   311  	if p.RestArgs == nil {
   312  		return nil
   313  	}
   314  	return &p.RestArgs[0]
   315  }
   316  
   317  // SetFrom3 assigns []Addr{a} to p.RestArgs.
   318  // In pair with Prog.GetFrom3 it can help in emulation of Prog.From3.
   319  //
   320  // Deprecated: for the same reasons as Prog.GetFrom3.
   321  func (p *Prog) SetFrom3(a Addr) {
   322  	p.RestArgs = []Addr{a}
   323  }
   324  
   325  // An As denotes an assembler opcode.
   326  // There are some portable opcodes, declared here in package obj,
   327  // that are common to all architectures.
   328  // However, the majority of opcodes are arch-specific
   329  // and are declared in their respective architecture's subpackage.
   330  type As int16
   331  
   332  // These are the portable opcodes.
   333  const (
   334  	AXXX As = iota
   335  	ACALL
   336  	ADUFFCOPY
   337  	ADUFFZERO
   338  	AEND
   339  	AFUNCDATA
   340  	AJMP
   341  	ANOP
   342  	APCDATA
   343  	ARET
   344  	ATEXT
   345  	AUNDEF
   346  	A_ARCHSPECIFIC
   347  )
   348  
   349  // Each architecture is allotted a distinct subspace of opcode values
   350  // for declaring its arch-specific opcodes.
   351  // Within this subspace, the first arch-specific opcode should be
   352  // at offset A_ARCHSPECIFIC.
   353  //
   354  // Subspaces are aligned to a power of two so opcodes can be masked
   355  // with AMask and used as compact array indices.
   356  const (
   357  	ABase386 = (1 + iota) << 11
   358  	ABaseARM
   359  	ABaseAMD64
   360  	ABasePPC64
   361  	ABaseARM64
   362  	ABaseMIPS
   363  	ABaseS390X
   364  
   365  	AllowedOpCodes = 1 << 11            // The number of opcodes available for any given architecture.
   366  	AMask          = AllowedOpCodes - 1 // AND with this to use the opcode as an array index.
   367  )
   368  
   369  // An LSym is the sort of symbol that is written to an object file.
   370  type LSym struct {
   371  	Name string
   372  	Type objabi.SymKind
   373  	Attribute
   374  
   375  	RefIdx int // Index of this symbol in the symbol reference list.
   376  	Size   int64
   377  	Gotype *LSym
   378  	P      []byte
   379  	R      []Reloc
   380  
   381  	Func *FuncInfo
   382  }
   383  
   384  // A FuncInfo contains extra fields for STEXT symbols.
   385  type FuncInfo struct {
   386  	Args   int32
   387  	Locals int32
   388  	Text   *Prog
   389  	Autom  []*Auto
   390  	Pcln   Pcln
   391  
   392  	dwarfInfoSym   *LSym
   393  	dwarfLocSym    *LSym
   394  	dwarfRangesSym *LSym
   395  	dwarfAbsFnSym  *LSym
   396  
   397  	GCArgs   LSym
   398  	GCLocals LSym
   399  }
   400  
   401  // Attribute is a set of symbol attributes.
   402  type Attribute int16
   403  
   404  const (
   405  	AttrDuplicateOK Attribute = 1 << iota
   406  	AttrCFunc
   407  	AttrNoSplit
   408  	AttrLeaf
   409  	AttrWrapper
   410  	AttrNeedCtxt
   411  	AttrNoFrame
   412  	AttrSeenGlobl
   413  	AttrOnList
   414  	AttrStatic
   415  
   416  	// MakeTypelink means that the type should have an entry in the typelink table.
   417  	AttrMakeTypelink
   418  
   419  	// ReflectMethod means the function may call reflect.Type.Method or
   420  	// reflect.Type.MethodByName. Matching is imprecise (as reflect.Type
   421  	// can be used through a custom interface), so ReflectMethod may be
   422  	// set in some cases when the reflect package is not called.
   423  	//
   424  	// Used by the linker to determine what methods can be pruned.
   425  	AttrReflectMethod
   426  
   427  	// Local means make the symbol local even when compiling Go code to reference Go
   428  	// symbols in other shared libraries, as in this mode symbols are global by
   429  	// default. "local" here means in the sense of the dynamic linker, i.e. not
   430  	// visible outside of the module (shared library or executable) that contains its
   431  	// definition. (When not compiling to support Go shared libraries, all symbols are
   432  	// local in this sense unless there is a cgo_export_* directive).
   433  	AttrLocal
   434  
   435  	// For function symbols; indicates that the specified function was the
   436  	// target of an inline during compilation
   437  	AttrWasInlined
   438  )
   439  
   440  func (a Attribute) DuplicateOK() bool   { return a&AttrDuplicateOK != 0 }
   441  func (a Attribute) MakeTypelink() bool  { return a&AttrMakeTypelink != 0 }
   442  func (a Attribute) CFunc() bool         { return a&AttrCFunc != 0 }
   443  func (a Attribute) NoSplit() bool       { return a&AttrNoSplit != 0 }
   444  func (a Attribute) Leaf() bool          { return a&AttrLeaf != 0 }
   445  func (a Attribute) SeenGlobl() bool     { return a&AttrSeenGlobl != 0 }
   446  func (a Attribute) OnList() bool        { return a&AttrOnList != 0 }
   447  func (a Attribute) ReflectMethod() bool { return a&AttrReflectMethod != 0 }
   448  func (a Attribute) Local() bool         { return a&AttrLocal != 0 }
   449  func (a Attribute) Wrapper() bool       { return a&AttrWrapper != 0 }
   450  func (a Attribute) NeedCtxt() bool      { return a&AttrNeedCtxt != 0 }
   451  func (a Attribute) NoFrame() bool       { return a&AttrNoFrame != 0 }
   452  func (a Attribute) Static() bool        { return a&AttrStatic != 0 }
   453  func (a Attribute) WasInlined() bool    { return a&AttrWasInlined != 0 }
   454  
   455  func (a *Attribute) Set(flag Attribute, value bool) {
   456  	if value {
   457  		*a |= flag
   458  	} else {
   459  		*a &^= flag
   460  	}
   461  }
   462  
   463  var textAttrStrings = [...]struct {
   464  	bit Attribute
   465  	s   string
   466  }{
   467  	{bit: AttrDuplicateOK, s: "DUPOK"},
   468  	{bit: AttrMakeTypelink, s: ""},
   469  	{bit: AttrCFunc, s: "CFUNC"},
   470  	{bit: AttrNoSplit, s: "NOSPLIT"},
   471  	{bit: AttrLeaf, s: "LEAF"},
   472  	{bit: AttrSeenGlobl, s: ""},
   473  	{bit: AttrOnList, s: ""},
   474  	{bit: AttrReflectMethod, s: "REFLECTMETHOD"},
   475  	{bit: AttrLocal, s: "LOCAL"},
   476  	{bit: AttrWrapper, s: "WRAPPER"},
   477  	{bit: AttrNeedCtxt, s: "NEEDCTXT"},
   478  	{bit: AttrNoFrame, s: "NOFRAME"},
   479  	{bit: AttrStatic, s: "STATIC"},
   480  	{bit: AttrWasInlined, s: ""},
   481  }
   482  
   483  // TextAttrString formats a for printing in as part of a TEXT prog.
   484  func (a Attribute) TextAttrString() string {
   485  	var s string
   486  	for _, x := range textAttrStrings {
   487  		if a&x.bit != 0 {
   488  			if x.s != "" {
   489  				s += x.s + "|"
   490  			}
   491  			a &^= x.bit
   492  		}
   493  	}
   494  	if a != 0 {
   495  		s += fmt.Sprintf("UnknownAttribute(%d)|", a)
   496  	}
   497  	// Chop off trailing |, if present.
   498  	if len(s) > 0 {
   499  		s = s[:len(s)-1]
   500  	}
   501  	return s
   502  }
   503  
   504  // The compiler needs LSym to satisfy fmt.Stringer, because it stores
   505  // an LSym in ssa.ExternSymbol.
   506  func (s *LSym) String() string {
   507  	return s.Name
   508  }
   509  
   510  type Pcln struct {
   511  	Pcsp        Pcdata
   512  	Pcfile      Pcdata
   513  	Pcline      Pcdata
   514  	Pcinline    Pcdata
   515  	Pcdata      []Pcdata
   516  	Funcdata    []*LSym
   517  	Funcdataoff []int64
   518  	File        []string
   519  	Lastfile    string
   520  	Lastindex   int
   521  	InlTree     InlTree // per-function inlining tree extracted from the global tree
   522  }
   523  
   524  type Reloc struct {
   525  	Off  int32
   526  	Siz  uint8
   527  	Type objabi.RelocType
   528  	Add  int64
   529  	Sym  *LSym
   530  }
   531  
   532  type Auto struct {
   533  	Asym    *LSym
   534  	Aoffset int32
   535  	Name    AddrName
   536  	Gotype  *LSym
   537  }
   538  
   539  type Pcdata struct {
   540  	P []byte
   541  }
   542  
   543  // Link holds the context for writing object code from a compiler
   544  // to be linker input or for reading that input into the linker.
   545  type Link struct {
   546  	Headtype           objabi.HeadType
   547  	Arch               *LinkArch
   548  	Debugasm           bool
   549  	Debugvlog          bool
   550  	Debugpcln          string
   551  	Flag_shared        bool
   552  	Flag_dynlink       bool
   553  	Flag_optimize      bool
   554  	Flag_locationlists bool
   555  	Bso                *bufio.Writer
   556  	Pathname           string
   557  	hashmu             sync.Mutex       // protects hash
   558  	hash               map[string]*LSym // name -> sym mapping
   559  	statichash         map[string]*LSym // name -> sym mapping for static syms
   560  	PosTable           src.PosTable
   561  	InlTree            InlTree // global inlining tree used by gc/inl.go
   562  	DwFixups           *DwarfFixupTable
   563  	Imports            []string
   564  	DiagFunc           func(string, ...interface{})
   565  	DiagFlush          func()
   566  	DebugInfo          func(fn *LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCalls) // if non-nil, curfn is a *gc.Node
   567  	GenAbstractFunc    func(fn *LSym)
   568  	Errors             int
   569  
   570  	InParallel           bool // parallel backend phase in effect
   571  	Framepointer_enabled bool
   572  
   573  	// state for writing objects
   574  	Text []*LSym
   575  	Data []*LSym
   576  }
   577  
   578  func (ctxt *Link) Diag(format string, args ...interface{}) {
   579  	ctxt.Errors++
   580  	ctxt.DiagFunc(format, args...)
   581  }
   582  
   583  func (ctxt *Link) Logf(format string, args ...interface{}) {
   584  	fmt.Fprintf(ctxt.Bso, format, args...)
   585  	ctxt.Bso.Flush()
   586  }
   587  
   588  // The smallest possible offset from the hardware stack pointer to a local
   589  // variable on the stack. Architectures that use a link register save its value
   590  // on the stack in the function prologue and so always have a pointer between
   591  // the hardware stack pointer and the local variable area.
   592  func (ctxt *Link) FixedFrameSize() int64 {
   593  	switch ctxt.Arch.Family {
   594  	case sys.AMD64, sys.I386:
   595  		return 0
   596  	case sys.PPC64:
   597  		// PIC code on ppc64le requires 32 bytes of stack, and it's easier to
   598  		// just use that much stack always on ppc64x.
   599  		return int64(4 * ctxt.Arch.PtrSize)
   600  	default:
   601  		return int64(ctxt.Arch.PtrSize)
   602  	}
   603  }
   604  
   605  // LinkArch is the definition of a single architecture.
   606  type LinkArch struct {
   607  	*sys.Arch
   608  	Init           func(*Link)
   609  	Preprocess     func(*Link, *LSym, ProgAlloc)
   610  	Assemble       func(*Link, *LSym, ProgAlloc)
   611  	Progedit       func(*Link, *Prog, ProgAlloc)
   612  	UnaryDst       map[As]bool // Instruction takes one operand, a destination.
   613  	DWARFRegisters map[int16]int16
   614  }