...
Run Format

Source file src/cmd/internal/obj/link.go

Documentation: cmd/internal/obj

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

View as plain text