aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/obj
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/internal/obj')
-rw-r--r--src/cmd/internal/obj/arm/asm5.go8
-rw-r--r--src/cmd/internal/obj/arm/obj5.go15
-rw-r--r--src/cmd/internal/obj/arm64/asm7.go8
-rw-r--r--src/cmd/internal/obj/arm64/list7.go2
-rw-r--r--src/cmd/internal/obj/arm64/obj7.go19
-rw-r--r--src/cmd/internal/obj/data.go38
-rw-r--r--src/cmd/internal/obj/link.go78
-rw-r--r--src/cmd/internal/obj/mips/asm0.go8
-rw-r--r--src/cmd/internal/obj/mips/obj0.go22
-rw-r--r--src/cmd/internal/obj/objfile.go204
-rw-r--r--src/cmd/internal/obj/pcln.go23
-rw-r--r--src/cmd/internal/obj/plist.go218
-rw-r--r--src/cmd/internal/obj/ppc64/asm9.go24
-rw-r--r--src/cmd/internal/obj/ppc64/obj9.go26
-rw-r--r--src/cmd/internal/obj/s390x/a.out.go1
-rw-r--r--src/cmd/internal/obj/s390x/anames.go1
-rw-r--r--src/cmd/internal/obj/s390x/asmz.go38
-rw-r--r--src/cmd/internal/obj/s390x/objz.go15
-rw-r--r--src/cmd/internal/obj/sym.go3
-rw-r--r--src/cmd/internal/obj/util.go142
-rw-r--r--src/cmd/internal/obj/x86/a.out.go2
-rw-r--r--src/cmd/internal/obj/x86/anames.go1
-rw-r--r--src/cmd/internal/obj/x86/asm6.go49
-rw-r--r--src/cmd/internal/obj/x86/obj6.go59
-rw-r--r--src/cmd/internal/obj/x86/obj6_test.go1
25 files changed, 433 insertions, 572 deletions
diff --git a/src/cmd/internal/obj/arm/asm5.go b/src/cmd/internal/obj/arm/asm5.go
index f49ee65a04..564f96a94e 100644
--- a/src/cmd/internal/obj/arm/asm5.go
+++ b/src/cmd/internal/obj/arm/asm5.go
@@ -870,7 +870,7 @@ func addpool(ctxt *obj.Link, p *obj.Prog, a *obj.Addr) {
t.To.Type = a.Type
t.To.Name = a.Name
- if ctxt.Flag_shared != 0 && t.To.Sym != nil {
+ if ctxt.Flag_shared && t.To.Sym != nil {
t.Rel = p
}
@@ -1015,7 +1015,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
ctxt.Instoffset = 0 // s.b. unused but just in case
if a.Sym.Type == obj.STLSBSS {
- if ctxt.Flag_shared != 0 {
+ if ctxt.Flag_shared {
return C_TLS_IE
} else {
return C_TLS_LE
@@ -1322,7 +1322,7 @@ func buildop(ctxt *obj.Link) {
}
for n = 0; optab[n].as != obj.AXXX; n++ {
if optab[n].flag&LPCREL != 0 {
- if ctxt.Flag_shared != 0 {
+ if ctxt.Flag_shared {
optab[n].size += int8(optab[n].pcrelsiz)
} else {
optab[n].flag &^= LPCREL
@@ -1633,7 +1633,7 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
rel.Sym = p.To.Sym
rel.Add = p.To.Offset
- if ctxt.Flag_shared != 0 {
+ if ctxt.Flag_shared {
if p.To.Name == obj.NAME_GOTREF {
rel.Type = obj.R_GOTPCREL
} else {
diff --git a/src/cmd/internal/obj/arm/obj5.go b/src/cmd/internal/obj/arm/obj5.go
index 92ffc7b2f3..042e6ab648 100644
--- a/src/cmd/internal/obj/arm/obj5.go
+++ b/src/cmd/internal/obj/arm/obj5.go
@@ -32,7 +32,7 @@ package arm
import (
"cmd/internal/obj"
- "encoding/binary"
+ "cmd/internal/sys"
"fmt"
"log"
"math"
@@ -412,7 +412,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
p.As = AMOVW
p.From.Type = obj.TYPE_MEM
p.From.Reg = REGG
- p.From.Offset = 4 * int64(ctxt.Arch.Ptrsize) // G.panic
+ p.From.Offset = 4 * int64(ctxt.Arch.PtrSize) // G.panic
p.To.Type = obj.TYPE_REG
p.To.Reg = REG_R1
@@ -708,9 +708,9 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, framesize int32) *obj.Prog {
p.As = AMOVW
p.From.Type = obj.TYPE_MEM
p.From.Reg = REGG
- p.From.Offset = 2 * int64(ctxt.Arch.Ptrsize) // G.stackguard0
+ p.From.Offset = 2 * int64(ctxt.Arch.PtrSize) // G.stackguard0
if ctxt.Cursym.Cfunc {
- p.From.Offset = 3 * int64(ctxt.Arch.Ptrsize) // G.stackguard1
+ p.From.Offset = 3 * int64(ctxt.Arch.PtrSize) // G.stackguard1
}
p.To.Type = obj.TYPE_REG
p.To.Reg = REG_R1
@@ -1032,15 +1032,10 @@ var unaryDst = map[obj.As]bool{
}
var Linkarm = obj.LinkArch{
- ByteOrder: binary.LittleEndian,
- Name: "arm",
- Thechar: '5',
+ Arch: sys.ArchARM,
Preprocess: preprocess,
Assemble: span5,
Follow: follow,
Progedit: progedit,
UnaryDst: unaryDst,
- Minlc: 4,
- Ptrsize: 4,
- Regsize: 4,
}
diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go
index ff8d4fdf60..28bebaa3f7 100644
--- a/src/cmd/internal/obj/arm64/asm7.go
+++ b/src/cmd/internal/obj/arm64/asm7.go
@@ -155,6 +155,7 @@ var optab = []Optab{
{AADC, C_REG, C_REG, C_REG, 1, 4, 0, 0, 0},
{AADC, C_REG, C_NONE, C_REG, 1, 4, 0, 0, 0},
{ANEG, C_REG, C_NONE, C_REG, 25, 4, 0, 0, 0},
+ {ANEG, C_NONE, C_NONE, C_REG, 25, 4, 0, 0, 0},
{ANGC, C_REG, C_NONE, C_REG, 17, 4, 0, 0, 0},
{ACMP, C_REG, C_REG, C_NONE, 1, 4, 0, 0, 0},
{AADD, C_ADDCON, C_RSP, C_RSP, 2, 4, 0, 0, 0},
@@ -972,7 +973,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
ctxt.Instoffset = a.Offset
if a.Sym != nil { // use relocation
if a.Sym.Type == obj.STLSBSS {
- if ctxt.Flag_shared != 0 {
+ if ctxt.Flag_shared {
return C_TLS_IE
} else {
return C_TLS_LE
@@ -1087,7 +1088,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
a1 := int(p.Optab)
if a1 != 0 {
- return &optab[a1-1:][0]
+ return &optab[a1-1]
}
a1 = int(p.From.Class)
if a1 == 0 {
@@ -2198,6 +2199,9 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
o1 = oprrr(ctxt, p.As)
rf := int(p.From.Reg)
+ if rf == C_NONE {
+ rf = int(p.To.Reg)
+ }
rt := int(p.To.Reg)
o1 |= (uint32(rf&31) << 16) | (REGZERO & 31 << 5) | uint32(rt&31)
diff --git a/src/cmd/internal/obj/arm64/list7.go b/src/cmd/internal/obj/arm64/list7.go
index 36f544b53a..ad9ff0965c 100644
--- a/src/cmd/internal/obj/arm64/list7.go
+++ b/src/cmd/internal/obj/arm64/list7.go
@@ -71,7 +71,7 @@ func Rconv(r int) string {
case REG_F0 <= r && r <= REG_F31:
return fmt.Sprintf("F%d", r-REG_F0)
case REG_V0 <= r && r <= REG_V31:
- return fmt.Sprintf("V%d", r-REG_F0)
+ return fmt.Sprintf("V%d", r-REG_V0)
case COND_EQ <= r && r <= COND_NV:
return strcond[r-COND_EQ]
case r == REGSP:
diff --git a/src/cmd/internal/obj/arm64/obj7.go b/src/cmd/internal/obj/arm64/obj7.go
index b3de44c029..ffa1b416d6 100644
--- a/src/cmd/internal/obj/arm64/obj7.go
+++ b/src/cmd/internal/obj/arm64/obj7.go
@@ -32,7 +32,7 @@ package arm64
import (
"cmd/internal/obj"
- "encoding/binary"
+ "cmd/internal/sys"
"fmt"
"log"
"math"
@@ -56,9 +56,9 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, framesize int32) *obj.Prog {
p.As = AMOVD
p.From.Type = obj.TYPE_MEM
p.From.Reg = REGG
- p.From.Offset = 2 * int64(ctxt.Arch.Ptrsize) // G.stackguard0
+ p.From.Offset = 2 * int64(ctxt.Arch.PtrSize) // G.stackguard0
if ctxt.Cursym.Cfunc {
- p.From.Offset = 3 * int64(ctxt.Arch.Ptrsize) // G.stackguard1
+ p.From.Offset = 3 * int64(ctxt.Arch.PtrSize) // G.stackguard1
}
p.To.Type = obj.TYPE_REG
p.To.Reg = REG_R1
@@ -250,7 +250,7 @@ func progedit(ctxt *obj.Link, p *obj.Prog) {
if p.From.Type == obj.TYPE_FCONST {
f32 := float32(p.From.Val.(float64))
i32 := math.Float32bits(f32)
- literal := fmt.Sprintf("$f32.%08x", uint32(i32))
+ literal := fmt.Sprintf("$f32.%08x", i32)
s := obj.Linklookup(ctxt, literal, 0)
s.Size = 4
p.From.Type = obj.TYPE_MEM
@@ -263,7 +263,7 @@ func progedit(ctxt *obj.Link, p *obj.Prog) {
case AFMOVD:
if p.From.Type == obj.TYPE_FCONST {
i64 := math.Float64bits(p.From.Val.(float64))
- literal := fmt.Sprintf("$f64.%016x", uint64(i64))
+ literal := fmt.Sprintf("$f64.%016x", i64)
s := obj.Linklookup(ctxt, literal, 0)
s.Size = 8
p.From.Type = obj.TYPE_MEM
@@ -778,7 +778,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
q.As = AMOVD
q.From.Type = obj.TYPE_MEM
q.From.Reg = REGG
- q.From.Offset = 4 * int64(ctxt.Arch.Ptrsize) // G.panic
+ q.From.Offset = 4 * int64(ctxt.Arch.PtrSize) // G.panic
q.To.Type = obj.TYPE_REG
q.To.Reg = REG_R1
@@ -941,15 +941,10 @@ var unaryDst = map[obj.As]bool{
}
var Linkarm64 = obj.LinkArch{
- ByteOrder: binary.LittleEndian,
- Name: "arm64",
- Thechar: '7',
+ Arch: sys.ArchARM64,
Preprocess: preprocess,
Assemble: span7,
Follow: follow,
Progedit: progedit,
UnaryDst: unaryDst,
- Minlc: 4,
- Ptrsize: 8,
- Regsize: 8,
}
diff --git a/src/cmd/internal/obj/data.go b/src/cmd/internal/obj/data.go
index a3cc178adc..5fe4cb10a5 100644
--- a/src/cmd/internal/obj/data.go
+++ b/src/cmd/internal/obj/data.go
@@ -75,7 +75,11 @@ func (s *LSym) prepwrite(ctxt *Link, off int64, siz int) {
if s.Type == SBSS || s.Type == STLSBSS {
ctxt.Diag("cannot supply data for BSS var")
}
- s.Grow(off + int64(siz))
+ l := off + int64(siz)
+ s.Grow(l)
+ if l > s.Size {
+ s.Size = l
+ }
}
// WriteFloat32 writes f into s at offset off.
@@ -110,18 +114,37 @@ func (s *LSym) WriteInt(ctxt *Link, off int64, siz int, i int64) {
// WriteAddr writes an address of size siz into s at offset off.
// rsym and roff specify the relocation for the address.
func (s *LSym) WriteAddr(ctxt *Link, off int64, siz int, rsym *LSym, roff int64) {
- if siz != ctxt.Arch.Ptrsize {
- ctxt.Diag("WriteAddr: bad address size: %d", siz)
+ if siz != ctxt.Arch.PtrSize {
+ ctxt.Diag("WriteAddr: bad address size %d in %s", siz, s.Name)
}
s.prepwrite(ctxt, off, siz)
r := Addrel(s)
r.Off = int32(off)
+ if int64(r.Off) != off {
+ ctxt.Diag("WriteAddr: off overflow %d in %s", off, s.Name)
+ }
r.Siz = uint8(siz)
r.Sym = rsym
r.Type = R_ADDR
r.Add = roff
}
+// WriteOff writes a 4 byte offset to rsym+roff into s at offset off.
+// After linking the 4 bytes stored at s+off will be
+// rsym+roff-(start of section that s is in).
+func (s *LSym) WriteOff(ctxt *Link, off int64, rsym *LSym, roff int64) {
+ s.prepwrite(ctxt, off, 4)
+ r := Addrel(s)
+ r.Off = int32(off)
+ if int64(r.Off) != off {
+ ctxt.Diag("WriteOff: off overflow %d in %s", off, s.Name)
+ }
+ r.Siz = 4
+ r.Sym = rsym
+ r.Type = R_ADDROFF
+ r.Add = roff
+}
+
// WriteString writes a string of size siz into s at offset off.
func (s *LSym) WriteString(ctxt *Link, off int64, siz int, str string) {
if siz < len(str) {
@@ -131,6 +154,13 @@ func (s *LSym) WriteString(ctxt *Link, off int64, siz int, str string) {
copy(s.P[off:off+int64(siz)], str)
}
+// WriteBytes writes a slice of bytes into s at offset off.
+func (s *LSym) WriteBytes(ctxt *Link, off int64, b []byte) int64 {
+ s.prepwrite(ctxt, off, len(b))
+ copy(s.P[off:], b)
+ return off + int64(len(b))
+}
+
func Addrel(s *LSym) *Reloc {
s.R = append(s.R, Reloc{})
return &s.R[len(s.R)-1]
@@ -153,7 +183,7 @@ func Setuintxx(ctxt *Link, s *LSym, off int64, v uint64, wid int64) int64 {
case 4:
ctxt.Arch.ByteOrder.PutUint32(s.P[off:], uint32(v))
case 8:
- ctxt.Arch.ByteOrder.PutUint64(s.P[off:], uint64(v))
+ ctxt.Arch.ByteOrder.PutUint64(s.P[off:], v)
}
return off + wid
diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go
index 24f028f737..5f257f60ab 100644
--- a/src/cmd/internal/obj/link.go
+++ b/src/cmd/internal/obj/link.go
@@ -30,7 +30,10 @@
package obj
-import "encoding/binary"
+import (
+ "bufio"
+ "cmd/internal/sys"
+)
// An Addr is an argument to an instruction.
// The general forms and their encodings are:
@@ -423,6 +426,8 @@ const (
SCONST
SDYNIMPORT
SHOSTOBJ
+ SDWARFSECT
+ SDWARFINFO
SSUB = 1 << 8
SMASK = SSUB - 1
SHIDDEN = 1 << 9
@@ -452,6 +457,9 @@ const (
// R_ADDRMIPS (only used on mips64) resolves to a 32-bit external address,
// by loading the address into a register with two instructions (lui, ori).
R_ADDRMIPS
+ // R_ADDROFF resolves to a 32-bit offset from the beginning of the section
+ // holding the data being relocated to the referenced symbol.
+ R_ADDROFF
R_SIZE
R_CALL
R_CALLARM
@@ -484,17 +492,20 @@ const (
// should be linked into the final binary, even if there are no other
// direct references. (This is used for types reachable by reflection.)
R_USETYPE
- // R_METHOD resolves to an *rtype for a method.
- // It is used when linking from the uncommonType of another *rtype, and
- // may be set to zero by the linker if it determines the method text is
- // unreachable by the linked program.
- R_METHOD
+ // R_METHODOFF resolves to a 32-bit offset from the beginning of the section
+ // holding the data being relocated to the referenced symbol.
+ // It is a variant of R_ADDROFF used when linking from the uncommonType of a
+ // *rtype, and may be set to zero by the linker if it determines the method
+ // text is unreachable by the linked program.
+ R_METHODOFF
R_POWER_TOC
R_GOTPCREL
// R_JMPMIPS (only used on mips64) resolves to non-PC-relative target address
// of a JMP instruction, by encoding the address into the instruction.
// The stack nosplit check ignores this since it is not a function call.
R_JMPMIPS
+ // R_DWARFREF resolves to the offset of the symbol from its section.
+ R_DWARFREF
// Platform dependent relocations. Architectures with fixed width instructions
// have the inherent issue that a 32-bit (or 64-bit!) displacement cannot be
@@ -590,19 +601,6 @@ type Pcdata struct {
P []byte
}
-// Pcdata iterator.
-// for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) }
-type Pciter struct {
- d Pcdata
- p []byte
- pc uint32
- nextpc uint32
- pcscale uint32
- value int32
- start int
- done int
-}
-
// symbol version, incremented each time a file is loaded.
// version==1 is reserved for savehist.
const (
@@ -619,10 +617,10 @@ type Link struct {
Debugvlog int32
Debugdivmod int32
Debugpcln int32
- Flag_shared int32
+ Flag_shared bool
Flag_dynlink bool
Flag_optimize bool
- Bso *Biobuf
+ Bso *bufio.Writer
Pathname string
Goroot string
Goroot_final string
@@ -678,15 +676,15 @@ func (ctxt *Link) Diag(format string, args ...interface{}) {
// 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 {
- switch ctxt.Arch.Thechar {
- case '6', '8':
+ switch ctxt.Arch.Family {
+ case sys.AMD64, sys.I386:
return 0
- case '9':
+ case sys.PPC64:
// PIC code on ppc64le requires 32 bytes of stack, and it's easier to
// just use that much stack always on ppc64x.
- return int64(4 * ctxt.Arch.Ptrsize)
+ return int64(4 * ctxt.Arch.PtrSize)
default:
- return int64(ctxt.Arch.Ptrsize)
+ return int64(ctxt.Arch.PtrSize)
}
}
@@ -697,17 +695,12 @@ type SymVer struct {
// LinkArch is the definition of a single architecture.
type LinkArch struct {
- ByteOrder binary.ByteOrder
- Name string
- Thechar int
+ *sys.Arch
Preprocess func(*Link, *LSym)
Assemble func(*Link, *LSym)
Follow func(*Link, *LSym)
Progedit func(*Link, *Prog)
UnaryDst map[As]bool // Instruction takes one operand, a destination.
- Minlc int
- Ptrsize int
- Regsize int
}
/* executable header types */
@@ -725,27 +718,6 @@ const (
Hwindows
)
-type Plist struct {
- Name *LSym
- Firstpc *Prog
- Recur int
- Link *Plist
-}
-
-/*
- * start a new Prog list.
- */
-func Linknewplist(ctxt *Link) *Plist {
- pl := new(Plist)
- if ctxt.Plist == nil {
- ctxt.Plist = pl
- } else {
- ctxt.Plast.Link = pl
- }
- ctxt.Plast = pl
- return pl
-}
-
// AsmBuf is a simple buffer to assemble variable-length x86 instructions into.
type AsmBuf struct {
buf [100]byte
diff --git a/src/cmd/internal/obj/mips/asm0.go b/src/cmd/internal/obj/mips/asm0.go
index 521cb66dec..73d6cabbcb 100644
--- a/src/cmd/internal/obj/mips/asm0.go
+++ b/src/cmd/internal/obj/mips/asm0.go
@@ -611,7 +611,7 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
a1 := int(p.Optab)
if a1 != 0 {
- return &optab[a1-1:][0]
+ return &optab[a1-1]
}
a1 = int(p.From.Class)
if a1 == 0 {
@@ -974,10 +974,6 @@ func OP_JMP(op uint32, i uint32) uint32 {
return op | i&0x3FFFFFF
}
-func oclass(a *obj.Addr) int {
- return int(a.Class) - 1
-}
-
func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
o1 := uint32(0)
o2 := uint32(0)
@@ -1028,7 +1024,7 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
o1 = OP_IRR(opirr(ctxt, p.As), uint32(v), uint32(r), uint32(p.To.Reg))
case 5: /* syscall */
- o1 = uint32(oprrr(ctxt, p.As))
+ o1 = oprrr(ctxt, p.As)
case 6: /* beq r1,[r2],sbra */
v := int32(0)
diff --git a/src/cmd/internal/obj/mips/obj0.go b/src/cmd/internal/obj/mips/obj0.go
index ca7d4465c9..49fc2fb864 100644
--- a/src/cmd/internal/obj/mips/obj0.go
+++ b/src/cmd/internal/obj/mips/obj0.go
@@ -31,7 +31,7 @@ package mips
import (
"cmd/internal/obj"
- "encoding/binary"
+ "cmd/internal/sys"
"fmt"
"math"
)
@@ -336,7 +336,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
q.As = AMOVV
q.From.Type = obj.TYPE_MEM
q.From.Reg = REGG
- q.From.Offset = 4 * int64(ctxt.Arch.Ptrsize) // G.panic
+ q.From.Offset = 4 * int64(ctxt.Arch.PtrSize) // G.panic
q.To.Type = obj.TYPE_REG
q.To.Reg = REG_R1
@@ -559,9 +559,9 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, framesize int32) *obj.Prog {
p.As = AMOVV
p.From.Type = obj.TYPE_MEM
p.From.Reg = REGG
- p.From.Offset = 2 * int64(ctxt.Arch.Ptrsize) // G.stackguard0
+ p.From.Offset = 2 * int64(ctxt.Arch.PtrSize) // G.stackguard0
if ctxt.Cursym.Cfunc {
- p.From.Offset = 3 * int64(ctxt.Arch.Ptrsize) // G.stackguard1
+ p.From.Offset = 3 * int64(ctxt.Arch.PtrSize) // G.stackguard1
}
p.To.Type = obj.TYPE_REG
p.To.Reg = REG_R1
@@ -1469,27 +1469,17 @@ loop:
}
var Linkmips64 = obj.LinkArch{
- ByteOrder: binary.BigEndian,
- Name: "mips64",
- Thechar: '0',
+ Arch: sys.ArchMIPS64,
Preprocess: preprocess,
Assemble: span0,
Follow: follow,
Progedit: progedit,
- Minlc: 4,
- Ptrsize: 8,
- Regsize: 8,
}
var Linkmips64le = obj.LinkArch{
- ByteOrder: binary.LittleEndian,
- Name: "mips64le",
- Thechar: '0',
+ Arch: sys.ArchMIPS64LE,
Preprocess: preprocess,
Assemble: span0,
Follow: follow,
Progedit: progedit,
- Minlc: 4,
- Ptrsize: 8,
- Regsize: 8,
}
diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go
index 30a380fadf..17175ebf06 100644
--- a/src/cmd/internal/obj/objfile.go
+++ b/src/cmd/internal/obj/objfile.go
@@ -109,207 +109,21 @@ package obj
import (
"bufio"
+ "cmd/internal/sys"
"fmt"
"log"
"path/filepath"
"sort"
- "strings"
)
// The Go and C compilers, and the assembler, call writeobj to write
// out a Go object file. The linker does not call this; the linker
// does not write out object files.
-func Writeobjdirect(ctxt *Link, b *Biobuf) {
+func Writeobjdirect(ctxt *Link, b *bufio.Writer) {
Flushplist(ctxt)
WriteObjFile(ctxt, b)
}
-func Flushplist(ctxt *Link) {
- flushplist(ctxt, ctxt.Debugasm == 0)
-}
-func FlushplistNoFree(ctxt *Link) {
- flushplist(ctxt, false)
-}
-func flushplist(ctxt *Link, freeProgs bool) {
- // Build list of symbols, and assign instructions to lists.
- // Ignore ctxt->plist boundaries. There are no guarantees there,
- // and the assemblers just use one big list.
- var curtext *LSym
- var etext *Prog
- var text []*LSym
-
- for pl := ctxt.Plist; pl != nil; pl = pl.Link {
- var plink *Prog
- for p := pl.Firstpc; p != nil; p = plink {
- if ctxt.Debugasm != 0 && ctxt.Debugvlog != 0 {
- fmt.Printf("obj: %v\n", p)
- }
- plink = p.Link
- p.Link = nil
-
- switch p.As {
- case AEND:
- continue
-
- case ATYPE:
- // Assume each TYPE instruction describes
- // a different local variable or parameter,
- // so no dedup.
- // Using only the TYPE instructions means
- // that we discard location information about local variables
- // in C and assembly functions; that information is inferred
- // from ordinary references, because there are no TYPE
- // instructions there. Without the type information, gdb can't
- // use the locations, so we don't bother to save them.
- // If something else could use them, we could arrange to
- // preserve them.
- if curtext == nil {
- continue
- }
- a := new(Auto)
- a.Asym = p.From.Sym
- a.Aoffset = int32(p.From.Offset)
- a.Name = int16(p.From.Name)
- a.Gotype = p.From.Gotype
- a.Link = curtext.Autom
- curtext.Autom = a
- continue
-
- case AGLOBL:
- s := p.From.Sym
- if s.Seenglobl {
- fmt.Printf("duplicate %v\n", p)
- }
- s.Seenglobl = true
- if s.Onlist {
- log.Fatalf("symbol %s listed multiple times", s.Name)
- }
- s.Onlist = true
- ctxt.Data = append(ctxt.Data, s)
- s.Size = p.To.Offset
- if s.Type == 0 || s.Type == SXREF {
- s.Type = SBSS
- }
- flag := int(p.From3.Offset)
- if flag&DUPOK != 0 {
- s.Dupok = true
- }
- if flag&RODATA != 0 {
- s.Type = SRODATA
- } else if flag&NOPTR != 0 {
- s.Type = SNOPTRBSS
- } else if flag&TLSBSS != 0 {
- s.Type = STLSBSS
- }
- continue
-
- case ATEXT:
- s := p.From.Sym
- if s == nil {
- // func _() { }
- curtext = nil
-
- continue
- }
-
- if s.Text != nil {
- log.Fatalf("duplicate TEXT for %s", s.Name)
- }
- if s.Onlist {
- log.Fatalf("symbol %s listed multiple times", s.Name)
- }
- s.Onlist = true
- text = append(text, s)
- flag := int(p.From3Offset())
- if flag&DUPOK != 0 {
- s.Dupok = true
- }
- if flag&NOSPLIT != 0 {
- s.Nosplit = true
- }
- if flag&REFLECTMETHOD != 0 {
- s.ReflectMethod = true
- }
- s.Type = STEXT
- s.Text = p
- etext = p
- curtext = s
- continue
-
- case AFUNCDATA:
- // Rewrite reference to go_args_stackmap(SB) to the Go-provided declaration information.
- if curtext == nil { // func _() {}
- continue
- }
- if p.To.Sym.Name == "go_args_stackmap" {
- if p.From.Type != TYPE_CONST || p.From.Offset != FUNCDATA_ArgsPointerMaps {
- ctxt.Diag("FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps")
- }
- p.To.Sym = Linklookup(ctxt, fmt.Sprintf("%s.args_stackmap", curtext.Name), int(curtext.Version))
- }
-
- }
-
- if curtext == nil {
- etext = nil
- continue
- }
- etext.Link = p
- etext = p
- }
- }
-
- // Add reference to Go arguments for C or assembly functions without them.
- for _, s := range text {
- if !strings.HasPrefix(s.Name, "\"\".") {
- continue
- }
- found := false
- var p *Prog
- for p = s.Text; p != nil; p = p.Link {
- if p.As == AFUNCDATA && p.From.Type == TYPE_CONST && p.From.Offset == FUNCDATA_ArgsPointerMaps {
- found = true
- break
- }
- }
-
- if !found {
- p = Appendp(ctxt, s.Text)
- p.As = AFUNCDATA
- p.From.Type = TYPE_CONST
- p.From.Offset = FUNCDATA_ArgsPointerMaps
- p.To.Type = TYPE_MEM
- p.To.Name = NAME_EXTERN
- p.To.Sym = Linklookup(ctxt, fmt.Sprintf("%s.args_stackmap", s.Name), int(s.Version))
- }
- }
-
- // Turn functions into machine code images.
- for _, s := range text {
- mkfwd(s)
- linkpatch(ctxt, s)
- if ctxt.Flag_optimize {
- ctxt.Arch.Follow(ctxt, s)
- }
- ctxt.Arch.Preprocess(ctxt, s)
- ctxt.Arch.Assemble(ctxt, s)
- fieldtrack(ctxt, s)
- linkpcln(ctxt, s)
- if freeProgs {
- s.Text = nil
- }
- }
-
- // Add to running list in ctxt.
- ctxt.Text = append(ctxt.Text, text...)
- ctxt.Plist = nil
- ctxt.Plast = nil
- ctxt.Curp = nil
- if freeProgs {
- ctxt.freeProgs()
- }
-}
-
// objWriter writes Go object files.
type objWriter struct {
wr *bufio.Writer
@@ -372,16 +186,16 @@ func (w *objWriter) writeLengths() {
w.writeInt(int64(w.nFile))
}
-func newObjWriter(ctxt *Link, b *Biobuf) *objWriter {
+func newObjWriter(ctxt *Link, b *bufio.Writer) *objWriter {
return &objWriter{
ctxt: ctxt,
- wr: b.w,
+ wr: b,
vrefIdx: make(map[string]int),
refIdx: make(map[string]int),
}
}
-func WriteObjFile(ctxt *Link, b *Biobuf) {
+func WriteObjFile(ctxt *Link, b *bufio.Writer) {
w := newObjWriter(ctxt, b)
// Magic header
@@ -556,10 +370,10 @@ func (w *objWriter) writeSymDebug(s *LSym) {
} else if r.Type == R_TLS_LE {
name = "TLS"
}
- if ctxt.Arch.Thechar == '5' || ctxt.Arch.Thechar == '9' {
- fmt.Fprintf(ctxt.Bso, "\trel %d+%d t=%d %s+%x\n", int(r.Off), r.Siz, r.Type, name, uint64(int64(r.Add)))
+ if ctxt.Arch.InFamily(sys.ARM, sys.PPC64) {
+ fmt.Fprintf(ctxt.Bso, "\trel %d+%d t=%d %s+%x\n", int(r.Off), r.Siz, r.Type, name, uint64(r.Add))
} else {
- fmt.Fprintf(ctxt.Bso, "\trel %d+%d t=%d %s+%d\n", int(r.Off), r.Siz, r.Type, name, int64(r.Add))
+ fmt.Fprintf(ctxt.Bso, "\trel %d+%d t=%d %s+%d\n", int(r.Off), r.Siz, r.Type, name, r.Add)
}
}
}
@@ -659,7 +473,7 @@ func (w *objWriter) writeSym(s *LSym) {
func (w *objWriter) writeInt(sval int64) {
var v uint64
- uv := (uint64(sval) << 1) ^ uint64(int64(sval>>63))
+ uv := (uint64(sval) << 1) ^ uint64(sval>>63)
p := w.varintbuf[:]
for v = uv; v >= 0x80; v >>= 7 {
p[0] = uint8(v | 0x80)
diff --git a/src/cmd/internal/obj/pcln.go b/src/cmd/internal/obj/pcln.go
index 9770c96fcc..b1536eb224 100644
--- a/src/cmd/internal/obj/pcln.go
+++ b/src/cmd/internal/obj/pcln.go
@@ -64,7 +64,7 @@ func funcpctab(ctxt *Link, dst *Pcdata, func_ *LSym, desc string, valfunc func(*
if val == oldval && started != 0 {
val = valfunc(ctxt, func_, val, p, 1, arg)
if ctxt.Debugpcln != 0 {
- fmt.Fprintf(ctxt.Bso, "%6x %6s %v\n", uint64(int64(p.Pc)), "", p)
+ fmt.Fprintf(ctxt.Bso, "%6x %6s %v\n", uint64(p.Pc), "", p)
}
continue
}
@@ -76,7 +76,7 @@ func funcpctab(ctxt *Link, dst *Pcdata, func_ *LSym, desc string, valfunc func(*
if p.Link != nil && p.Link.Pc == p.Pc {
val = valfunc(ctxt, func_, val, p, 1, arg)
if ctxt.Debugpcln != 0 {
- fmt.Fprintf(ctxt.Bso, "%6x %6s %v\n", uint64(int64(p.Pc)), "", p)
+ fmt.Fprintf(ctxt.Bso, "%6x %6s %v\n", uint64(p.Pc), "", p)
}
continue
}
@@ -96,11 +96,11 @@ func funcpctab(ctxt *Link, dst *Pcdata, func_ *LSym, desc string, valfunc func(*
// where the 0x80 bit indicates that the integer continues.
if ctxt.Debugpcln != 0 {
- fmt.Fprintf(ctxt.Bso, "%6x %6d %v\n", uint64(int64(p.Pc)), val, p)
+ fmt.Fprintf(ctxt.Bso, "%6x %6d %v\n", uint64(p.Pc), val, p)
}
if started != 0 {
- addvarint(ctxt, dst, uint32((p.Pc-pc)/int64(ctxt.Arch.Minlc)))
+ addvarint(ctxt, dst, uint32((p.Pc-pc)/int64(ctxt.Arch.MinLC)))
pc = p.Pc
}
@@ -118,9 +118,9 @@ func funcpctab(ctxt *Link, dst *Pcdata, func_ *LSym, desc string, valfunc func(*
if started != 0 {
if ctxt.Debugpcln != 0 {
- fmt.Fprintf(ctxt.Bso, "%6x done\n", uint64(int64(func_.Text.Pc)+func_.Size))
+ fmt.Fprintf(ctxt.Bso, "%6x done\n", uint64(func_.Text.Pc+func_.Size))
}
- addvarint(ctxt, dst, uint32((func_.Size-pc)/int64(ctxt.Arch.Minlc)))
+ addvarint(ctxt, dst, uint32((func_.Size-pc)/int64(ctxt.Arch.MinLC)))
addvarint(ctxt, dst, 0) // terminator
}
@@ -158,19 +158,18 @@ func pctofileline(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg
return int32(pcln.Lastindex)
}
- var i int32
- for i = 0; i < int32(len(pcln.File)); i++ {
- file := pcln.File[i]
+ for i, file := range pcln.File {
if file == f {
pcln.Lastfile = f
- pcln.Lastindex = int(i)
+ pcln.Lastindex = i
return int32(i)
}
}
+ i := len(pcln.File)
pcln.File = append(pcln.File, f)
pcln.Lastfile = f
- pcln.Lastindex = int(i)
- return i
+ pcln.Lastindex = i
+ return int32(i)
}
// pctospadj computes the sp adjustment in effect.
diff --git a/src/cmd/internal/obj/plist.go b/src/cmd/internal/obj/plist.go
new file mode 100644
index 0000000000..e55dbeca1e
--- /dev/null
+++ b/src/cmd/internal/obj/plist.go
@@ -0,0 +1,218 @@
+// Copyright 2013 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 (
+ "fmt"
+ "log"
+ "strings"
+)
+
+type Plist struct {
+ Name *LSym
+ Firstpc *Prog
+ Recur int
+ Link *Plist
+}
+
+/*
+ * start a new Prog list.
+ */
+func Linknewplist(ctxt *Link) *Plist {
+ pl := new(Plist)
+ if ctxt.Plist == nil {
+ ctxt.Plist = pl
+ } else {
+ ctxt.Plast.Link = pl
+ }
+ ctxt.Plast = pl
+ return pl
+}
+
+func Flushplist(ctxt *Link) {
+ flushplist(ctxt, ctxt.Debugasm == 0)
+}
+func FlushplistNoFree(ctxt *Link) {
+ flushplist(ctxt, false)
+}
+func flushplist(ctxt *Link, freeProgs bool) {
+ // Build list of symbols, and assign instructions to lists.
+ // Ignore ctxt->plist boundaries. There are no guarantees there,
+ // and the assemblers just use one big list.
+ var curtext *LSym
+ var etext *Prog
+ var text []*LSym
+
+ for pl := ctxt.Plist; pl != nil; pl = pl.Link {
+ var plink *Prog
+ for p := pl.Firstpc; p != nil; p = plink {
+ if ctxt.Debugasm != 0 && ctxt.Debugvlog != 0 {
+ fmt.Printf("obj: %v\n", p)
+ }
+ plink = p.Link
+ p.Link = nil
+
+ switch p.As {
+ case AEND:
+ continue
+
+ case ATYPE:
+ // Assume each TYPE instruction describes
+ // a different local variable or parameter,
+ // so no dedup.
+ // Using only the TYPE instructions means
+ // that we discard location information about local variables
+ // in C and assembly functions; that information is inferred
+ // from ordinary references, because there are no TYPE
+ // instructions there. Without the type information, gdb can't
+ // use the locations, so we don't bother to save them.
+ // If something else could use them, we could arrange to
+ // preserve them.
+ if curtext == nil {
+ continue
+ }
+ a := new(Auto)
+ a.Asym = p.From.Sym
+ a.Aoffset = int32(p.From.Offset)
+ a.Name = int16(p.From.Name)
+ a.Gotype = p.From.Gotype
+ a.Link = curtext.Autom
+ curtext.Autom = a
+ continue
+
+ case AGLOBL:
+ s := p.From.Sym
+ if s.Seenglobl {
+ fmt.Printf("duplicate %v\n", p)
+ }
+ s.Seenglobl = true
+ if s.Onlist {
+ log.Fatalf("symbol %s listed multiple times", s.Name)
+ }
+ s.Onlist = true
+ ctxt.Data = append(ctxt.Data, s)
+ s.Size = p.To.Offset
+ if s.Type == 0 || s.Type == SXREF {
+ s.Type = SBSS
+ }
+ flag := int(p.From3.Offset)
+ if flag&DUPOK != 0 {
+ s.Dupok = true
+ }
+ if flag&RODATA != 0 {
+ s.Type = SRODATA
+ } else if flag&NOPTR != 0 {
+ s.Type = SNOPTRBSS
+ } else if flag&TLSBSS != 0 {
+ s.Type = STLSBSS
+ }
+ continue
+
+ case ATEXT:
+ s := p.From.Sym
+ if s == nil {
+ // func _() { }
+ curtext = nil
+
+ continue
+ }
+
+ if s.Text != nil {
+ log.Fatalf("duplicate TEXT for %s", s.Name)
+ }
+ if s.Onlist {
+ log.Fatalf("symbol %s listed multiple times", s.Name)
+ }
+ s.Onlist = true
+ text = append(text, s)
+ flag := int(p.From3Offset())
+ if flag&DUPOK != 0 {
+ s.Dupok = true
+ }
+ if flag&NOSPLIT != 0 {
+ s.Nosplit = true
+ }
+ if flag&REFLECTMETHOD != 0 {
+ s.ReflectMethod = true
+ }
+ s.Type = STEXT
+ s.Text = p
+ etext = p
+ curtext = s
+ continue
+
+ case AFUNCDATA:
+ // Rewrite reference to go_args_stackmap(SB) to the Go-provided declaration information.
+ if curtext == nil { // func _() {}
+ continue
+ }
+ if p.To.Sym.Name == "go_args_stackmap" {
+ if p.From.Type != TYPE_CONST || p.From.Offset != FUNCDATA_ArgsPointerMaps {
+ ctxt.Diag("FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps")
+ }
+ p.To.Sym = Linklookup(ctxt, fmt.Sprintf("%s.args_stackmap", curtext.Name), int(curtext.Version))
+ }
+
+ }
+
+ if curtext == nil {
+ etext = nil
+ continue
+ }
+ etext.Link = p
+ etext = p
+ }
+ }
+
+ // Add reference to Go arguments for C or assembly functions without them.
+ for _, s := range text {
+ if !strings.HasPrefix(s.Name, "\"\".") {
+ continue
+ }
+ found := false
+ var p *Prog
+ for p = s.Text; p != nil; p = p.Link {
+ if p.As == AFUNCDATA && p.From.Type == TYPE_CONST && p.From.Offset == FUNCDATA_ArgsPointerMaps {
+ found = true
+ break
+ }
+ }
+
+ if !found {
+ p = Appendp(ctxt, s.Text)
+ p.As = AFUNCDATA
+ p.From.Type = TYPE_CONST
+ p.From.Offset = FUNCDATA_ArgsPointerMaps
+ p.To.Type = TYPE_MEM
+ p.To.Name = NAME_EXTERN
+ p.To.Sym = Linklookup(ctxt, fmt.Sprintf("%s.args_stackmap", s.Name), int(s.Version))
+ }
+ }
+
+ // Turn functions into machine code images.
+ for _, s := range text {
+ mkfwd(s)
+ linkpatch(ctxt, s)
+ if ctxt.Flag_optimize {
+ ctxt.Arch.Follow(ctxt, s)
+ }
+ ctxt.Arch.Preprocess(ctxt, s)
+ ctxt.Arch.Assemble(ctxt, s)
+ fieldtrack(ctxt, s)
+ linkpcln(ctxt, s)
+ if freeProgs {
+ s.Text = nil
+ }
+ }
+
+ // Add to running list in ctxt.
+ ctxt.Text = append(ctxt.Text, text...)
+ ctxt.Plist = nil
+ ctxt.Plast = nil
+ ctxt.Curp = nil
+ if freeProgs {
+ ctxt.freeProgs()
+ }
+}
diff --git a/src/cmd/internal/obj/ppc64/asm9.go b/src/cmd/internal/obj/ppc64/asm9.go
index 0497d3b678..f786f3c443 100644
--- a/src/cmd/internal/obj/ppc64/asm9.go
+++ b/src/cmd/internal/obj/ppc64/asm9.go
@@ -585,7 +585,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
ctxt.Instoffset = a.Offset
if a.Sym != nil { // use relocation
if a.Sym.Type == obj.STLSBSS {
- if ctxt.Flag_shared != 0 {
+ if ctxt.Flag_shared {
return C_TLS_IE
} else {
return C_TLS_LE
@@ -1384,7 +1384,7 @@ const (
// which relocation to use with a load or store and only supports the needed
// instructions.
func opform(ctxt *obj.Link, insn uint32) int {
- switch uint32(insn) {
+ switch insn {
default:
ctxt.Diag("bad insn in loadform: %x", insn)
case OPVCC(58, 0, 0, 0), // ld
@@ -1413,7 +1413,7 @@ func opform(ctxt *obj.Link, insn uint32) int {
func symbolAccess(ctxt *obj.Link, s *obj.LSym, d int64, reg int16, op uint32) (o1, o2 uint32) {
var base uint32
form := opform(ctxt, op)
- if ctxt.Flag_shared != 0 {
+ if ctxt.Flag_shared {
base = REG_R2
} else {
base = REG_R0
@@ -1425,7 +1425,7 @@ func symbolAccess(ctxt *obj.Link, s *obj.LSym, d int64, reg int16, op uint32) (o
rel.Siz = 8
rel.Sym = s
rel.Add = d
- if ctxt.Flag_shared != 0 {
+ if ctxt.Flag_shared {
switch form {
case D_FORM:
rel.Type = obj.R_ADDRPOWER_TOCREL
@@ -1646,7 +1646,7 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
if v != 0 {
ctxt.Diag("illegal indexed instruction\n%v", p)
}
- if ctxt.Flag_shared != 0 && r == REG_R13 {
+ if ctxt.Flag_shared && r == REG_R13 {
rel := obj.Addrel(ctxt.Cursym)
rel.Off = int32(ctxt.Pc)
rel.Siz = 4
@@ -1677,7 +1677,7 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
if v != 0 {
ctxt.Diag("illegal indexed instruction\n%v", p)
}
- if ctxt.Flag_shared != 0 && r == REG_R13 {
+ if ctxt.Flag_shared && r == REG_R13 {
rel := obj.Addrel(ctxt.Cursym)
rel.Off = int32(ctxt.Pc)
rel.Siz = 4
@@ -2198,9 +2198,9 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
}
v := oprrr(ctxt, p.As)
t := v & (1<<10 | 1) /* OE|Rc */
- o1 = AOP_RRR(uint32(v)&^uint32(t), REGTMP, uint32(r), uint32(p.From.Reg))
+ o1 = AOP_RRR(v&^t, REGTMP, uint32(r), uint32(p.From.Reg))
o2 = AOP_RRR(OP_MULLW, REGTMP, REGTMP, uint32(p.From.Reg))
- o3 = AOP_RRR(OP_SUBF|uint32(t), uint32(p.To.Reg), REGTMP, uint32(r))
+ o3 = AOP_RRR(OP_SUBF|t, uint32(p.To.Reg), REGTMP, uint32(r))
if p.As == AREMU {
o4 = o3
@@ -2216,9 +2216,9 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
}
v := oprrr(ctxt, p.As)
t := v & (1<<10 | 1) /* OE|Rc */
- o1 = AOP_RRR(uint32(v)&^uint32(t), REGTMP, uint32(r), uint32(p.From.Reg))
+ o1 = AOP_RRR(v&^t, REGTMP, uint32(r), uint32(p.From.Reg))
o2 = AOP_RRR(OP_MULLD, REGTMP, REGTMP, uint32(p.From.Reg))
- o3 = AOP_RRR(OP_SUBF|uint32(t), uint32(p.To.Reg), REGTMP, uint32(r))
+ o3 = AOP_RRR(OP_SUBF|t, uint32(p.To.Reg), REGTMP, uint32(r))
case 52: /* mtfsbNx cr(n) */
v := regoff(ctxt, &p.From) & 31
@@ -2485,7 +2485,7 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
ctxt.Diag("invalid offset against tls var %v", p)
}
o1 = AOP_IRR(OP_ADDIS, uint32(p.To.Reg), REG_R2, 0)
- o2 = AOP_IRR(uint32(opload(ctxt, AMOVD)), uint32(p.To.Reg), uint32(p.To.Reg), 0)
+ o2 = AOP_IRR(opload(ctxt, AMOVD), uint32(p.To.Reg), uint32(p.To.Reg), 0)
rel := obj.Addrel(ctxt.Cursym)
rel.Off = int32(ctxt.Pc)
rel.Siz = 8
@@ -2499,7 +2499,7 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
}
o1 = AOP_IRR(OP_ADDIS, uint32(p.To.Reg), REG_R2, 0)
- o2 = AOP_IRR(uint32(opload(ctxt, AMOVD)), uint32(p.To.Reg), uint32(p.To.Reg), 0)
+ o2 = AOP_IRR(opload(ctxt, AMOVD), uint32(p.To.Reg), uint32(p.To.Reg), 0)
rel := obj.Addrel(ctxt.Cursym)
rel.Off = int32(ctxt.Pc)
rel.Siz = 8
diff --git a/src/cmd/internal/obj/ppc64/obj9.go b/src/cmd/internal/obj/ppc64/obj9.go
index 483df3a2b3..4f9b3943cf 100644
--- a/src/cmd/internal/obj/ppc64/obj9.go
+++ b/src/cmd/internal/obj/ppc64/obj9.go
@@ -31,7 +31,7 @@ package ppc64
import (
"cmd/internal/obj"
- "encoding/binary"
+ "cmd/internal/sys"
"fmt"
"math"
)
@@ -470,7 +470,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
q = p
- if ctxt.Flag_shared != 0 && cursym.Name != "runtime.duffzero" && cursym.Name != "runtime.duffcopy" && cursym.Name != "runtime.stackBarrier" {
+ if ctxt.Flag_shared && cursym.Name != "runtime.duffzero" && cursym.Name != "runtime.duffcopy" && cursym.Name != "runtime.stackBarrier" {
// When compiling Go into PIC, all functions must start
// with instructions to load the TOC pointer into r2:
//
@@ -558,7 +558,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
q.Spadj = int32(-aoffset)
}
- if ctxt.Flag_shared != 0 {
+ if ctxt.Flag_shared {
q = obj.Appendp(ctxt, q)
q.As = AMOVD
q.Lineno = p.Lineno
@@ -592,7 +592,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
q.As = AMOVD
q.From.Type = obj.TYPE_MEM
q.From.Reg = REGG
- q.From.Offset = 4 * int64(ctxt.Arch.Ptrsize) // G.panic
+ q.From.Offset = 4 * int64(ctxt.Arch.PtrSize) // G.panic
q.To.Type = obj.TYPE_REG
q.To.Reg = REG_R3
@@ -827,9 +827,9 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, framesize int32) *obj.Prog {
p.As = AMOVD
p.From.Type = obj.TYPE_MEM
p.From.Reg = REGG
- p.From.Offset = 2 * int64(ctxt.Arch.Ptrsize) // G.stackguard0
+ p.From.Offset = 2 * int64(ctxt.Arch.PtrSize) // G.stackguard0
if ctxt.Cursym.Cfunc {
- p.From.Offset = 3 * int64(ctxt.Arch.Ptrsize) // G.stackguard1
+ p.From.Offset = 3 * int64(ctxt.Arch.PtrSize) // G.stackguard1
}
p.To.Type = obj.TYPE_REG
p.To.Reg = REG_R3
@@ -1181,27 +1181,17 @@ loop:
}
var Linkppc64 = obj.LinkArch{
- ByteOrder: binary.BigEndian,
- Name: "ppc64",
- Thechar: '9',
+ Arch: sys.ArchPPC64,
Preprocess: preprocess,
Assemble: span9,
Follow: follow,
Progedit: progedit,
- Minlc: 4,
- Ptrsize: 8,
- Regsize: 8,
}
var Linkppc64le = obj.LinkArch{
- ByteOrder: binary.LittleEndian,
- Name: "ppc64le",
- Thechar: '9',
+ Arch: sys.ArchPPC64LE,
Preprocess: preprocess,
Assemble: span9,
Follow: follow,
Progedit: progedit,
- Minlc: 4,
- Ptrsize: 8,
- Regsize: 8,
}
diff --git a/src/cmd/internal/obj/s390x/a.out.go b/src/cmd/internal/obj/s390x/a.out.go
index 2cb03ae603..e7256d1d41 100644
--- a/src/cmd/internal/obj/s390x/a.out.go
+++ b/src/cmd/internal/obj/s390x/a.out.go
@@ -218,6 +218,7 @@ const (
ADIVDU
AMULLW
AMULLD
+ AMULHD
AMULHDU
ASUB
ASUBC
diff --git a/src/cmd/internal/obj/s390x/anames.go b/src/cmd/internal/obj/s390x/anames.go
index e79a147a90..62dd181eda 100644
--- a/src/cmd/internal/obj/s390x/anames.go
+++ b/src/cmd/internal/obj/s390x/anames.go
@@ -17,6 +17,7 @@ var Anames = []string{
"DIVDU",
"MULLW",
"MULLD",
+ "MULHD",
"MULHDU",
"SUB",
"SUBC",
diff --git a/src/cmd/internal/obj/s390x/asmz.go b/src/cmd/internal/obj/s390x/asmz.go
index bccd7c3bd8..9b26580d11 100644
--- a/src/cmd/internal/obj/s390x/asmz.go
+++ b/src/cmd/internal/obj/s390x/asmz.go
@@ -150,6 +150,8 @@ var optab = []Optab{
Optab{AMULLW, C_REG, C_NONE, C_NONE, C_REG, 2, 0},
Optab{AMULLW, C_LCON, C_REG, C_NONE, C_REG, 22, 0},
Optab{AMULLW, C_LCON, C_NONE, C_NONE, C_REG, 22, 0},
+ Optab{AMULHD, C_REG, C_NONE, C_NONE, C_REG, 4, 0},
+ Optab{AMULHD, C_REG, C_REG, C_NONE, C_REG, 4, 0},
Optab{ASUBC, C_REG, C_REG, C_NONE, C_REG, 10, 0},
Optab{ASUBC, C_REG, C_NONE, C_NONE, C_REG, 10, 0},
Optab{ADIVW, C_REG, C_REG, C_NONE, C_REG, 2, 0},
@@ -471,7 +473,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
}
ctxt.Instoffset = a.Offset
if a.Sym.Type == obj.STLSBSS {
- if ctxt.Flag_shared != 0 {
+ if ctxt.Flag_shared {
return C_TLS_IE // initial exec model
}
return C_TLS_LE // local exec model
@@ -604,7 +606,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
a1 := int(p.Optab)
if a1 != 0 {
- return &optab[a1-1:][0]
+ return &optab[a1-1]
}
a1 = int(p.From.Class)
if a1 == 0 {
@@ -793,10 +795,11 @@ func buildop(ctxt *obj.Link) {
case ADIVW:
opset(AADDE, r)
opset(AMULLD, r)
- opset(AMULHDU, r)
opset(ADIVD, r)
opset(ADIVDU, r)
opset(ADIVWU, r)
+ case AMULHD:
+ opset(AMULHDU, r)
case AMOVBZ:
opset(AMOVH, r)
opset(AMOVHZ, r)
@@ -2580,8 +2583,6 @@ func asmout(ctxt *obj.Link, asm *[]byte) {
opcode = op_MSGFR
case AMULLD:
opcode = op_MSGR
- case AMULHDU:
- opcode = op_MLGR
case ADIVW:
opcode = op_DSGFR
case ADIVWU:
@@ -2628,11 +2629,6 @@ func asmout(ctxt *obj.Link, asm *[]byte) {
zRRE(opcode, REGTMP, uint32(p.From.Reg), asm)
zRRE(op_LGR, uint32(p.To.Reg), REGTMP2, asm)
- case AMULHDU:
- zRRE(op_LGR, REGTMP2, uint32(r), asm)
- zRRE(opcode, REGTMP, uint32(p.From.Reg), asm)
- zRRE(op_LGR, uint32(p.To.Reg), REGTMP, asm)
-
case AFADD, AFADDS:
if r == int(p.To.Reg) {
zRRE(opcode, uint32(p.To.Reg), uint32(p.From.Reg), asm)
@@ -2695,6 +2691,28 @@ func asmout(ctxt *obj.Link, asm *[]byte) {
zRIL(_a, op_IIHF, uint32(p.To.Reg), uint32(v>>32), asm)
}
+ case 4: // multiply high (a*b)>>64
+ r := p.Reg
+ if r == 0 {
+ r = p.To.Reg
+ }
+ zRRE(op_LGR, REGTMP2, uint32(r), asm)
+ zRRE(op_MLGR, REGTMP, uint32(p.From.Reg), asm)
+ switch p.As {
+ case AMULHDU:
+ // Unsigned: move result into correct register.
+ zRRE(op_LGR, uint32(p.To.Reg), REGTMP, asm)
+ case AMULHD:
+ // Signed: need to convert result.
+ // See Hacker's Delight 8-3.
+ zRSY(op_SRAG, REGTMP2, uint32(p.From.Reg), 0, 63, asm)
+ zRRE(op_NGR, REGTMP2, uint32(r), asm)
+ zRRE(op_SGR, REGTMP, REGTMP2, asm)
+ zRSY(op_SRAG, REGTMP2, uint32(r), 0, 63, asm)
+ zRRE(op_NGR, REGTMP2, uint32(p.From.Reg), asm)
+ zRRF(op_SGRK, REGTMP2, 0, uint32(p.To.Reg), REGTMP, asm)
+ }
+
case 5: // syscall
zI(op_SVC, 0, asm)
diff --git a/src/cmd/internal/obj/s390x/objz.go b/src/cmd/internal/obj/s390x/objz.go
index 239deec6a1..454a0d76ec 100644
--- a/src/cmd/internal/obj/s390x/objz.go
+++ b/src/cmd/internal/obj/s390x/objz.go
@@ -31,7 +31,7 @@ package s390x
import (
"cmd/internal/obj"
- "encoding/binary"
+ "cmd/internal/sys"
"fmt"
"math"
)
@@ -460,7 +460,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
q.As = AMOVD
q.From.Type = obj.TYPE_MEM
q.From.Reg = REGG
- q.From.Offset = 4 * int64(ctxt.Arch.Ptrsize) // G.panic
+ q.From.Offset = 4 * int64(ctxt.Arch.PtrSize) // G.panic
q.To.Type = obj.TYPE_REG
q.To.Reg = REG_R3
@@ -664,9 +664,9 @@ func stacksplitPre(ctxt *obj.Link, p *obj.Prog, framesize int32) (*obj.Prog, *ob
p.As = AMOVD
p.From.Type = obj.TYPE_MEM
p.From.Reg = REGG
- p.From.Offset = 2 * int64(ctxt.Arch.Ptrsize) // G.stackguard0
+ p.From.Offset = 2 * int64(ctxt.Arch.PtrSize) // G.stackguard0
if ctxt.Cursym.Cfunc {
- p.From.Offset = 3 * int64(ctxt.Arch.Ptrsize) // G.stackguard1
+ p.From.Offset = 3 * int64(ctxt.Arch.PtrSize) // G.stackguard1
}
p.To.Type = obj.TYPE_REG
p.To.Reg = REG_R3
@@ -999,15 +999,10 @@ var unaryDst = map[obj.As]bool{
}
var Links390x = obj.LinkArch{
- ByteOrder: binary.BigEndian,
- Name: "s390x",
- Thechar: 'z',
+ Arch: sys.ArchS390X,
Preprocess: preprocess,
Assemble: spanz,
Follow: follow,
Progedit: progedit,
UnaryDst: unaryDst,
- Minlc: 2,
- Ptrsize: 8,
- Regsize: 8,
}
diff --git a/src/cmd/internal/obj/sym.go b/src/cmd/internal/obj/sym.go
index 64df62a2ae..beacc94ee8 100644
--- a/src/cmd/internal/obj/sym.go
+++ b/src/cmd/internal/obj/sym.go
@@ -32,6 +32,7 @@
package obj
import (
+ "cmd/internal/sys"
"log"
"os"
"path/filepath"
@@ -100,7 +101,7 @@ func Linknew(arch *LinkArch) *Link {
}
// On arm, record goarm.
- if ctxt.Arch.Thechar == '5' {
+ if ctxt.Arch.Family == sys.ARM {
ctxt.Goarm = Getgoarm()
}
diff --git a/src/cmd/internal/obj/util.go b/src/cmd/internal/obj/util.go
index 245fab9690..294cedcb0a 100644
--- a/src/cmd/internal/obj/util.go
+++ b/src/cmd/internal/obj/util.go
@@ -5,10 +5,8 @@
package obj
import (
- "bufio"
"bytes"
"fmt"
- "io"
"log"
"os"
"strings"
@@ -26,144 +24,6 @@ func Cputime() float64 {
return time.Since(start).Seconds()
}
-type Biobuf struct {
- f *os.File
- r *bufio.Reader
- w *bufio.Writer
- linelen int
-}
-
-func (b *Biobuf) Reader() *bufio.Reader { return b.r }
-
-func Bopenw(name string) (*Biobuf, error) {
- f, err := os.Create(name)
- if err != nil {
- return nil, err
- }
- return &Biobuf{f: f, w: bufio.NewWriter(f)}, nil
-}
-
-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
-}
-
-func Binitw(w io.Writer) *Biobuf {
- return &Biobuf{w: bufio.NewWriter(w)}
-}
-
-func Binitr(r io.Reader) *Biobuf {
- return &Biobuf{r: bufio.NewReader(r)}
-}
-
-func (b *Biobuf) Write(p []byte) (int, error) {
- return b.w.Write(p)
-}
-
-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 {
- log.Fatalf("writing output: %v", err)
- }
- } else if b.r != nil {
- if whence == 1 {
- offset -= int64(b.r.Buffered())
- }
- }
- off, err := b.f.Seek(offset, whence)
- if err != nil {
- log.Fatalf("seeking in output: %v", err)
- }
- if b.r != nil {
- b.r.Reset(b.f)
- }
- return off
-}
-
-func Boffset(b *Biobuf) int64 {
- if b.w != nil {
- if err := b.w.Flush(); err != nil {
- log.Fatalf("writing output: %v", err)
- }
- }
- off, err := b.f.Seek(0, 1)
- if err != nil {
- log.Fatalf("seeking in output [0, 1]: %v", err)
- }
- if b.r != nil {
- off -= int64(b.r.Buffered())
- }
- return off
-}
-
-func (b *Biobuf) Flush() error {
- return b.w.Flush()
-}
-
-func Bputc(b *Biobuf, c byte) {
- b.w.WriteByte(c)
-}
-
-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
-}
-
-func Bgetc(b *Biobuf) int {
- c, err := b.r.ReadByte()
- if err != nil {
- return -1
- }
- return int(c)
-}
-
-func (b *Biobuf) Read(p []byte) (int, error) {
- return b.r.Read(p)
-}
-
-func (b *Biobuf) Peek(n int) ([]byte, error) {
- return b.r.Peek(n)
-}
-
-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 Blinelen(b *Biobuf) int {
- return b.linelen
-}
-
-func Bterm(b *Biobuf) error {
- var err error
- if b.w != nil {
- err = b.w.Flush()
- }
- err1 := b.f.Close()
- if err == nil {
- err = err1
- }
- return err
-}
-
func envOr(key, value string) string {
if x := os.Getenv(key); x != "" {
return x
@@ -419,7 +279,7 @@ func Dconv(p *Prog, a *Addr) string {
case TYPE_SHIFT:
v := int(a.Offset)
- op := string("<<>>->@>"[((v>>5)&3)<<1:])
+ op := "<<>>->@>"[((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 {
diff --git a/src/cmd/internal/obj/x86/a.out.go b/src/cmd/internal/obj/x86/a.out.go
index 64bd865e42..c41fd953e7 100644
--- a/src/cmd/internal/obj/x86/a.out.go
+++ b/src/cmd/internal/obj/x86/a.out.go
@@ -739,6 +739,8 @@ const (
AUNPCKLPS
AXORPD
AXORPS
+ APCMPESTRI
+
ARETFW
ARETFL
ARETFQ
diff --git a/src/cmd/internal/obj/x86/anames.go b/src/cmd/internal/obj/x86/anames.go
index 3b59e2f36f..e3fef54e71 100644
--- a/src/cmd/internal/obj/x86/anames.go
+++ b/src/cmd/internal/obj/x86/anames.go
@@ -682,6 +682,7 @@ var Anames = []string{
"UNPCKLPS",
"XORPD",
"XORPS",
+ "PCMPESTRI",
"RETFW",
"RETFL",
"RETFQ",
diff --git a/src/cmd/internal/obj/x86/asm6.go b/src/cmd/internal/obj/x86/asm6.go
index 773494b7af..1c7fcf37be 100644
--- a/src/cmd/internal/obj/x86/asm6.go
+++ b/src/cmd/internal/obj/x86/asm6.go
@@ -884,11 +884,6 @@ var yvex_vpbroadcast = []ytab{
{Yxm, Ynone, Yyr, Zvex_rm_v_r, 2},
}
-var yvex_xxmyxm = []ytab{
- {Yxr, Ynone, Yxm, Zvex_r_v_rm, 2},
- {Yyr, Ynone, Yxm, Zvex_r_v_rm, 2},
-}
-
var ymmxmm0f38 = []ytab{
{Ymm, Ynone, Ymr, Zlitm_r, 3},
{Yxm, Ynone, Yxr, Zlitm_r, 5},
@@ -1653,6 +1648,7 @@ var optab =
{AROUNDSS, yaes2, Pq, [23]uint8{0x3a, 0x0a, 0}},
{APSHUFD, yxshuf, Pq, [23]uint8{0x70, 0}},
{APCLMULQDQ, yxshuf, Pq, [23]uint8{0x3a, 0x44, 0}},
+ {APCMPESTRI, yxshuf, Pq, [23]uint8{0x3a, 0x61, 0}},
{AANDNL, yvex_r3, Pvex, [23]uint8{VEX_LZ_0F38_W0, 0xF2}},
{AANDNQ, yvex_r3, Pvex, [23]uint8{VEX_LZ_0F38_W1, 0xF2}},
@@ -1754,7 +1750,7 @@ func naclpad(ctxt *obj.Link, s *obj.LSym, c int32, pad int32) int32 {
}
func spadjop(ctxt *obj.Link, p *obj.Prog, l, q obj.As) obj.As {
- if p.Mode != 64 || ctxt.Arch.Ptrsize == 4 {
+ if p.Mode != 64 || ctxt.Arch.PtrSize == 4 {
return l
}
return q
@@ -2170,7 +2166,7 @@ func prefixof(ctxt *obj.Link, p *obj.Prog, a *obj.Addr) int {
return 0x64 // FS
}
- if ctxt.Flag_shared != 0 {
+ if ctxt.Flag_shared {
log.Fatalf("unknown TLS base register for linux with -shared")
} else {
return 0x64 // FS
@@ -2190,7 +2186,7 @@ func prefixof(ctxt *obj.Link, p *obj.Prog, a *obj.Addr) int {
}
if p.Mode == 32 {
- if a.Index == REG_TLS && ctxt.Flag_shared != 0 {
+ if a.Index == REG_TLS && ctxt.Flag_shared {
// When building for inclusion into a shared library, an instruction of the form
// MOVL 0(CX)(TLS*1), AX
// becomes
@@ -2219,7 +2215,7 @@ func prefixof(ctxt *obj.Link, p *obj.Prog, a *obj.Addr) int {
return 0x26
case REG_TLS:
- if ctxt.Flag_shared != 0 {
+ if ctxt.Flag_shared {
// When building for inclusion into a shared library, an instruction of the form
// MOV 0(CX)(TLS*1), AX
// becomes
@@ -2293,7 +2289,7 @@ func oclass(ctxt *obj.Link, p *obj.Prog, a *obj.Addr) int {
case obj.NAME_EXTERN,
obj.NAME_STATIC:
- if a.Sym != nil && isextern(a.Sym) || (p.Mode == 32 && ctxt.Flag_shared == 0) {
+ if a.Sym != nil && isextern(a.Sym) || (p.Mode == 32 && !ctxt.Flag_shared) {
return Yi32
}
return Yiauto // use pc-relative addressing
@@ -2712,7 +2708,7 @@ func vaddr(ctxt *obj.Link, p *obj.Prog, a *obj.Addr, r *obj.Reloc) int64 {
if a.Name == obj.NAME_GOTREF {
r.Siz = 4
r.Type = obj.R_GOTPCREL
- } else if isextern(s) || (p.Mode != 64 && ctxt.Flag_shared == 0) {
+ } else if isextern(s) || (p.Mode != 64 && !ctxt.Flag_shared) {
r.Siz = 4
r.Type = obj.R_ADDR
} else {
@@ -2733,7 +2729,7 @@ func vaddr(ctxt *obj.Link, p *obj.Prog, a *obj.Addr, r *obj.Reloc) int64 {
log.Fatalf("reloc")
}
- if ctxt.Flag_shared == 0 || isAndroid {
+ if !ctxt.Flag_shared || isAndroid {
r.Type = obj.R_TLS_LE
r.Siz = 4
r.Off = -1 // caller must fill in
@@ -2798,7 +2794,7 @@ func asmandsz(ctxt *obj.Link, p *obj.Prog, a *obj.Addr, r int, rex int, m64 int)
if !isextern(a.Sym) && p.Mode == 64 {
goto bad
}
- if p.Mode == 32 && ctxt.Flag_shared != 0 {
+ if p.Mode == 32 && ctxt.Flag_shared {
base = REG_CX
} else {
base = REG_NONE
@@ -2843,7 +2839,7 @@ func asmandsz(ctxt *obj.Link, p *obj.Prog, a *obj.Addr, r int, rex int, m64 int)
if a.Sym == nil {
ctxt.Diag("bad addr: %v", p)
}
- if p.Mode == 32 && ctxt.Flag_shared != 0 {
+ if p.Mode == 32 && ctxt.Flag_shared {
base = REG_CX
} else {
base = REG_NONE
@@ -2897,7 +2893,7 @@ func asmandsz(ctxt *obj.Link, p *obj.Prog, a *obj.Addr, r int, rex int, m64 int)
}
if REG_AX <= base && base <= REG_R15 {
- if a.Index == REG_TLS && ctxt.Flag_shared == 0 {
+ if a.Index == REG_TLS && !ctxt.Flag_shared {
rel = obj.Reloc{}
rel.Type = obj.R_TLS_LE
rel.Siz = 4
@@ -3313,7 +3309,7 @@ func doasm(ctxt *obj.Link, p *obj.Prog) {
case Pf2, /* xmm opcode escape */
Pf3:
- ctxt.AsmBuf.Put2(byte(o.prefix), Pm)
+ ctxt.AsmBuf.Put2(o.prefix, Pm)
case Pef3:
ctxt.AsmBuf.Put3(Pe, Pf3, Pm)
@@ -3426,7 +3422,7 @@ func doasm(ctxt *obj.Link, p *obj.Prog) {
asmand(ctxt, p, &p.From, &p.To)
case Zm2_r:
- ctxt.AsmBuf.Put2(byte(op), byte(o.op[z+1]))
+ ctxt.AsmBuf.Put2(byte(op), o.op[z+1])
asmand(ctxt, p, &p.From, &p.To)
case Zm_r_xm:
@@ -3536,7 +3532,7 @@ func doasm(ctxt *obj.Link, p *obj.Prog) {
}
ctxt.AsmBuf.Put1(byte(op))
if p.As == AXABORT {
- ctxt.AsmBuf.Put1(byte(o.op[z+1]))
+ ctxt.AsmBuf.Put1(o.op[z+1])
}
ctxt.AsmBuf.Put1(byte(vaddr(ctxt, p, a, nil)))
@@ -3662,7 +3658,7 @@ func doasm(ctxt *obj.Link, p *obj.Prog) {
if yt.zcase == Zcallcon {
ctxt.AsmBuf.Put1(byte(op))
} else {
- ctxt.AsmBuf.Put1(byte(o.op[z+1]))
+ ctxt.AsmBuf.Put1(o.op[z+1])
}
r = obj.Addrel(ctxt.Cursym)
r.Off = int32(p.Pc + int64(ctxt.AsmBuf.Len()))
@@ -3672,7 +3668,7 @@ func doasm(ctxt *obj.Link, p *obj.Prog) {
ctxt.AsmBuf.PutInt32(0)
case Zcallind:
- ctxt.AsmBuf.Put2(byte(op), byte(o.op[z+1]))
+ ctxt.AsmBuf.Put2(byte(op), o.op[z+1])
r = obj.Addrel(ctxt.Cursym)
r.Off = int32(p.Pc + int64(ctxt.AsmBuf.Len()))
r.Type = obj.R_ADDR
@@ -3727,7 +3723,7 @@ func doasm(ctxt *obj.Link, p *obj.Prog) {
log.Fatalf("bad code")
}
- ctxt.AsmBuf.Put1(byte(o.op[z+1]))
+ ctxt.AsmBuf.Put1(o.op[z+1])
r = obj.Addrel(ctxt.Cursym)
r.Off = int32(p.Pc + int64(ctxt.AsmBuf.Len()))
r.Sym = p.To.Sym
@@ -3767,7 +3763,7 @@ func doasm(ctxt *obj.Link, p *obj.Prog) {
v--
}
- ctxt.AsmBuf.Put1(byte(o.op[z+1]))
+ ctxt.AsmBuf.Put1(o.op[z+1])
ctxt.AsmBuf.PutInt32(int32(v))
}
@@ -3789,7 +3785,7 @@ func doasm(ctxt *obj.Link, p *obj.Prog) {
if yt.zcase == Zbr {
ctxt.AsmBuf.Put1(0x0f)
}
- ctxt.AsmBuf.Put1(byte(o.op[z+1]))
+ ctxt.AsmBuf.Put1(o.op[z+1])
ctxt.AsmBuf.PutInt32(0)
}
@@ -3950,7 +3946,7 @@ func doasm(ctxt *obj.Link, p *obj.Prog) {
case obj.Hlinux,
obj.Hnacl:
- if ctxt.Flag_shared != 0 {
+ if ctxt.Flag_shared {
// Note that this is not generating the same insns as the other cases.
// MOV TLS, R_to
// becomes
@@ -4024,7 +4020,7 @@ func doasm(ctxt *obj.Link, p *obj.Prog) {
log.Fatalf("unknown TLS base location for %s", obj.Headstr(ctxt.Headtype))
case obj.Hlinux:
- if ctxt.Flag_shared == 0 {
+ if !ctxt.Flag_shared {
log.Fatalf("unknown TLS base location for linux without -shared")
}
// Note that this is not generating the same insn as the other cases.
@@ -4457,9 +4453,8 @@ func asmins(ctxt *obj.Link, p *obj.Prog) {
}
n := ctxt.AsmBuf.Len()
- var r *obj.Reloc
for i := len(ctxt.Cursym.R) - 1; i >= 0; i-- {
- r = &ctxt.Cursym.R[i:][0]
+ r := &ctxt.Cursym.R[i]
if int64(r.Off) < p.Pc {
break
}
diff --git a/src/cmd/internal/obj/x86/obj6.go b/src/cmd/internal/obj/x86/obj6.go
index 0e8aeca4d3..b638c048e8 100644
--- a/src/cmd/internal/obj/x86/obj6.go
+++ b/src/cmd/internal/obj/x86/obj6.go
@@ -32,7 +32,7 @@ package x86
import (
"cmd/internal/obj"
- "encoding/binary"
+ "cmd/internal/sys"
"fmt"
"log"
"math"
@@ -49,7 +49,7 @@ func CanUse1InsnTLS(ctxt *obj.Link) bool {
return true
}
- if ctxt.Arch.Regsize == 4 {
+ if ctxt.Arch.RegSize == 4 {
switch ctxt.Headtype {
case obj.Hlinux,
obj.Hnacl,
@@ -66,7 +66,7 @@ func CanUse1InsnTLS(ctxt *obj.Link) bool {
obj.Hwindows:
return false
case obj.Hlinux:
- return ctxt.Flag_shared == 0
+ return !ctxt.Flag_shared
}
return true
@@ -75,7 +75,7 @@ func CanUse1InsnTLS(ctxt *obj.Link) bool {
func progedit(ctxt *obj.Link, p *obj.Prog) {
// Maintain information about code generation mode.
if ctxt.Mode == 0 {
- ctxt.Mode = ctxt.Arch.Regsize * 8
+ ctxt.Mode = ctxt.Arch.RegSize * 8
}
p.Mode = int8(ctxt.Mode)
@@ -207,7 +207,7 @@ func progedit(ctxt *obj.Link, p *obj.Prog) {
}
// Rewrite MOVL/MOVQ $XXX(FP/SP) as LEAL/LEAQ.
- if p.From.Type == obj.TYPE_ADDR && (ctxt.Arch.Thechar == '6' || p.From.Name != obj.NAME_EXTERN && p.From.Name != obj.NAME_STATIC) {
+ if p.From.Type == obj.TYPE_ADDR && (ctxt.Arch.Family == sys.AMD64 || p.From.Name != obj.NAME_EXTERN && p.From.Name != obj.NAME_STATIC) {
switch p.As {
case AMOVL:
p.As = ALEAL
@@ -314,7 +314,7 @@ func progedit(ctxt *obj.Link, p *obj.Prog) {
rewriteToUseGot(ctxt, p)
}
- if ctxt.Flag_shared != 0 && p.Mode == 32 {
+ if ctxt.Flag_shared && p.Mode == 32 {
rewriteToPcrel(ctxt, p)
}
}
@@ -614,7 +614,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
// Make room for to save a base pointer. If autoffset == 0,
// this might do something special like a tail jump to
// another function, so in that case we omit this.
- bpsize = ctxt.Arch.Ptrsize
+ bpsize = ctxt.Arch.PtrSize
autoffset += int32(bpsize)
p.To.Offset += int64(bpsize)
@@ -656,7 +656,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
}
if autoffset != 0 {
- if autoffset%int32(ctxt.Arch.Regsize) != 0 {
+ if autoffset%int32(ctxt.Arch.RegSize) != 0 {
ctxt.Diag("unaligned stack size %d", autoffset)
}
p = obj.Appendp(ctxt, p)
@@ -671,10 +671,10 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
p = obj.Appendp(ctxt, p)
p.As = obj.ANOP
- p.Spadj = int32(-ctxt.Arch.Ptrsize)
+ p.Spadj = int32(-ctxt.Arch.PtrSize)
p = obj.Appendp(ctxt, p)
p.As = obj.ANOP
- p.Spadj = int32(ctxt.Arch.Ptrsize)
+ p.Spadj = int32(ctxt.Arch.PtrSize)
}
deltasp := autoffset
@@ -724,7 +724,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
p.As = AMOVQ
p.From.Type = obj.TYPE_MEM
p.From.Reg = REG_CX
- p.From.Offset = 4 * int64(ctxt.Arch.Ptrsize) // G.panic
+ p.From.Offset = 4 * int64(ctxt.Arch.PtrSize) // G.panic
p.To.Type = obj.TYPE_REG
p.To.Reg = REG_BX
if ctxt.Headtype == obj.Hnacl && p.Mode == 64 {
@@ -757,7 +757,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
p.As = ALEAQ
p.From.Type = obj.TYPE_MEM
p.From.Reg = REG_SP
- p.From.Offset = int64(autoffset) + int64(ctxt.Arch.Regsize)
+ p.From.Offset = int64(autoffset) + int64(ctxt.Arch.RegSize)
p.To.Type = obj.TYPE_REG
p.To.Reg = REG_DI
if ctxt.Headtype == obj.Hnacl || p.Mode == 32 {
@@ -935,7 +935,7 @@ func indir_cx(ctxt *obj.Link, p *obj.Prog, a *obj.Addr) {
// Returns last new instruction.
func load_g_cx(ctxt *obj.Link, p *obj.Prog) *obj.Prog {
p.As = AMOVQ
- if ctxt.Arch.Ptrsize == 4 {
+ if ctxt.Arch.PtrSize == 4 {
p.As = AMOVL
}
p.From.Type = obj.TYPE_MEM
@@ -984,9 +984,9 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, framesize int32, textarg int32) *ob
p.From.Type = obj.TYPE_REG
p.From.Reg = REG_SP
indir_cx(ctxt, p, &p.To)
- p.To.Offset = 2 * int64(ctxt.Arch.Ptrsize) // G.stackguard0
+ p.To.Offset = 2 * int64(ctxt.Arch.PtrSize) // G.stackguard0
if ctxt.Cursym.Cfunc {
- p.To.Offset = 3 * int64(ctxt.Arch.Ptrsize) // G.stackguard1
+ p.To.Offset = 3 * int64(ctxt.Arch.PtrSize) // G.stackguard1
}
} else if framesize <= obj.StackBig {
// large stack: SP-framesize <= stackguard-StackSmall
@@ -1006,9 +1006,9 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, framesize int32, textarg int32) *ob
p.From.Type = obj.TYPE_REG
p.From.Reg = REG_AX
indir_cx(ctxt, p, &p.To)
- p.To.Offset = 2 * int64(ctxt.Arch.Ptrsize) // G.stackguard0
+ p.To.Offset = 2 * int64(ctxt.Arch.PtrSize) // G.stackguard0
if ctxt.Cursym.Cfunc {
- p.To.Offset = 3 * int64(ctxt.Arch.Ptrsize) // G.stackguard1
+ p.To.Offset = 3 * int64(ctxt.Arch.PtrSize) // G.stackguard1
}
} else {
// Such a large stack we need to protect against wraparound.
@@ -1030,9 +1030,9 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, framesize int32, textarg int32) *ob
p.As = mov
indir_cx(ctxt, p, &p.From)
- p.From.Offset = 2 * int64(ctxt.Arch.Ptrsize) // G.stackguard0
+ p.From.Offset = 2 * int64(ctxt.Arch.PtrSize) // G.stackguard0
if ctxt.Cursym.Cfunc {
- p.From.Offset = 3 * int64(ctxt.Arch.Ptrsize) // G.stackguard1
+ p.From.Offset = 3 * int64(ctxt.Arch.PtrSize) // G.stackguard1
}
p.To.Type = obj.TYPE_REG
p.To.Reg = REG_SI
@@ -1402,43 +1402,28 @@ var unaryDst = map[obj.As]bool{
}
var Linkamd64 = obj.LinkArch{
- ByteOrder: binary.LittleEndian,
- Name: "amd64",
- Thechar: '6',
+ Arch: sys.ArchAMD64,
Preprocess: preprocess,
Assemble: span6,
Follow: follow,
Progedit: progedit,
UnaryDst: unaryDst,
- Minlc: 1,
- Ptrsize: 8,
- Regsize: 8,
}
var Linkamd64p32 = obj.LinkArch{
- ByteOrder: binary.LittleEndian,
- Name: "amd64p32",
- Thechar: '6',
+ Arch: sys.ArchAMD64P32,
Preprocess: preprocess,
Assemble: span6,
Follow: follow,
Progedit: progedit,
UnaryDst: unaryDst,
- Minlc: 1,
- Ptrsize: 4,
- Regsize: 8,
}
var Link386 = obj.LinkArch{
- ByteOrder: binary.LittleEndian,
- Name: "386",
- Thechar: '8',
+ Arch: sys.Arch386,
Preprocess: preprocess,
Assemble: span6,
Follow: follow,
Progedit: progedit,
UnaryDst: unaryDst,
- Minlc: 1,
- Ptrsize: 4,
- Regsize: 4,
}
diff --git a/src/cmd/internal/obj/x86/obj6_test.go b/src/cmd/internal/obj/x86/obj6_test.go
index a5c80cea3b..fe1f95cc0d 100644
--- a/src/cmd/internal/obj/x86/obj6_test.go
+++ b/src/cmd/internal/obj/x86/obj6_test.go
@@ -76,7 +76,6 @@ func parseTestData(t *testing.T) *ParsedTestData {
}
var spaces_re *regexp.Regexp = regexp.MustCompile("\\s+")
-var marker_re *regexp.Regexp = regexp.MustCompile("MOVQ \\$([0-9]+), AX")
func normalize(s string) string {
return spaces_re.ReplaceAllLiteralString(strings.TrimSpace(s), " ")