2015-01-19 14:34:58 -05:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package obj
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
2015-03-05 10:39:23 -08:00
|
|
|
"bytes"
|
2015-01-19 14:34:58 -05:00
|
|
|
"fmt"
|
|
|
|
|
"io"
|
2015-02-13 14:40:36 -05:00
|
|
|
"log"
|
2015-01-19 14:34:58 -05:00
|
|
|
"os"
|
2015-02-25 09:07:02 -08:00
|
|
|
"strings"
|
2015-01-19 14:34:58 -05:00
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2015-02-25 09:07:02 -08:00
|
|
|
const REG_NONE = 0
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
var start time.Time
|
|
|
|
|
|
|
|
|
|
func Cputime() float64 {
|
|
|
|
|
if start.IsZero() {
|
|
|
|
|
start = time.Now()
|
|
|
|
|
}
|
|
|
|
|
return time.Since(start).Seconds()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Biobuf struct {
|
2015-05-01 15:29:11 +10:00
|
|
|
f *os.File
|
|
|
|
|
r *bufio.Reader
|
|
|
|
|
w *bufio.Writer
|
|
|
|
|
linelen int
|
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
|
|
|
func Bopenw(name string) (*Biobuf, error) {
|
2015-02-13 14:40:36 -05:00
|
|
|
f, err := os.Create(name)
|
[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
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &Biobuf{f: f, w: bufio.NewWriter(f)}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
func Bopenr(name string) (*Biobuf, error) {
|
|
|
|
|
f, err := os.Open(name)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &Biobuf{f: f, r: bufio.NewReader(f)}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
func Binitw(w io.Writer) *Biobuf {
|
|
|
|
|
return &Biobuf{w: bufio.NewWriter(w)}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 19:05:37 -07:00
|
|
|
func Binitr(r io.Reader) *Biobuf {
|
|
|
|
|
return &Biobuf{r: bufio.NewReader(r)}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
func (b *Biobuf) Write(p []byte) (int, error) {
|
|
|
|
|
return b.w.Write(p)
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
func Bwritestring(b *Biobuf, p string) (int, error) {
|
|
|
|
|
return b.w.WriteString(p)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Bseek(b *Biobuf, offset int64, whence int) int64 {
|
|
|
|
|
if b.w != nil {
|
|
|
|
|
if err := b.w.Flush(); err != nil {
|
2015-02-25 09:07:02 -08:00
|
|
|
log.Fatalf("writing output: %v", err)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
} else if b.r != nil {
|
|
|
|
|
if whence == 1 {
|
|
|
|
|
offset -= int64(b.r.Buffered())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
off, err := b.f.Seek(offset, whence)
|
|
|
|
|
if err != nil {
|
2015-02-25 09:07:02 -08:00
|
|
|
log.Fatalf("seeking in output: %v", err)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if b.r != nil {
|
|
|
|
|
b.r.Reset(b.f)
|
|
|
|
|
}
|
|
|
|
|
return off
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Boffset(b *Biobuf) int64 {
|
2015-05-02 12:44:49 +10:00
|
|
|
if b.w != nil {
|
|
|
|
|
if err := b.w.Flush(); err != nil {
|
|
|
|
|
log.Fatalf("writing output: %v", err)
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
off, err := b.f.Seek(0, 1)
|
|
|
|
|
if err != nil {
|
2015-05-02 12:44:49 +10:00
|
|
|
log.Fatalf("seeking in output [0, 1]: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if b.r != nil {
|
|
|
|
|
off -= int64(b.r.Buffered())
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
return off
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
func (b *Biobuf) Flush() error {
|
|
|
|
|
return b.w.Flush()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Bputc(b *Biobuf, c byte) {
|
|
|
|
|
b.w.WriteByte(c)
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
const Beof = -1
|
|
|
|
|
|
|
|
|
|
func Bread(b *Biobuf, p []byte) int {
|
|
|
|
|
n, err := io.ReadFull(b.r, p)
|
|
|
|
|
if n == 0 {
|
|
|
|
|
if err != nil && err != io.EOF {
|
|
|
|
|
n = -1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
func Bgetc(b *Biobuf) int {
|
|
|
|
|
c, err := b.r.ReadByte()
|
2015-02-13 14:40:36 -05:00
|
|
|
if err != nil {
|
2015-05-01 15:29:11 +10:00
|
|
|
return -1
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-05-01 15:29:11 +10:00
|
|
|
return int(c)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Bgetrune(b *Biobuf) int {
|
|
|
|
|
r, _, err := b.r.ReadRune()
|
2015-01-19 14:34:58 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
return int(r)
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
func Bungetrune(b *Biobuf) {
|
|
|
|
|
b.r.UnreadRune()
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
func (b *Biobuf) Read(p []byte) (int, error) {
|
|
|
|
|
return b.r.Read(p)
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-01 15:29:11 +10:00
|
|
|
func (b *Biobuf) Peek(n int) ([]byte, error) {
|
|
|
|
|
return b.r.Peek(n)
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
func Brdline(b *Biobuf, delim int) string {
|
|
|
|
|
s, err := b.r.ReadBytes(byte(delim))
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("reading input: %v", err)
|
|
|
|
|
}
|
|
|
|
|
b.linelen = len(s)
|
|
|
|
|
return string(s)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Brdstr(b *Biobuf, delim int, cut int) string {
|
|
|
|
|
s, err := b.r.ReadString(byte(delim))
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("reading input: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if len(s) > 0 && cut > 0 {
|
|
|
|
|
s = s[:len(s)-1]
|
|
|
|
|
}
|
|
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Blinelen(b *Biobuf) int {
|
|
|
|
|
return b.linelen
|
|
|
|
|
}
|
|
|
|
|
|
[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
|
|
|
func Bterm(b *Biobuf) error {
|
2015-02-13 14:40:36 -05:00
|
|
|
var err error
|
|
|
|
|
if b.w != nil {
|
|
|
|
|
err = b.w.Flush()
|
|
|
|
|
}
|
[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
|
|
|
err1 := b.f.Close()
|
|
|
|
|
if err == nil {
|
|
|
|
|
err = err1
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-21 12:27:36 -05:00
|
|
|
func envOr(key, value string) string {
|
|
|
|
|
if x := os.Getenv(key); x != "" {
|
|
|
|
|
return x
|
|
|
|
|
}
|
|
|
|
|
return value
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
func Getgoroot() string {
|
2015-01-21 12:27:36 -05:00
|
|
|
return envOr("GOROOT", defaultGOROOT)
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Getgoarch() string {
|
2015-01-21 12:27:36 -05:00
|
|
|
return envOr("GOARCH", defaultGOARCH)
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Getgoos() string {
|
2015-01-21 12:27:36 -05:00
|
|
|
return envOr("GOOS", defaultGOOS)
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-07 15:00:52 +12:00
|
|
|
func Getgoarm() int32 {
|
2015-05-13 15:28:11 -07:00
|
|
|
switch v := envOr("GOARM", defaultGOARM); v {
|
2015-09-07 15:00:52 +12:00
|
|
|
case "5":
|
|
|
|
|
return 5
|
|
|
|
|
case "6":
|
|
|
|
|
return 6
|
|
|
|
|
case "7":
|
|
|
|
|
return 7
|
2015-05-13 15:28:11 -07:00
|
|
|
}
|
|
|
|
|
// Fail here, rather than validate at multiple call sites.
|
|
|
|
|
log.Fatalf("Invalid GOARM value. Must be 5, 6, or 7.")
|
|
|
|
|
panic("unreachable")
|
2015-01-21 12:27:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
func Getgo386() string {
|
2015-06-24 09:50:12 +10:00
|
|
|
// Validated by cmd/compile.
|
2015-02-13 14:40:36 -05:00
|
|
|
return envOr("GO386", defaultGO386)
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 22:50:01 -05:00
|
|
|
func Getgoextlinkenabled() string {
|
|
|
|
|
return envOr("GO_EXTLINK_ENABLED", defaultGO_EXTLINK_ENABLED)
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-21 12:27:36 -05:00
|
|
|
func Getgoversion() string {
|
|
|
|
|
return version
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Prog) Line() string {
|
2015-04-20 13:32:40 -07:00
|
|
|
return p.Ctxt.LineHist.LineString(int(p.Lineno))
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-05 10:39:23 -08:00
|
|
|
var armCondCode = []string{
|
|
|
|
|
".EQ",
|
|
|
|
|
".NE",
|
|
|
|
|
".CS",
|
|
|
|
|
".CC",
|
|
|
|
|
".MI",
|
|
|
|
|
".PL",
|
|
|
|
|
".VS",
|
|
|
|
|
".VC",
|
|
|
|
|
".HI",
|
|
|
|
|
".LS",
|
|
|
|
|
".GE",
|
|
|
|
|
".LT",
|
|
|
|
|
".GT",
|
|
|
|
|
".LE",
|
|
|
|
|
"",
|
|
|
|
|
".NV",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ARM scond byte */
|
|
|
|
|
const (
|
|
|
|
|
C_SCOND = (1 << 4) - 1
|
|
|
|
|
C_SBIT = 1 << 4
|
|
|
|
|
C_PBIT = 1 << 5
|
|
|
|
|
C_WBIT = 1 << 6
|
|
|
|
|
C_FBIT = 1 << 7
|
|
|
|
|
C_UBIT = 1 << 7
|
|
|
|
|
C_SCOND_XOR = 14
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// CConv formats ARM condition codes.
|
|
|
|
|
func CConv(s uint8) string {
|
|
|
|
|
if s == 0 {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
sc := armCondCode[(s&C_SCOND)^C_SCOND_XOR]
|
|
|
|
|
if s&C_SBIT != 0 {
|
|
|
|
|
sc += ".S"
|
|
|
|
|
}
|
|
|
|
|
if s&C_PBIT != 0 {
|
|
|
|
|
sc += ".P"
|
|
|
|
|
}
|
|
|
|
|
if s&C_WBIT != 0 {
|
|
|
|
|
sc += ".W"
|
|
|
|
|
}
|
|
|
|
|
if s&C_UBIT != 0 { /* ambiguous with FBIT */
|
|
|
|
|
sc += ".U"
|
|
|
|
|
}
|
|
|
|
|
return sc
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
func (p *Prog) String() string {
|
|
|
|
|
if p.Ctxt == nil {
|
2015-02-28 20:31:32 +00:00
|
|
|
return "<Prog without ctxt>"
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
2015-03-05 10:39:23 -08:00
|
|
|
|
|
|
|
|
sc := CConv(p.Scond)
|
|
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
|
|
|
|
|
|
fmt.Fprintf(&buf, "%.5d (%v)\t%v%s", p.Pc, p.Line(), Aconv(int(p.As)), sc)
|
|
|
|
|
sep := "\t"
|
|
|
|
|
if p.From.Type != TYPE_NONE {
|
|
|
|
|
fmt.Fprintf(&buf, "%s%v", sep, Dconv(p, &p.From))
|
|
|
|
|
sep = ", "
|
|
|
|
|
}
|
|
|
|
|
if p.Reg != REG_NONE {
|
|
|
|
|
// Should not happen but might as well show it if it does.
|
|
|
|
|
fmt.Fprintf(&buf, "%s%v", sep, Rconv(int(p.Reg)))
|
|
|
|
|
sep = ", "
|
|
|
|
|
}
|
2015-05-27 15:01:44 -04:00
|
|
|
if p.From3Type() != TYPE_NONE {
|
2015-03-05 10:39:23 -08:00
|
|
|
if p.From3.Type == TYPE_CONST && (p.As == ADATA || p.As == ATEXT || p.As == AGLOBL) {
|
|
|
|
|
// Special case - omit $.
|
|
|
|
|
fmt.Fprintf(&buf, "%s%d", sep, p.From3.Offset)
|
|
|
|
|
} else {
|
2015-05-27 15:01:44 -04:00
|
|
|
fmt.Fprintf(&buf, "%s%v", sep, Dconv(p, p.From3))
|
2015-03-05 10:39:23 -08:00
|
|
|
}
|
|
|
|
|
sep = ", "
|
|
|
|
|
}
|
|
|
|
|
if p.To.Type != TYPE_NONE {
|
|
|
|
|
fmt.Fprintf(&buf, "%s%v", sep, Dconv(p, &p.To))
|
|
|
|
|
}
|
2015-05-21 17:51:34 -04:00
|
|
|
if p.RegTo2 != REG_NONE {
|
|
|
|
|
fmt.Fprintf(&buf, "%s%v", sep, Rconv(int(p.RegTo2)))
|
cmd/internal/obj, cmd/internal/obj/arm64: add support for GOARCH=arm64
ARM64 (ARMv8) has 32 general purpose, 64-bit integer registers
(R0-R31), 32 64-bit scalar floating point registers (F0-F31), and
32 128-bit vector registers (unused, V0-V31).
R31 is either the stack pointer (RSP), or the zero register (ZR),
depending on the instruction. Note the distinction between the
hardware stack pointer, RSP, and the virtual stack pointer SP.
The (hardware) stack pointer must be 16-byte aligned at all times;
the RSP register itself must be aligned, offset(RSP) only has to
have natural alignment.
Instructions are fixed-width, and are 32-bit wide. ARM64 supports
ARMv7 too (32-bit ARM), but not in the same process. In general,
there is not much in common between 32-bit ARM and ARM64, it's a
new architecture.
All implementations have floating point instructions.
This change adds a Prog.To3 field analogous to Prog.To. It is used
by exclusive load/store instructions such as STLXR which read from
one register, and write to both a register and a memory address.
STLXRW R1, (R0), R3
This will store the word contained in R1 to the memory address
pointed by R0. R3 will be updated with the status result of the
store. It is used to implement atomic operations.
No other changes are made to the portable Prog and Addr structures.
Change-Id: Ie839029aa5265bbad35769d9689eca11e1c48c47
Reviewed-on: https://go-review.googlesource.com/7046
Reviewed-by: Russ Cox <rsc@golang.org>
2015-03-08 13:58:16 +01:00
|
|
|
}
|
2015-03-05 10:39:23 -08:00
|
|
|
return buf.String()
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
2015-01-21 21:45:29 -05:00
|
|
|
|
|
|
|
|
func (ctxt *Link) NewProg() *Prog {
|
[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
|
|
|
p := new(Prog) // should be the only call to this; all others should use ctxt.NewProg
|
2015-01-21 21:45:29 -05:00
|
|
|
p.Ctxt = ctxt
|
|
|
|
|
return p
|
|
|
|
|
}
|
[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
|
|
|
|
|
|
|
|
func (ctxt *Link) Line(n int) string {
|
2015-04-20 13:32:40 -07:00
|
|
|
return ctxt.LineHist.LineString(n)
|
[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-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
func Getcallerpc(interface{}) uintptr {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
2015-02-25 09:07:02 -08:00
|
|
|
|
|
|
|
|
func (ctxt *Link) Dconv(a *Addr) string {
|
2015-02-26 17:09:16 -08:00
|
|
|
return Dconv(nil, a)
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
2015-02-26 17:09:16 -08:00
|
|
|
func Dconv(p *Prog, a *Addr) string {
|
2015-02-25 09:07:02 -08:00
|
|
|
var str string
|
|
|
|
|
|
|
|
|
|
switch a.Type {
|
|
|
|
|
default:
|
|
|
|
|
str = fmt.Sprintf("type=%d", a.Type)
|
|
|
|
|
|
|
|
|
|
case TYPE_NONE:
|
|
|
|
|
str = ""
|
|
|
|
|
if a.Name != NAME_NONE || a.Reg != 0 || a.Sym != nil {
|
2015-02-26 17:09:16 -08:00
|
|
|
str = fmt.Sprintf("%v(%v)(NONE)", Mconv(a), Rconv(int(a.Reg)))
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TYPE_REG:
|
|
|
|
|
// TODO(rsc): This special case is for x86 instructions like
|
|
|
|
|
// PINSRQ CX,$1,X6
|
|
|
|
|
// where the $1 is included in the p->to Addr.
|
|
|
|
|
// Move into a new field.
|
|
|
|
|
if a.Offset != 0 {
|
|
|
|
|
str = fmt.Sprintf("$%d,%v", a.Offset, Rconv(int(a.Reg)))
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-20 13:50:46 -07:00
|
|
|
str = Rconv(int(a.Reg))
|
2015-02-25 09:07:02 -08:00
|
|
|
if a.Name != TYPE_NONE || a.Sym != nil {
|
2015-02-26 17:09:16 -08:00
|
|
|
str = fmt.Sprintf("%v(%v)(REG)", Mconv(a), Rconv(int(a.Reg)))
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TYPE_BRANCH:
|
|
|
|
|
if a.Sym != nil {
|
|
|
|
|
str = fmt.Sprintf("%s(SB)", a.Sym.Name)
|
|
|
|
|
} else if p != nil && p.Pcond != nil {
|
2015-04-20 13:50:46 -07:00
|
|
|
str = fmt.Sprint(p.Pcond.Pc)
|
2015-03-16 15:54:44 -04:00
|
|
|
} else if a.Val != nil {
|
2015-04-20 13:50:46 -07:00
|
|
|
str = fmt.Sprint(a.Val.(*Prog).Pc)
|
2015-02-25 09:07:02 -08:00
|
|
|
} else {
|
|
|
|
|
str = fmt.Sprintf("%d(PC)", a.Offset)
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-26 10:58:48 -08:00
|
|
|
case TYPE_INDIR:
|
2015-02-26 17:09:16 -08:00
|
|
|
str = fmt.Sprintf("*%s", Mconv(a))
|
2015-02-26 10:58:48 -08:00
|
|
|
|
2015-02-25 09:07:02 -08:00
|
|
|
case TYPE_MEM:
|
2015-02-26 17:09:16 -08:00
|
|
|
str = Mconv(a)
|
2015-02-25 09:07:02 -08:00
|
|
|
if a.Index != REG_NONE {
|
|
|
|
|
str += fmt.Sprintf("(%v*%d)", Rconv(int(a.Index)), int(a.Scale))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TYPE_CONST:
|
|
|
|
|
if a.Reg != 0 {
|
2015-02-26 17:09:16 -08:00
|
|
|
str = fmt.Sprintf("$%v(%v)", Mconv(a), Rconv(int(a.Reg)))
|
2015-02-25 09:07:02 -08:00
|
|
|
} else {
|
2015-02-26 17:09:16 -08:00
|
|
|
str = fmt.Sprintf("$%v", Mconv(a))
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TYPE_TEXTSIZE:
|
2015-03-16 15:54:44 -04:00
|
|
|
if a.Val.(int32) == ArgsSizeUnknown {
|
2015-02-25 09:07:02 -08:00
|
|
|
str = fmt.Sprintf("$%d", a.Offset)
|
|
|
|
|
} else {
|
2015-03-16 15:54:44 -04:00
|
|
|
str = fmt.Sprintf("$%d-%d", a.Offset, a.Val.(int32))
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TYPE_FCONST:
|
2015-03-16 15:54:44 -04:00
|
|
|
str = fmt.Sprintf("%.17g", a.Val.(float64))
|
2015-02-25 09:07:02 -08:00
|
|
|
// Make sure 1 prints as 1.0
|
|
|
|
|
if !strings.ContainsAny(str, ".e") {
|
|
|
|
|
str += ".0"
|
|
|
|
|
}
|
|
|
|
|
str = fmt.Sprintf("$(%s)", str)
|
|
|
|
|
|
|
|
|
|
case TYPE_SCONST:
|
2015-03-16 15:54:44 -04:00
|
|
|
str = fmt.Sprintf("$%q", a.Val.(string))
|
2015-02-25 09:07:02 -08:00
|
|
|
|
|
|
|
|
case TYPE_ADDR:
|
2015-02-26 17:09:16 -08:00
|
|
|
str = fmt.Sprintf("$%s", Mconv(a))
|
2015-02-25 09:07:02 -08:00
|
|
|
|
|
|
|
|
case TYPE_SHIFT:
|
|
|
|
|
v := int(a.Offset)
|
|
|
|
|
op := string("<<>>->@>"[((v>>5)&3)<<1:])
|
|
|
|
|
if v&(1<<4) != 0 {
|
|
|
|
|
str = fmt.Sprintf("R%d%c%cR%d", v&15, op[0], op[1], (v>>8)&15)
|
|
|
|
|
} else {
|
|
|
|
|
str = fmt.Sprintf("R%d%c%c%d", v&15, op[0], op[1], (v>>7)&31)
|
|
|
|
|
}
|
|
|
|
|
if a.Reg != 0 {
|
|
|
|
|
str += fmt.Sprintf("(%v)", Rconv(int(a.Reg)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TYPE_REGREG:
|
|
|
|
|
str = fmt.Sprintf("(%v, %v)", Rconv(int(a.Reg)), Rconv(int(a.Offset)))
|
|
|
|
|
|
|
|
|
|
case TYPE_REGREG2:
|
|
|
|
|
str = fmt.Sprintf("%v, %v", Rconv(int(a.Reg)), Rconv(int(a.Offset)))
|
2015-02-27 13:50:26 -08:00
|
|
|
|
|
|
|
|
case TYPE_REGLIST:
|
|
|
|
|
str = regListConv(int(a.Offset))
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-26 17:09:16 -08:00
|
|
|
func Mconv(a *Addr) string {
|
2015-02-25 09:07:02 -08:00
|
|
|
var str string
|
|
|
|
|
|
|
|
|
|
switch a.Name {
|
|
|
|
|
default:
|
|
|
|
|
str = fmt.Sprintf("name=%d", a.Name)
|
|
|
|
|
|
|
|
|
|
case NAME_NONE:
|
|
|
|
|
switch {
|
|
|
|
|
case a.Reg == REG_NONE:
|
2015-04-20 13:50:46 -07:00
|
|
|
str = fmt.Sprint(a.Offset)
|
2015-02-25 09:07:02 -08:00
|
|
|
case a.Offset == 0:
|
|
|
|
|
str = fmt.Sprintf("(%v)", Rconv(int(a.Reg)))
|
|
|
|
|
case a.Offset != 0:
|
|
|
|
|
str = fmt.Sprintf("%d(%v)", a.Offset, Rconv(int(a.Reg)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NAME_EXTERN:
|
2015-09-15 10:59:27 -07:00
|
|
|
if a.Sym != nil {
|
|
|
|
|
str = fmt.Sprintf("%s%s(SB)", a.Sym.Name, offConv(a.Offset))
|
|
|
|
|
} else {
|
|
|
|
|
str = fmt.Sprintf("%s(SB)", offConv(a.Offset))
|
|
|
|
|
}
|
2015-02-25 09:07:02 -08:00
|
|
|
|
2015-03-30 00:49:25 +00:00
|
|
|
case NAME_GOTREF:
|
2015-09-15 10:59:27 -07:00
|
|
|
if a.Sym != nil {
|
|
|
|
|
str = fmt.Sprintf("%s%s@GOT(SB)", a.Sym.Name, offConv(a.Offset))
|
|
|
|
|
} else {
|
|
|
|
|
str = fmt.Sprintf("%s@GOT(SB)", offConv(a.Offset))
|
|
|
|
|
}
|
2015-03-30 00:49:25 +00:00
|
|
|
|
2015-02-25 09:07:02 -08:00
|
|
|
case NAME_STATIC:
|
2015-09-15 10:59:27 -07:00
|
|
|
if a.Sym != nil {
|
|
|
|
|
str = fmt.Sprintf("%s<>%s(SB)", a.Sym.Name, offConv(a.Offset))
|
|
|
|
|
} else {
|
|
|
|
|
str = fmt.Sprintf("<>%s(SB)", offConv(a.Offset))
|
|
|
|
|
}
|
2015-02-25 09:07:02 -08:00
|
|
|
|
|
|
|
|
case NAME_AUTO:
|
|
|
|
|
if a.Sym != nil {
|
|
|
|
|
str = fmt.Sprintf("%s%s(SP)", a.Sym.Name, offConv(a.Offset))
|
|
|
|
|
} else {
|
|
|
|
|
str = fmt.Sprintf("%s(SP)", offConv(a.Offset))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NAME_PARAM:
|
|
|
|
|
if a.Sym != nil {
|
|
|
|
|
str = fmt.Sprintf("%s%s(FP)", a.Sym.Name, offConv(a.Offset))
|
|
|
|
|
} else {
|
|
|
|
|
str = fmt.Sprintf("%s(FP)", offConv(a.Offset))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return str
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func offConv(off int64) string {
|
|
|
|
|
if off == 0 {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("%+d", off)
|
|
|
|
|
}
|
2015-02-26 17:09:16 -08:00
|
|
|
|
|
|
|
|
type regSet struct {
|
|
|
|
|
lo int
|
|
|
|
|
hi int
|
|
|
|
|
Rconv func(int) string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Few enough architectures that a linear scan is fastest.
|
|
|
|
|
// Not even worth sorting.
|
|
|
|
|
var regSpace []regSet
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Each architecture defines a register space as a unique
|
|
|
|
|
integer range.
|
|
|
|
|
Here is the list of architectures and the base of their register spaces.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// Because of masking operations in the encodings, each register
|
|
|
|
|
// space should start at 0 modulo some power of 2.
|
2015-09-10 11:13:00 -04:00
|
|
|
RBase386 = 1 * 1024
|
|
|
|
|
RBaseAMD64 = 2 * 1024
|
|
|
|
|
RBaseARM = 3 * 1024
|
|
|
|
|
RBasePPC64 = 4 * 1024 // range [4k, 8k)
|
|
|
|
|
RBaseARM64 = 8 * 1024 // range [8k, 13k)
|
2016-01-21 16:45:36 -05:00
|
|
|
RBaseMIPS64 = 13 * 1024 // range [13k, 14k)
|
2015-02-26 17:09:16 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// RegisterRegister binds a pretty-printer (Rconv) for register
|
|
|
|
|
// numbers to a given register number range. Lo is inclusive,
|
|
|
|
|
// hi exclusive (valid registers are lo through hi-1).
|
|
|
|
|
func RegisterRegister(lo, hi int, Rconv func(int) string) {
|
|
|
|
|
regSpace = append(regSpace, regSet{lo, hi, Rconv})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Rconv(reg int) string {
|
|
|
|
|
if reg == REG_NONE {
|
|
|
|
|
return "NONE"
|
|
|
|
|
}
|
|
|
|
|
for i := range regSpace {
|
|
|
|
|
rs := ®Space[i]
|
|
|
|
|
if rs.lo <= reg && reg < rs.hi {
|
|
|
|
|
return rs.Rconv(reg)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("R???%d", reg)
|
|
|
|
|
}
|
2015-02-27 13:50:26 -08:00
|
|
|
|
|
|
|
|
func regListConv(list int) string {
|
|
|
|
|
str := ""
|
|
|
|
|
|
|
|
|
|
for i := 0; i < 16; i++ { // TODO: 16 is ARM-specific.
|
|
|
|
|
if list&(1<<uint(i)) != 0 {
|
|
|
|
|
if str == "" {
|
|
|
|
|
str += "["
|
|
|
|
|
} else {
|
|
|
|
|
str += ","
|
|
|
|
|
}
|
|
|
|
|
// This is ARM-specific; R10 is g.
|
|
|
|
|
if i == 10 {
|
|
|
|
|
str += "g"
|
|
|
|
|
} else {
|
|
|
|
|
str += fmt.Sprintf("R%d", i)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
str += "]"
|
|
|
|
|
return str
|
|
|
|
|
}
|
2015-03-02 20:17:20 -08:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Each architecture defines an instruction (A*) space as a unique
|
|
|
|
|
integer range.
|
|
|
|
|
Global opcodes like CALL start at 0; the architecture-specific ones
|
|
|
|
|
start at a distinct, big-maskable offsets.
|
|
|
|
|
Here is the list of architectures and the base of their opcode spaces.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
ABase386 = (1 + iota) << 12
|
|
|
|
|
ABaseARM
|
|
|
|
|
ABaseAMD64
|
|
|
|
|
ABasePPC64
|
cmd/internal/obj, cmd/internal/obj/arm64: add support for GOARCH=arm64
ARM64 (ARMv8) has 32 general purpose, 64-bit integer registers
(R0-R31), 32 64-bit scalar floating point registers (F0-F31), and
32 128-bit vector registers (unused, V0-V31).
R31 is either the stack pointer (RSP), or the zero register (ZR),
depending on the instruction. Note the distinction between the
hardware stack pointer, RSP, and the virtual stack pointer SP.
The (hardware) stack pointer must be 16-byte aligned at all times;
the RSP register itself must be aligned, offset(RSP) only has to
have natural alignment.
Instructions are fixed-width, and are 32-bit wide. ARM64 supports
ARMv7 too (32-bit ARM), but not in the same process. In general,
there is not much in common between 32-bit ARM and ARM64, it's a
new architecture.
All implementations have floating point instructions.
This change adds a Prog.To3 field analogous to Prog.To. It is used
by exclusive load/store instructions such as STLXR which read from
one register, and write to both a register and a memory address.
STLXRW R1, (R0), R3
This will store the word contained in R1 to the memory address
pointed by R0. R3 will be updated with the status result of the
store. It is used to implement atomic operations.
No other changes are made to the portable Prog and Addr structures.
Change-Id: Ie839029aa5265bbad35769d9689eca11e1c48c47
Reviewed-on: https://go-review.googlesource.com/7046
Reviewed-by: Russ Cox <rsc@golang.org>
2015-03-08 13:58:16 +01:00
|
|
|
ABaseARM64
|
2015-09-10 11:13:00 -04:00
|
|
|
ABaseMIPS64
|
2015-03-02 20:17:20 -08:00
|
|
|
AMask = 1<<12 - 1 // AND with this to use the opcode as an array index.
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type opSet struct {
|
|
|
|
|
lo int
|
|
|
|
|
names []string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Not even worth sorting
|
|
|
|
|
var aSpace []opSet
|
|
|
|
|
|
|
|
|
|
// RegisterOpcode binds a list of instruction names
|
|
|
|
|
// to a given instruction number range.
|
|
|
|
|
func RegisterOpcode(lo int, Anames []string) {
|
|
|
|
|
aSpace = append(aSpace, opSet{lo, Anames})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Aconv(a int) string {
|
cmd/compile: recognize Syscall-like functions for liveness analysis
Consider this code:
func f(*int)
func g() {
p := new(int)
f(p)
}
where f is an assembly function.
In general liveness analysis assumes that during the call to f, p is dead
in this frame. If f has retained p, p will be found alive in f's frame and keep
the new(int) from being garbage collected. This is all correct and works.
We use the Go func declaration for f to give the assembly function
liveness information (the arguments are assumed live for the entire call).
Now consider this code:
func h1() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
}
Here syscall.Syscall is taking the place of f, but because its arguments
are uintptr, the liveness analysis and the garbage collector ignore them.
Since p is no longer live in h once the call starts, if the garbage collector
scans the stack while the system call is blocked, it will find no reference
to the new(int) and reclaim it. If the kernel is going to write to *p once
the call finishes, reclaiming the memory is a mistake.
We can't change the arguments or the liveness information for
syscall.Syscall itself, both for compatibility and because sometimes the
arguments really are integers, and the garbage collector will get quite upset
if it finds an integer where it expects a pointer. The problem is that
these arguments are fundamentally untyped.
The solution we have taken in the syscall package's wrappers in past
releases is to insert a call to a dummy function named "use", to make
it look like the argument is live during the call to syscall.Syscall:
func h2() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
use(unsafe.Pointer(p))
}
Keeping p alive during the call means that if the garbage collector
scans the stack during the system call now, it will find the reference to p.
Unfortunately, this approach is not available to users outside syscall,
because 'use' is unexported, and people also have to realize they need
to use it and do so. There is much existing code using syscall.Syscall
without a 'use'-like function. That code will fail very occasionally in
mysterious ways (see #13372).
This CL fixes all that existing code by making the compiler do the right
thing automatically, without any code modifications. That is, it takes h1
above, which is incorrect code today, and makes it correct code.
Specifically, if the compiler sees a foreign func definition (one
without a body) that has uintptr arguments, it marks those arguments
as "unsafe uintptrs". If it later sees the function being called
with uintptr(unsafe.Pointer(x)) as an argument, it arranges to mark x
as having escaped, and it makes sure to hold x in a live temporary
variable until the call returns, so that the garbage collector cannot
reclaim whatever heap memory x points to.
For now I am leaving the explicit calls to use in package syscall,
but they can be removed early in a future cycle (likely Go 1.7).
The rule has no effect on escape analysis, only on liveness analysis.
Fixes #13372.
Change-Id: I2addb83f70d08db08c64d394f9d06ff0a063c500
Reviewed-on: https://go-review.googlesource.com/18584
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-13 00:46:28 -05:00
|
|
|
if 0 <= a && a < len(Anames) {
|
2015-03-02 20:17:20 -08:00
|
|
|
return Anames[a]
|
|
|
|
|
}
|
|
|
|
|
for i := range aSpace {
|
|
|
|
|
as := &aSpace[i]
|
|
|
|
|
if as.lo <= a && a < as.lo+len(as.names) {
|
|
|
|
|
return as.names[a-as.lo]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("A???%d", a)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var Anames = []string{
|
|
|
|
|
"XXX",
|
|
|
|
|
"CALL",
|
|
|
|
|
"CHECKNIL",
|
|
|
|
|
"DATA",
|
|
|
|
|
"DUFFCOPY",
|
|
|
|
|
"DUFFZERO",
|
|
|
|
|
"END",
|
|
|
|
|
"FUNCDATA",
|
|
|
|
|
"GLOBL",
|
|
|
|
|
"JMP",
|
|
|
|
|
"NOP",
|
|
|
|
|
"PCDATA",
|
|
|
|
|
"RET",
|
|
|
|
|
"TEXT",
|
|
|
|
|
"TYPE",
|
|
|
|
|
"UNDEF",
|
|
|
|
|
"USEFIELD",
|
|
|
|
|
"VARDEF",
|
|
|
|
|
"VARKILL",
|
2016-01-13 21:02:12 -05:00
|
|
|
"VARLIVE",
|
2015-03-02 20:17:20 -08:00
|
|
|
}
|
2015-04-22 12:41:14 +12:00
|
|
|
|
|
|
|
|
func Bool2int(b bool) int {
|
|
|
|
|
if b {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
}
|