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 // Indicates that this is a reference to a TOC anchor. 218 NAME_TOCREF 219 ) 220 221 //go:generate stringer -type AddrType 222 223 type AddrType uint8 224 225 const ( 226 TYPE_NONE AddrType = iota 227 TYPE_BRANCH 228 TYPE_TEXTSIZE 229 TYPE_MEM 230 TYPE_CONST 231 TYPE_FCONST 232 TYPE_SCONST 233 TYPE_REG 234 TYPE_ADDR 235 TYPE_SHIFT 236 TYPE_REGREG 237 TYPE_REGREG2 238 TYPE_INDIR 239 TYPE_REGLIST 240 ) 241 242 // Prog describes a single machine instruction. 243 // 244 // The general instruction form is: 245 // 246 // (1) As.Scond From [, ...RestArgs], To 247 // (2) As.Scond From, Reg [, ...RestArgs], To, RegTo2 248 // 249 // where As is an opcode and the others are arguments: 250 // From, Reg are sources, and To, RegTo2 are destinations. 251 // RestArgs can hold additional sources and destinations. 252 // Usually, not all arguments are present. 253 // For example, MOVL R1, R2 encodes using only As=MOVL, From=R1, To=R2. 254 // The Scond field holds additional condition bits for systems (like arm) 255 // that have generalized conditional execution. 256 // (2) form is present for compatibility with older code, 257 // to avoid too much changes in a single swing. 258 // (1) scheme is enough to express any kind of operand combination. 259 // 260 // Jump instructions use the Pcond field to point to the target instruction, 261 // which must be in the same linked list as the jump instruction. 262 // 263 // The Progs for a given function are arranged in a list linked through the Link field. 264 // 265 // Each Prog is charged to a specific source line in the debug information, 266 // specified by Pos.Line(). 267 // Every Prog has a Ctxt field that defines its context. 268 // For performance reasons, Progs usually are usually bulk allocated, cached, and reused; 269 // those bulk allocators should always be used, rather than new(Prog). 270 // 271 // The other fields not yet mentioned are for use by the back ends and should 272 // be left zeroed by creators of Prog lists. 273 type Prog struct { 274 Ctxt *Link // linker context 275 Link *Prog // next Prog in linked list 276 From Addr // first source operand 277 RestArgs []Addr // can pack any operands that not fit into {Prog.From, Prog.To} 278 To Addr // destination operand (second is RegTo2 below) 279 Pcond *Prog // target of conditional jump 280 Forwd *Prog // for x86 back end 281 Rel *Prog // for x86, arm back ends 282 Pc int64 // for back ends or assembler: virtual or actual program counter, depending on phase 283 Pos src.XPos // source position of this instruction 284 Spadj int32 // effect of instruction on stack pointer (increment or decrement amount) 285 As As // assembler opcode 286 Reg int16 // 2nd source operand 287 RegTo2 int16 // 2nd destination operand 288 Mark uint16 // bitmask of arch-specific items 289 Optab uint16 // arch-specific opcode index 290 Scond uint8 // bits that describe instruction suffixes (e.g. ARM conditions) 291 Back uint8 // for x86 back end: backwards branch state 292 Ft uint8 // for x86 back end: type index of Prog.From 293 Tt uint8 // for x86 back end: type index of Prog.To 294 Isize uint8 // for x86 back end: size of the instruction in bytes 295 } 296 297 // From3Type returns p.GetFrom3().Type, or TYPE_NONE when 298 // p.GetFrom3() returns nil. 299 // 300 // Deprecated: for the same reasons as Prog.GetFrom3. 301 func (p *Prog) From3Type() AddrType { 302 if p.RestArgs == nil { 303 return TYPE_NONE 304 } 305 return p.RestArgs[0].Type 306 } 307 308 // GetFrom3 returns second source operand (the first is Prog.From). 309 // In combination with Prog.From and Prog.To it makes common 3 operand 310 // case easier to use. 311 // 312 // Should be used only when RestArgs is set with SetFrom3. 313 // 314 // Deprecated: better use RestArgs directly or define backend-specific getters. 315 // Introduced to simplify transition to []Addr. 316 // Usage of this is discouraged due to fragility and lack of guarantees. 317 func (p *Prog) GetFrom3() *Addr { 318 if p.RestArgs == nil { 319 return nil 320 } 321 return &p.RestArgs[0] 322 } 323 324 // SetFrom3 assigns []Addr{a} to p.RestArgs. 325 // In pair with Prog.GetFrom3 it can help in emulation of Prog.From3. 326 // 327 // Deprecated: for the same reasons as Prog.GetFrom3. 328 func (p *Prog) SetFrom3(a Addr) { 329 p.RestArgs = []Addr{a} 330 } 331 332 // An As denotes an assembler opcode. 333 // There are some portable opcodes, declared here in package obj, 334 // that are common to all architectures. 335 // However, the majority of opcodes are arch-specific 336 // and are declared in their respective architecture's subpackage. 337 type As int16 338 339 // These are the portable opcodes. 340 const ( 341 AXXX As = iota 342 ACALL 343 ADUFFCOPY 344 ADUFFZERO 345 AEND 346 AFUNCDATA 347 AJMP 348 ANOP 349 APCALIGN 350 APCDATA 351 ARET 352 AGETCALLERPC 353 ATEXT 354 AUNDEF 355 A_ARCHSPECIFIC 356 ) 357 358 // Each architecture is allotted a distinct subspace of opcode values 359 // for declaring its arch-specific opcodes. 360 // Within this subspace, the first arch-specific opcode should be 361 // at offset A_ARCHSPECIFIC. 362 // 363 // Subspaces are aligned to a power of two so opcodes can be masked 364 // with AMask and used as compact array indices. 365 const ( 366 ABase386 = (1 + iota) << 11 367 ABaseARM 368 ABaseAMD64 369 ABasePPC64 370 ABaseARM64 371 ABaseMIPS 372 ABaseS390X 373 ABaseWasm 374 375 AllowedOpCodes = 1 << 11 // The number of opcodes available for any given architecture. 376 AMask = AllowedOpCodes - 1 // AND with this to use the opcode as an array index. 377 ) 378 379 // An LSym is the sort of symbol that is written to an object file. 380 // It represents Go symbols in a flat pkg+"."+name namespace. 381 type LSym struct { 382 Name string 383 Type objabi.SymKind 384 Attribute 385 386 RefIdx int // Index of this symbol in the symbol reference list. 387 Size int64 388 Gotype *LSym 389 P []byte 390 R []Reloc 391 392 Func *FuncInfo 393 } 394 395 // A FuncInfo contains extra fields for STEXT symbols. 396 type FuncInfo struct { 397 Args int32 398 Locals int32 399 Text *Prog 400 Autom []*Auto 401 Pcln Pcln 402 InlMarks []InlMark 403 404 dwarfInfoSym *LSym 405 dwarfLocSym *LSym 406 dwarfRangesSym *LSym 407 dwarfAbsFnSym *LSym 408 dwarfIsStmtSym *LSym 409 410 GCArgs *LSym 411 GCLocals *LSym 412 GCRegs *LSym 413 StackObjects *LSym 414 } 415 416 type InlMark struct { 417 // When unwinding from an instruction in an inlined body, mark 418 // where we should unwind to. 419 // id records the global inlining id of the inlined body. 420 // p records the location of an instruction in the parent (inliner) frame. 421 p *Prog 422 id int32 423 } 424 425 // Mark p as the instruction to set as the pc when 426 // "unwinding" the inlining global frame id. Usually it should be 427 // instruction with a file:line at the callsite, and occur 428 // just before the body of the inlined function. 429 func (fi *FuncInfo) AddInlMark(p *Prog, id int32) { 430 fi.InlMarks = append(fi.InlMarks, InlMark{p: p, id: id}) 431 } 432 433 //go:generate stringer -type ABI 434 435 // ABI is the calling convention of a text symbol. 436 type ABI uint8 437 438 const ( 439 // ABI0 is the stable stack-based ABI. It's important that the 440 // value of this is "0": we can't distinguish between 441 // references to data and ABI0 text symbols in assembly code, 442 // and hence this doesn't distinguish between symbols without 443 // an ABI and text symbols with ABI0. 444 ABI0 ABI = iota 445 446 // ABIInternal is the internal ABI that may change between Go 447 // versions. All Go functions use the internal ABI and the 448 // compiler generates wrappers for calls to and from other 449 // ABIs. 450 ABIInternal 451 452 ABICount 453 ) 454 455 // Attribute is a set of symbol attributes. 456 type Attribute uint16 457 458 const ( 459 AttrDuplicateOK Attribute = 1 << iota 460 AttrCFunc 461 AttrNoSplit 462 AttrLeaf 463 AttrWrapper 464 AttrNeedCtxt 465 AttrNoFrame 466 AttrSeenGlobl 467 AttrOnList 468 AttrStatic 469 470 // MakeTypelink means that the type should have an entry in the typelink table. 471 AttrMakeTypelink 472 473 // ReflectMethod means the function may call reflect.Type.Method or 474 // reflect.Type.MethodByName. Matching is imprecise (as reflect.Type 475 // can be used through a custom interface), so ReflectMethod may be 476 // set in some cases when the reflect package is not called. 477 // 478 // Used by the linker to determine what methods can be pruned. 479 AttrReflectMethod 480 481 // Local means make the symbol local even when compiling Go code to reference Go 482 // symbols in other shared libraries, as in this mode symbols are global by 483 // default. "local" here means in the sense of the dynamic linker, i.e. not 484 // visible outside of the module (shared library or executable) that contains its 485 // definition. (When not compiling to support Go shared libraries, all symbols are 486 // local in this sense unless there is a cgo_export_* directive). 487 AttrLocal 488 489 // For function symbols; indicates that the specified function was the 490 // target of an inline during compilation 491 AttrWasInlined 492 493 // TopFrame means that this function is an entry point and unwinders should not 494 // keep unwinding beyond this frame. 495 AttrTopFrame 496 497 // attrABIBase is the value at which the ABI is encoded in 498 // Attribute. This must be last; all bits after this are 499 // assumed to be an ABI value. 500 // 501 // MUST BE LAST since all bits above this comprise the ABI. 502 attrABIBase 503 ) 504 505 func (a Attribute) DuplicateOK() bool { return a&AttrDuplicateOK != 0 } 506 func (a Attribute) MakeTypelink() bool { return a&AttrMakeTypelink != 0 } 507 func (a Attribute) CFunc() bool { return a&AttrCFunc != 0 } 508 func (a Attribute) NoSplit() bool { return a&AttrNoSplit != 0 } 509 func (a Attribute) Leaf() bool { return a&AttrLeaf != 0 } 510 func (a Attribute) SeenGlobl() bool { return a&AttrSeenGlobl != 0 } 511 func (a Attribute) OnList() bool { return a&AttrOnList != 0 } 512 func (a Attribute) ReflectMethod() bool { return a&AttrReflectMethod != 0 } 513 func (a Attribute) Local() bool { return a&AttrLocal != 0 } 514 func (a Attribute) Wrapper() bool { return a&AttrWrapper != 0 } 515 func (a Attribute) NeedCtxt() bool { return a&AttrNeedCtxt != 0 } 516 func (a Attribute) NoFrame() bool { return a&AttrNoFrame != 0 } 517 func (a Attribute) Static() bool { return a&AttrStatic != 0 } 518 func (a Attribute) WasInlined() bool { return a&AttrWasInlined != 0 } 519 func (a Attribute) TopFrame() bool { return a&AttrTopFrame != 0 } 520 521 func (a *Attribute) Set(flag Attribute, value bool) { 522 if value { 523 *a |= flag 524 } else { 525 *a &^= flag 526 } 527 } 528 529 func (a Attribute) ABI() ABI { return ABI(a / attrABIBase) } 530 func (a *Attribute) SetABI(abi ABI) { 531 const mask = 1 // Only one ABI bit for now. 532 *a = (*a &^ (mask * attrABIBase)) | Attribute(abi)*attrABIBase 533 } 534 535 var textAttrStrings = [...]struct { 536 bit Attribute 537 s string 538 }{ 539 {bit: AttrDuplicateOK, s: "DUPOK"}, 540 {bit: AttrMakeTypelink, s: ""}, 541 {bit: AttrCFunc, s: "CFUNC"}, 542 {bit: AttrNoSplit, s: "NOSPLIT"}, 543 {bit: AttrLeaf, s: "LEAF"}, 544 {bit: AttrSeenGlobl, s: ""}, 545 {bit: AttrOnList, s: ""}, 546 {bit: AttrReflectMethod, s: "REFLECTMETHOD"}, 547 {bit: AttrLocal, s: "LOCAL"}, 548 {bit: AttrWrapper, s: "WRAPPER"}, 549 {bit: AttrNeedCtxt, s: "NEEDCTXT"}, 550 {bit: AttrNoFrame, s: "NOFRAME"}, 551 {bit: AttrStatic, s: "STATIC"}, 552 {bit: AttrWasInlined, s: ""}, 553 {bit: AttrTopFrame, s: "TOPFRAME"}, 554 } 555 556 // TextAttrString formats a for printing in as part of a TEXT prog. 557 func (a Attribute) TextAttrString() string { 558 var s string 559 for _, x := range textAttrStrings { 560 if a&x.bit != 0 { 561 if x.s != "" { 562 s += x.s + "|" 563 } 564 a &^= x.bit 565 } 566 } 567 switch a.ABI() { 568 case ABI0: 569 case ABIInternal: 570 s += "ABIInternal|" 571 a.SetABI(0) // Clear ABI so we don't print below. 572 } 573 if a != 0 { 574 s += fmt.Sprintf("UnknownAttribute(%d)|", a) 575 } 576 // Chop off trailing |, if present. 577 if len(s) > 0 { 578 s = s[:len(s)-1] 579 } 580 return s 581 } 582 583 // The compiler needs LSym to satisfy fmt.Stringer, because it stores 584 // an LSym in ssa.ExternSymbol. 585 func (s *LSym) String() string { 586 return s.Name 587 } 588 589 type Pcln struct { 590 Pcsp Pcdata 591 Pcfile Pcdata 592 Pcline Pcdata 593 Pcinline Pcdata 594 Pcdata []Pcdata 595 Funcdata []*LSym 596 Funcdataoff []int64 597 File []string 598 Lastfile string 599 Lastindex int 600 InlTree InlTree // per-function inlining tree extracted from the global tree 601 } 602 603 type Reloc struct { 604 Off int32 605 Siz uint8 606 Type objabi.RelocType 607 Add int64 608 Sym *LSym 609 } 610 611 type Auto struct { 612 Asym *LSym 613 Aoffset int32 614 Name AddrName 615 Gotype *LSym 616 } 617 618 type Pcdata struct { 619 P []byte 620 } 621 622 // Link holds the context for writing object code from a compiler 623 // to be linker input or for reading that input into the linker. 624 type Link struct { 625 Headtype objabi.HeadType 626 Arch *LinkArch 627 Debugasm int 628 Debugvlog bool 629 Debugpcln string 630 Flag_shared bool 631 Flag_dynlink bool 632 Flag_optimize bool 633 Flag_locationlists bool 634 Bso *bufio.Writer 635 Pathname string 636 hashmu sync.Mutex // protects hash, funchash 637 hash map[string]*LSym // name -> sym mapping 638 funchash map[string]*LSym // name -> sym mapping for ABIInternal syms 639 statichash map[string]*LSym // name -> sym mapping for static syms 640 PosTable src.PosTable 641 InlTree InlTree // global inlining tree used by gc/inl.go 642 DwFixups *DwarfFixupTable 643 Imports []string 644 DiagFunc func(string, ...interface{}) 645 DiagFlush func() 646 DebugInfo func(fn *LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCalls) // if non-nil, curfn is a *gc.Node 647 GenAbstractFunc func(fn *LSym) 648 Errors int 649 650 InParallel bool // parallel backend phase in effect 651 Framepointer_enabled bool 652 UseBASEntries bool // Use Base Address Selection Entries in location lists and PC ranges 653 654 // state for writing objects 655 Text []*LSym 656 Data []*LSym 657 658 // ABIAliases are text symbols that should be aliased to all 659 // ABIs. These symbols may only be referenced and not defined 660 // by this object, since the need for an alias may appear in a 661 // different object than the definition. Hence, this 662 // information can't be carried in the symbol definition. 663 // 664 // TODO(austin): Replace this with ABI wrappers once the ABIs 665 // actually diverge. 666 ABIAliases []*LSym 667 } 668 669 func (ctxt *Link) Diag(format string, args ...interface{}) { 670 ctxt.Errors++ 671 ctxt.DiagFunc(format, args...) 672 } 673 674 func (ctxt *Link) Logf(format string, args ...interface{}) { 675 fmt.Fprintf(ctxt.Bso, format, args...) 676 ctxt.Bso.Flush() 677 } 678 679 // The smallest possible offset from the hardware stack pointer to a local 680 // variable on the stack. Architectures that use a link register save its value 681 // on the stack in the function prologue and so always have a pointer between 682 // the hardware stack pointer and the local variable area. 683 func (ctxt *Link) FixedFrameSize() int64 { 684 switch ctxt.Arch.Family { 685 case sys.AMD64, sys.I386, sys.Wasm: 686 return 0 687 case sys.PPC64: 688 // PIC code on ppc64le requires 32 bytes of stack, and it's easier to 689 // just use that much stack always on ppc64x. 690 return int64(4 * ctxt.Arch.PtrSize) 691 default: 692 return int64(ctxt.Arch.PtrSize) 693 } 694 } 695 696 // LinkArch is the definition of a single architecture. 697 type LinkArch struct { 698 *sys.Arch 699 Init func(*Link) 700 Preprocess func(*Link, *LSym, ProgAlloc) 701 Assemble func(*Link, *LSym, ProgAlloc) 702 Progedit func(*Link, *Prog, ProgAlloc) 703 UnaryDst map[As]bool // Instruction takes one operand, a destination. 704 DWARFRegisters map[int16]int16 705 } 706