2015-01-19 14:34:58 -05:00
|
|
|
// Derived from Inferno utils/6l/l.h and related files.
|
2016-08-28 17:04:46 -07:00
|
|
|
// https://bitbucket.org/inferno-os/inferno-os/src/default/utils/6l/l.h
|
2015-01-19 14:34:58 -05:00
|
|
|
//
|
|
|
|
|
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
|
|
|
|
|
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
|
|
|
|
|
// Portions Copyright © 1997-1999 Vita Nuova Limited
|
|
|
|
|
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
|
|
|
|
|
// Portions Copyright © 2004,2006 Bruce Ellis
|
|
|
|
|
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
|
|
|
|
|
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
|
2016-04-10 14:32:26 -07:00
|
|
|
// Portions Copyright © 2009 The Go Authors. All rights reserved.
|
2015-01-19 14:34:58 -05:00
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
package obj
|
|
|
|
|
|
2016-04-06 21:45:29 -07:00
|
|
|
import (
|
2016-04-08 19:30:41 +10:00
|
|
|
"bufio"
|
2017-03-06 07:32:37 -08:00
|
|
|
"cmd/internal/dwarf"
|
2017-04-18 12:53:25 -07:00
|
|
|
"cmd/internal/objabi"
|
2016-12-09 12:34:01 -05:00
|
|
|
"cmd/internal/src"
|
2016-04-06 21:45:29 -07:00
|
|
|
"cmd/internal/sys"
|
2016-08-25 12:32:42 +10:00
|
|
|
"fmt"
|
2016-04-06 21:45:29 -07:00
|
|
|
)
|
2015-01-19 14:34:58 -05:00
|
|
|
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
// An Addr is an argument to an instruction.
|
|
|
|
|
// The general forms and their encodings are:
|
|
|
|
|
//
|
|
|
|
|
// sym±offset(symkind)(reg)(index*scale)
|
|
|
|
|
// Memory reference at address &sym(symkind) + offset + reg + index*scale.
|
|
|
|
|
// Any of sym(symkind), ±offset, (reg), (index*scale), and *scale can be omitted.
|
|
|
|
|
// If (reg) and *scale are both omitted, the resulting expression (index) is parsed as (reg).
|
|
|
|
|
// To force a parsing as index*scale, write (index*1).
|
|
|
|
|
// Encoding:
|
|
|
|
|
// type = TYPE_MEM
|
|
|
|
|
// name = symkind (NAME_AUTO, ...) or 0 (NAME_NONE)
|
|
|
|
|
// sym = sym
|
|
|
|
|
// offset = ±offset
|
|
|
|
|
// reg = reg (REG_*)
|
|
|
|
|
// index = index (REG_*)
|
|
|
|
|
// scale = scale (1, 2, 4, 8)
|
|
|
|
|
//
|
|
|
|
|
// $<mem>
|
|
|
|
|
// Effective address of memory reference <mem>, defined above.
|
|
|
|
|
// Encoding: same as memory reference, but type = TYPE_ADDR.
|
|
|
|
|
//
|
|
|
|
|
// $<±integer value>
|
|
|
|
|
// This is a special case of $<mem>, in which only ±offset is present.
|
|
|
|
|
// It has a separate type for easy recognition.
|
|
|
|
|
// Encoding:
|
|
|
|
|
// type = TYPE_CONST
|
|
|
|
|
// offset = ±integer value
|
|
|
|
|
//
|
|
|
|
|
// *<mem>
|
|
|
|
|
// Indirect reference through memory reference <mem>, defined above.
|
|
|
|
|
// Only used on x86 for CALL/JMP *sym(SB), which calls/jumps to a function
|
|
|
|
|
// pointer stored in the data word sym(SB), not a function named sym(SB).
|
|
|
|
|
// Encoding: same as above, but type = TYPE_INDIR.
|
|
|
|
|
//
|
|
|
|
|
// $*$<mem>
|
|
|
|
|
// No longer used.
|
|
|
|
|
// On machines with actual SB registers, $*$<mem> forced the
|
|
|
|
|
// instruction encoding to use a full 32-bit constant, never a
|
|
|
|
|
// reference relative to SB.
|
|
|
|
|
//
|
|
|
|
|
// $<floating point literal>
|
|
|
|
|
// Floating point constant value.
|
|
|
|
|
// Encoding:
|
|
|
|
|
// type = TYPE_FCONST
|
2015-03-16 15:54:44 -04:00
|
|
|
// val = floating point value
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
//
|
|
|
|
|
// $<string literal, up to 8 chars>
|
|
|
|
|
// String literal value (raw bytes used for DATA instruction).
|
|
|
|
|
// Encoding:
|
|
|
|
|
// type = TYPE_SCONST
|
2015-03-16 15:54:44 -04:00
|
|
|
// val = string
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
//
|
|
|
|
|
// <register name>
|
|
|
|
|
// Any register: integer, floating point, control, segment, and so on.
|
|
|
|
|
// If looking for specific register kind, must check type and reg value range.
|
|
|
|
|
// Encoding:
|
|
|
|
|
// type = TYPE_REG
|
|
|
|
|
// reg = reg (REG_*)
|
|
|
|
|
//
|
|
|
|
|
// x(PC)
|
|
|
|
|
// Encoding:
|
|
|
|
|
// type = TYPE_BRANCH
|
2015-03-16 15:54:44 -04:00
|
|
|
// val = Prog* reference OR ELSE offset = target pc (branch takes priority)
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
//
|
|
|
|
|
// $±x-±y
|
|
|
|
|
// Final argument to TEXT, specifying local frame size x and argument size y.
|
|
|
|
|
// In this form, x and y are integer literals only, not arbitrary expressions.
|
|
|
|
|
// This avoids parsing ambiguities due to the use of - as a separator.
|
|
|
|
|
// The ± are optional.
|
|
|
|
|
// If the final argument to TEXT omits the -±y, the encoding should still
|
|
|
|
|
// use TYPE_TEXTSIZE (not TYPE_CONST), with u.argsize = ArgsSizeUnknown.
|
|
|
|
|
// Encoding:
|
|
|
|
|
// type = TYPE_TEXTSIZE
|
|
|
|
|
// offset = x
|
2015-03-16 15:54:44 -04:00
|
|
|
// val = int32(y)
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
//
|
|
|
|
|
// reg<<shift, reg>>shift, reg->shift, reg@>shift
|
2016-08-10 13:24:03 -04:00
|
|
|
// Shifted register value, for ARM and ARM64.
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
// In this form, reg must be a register and shift can be a register or an integer constant.
|
|
|
|
|
// Encoding:
|
|
|
|
|
// type = TYPE_SHIFT
|
2016-08-10 13:24:03 -04:00
|
|
|
// On ARM:
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
// offset = (reg&15) | shifttype<<5 | count
|
|
|
|
|
// shifttype = 0, 1, 2, 3 for <<, >>, ->, @>
|
|
|
|
|
// count = (reg&15)<<8 | 1<<4 for a register shift count, (n&31)<<7 for an integer constant.
|
2016-08-10 13:24:03 -04:00
|
|
|
// On ARM64:
|
|
|
|
|
// offset = (reg&31)<<16 | shifttype<<22 | (count&63)<<10
|
|
|
|
|
// shifttype = 0, 1, 2 for <<, >>, ->
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
//
|
|
|
|
|
// (reg, reg)
|
|
|
|
|
// A destination register pair. When used as the last argument of an instruction,
|
|
|
|
|
// this form makes clear that both registers are destinations.
|
|
|
|
|
// Encoding:
|
|
|
|
|
// type = TYPE_REGREG
|
|
|
|
|
// reg = first register
|
|
|
|
|
// offset = second register
|
|
|
|
|
//
|
2015-02-27 13:50:26 -08:00
|
|
|
// [reg, reg, reg-reg]
|
|
|
|
|
// Register list for ARM.
|
|
|
|
|
// Encoding:
|
|
|
|
|
// type = TYPE_REGLIST
|
|
|
|
|
// offset = bit mask of registers in list; R0 is low bit.
|
|
|
|
|
//
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
// reg, reg
|
2015-03-05 10:39:23 -08:00
|
|
|
// Register pair for ARM.
|
|
|
|
|
// TYPE_REGREG2
|
|
|
|
|
//
|
|
|
|
|
// (reg+reg)
|
|
|
|
|
// Register pair for PPC64.
|
|
|
|
|
// Encoding:
|
|
|
|
|
// type = TYPE_MEM
|
|
|
|
|
// reg = first register
|
|
|
|
|
// index = second register
|
|
|
|
|
// scale = 1
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
//
|
2015-03-16 15:31:32 -04:00
|
|
|
type Addr struct {
|
|
|
|
|
Reg int16
|
|
|
|
|
Index int16
|
|
|
|
|
Scale int16 // Sometimes holds a register.
|
2015-05-14 20:11:28 -07:00
|
|
|
Type AddrType
|
2017-02-13 13:34:30 -08:00
|
|
|
Name AddrName
|
2015-03-16 15:31:32 -04:00
|
|
|
Class int8
|
2015-03-16 15:54:44 -04:00
|
|
|
Offset int64
|
|
|
|
|
Sym *LSym
|
|
|
|
|
|
|
|
|
|
// argument value:
|
|
|
|
|
// for TYPE_SCONST, a string
|
|
|
|
|
// for TYPE_FCONST, a float64
|
|
|
|
|
// for TYPE_BRANCH, a *Prog (optional)
|
|
|
|
|
// for TYPE_TEXTSIZE, an int32 (optional)
|
|
|
|
|
Val interface{}
|
2015-03-16 15:31:32 -04:00
|
|
|
}
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
|
2017-02-13 13:34:30 -08:00
|
|
|
type AddrName int8
|
2015-05-14 20:11:28 -07:00
|
|
|
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
const (
|
2017-02-13 13:34:30 -08:00
|
|
|
NAME_NONE AddrName = iota
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
NAME_EXTERN
|
|
|
|
|
NAME_STATIC
|
|
|
|
|
NAME_AUTO
|
|
|
|
|
NAME_PARAM
|
2015-03-30 00:49:25 +00:00
|
|
|
// A reference to name@GOT(SB) is a reference to the entry in the global offset
|
|
|
|
|
// table for 'name'.
|
|
|
|
|
NAME_GOTREF
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
)
|
|
|
|
|
|
2017-02-13 13:34:30 -08:00
|
|
|
type AddrType uint8
|
2015-03-05 14:04:12 -05:00
|
|
|
|
2017-02-13 13:34:30 -08:00
|
|
|
const (
|
|
|
|
|
TYPE_NONE AddrType = iota
|
|
|
|
|
TYPE_BRANCH
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
TYPE_TEXTSIZE
|
|
|
|
|
TYPE_MEM
|
|
|
|
|
TYPE_CONST
|
|
|
|
|
TYPE_FCONST
|
|
|
|
|
TYPE_SCONST
|
|
|
|
|
TYPE_REG
|
|
|
|
|
TYPE_ADDR
|
|
|
|
|
TYPE_SHIFT
|
|
|
|
|
TYPE_REGREG
|
|
|
|
|
TYPE_REGREG2
|
|
|
|
|
TYPE_INDIR
|
2015-02-27 13:50:26 -08:00
|
|
|
TYPE_REGLIST
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
)
|
|
|
|
|
|
2016-02-17 23:06:56 -08:00
|
|
|
// Prog describes a single machine instruction.
|
|
|
|
|
//
|
|
|
|
|
// The general instruction form is:
|
|
|
|
|
//
|
|
|
|
|
// As.Scond From, Reg, From3, To, RegTo2
|
|
|
|
|
//
|
|
|
|
|
// where As is an opcode and the others are arguments:
|
|
|
|
|
// From, Reg, From3 are sources, and To, RegTo2 are destinations.
|
|
|
|
|
// Usually, not all arguments are present.
|
|
|
|
|
// For example, MOVL R1, R2 encodes using only As=MOVL, From=R1, To=R2.
|
|
|
|
|
// The Scond field holds additional condition bits for systems (like arm)
|
|
|
|
|
// that have generalized conditional execution.
|
|
|
|
|
//
|
|
|
|
|
// Jump instructions use the Pcond field to point to the target instruction,
|
|
|
|
|
// which must be in the same linked list as the jump instruction.
|
|
|
|
|
//
|
|
|
|
|
// The Progs for a given function are arranged in a list linked through the Link field.
|
|
|
|
|
//
|
|
|
|
|
// Each Prog is charged to a specific source line in the debug information,
|
2016-12-28 17:58:51 -08:00
|
|
|
// specified by Pos.Line().
|
|
|
|
|
// Every Prog has a Ctxt field that defines its context.
|
2017-04-04 14:31:55 -07:00
|
|
|
// For performance reasons, Progs usually are usually bulk allocated, cached, and reused;
|
|
|
|
|
// those bulk allocators should always be used, rather than new(Prog).
|
2016-02-17 23:06:56 -08:00
|
|
|
//
|
|
|
|
|
// The other fields not yet mentioned are for use by the back ends and should
|
|
|
|
|
// be left zeroed by creators of Prog lists.
|
2015-03-16 15:31:32 -04:00
|
|
|
type Prog struct {
|
2017-03-11 17:17:15 -08:00
|
|
|
Ctxt *Link // linker context
|
|
|
|
|
Link *Prog // next Prog in linked list
|
|
|
|
|
From Addr // first source operand
|
|
|
|
|
From3 *Addr // third source operand (second is Reg below)
|
|
|
|
|
To Addr // destination operand (second is RegTo2 below)
|
|
|
|
|
Pcond *Prog // target of conditional jump
|
|
|
|
|
Forwd *Prog // for x86 back end
|
|
|
|
|
Rel *Prog // for x86, arm back ends
|
|
|
|
|
Pc int64 // for back ends or assembler: virtual or actual program counter, depending on phase
|
|
|
|
|
Pos src.XPos // source position of this instruction
|
|
|
|
|
Spadj int32 // effect of instruction on stack pointer (increment or decrement amount)
|
|
|
|
|
As As // assembler opcode
|
|
|
|
|
Reg int16 // 2nd source operand
|
|
|
|
|
RegTo2 int16 // 2nd destination operand
|
|
|
|
|
Mark uint16 // bitmask of arch-specific items
|
|
|
|
|
Optab uint16 // arch-specific opcode index
|
|
|
|
|
Scond uint8 // condition bits for conditional instruction (e.g., on ARM)
|
|
|
|
|
Back uint8 // for x86 back end: backwards branch state
|
|
|
|
|
Ft uint8 // for x86 back end: type index of Prog.From
|
|
|
|
|
Tt uint8 // for x86 back end: type index of Prog.To
|
|
|
|
|
Isize uint8 // for x86 back end: size of the instruction in bytes
|
2015-03-16 16:46:25 -04:00
|
|
|
}
|
|
|
|
|
|
2015-05-27 15:01:44 -04:00
|
|
|
// From3Type returns From3.Type, or TYPE_NONE when From3 is nil.
|
2015-05-14 20:11:28 -07:00
|
|
|
func (p *Prog) From3Type() AddrType {
|
2015-05-27 15:01:44 -04:00
|
|
|
if p.From3 == nil {
|
|
|
|
|
return TYPE_NONE
|
|
|
|
|
}
|
|
|
|
|
return p.From3.Type
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-07 18:00:08 -08:00
|
|
|
// An As denotes an assembler opcode.
|
|
|
|
|
// There are some portable opcodes, declared here in package obj,
|
|
|
|
|
// that are common to all architectures.
|
|
|
|
|
// However, the majority of opcodes are arch-specific
|
|
|
|
|
// and are declared in their respective architecture's subpackage.
|
|
|
|
|
type As int16
|
|
|
|
|
|
|
|
|
|
// These are the portable opcodes.
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
const (
|
2016-03-07 18:00:08 -08:00
|
|
|
AXXX As = iota
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
ACALL
|
|
|
|
|
ADUFFCOPY
|
|
|
|
|
ADUFFZERO
|
|
|
|
|
AEND
|
|
|
|
|
AFUNCDATA
|
|
|
|
|
AJMP
|
|
|
|
|
ANOP
|
|
|
|
|
APCDATA
|
|
|
|
|
ARET
|
|
|
|
|
ATEXT
|
|
|
|
|
AUNDEF
|
|
|
|
|
A_ARCHSPECIFIC
|
|
|
|
|
)
|
2015-01-19 14:34:58 -05:00
|
|
|
|
2016-03-07 18:00:08 -08:00
|
|
|
// Each architecture is allotted a distinct subspace of opcode values
|
|
|
|
|
// for declaring its arch-specific opcodes.
|
|
|
|
|
// Within this subspace, the first arch-specific opcode should be
|
|
|
|
|
// at offset A_ARCHSPECIFIC.
|
|
|
|
|
//
|
|
|
|
|
// Subspaces are aligned to a power of two so opcodes can be masked
|
|
|
|
|
// with AMask and used as compact array indices.
|
|
|
|
|
const (
|
2016-06-17 12:30:27 -07:00
|
|
|
ABase386 = (1 + iota) << 10
|
2016-03-07 18:00:08 -08:00
|
|
|
ABaseARM
|
|
|
|
|
ABaseAMD64
|
|
|
|
|
ABasePPC64
|
|
|
|
|
ABaseARM64
|
2016-10-18 23:50:37 +02:00
|
|
|
ABaseMIPS
|
2016-03-18 16:30:29 -04:00
|
|
|
ABaseS390X
|
2016-03-07 18:00:08 -08:00
|
|
|
|
2016-06-17 12:30:27 -07:00
|
|
|
AllowedOpCodes = 1 << 10 // The number of opcodes available for any given architecture.
|
2016-06-17 12:28:31 -07:00
|
|
|
AMask = AllowedOpCodes - 1 // AND with this to use the opcode as an array index.
|
2016-03-07 18:00:08 -08:00
|
|
|
)
|
|
|
|
|
|
2015-04-18 08:14:08 +12:00
|
|
|
// An LSym is the sort of symbol that is written to an object file.
|
2015-03-16 15:31:32 -04:00
|
|
|
type LSym struct {
|
2017-04-20 07:13:02 -07:00
|
|
|
Name string
|
|
|
|
|
Type objabi.SymKind
|
2016-10-24 23:15:41 +03:00
|
|
|
Attribute
|
|
|
|
|
|
|
|
|
|
RefIdx int // Index of this symbol in the symbol reference list.
|
|
|
|
|
Size int64
|
|
|
|
|
Gotype *LSym
|
|
|
|
|
P []byte
|
|
|
|
|
R []Reloc
|
2017-03-03 16:45:21 -08:00
|
|
|
|
2017-04-18 10:18:34 -07:00
|
|
|
Func *FuncInfo
|
2017-03-03 16:45:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A FuncInfo contains extra fields for STEXT symbols.
|
|
|
|
|
type FuncInfo struct {
|
2017-04-13 08:00:09 -07:00
|
|
|
Args int32
|
|
|
|
|
Locals int32
|
|
|
|
|
Text *Prog
|
|
|
|
|
Autom []*Auto
|
|
|
|
|
Pcln Pcln
|
|
|
|
|
dwarfSym *LSym
|
2017-04-14 06:35:53 -07:00
|
|
|
GCArgs LSym
|
|
|
|
|
GCLocals LSym
|
2016-10-24 23:15:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Attribute is a set of symbol attributes.
|
|
|
|
|
type Attribute int16
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
AttrDuplicateOK Attribute = 1 << iota
|
|
|
|
|
AttrCFunc
|
|
|
|
|
AttrNoSplit
|
|
|
|
|
AttrLeaf
|
cmd/internal/obj: stop storing Text flags in From3
Prior to this CL, flags such as NOSPLIT
on ATEXT Progs were stored in From3.Offset.
Some but not all of those flags were also
duplicated into From.Sym.Attribute.
This CL migrates all of those flags into
From.Sym.Attribute and stops creating a From3.
A side-effect of this is that printing an
ATEXT Prog can no longer simply dump From3.Offset.
That's kind of good, since the raw flag value
wasn't very informative anyway, but it did
necessitate a bunch of updates to the cmd/asm tests.
The reason I'm doing this work now is that
avoiding storing flags in both From.Sym and From3.Offset
simplifies some other changes to fix the data
race first described in CL 40254.
This CL almost passes toolstash-check -all.
The only changes are in cases where the assembler
has decided that a function's flags may be altered,
e.g. to make a function with no calls in it NOSPLIT.
Prior to this CL, that information was not printed.
Sample before:
"".Ctz64 t=1 size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Sample after:
"".Ctz64 t=1 nosplit size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), NOSPLIT, $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Observe the additional "nosplit" in the first line
and the additional "NOSPLIT" in the second line.
Updates #15756
Change-Id: I5c59bd8f3bdc7c780361f801d94a261f0aef3d13
Reviewed-on: https://go-review.googlesource.com/40495
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-11 15:15:04 -07:00
|
|
|
AttrWrapper
|
|
|
|
|
AttrNeedCtxt
|
|
|
|
|
AttrNoFrame
|
2016-10-24 23:15:41 +03:00
|
|
|
AttrSeenGlobl
|
|
|
|
|
AttrOnList
|
2017-04-20 07:13:02 -07:00
|
|
|
AttrStatic
|
2016-03-10 16:15:26 -05:00
|
|
|
|
2016-10-19 07:33:16 +03:00
|
|
|
// MakeTypelink means that the type should have an entry in the typelink table.
|
2016-10-24 23:15:41 +03:00
|
|
|
AttrMakeTypelink
|
2016-10-19 07:33:16 +03:00
|
|
|
|
2016-03-10 16:15:26 -05:00
|
|
|
// ReflectMethod means the function may call reflect.Type.Method or
|
|
|
|
|
// reflect.Type.MethodByName. Matching is imprecise (as reflect.Type
|
|
|
|
|
// can be used through a custom interface), so ReflectMethod may be
|
|
|
|
|
// set in some cases when the reflect package is not called.
|
|
|
|
|
//
|
|
|
|
|
// Used by the linker to determine what methods can be pruned.
|
2016-10-24 23:15:41 +03:00
|
|
|
AttrReflectMethod
|
2016-03-10 16:15:26 -05:00
|
|
|
|
2015-04-18 08:14:08 +12:00
|
|
|
// Local means make the symbol local even when compiling Go code to reference Go
|
|
|
|
|
// symbols in other shared libraries, as in this mode symbols are global by
|
|
|
|
|
// default. "local" here means in the sense of the dynamic linker, i.e. not
|
|
|
|
|
// visible outside of the module (shared library or executable) that contains its
|
|
|
|
|
// definition. (When not compiling to support Go shared libraries, all symbols are
|
|
|
|
|
// local in this sense unless there is a cgo_export_* directive).
|
2016-10-24 23:15:41 +03:00
|
|
|
AttrLocal
|
|
|
|
|
)
|
2016-03-16 12:41:55 -07:00
|
|
|
|
2016-10-24 23:15:41 +03:00
|
|
|
func (a Attribute) DuplicateOK() bool { return a&AttrDuplicateOK != 0 }
|
|
|
|
|
func (a Attribute) MakeTypelink() bool { return a&AttrMakeTypelink != 0 }
|
|
|
|
|
func (a Attribute) CFunc() bool { return a&AttrCFunc != 0 }
|
|
|
|
|
func (a Attribute) NoSplit() bool { return a&AttrNoSplit != 0 }
|
|
|
|
|
func (a Attribute) Leaf() bool { return a&AttrLeaf != 0 }
|
|
|
|
|
func (a Attribute) SeenGlobl() bool { return a&AttrSeenGlobl != 0 }
|
|
|
|
|
func (a Attribute) OnList() bool { return a&AttrOnList != 0 }
|
|
|
|
|
func (a Attribute) ReflectMethod() bool { return a&AttrReflectMethod != 0 }
|
|
|
|
|
func (a Attribute) Local() bool { return a&AttrLocal != 0 }
|
cmd/internal/obj: stop storing Text flags in From3
Prior to this CL, flags such as NOSPLIT
on ATEXT Progs were stored in From3.Offset.
Some but not all of those flags were also
duplicated into From.Sym.Attribute.
This CL migrates all of those flags into
From.Sym.Attribute and stops creating a From3.
A side-effect of this is that printing an
ATEXT Prog can no longer simply dump From3.Offset.
That's kind of good, since the raw flag value
wasn't very informative anyway, but it did
necessitate a bunch of updates to the cmd/asm tests.
The reason I'm doing this work now is that
avoiding storing flags in both From.Sym and From3.Offset
simplifies some other changes to fix the data
race first described in CL 40254.
This CL almost passes toolstash-check -all.
The only changes are in cases where the assembler
has decided that a function's flags may be altered,
e.g. to make a function with no calls in it NOSPLIT.
Prior to this CL, that information was not printed.
Sample before:
"".Ctz64 t=1 size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Sample after:
"".Ctz64 t=1 nosplit size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), NOSPLIT, $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Observe the additional "nosplit" in the first line
and the additional "NOSPLIT" in the second line.
Updates #15756
Change-Id: I5c59bd8f3bdc7c780361f801d94a261f0aef3d13
Reviewed-on: https://go-review.googlesource.com/40495
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-11 15:15:04 -07:00
|
|
|
func (a Attribute) Wrapper() bool { return a&AttrWrapper != 0 }
|
|
|
|
|
func (a Attribute) NeedCtxt() bool { return a&AttrNeedCtxt != 0 }
|
|
|
|
|
func (a Attribute) NoFrame() bool { return a&AttrNoFrame != 0 }
|
2017-04-20 07:13:02 -07:00
|
|
|
func (a Attribute) Static() bool { return a&AttrStatic != 0 }
|
2016-10-24 23:15:41 +03:00
|
|
|
|
|
|
|
|
func (a *Attribute) Set(flag Attribute, value bool) {
|
|
|
|
|
if value {
|
|
|
|
|
*a |= flag
|
|
|
|
|
} else {
|
|
|
|
|
*a &^= flag
|
|
|
|
|
}
|
2015-03-16 15:31:32 -04:00
|
|
|
}
|
|
|
|
|
|
cmd/internal/obj: stop storing Text flags in From3
Prior to this CL, flags such as NOSPLIT
on ATEXT Progs were stored in From3.Offset.
Some but not all of those flags were also
duplicated into From.Sym.Attribute.
This CL migrates all of those flags into
From.Sym.Attribute and stops creating a From3.
A side-effect of this is that printing an
ATEXT Prog can no longer simply dump From3.Offset.
That's kind of good, since the raw flag value
wasn't very informative anyway, but it did
necessitate a bunch of updates to the cmd/asm tests.
The reason I'm doing this work now is that
avoiding storing flags in both From.Sym and From3.Offset
simplifies some other changes to fix the data
race first described in CL 40254.
This CL almost passes toolstash-check -all.
The only changes are in cases where the assembler
has decided that a function's flags may be altered,
e.g. to make a function with no calls in it NOSPLIT.
Prior to this CL, that information was not printed.
Sample before:
"".Ctz64 t=1 size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Sample after:
"".Ctz64 t=1 nosplit size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), NOSPLIT, $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Observe the additional "nosplit" in the first line
and the additional "NOSPLIT" in the second line.
Updates #15756
Change-Id: I5c59bd8f3bdc7c780361f801d94a261f0aef3d13
Reviewed-on: https://go-review.googlesource.com/40495
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-11 15:15:04 -07:00
|
|
|
var textAttrStrings = [...]struct {
|
|
|
|
|
bit Attribute
|
|
|
|
|
s string
|
|
|
|
|
}{
|
|
|
|
|
{bit: AttrDuplicateOK, s: "DUPOK"},
|
|
|
|
|
{bit: AttrMakeTypelink, s: ""},
|
|
|
|
|
{bit: AttrCFunc, s: "CFUNC"},
|
|
|
|
|
{bit: AttrNoSplit, s: "NOSPLIT"},
|
|
|
|
|
{bit: AttrLeaf, s: "LEAF"},
|
|
|
|
|
{bit: AttrSeenGlobl, s: ""},
|
|
|
|
|
{bit: AttrOnList, s: ""},
|
|
|
|
|
{bit: AttrReflectMethod, s: "REFLECTMETHOD"},
|
|
|
|
|
{bit: AttrLocal, s: "LOCAL"},
|
|
|
|
|
{bit: AttrWrapper, s: "WRAPPER"},
|
|
|
|
|
{bit: AttrNeedCtxt, s: "NEEDCTXT"},
|
|
|
|
|
{bit: AttrNoFrame, s: "NOFRAME"},
|
2017-04-20 07:13:02 -07:00
|
|
|
{bit: AttrStatic, s: "STATIC"},
|
cmd/internal/obj: stop storing Text flags in From3
Prior to this CL, flags such as NOSPLIT
on ATEXT Progs were stored in From3.Offset.
Some but not all of those flags were also
duplicated into From.Sym.Attribute.
This CL migrates all of those flags into
From.Sym.Attribute and stops creating a From3.
A side-effect of this is that printing an
ATEXT Prog can no longer simply dump From3.Offset.
That's kind of good, since the raw flag value
wasn't very informative anyway, but it did
necessitate a bunch of updates to the cmd/asm tests.
The reason I'm doing this work now is that
avoiding storing flags in both From.Sym and From3.Offset
simplifies some other changes to fix the data
race first described in CL 40254.
This CL almost passes toolstash-check -all.
The only changes are in cases where the assembler
has decided that a function's flags may be altered,
e.g. to make a function with no calls in it NOSPLIT.
Prior to this CL, that information was not printed.
Sample before:
"".Ctz64 t=1 size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Sample after:
"".Ctz64 t=1 nosplit size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), NOSPLIT, $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Observe the additional "nosplit" in the first line
and the additional "NOSPLIT" in the second line.
Updates #15756
Change-Id: I5c59bd8f3bdc7c780361f801d94a261f0aef3d13
Reviewed-on: https://go-review.googlesource.com/40495
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-11 15:15:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TextAttrString formats a for printing in as part of a TEXT prog.
|
|
|
|
|
func (a Attribute) TextAttrString() string {
|
|
|
|
|
var s string
|
|
|
|
|
for _, x := range textAttrStrings {
|
|
|
|
|
if a&x.bit != 0 {
|
|
|
|
|
if x.s != "" {
|
|
|
|
|
s += x.s + "|"
|
|
|
|
|
}
|
|
|
|
|
a &^= x.bit
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if a != 0 {
|
|
|
|
|
s += fmt.Sprintf("UnknownAttribute(%d)|", a)
|
|
|
|
|
}
|
|
|
|
|
// Chop off trailing |, if present.
|
|
|
|
|
if len(s) > 0 {
|
|
|
|
|
s = s[:len(s)-1]
|
|
|
|
|
}
|
|
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-16 22:22:58 -07:00
|
|
|
// The compiler needs LSym to satisfy fmt.Stringer, because it stores
|
|
|
|
|
// an LSym in ssa.ExternSymbol.
|
|
|
|
|
func (s *LSym) String() string {
|
|
|
|
|
return s.Name
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 15:31:32 -04:00
|
|
|
type Pcln struct {
|
|
|
|
|
Pcsp Pcdata
|
|
|
|
|
Pcfile Pcdata
|
|
|
|
|
Pcline Pcdata
|
cmd/compile,link: generate PC-value tables with inlining information
In order to generate accurate tracebacks, the runtime needs to know the
inlined call stack for a given PC. This creates two tables per function
for this purpose. The first table is the inlining tree (stored in the
function's funcdata), which has a node containing the file, line, and
function name for every inlined call. The second table is a PC-value
table that maps each PC to a node in the inlining tree (or -1 if the PC
is not the result of inlining).
To give the appearance that inlining hasn't happened, the runtime also
needs the original source position information of inlined AST nodes.
Previously the compiler plastered over the line numbers of inlined AST
nodes with the line number of the call. This meant that the PC-line
table mapped each PC to line number of the outermost call in its inlined
call stack, with no way to access the innermost line number.
Now the compiler retains line numbers of inlined AST nodes and writes
the innermost source position information to the PC-line and PC-file
tables. Some tools and tests expect to see outermost line numbers, so we
provide the OutermostLine function for displaying line info.
To keep track of the inlined call stack for an AST node, we extend the
src.PosBase type with an index into a global inlining tree. Every time
the compiler inlines a call, it creates a node in the global inlining
tree for the call, and writes its index to the PosBase of every inlined
AST node. The parent of this node is the inlining tree index of the
call. -1 signifies no parent.
For each function, the compiler creates a local inlining tree and a
PC-value table mapping each PC to an index in the local tree. These are
written to an object file, which is read by the linker. The linker
re-encodes these tables compactly by deduplicating function names and
file names.
This change increases the size of binaries by 4-5%. For example, this is
how the go1 benchmark binary is impacted by this change:
section old bytes new bytes delta
.text 3.49M ± 0% 3.49M ± 0% +0.06%
.rodata 1.12M ± 0% 1.21M ± 0% +8.21%
.gopclntab 1.50M ± 0% 1.68M ± 0% +11.89%
.debug_line 338k ± 0% 435k ± 0% +28.78%
Total 9.21M ± 0% 9.58M ± 0% +4.01%
Updates #19348.
Change-Id: Ic4f180c3b516018138236b0c35e0218270d957d3
Reviewed-on: https://go-review.googlesource.com/37231
Run-TryBot: David Lazar <lazard@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2017-02-17 12:28:05 -05:00
|
|
|
Pcinline Pcdata
|
2015-03-16 15:31:32 -04:00
|
|
|
Pcdata []Pcdata
|
|
|
|
|
Funcdata []*LSym
|
|
|
|
|
Funcdataoff []int64
|
2017-04-03 07:50:56 -07:00
|
|
|
File []string
|
|
|
|
|
Lastfile string
|
2015-03-16 15:31:32 -04:00
|
|
|
Lastindex int
|
cmd/compile,link: generate PC-value tables with inlining information
In order to generate accurate tracebacks, the runtime needs to know the
inlined call stack for a given PC. This creates two tables per function
for this purpose. The first table is the inlining tree (stored in the
function's funcdata), which has a node containing the file, line, and
function name for every inlined call. The second table is a PC-value
table that maps each PC to a node in the inlining tree (or -1 if the PC
is not the result of inlining).
To give the appearance that inlining hasn't happened, the runtime also
needs the original source position information of inlined AST nodes.
Previously the compiler plastered over the line numbers of inlined AST
nodes with the line number of the call. This meant that the PC-line
table mapped each PC to line number of the outermost call in its inlined
call stack, with no way to access the innermost line number.
Now the compiler retains line numbers of inlined AST nodes and writes
the innermost source position information to the PC-line and PC-file
tables. Some tools and tests expect to see outermost line numbers, so we
provide the OutermostLine function for displaying line info.
To keep track of the inlined call stack for an AST node, we extend the
src.PosBase type with an index into a global inlining tree. Every time
the compiler inlines a call, it creates a node in the global inlining
tree for the call, and writes its index to the PosBase of every inlined
AST node. The parent of this node is the inlining tree index of the
call. -1 signifies no parent.
For each function, the compiler creates a local inlining tree and a
PC-value table mapping each PC to an index in the local tree. These are
written to an object file, which is read by the linker. The linker
re-encodes these tables compactly by deduplicating function names and
file names.
This change increases the size of binaries by 4-5%. For example, this is
how the go1 benchmark binary is impacted by this change:
section old bytes new bytes delta
.text 3.49M ± 0% 3.49M ± 0% +0.06%
.rodata 1.12M ± 0% 1.21M ± 0% +8.21%
.gopclntab 1.50M ± 0% 1.68M ± 0% +11.89%
.debug_line 338k ± 0% 435k ± 0% +28.78%
Total 9.21M ± 0% 9.58M ± 0% +4.01%
Updates #19348.
Change-Id: Ic4f180c3b516018138236b0c35e0218270d957d3
Reviewed-on: https://go-review.googlesource.com/37231
Run-TryBot: David Lazar <lazard@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2017-02-17 12:28:05 -05:00
|
|
|
InlTree InlTree // per-function inlining tree extracted from the global tree
|
2015-03-16 15:31:32 -04:00
|
|
|
}
|
2015-01-19 14:34:58 -05:00
|
|
|
|
2015-03-16 15:31:32 -04:00
|
|
|
type Reloc struct {
|
2015-03-17 16:28:30 +13:00
|
|
|
Off int32
|
|
|
|
|
Siz uint8
|
2017-04-18 12:53:25 -07:00
|
|
|
Type objabi.RelocType
|
2015-03-17 16:28:30 +13:00
|
|
|
Add int64
|
|
|
|
|
Sym *LSym
|
2015-03-16 15:31:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Auto struct {
|
|
|
|
|
Asym *LSym
|
|
|
|
|
Aoffset int32
|
2017-02-13 13:34:30 -08:00
|
|
|
Name AddrName
|
2015-03-16 15:31:32 -04:00
|
|
|
Gotype *LSym
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Pcdata struct {
|
|
|
|
|
P []byte
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
// Link holds the context for writing object code from a compiler
|
|
|
|
|
// to be linker input or for reading that input into the linker.
|
2015-03-16 15:31:32 -04:00
|
|
|
type Link struct {
|
2017-04-18 12:53:25 -07:00
|
|
|
Headtype objabi.HeadType
|
2016-03-13 11:54:14 -07:00
|
|
|
Arch *LinkArch
|
2017-03-20 15:01:20 -07:00
|
|
|
Debugasm bool
|
|
|
|
|
Debugvlog bool
|
2017-02-17 16:55:40 -05:00
|
|
|
Debugpcln string
|
2016-04-13 18:41:59 -07:00
|
|
|
Flag_shared bool
|
2016-03-13 11:54:14 -07:00
|
|
|
Flag_dynlink bool
|
|
|
|
|
Flag_optimize bool
|
2016-04-08 19:30:41 +10:00
|
|
|
Bso *bufio.Writer
|
2016-03-13 11:54:14 -07:00
|
|
|
Pathname string
|
2017-04-20 07:13:02 -07:00
|
|
|
hash map[string]*LSym // name -> sym mapping
|
|
|
|
|
statichash map[string]*LSym // name -> sym mapping for static syms
|
2016-12-15 17:17:01 -08:00
|
|
|
PosTable src.PosTable
|
cmd/compile,link: generate PC-value tables with inlining information
In order to generate accurate tracebacks, the runtime needs to know the
inlined call stack for a given PC. This creates two tables per function
for this purpose. The first table is the inlining tree (stored in the
function's funcdata), which has a node containing the file, line, and
function name for every inlined call. The second table is a PC-value
table that maps each PC to a node in the inlining tree (or -1 if the PC
is not the result of inlining).
To give the appearance that inlining hasn't happened, the runtime also
needs the original source position information of inlined AST nodes.
Previously the compiler plastered over the line numbers of inlined AST
nodes with the line number of the call. This meant that the PC-line
table mapped each PC to line number of the outermost call in its inlined
call stack, with no way to access the innermost line number.
Now the compiler retains line numbers of inlined AST nodes and writes
the innermost source position information to the PC-line and PC-file
tables. Some tools and tests expect to see outermost line numbers, so we
provide the OutermostLine function for displaying line info.
To keep track of the inlined call stack for an AST node, we extend the
src.PosBase type with an index into a global inlining tree. Every time
the compiler inlines a call, it creates a node in the global inlining
tree for the call, and writes its index to the PosBase of every inlined
AST node. The parent of this node is the inlining tree index of the
call. -1 signifies no parent.
For each function, the compiler creates a local inlining tree and a
PC-value table mapping each PC to an index in the local tree. These are
written to an object file, which is read by the linker. The linker
re-encodes these tables compactly by deduplicating function names and
file names.
This change increases the size of binaries by 4-5%. For example, this is
how the go1 benchmark binary is impacted by this change:
section old bytes new bytes delta
.text 3.49M ± 0% 3.49M ± 0% +0.06%
.rodata 1.12M ± 0% 1.21M ± 0% +8.21%
.gopclntab 1.50M ± 0% 1.68M ± 0% +11.89%
.debug_line 338k ± 0% 435k ± 0% +28.78%
Total 9.21M ± 0% 9.58M ± 0% +4.01%
Updates #19348.
Change-Id: Ic4f180c3b516018138236b0c35e0218270d957d3
Reviewed-on: https://go-review.googlesource.com/37231
Run-TryBot: David Lazar <lazard@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2017-02-17 12:28:05 -05:00
|
|
|
InlTree InlTree // global inlining tree used by gc/inl.go
|
2016-03-13 11:54:14 -07:00
|
|
|
Imports []string
|
|
|
|
|
DiagFunc func(string, ...interface{})
|
2017-04-07 19:50:31 +00:00
|
|
|
DebugInfo func(fn *LSym, curfn interface{}) []*dwarf.Var // if non-nil, curfn is a *gc.Node
|
2016-03-13 11:54:14 -07:00
|
|
|
Errors int
|
2016-01-05 09:27:40 -05:00
|
|
|
|
2016-05-25 14:37:43 -04:00
|
|
|
Framepointer_enabled bool
|
|
|
|
|
|
2016-01-05 09:27:40 -05:00
|
|
|
// state for writing objects
|
2016-03-14 21:51:09 -07:00
|
|
|
Text []*LSym
|
|
|
|
|
Data []*LSym
|
2015-03-16 15:31:32 -04:00
|
|
|
}
|
|
|
|
|
|
2016-01-24 01:33:16 -05:00
|
|
|
func (ctxt *Link) Diag(format string, args ...interface{}) {
|
|
|
|
|
ctxt.Errors++
|
|
|
|
|
ctxt.DiagFunc(format, args...)
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 12:32:42 +10:00
|
|
|
func (ctxt *Link) Logf(format string, args ...interface{}) {
|
|
|
|
|
fmt.Fprintf(ctxt.Bso, format, args...)
|
|
|
|
|
ctxt.Bso.Flush()
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-08 22:13:44 +13:00
|
|
|
// The smallest possible offset from the hardware stack pointer to a local
|
|
|
|
|
// variable on the stack. Architectures that use a link register save its value
|
|
|
|
|
// on the stack in the function prologue and so always have a pointer between
|
|
|
|
|
// the hardware stack pointer and the local variable area.
|
|
|
|
|
func (ctxt *Link) FixedFrameSize() int64 {
|
2016-04-06 12:01:40 -07:00
|
|
|
switch ctxt.Arch.Family {
|
|
|
|
|
case sys.AMD64, sys.I386:
|
2015-10-08 22:13:44 +13:00
|
|
|
return 0
|
2016-04-06 12:01:40 -07:00
|
|
|
case sys.PPC64:
|
2015-10-30 12:36:08 +13:00
|
|
|
// PIC code on ppc64le requires 32 bytes of stack, and it's easier to
|
|
|
|
|
// just use that much stack always on ppc64x.
|
2016-04-06 12:01:40 -07:00
|
|
|
return int64(4 * ctxt.Arch.PtrSize)
|
2015-10-08 22:13:44 +13:00
|
|
|
default:
|
2016-04-06 12:01:40 -07:00
|
|
|
return int64(ctxt.Arch.PtrSize)
|
2015-10-08 22:13:44 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
// LinkArch is the definition of a single architecture.
|
2015-03-16 15:31:32 -04:00
|
|
|
type LinkArch struct {
|
2016-04-06 12:01:40 -07:00
|
|
|
*sys.Arch
|
2017-04-06 13:42:31 -07:00
|
|
|
Init func(*Link)
|
2017-04-04 14:31:55 -07:00
|
|
|
Preprocess func(*Link, *LSym, ProgAlloc)
|
|
|
|
|
Assemble func(*Link, *LSym, ProgAlloc)
|
|
|
|
|
Progedit func(*Link, *Prog, ProgAlloc)
|
2016-03-07 18:00:08 -08:00
|
|
|
UnaryDst map[As]bool // Instruction takes one operand, a destination.
|
2015-03-16 15:31:32 -04:00
|
|
|
}
|