Commit e248b96d authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/internal/obj/x86: clean up part of span6

Passes toolstash -cmp.

Change-Id: I38eb507de2e9dc2cf01822e420bf31a91fb1b720
Reviewed-on: https://go-review.googlesource.com/20766
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c1a4fe8d
...@@ -32,6 +32,7 @@ package x86 ...@@ -32,6 +32,7 @@ package x86
import ( import (
"cmd/internal/obj" "cmd/internal/obj"
"encoding/binary"
"fmt" "fmt"
"log" "log"
"strings" "strings"
...@@ -1770,7 +1771,6 @@ func span6(ctxt *obj.Link, s *obj.LSym) { ...@@ -1770,7 +1771,6 @@ func span6(ctxt *obj.Link, s *obj.LSym) {
instinit() instinit()
} }
var v int32
for p := ctxt.Cursym.Text; p != nil; p = p.Link { for p := ctxt.Cursym.Text; p != nil; p = p.Link {
if p.To.Type == obj.TYPE_BRANCH { if p.To.Type == obj.TYPE_BRANCH {
if p.Pcond == nil { if p.Pcond == nil {
...@@ -1780,7 +1780,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) { ...@@ -1780,7 +1780,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) {
if p.As == AADJSP { if p.As == AADJSP {
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = REG_SP p.To.Reg = REG_SP
v = int32(-p.From.Offset) v := int32(-p.From.Offset)
p.From.Offset = int64(v) p.From.Offset = int64(v)
p.As = spadjop(ctxt, p, AADDL, AADDQ) p.As = spadjop(ctxt, p, AADDL, AADDQ)
if v < 0 { if v < 0 {
...@@ -1807,7 +1807,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) { ...@@ -1807,7 +1807,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) {
if p.As == AADJSP { if p.As == AADJSP {
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = REG_SP p.To.Reg = REG_SP
v = int32(-p.From.Offset) v := int32(-p.From.Offset)
p.From.Offset = int64(v) p.From.Offset = int64(v)
p.As = spadjop(ctxt, p, AADDL, AADDQ) p.As = spadjop(ctxt, p, AADDL, AADDQ)
if v < 0 { if v < 0 {
...@@ -1823,28 +1823,22 @@ func span6(ctxt *obj.Link, s *obj.LSym) { ...@@ -1823,28 +1823,22 @@ func span6(ctxt *obj.Link, s *obj.LSym) {
} }
n := 0 n := 0
var bp []byte
var c int32 var c int32
var i int
var loop int32
var m int
var p *obj.Prog
errors := ctxt.Errors errors := ctxt.Errors
var deferreturn *obj.LSym
if ctxt.Headtype == obj.Hnacl {
deferreturn = obj.Linklookup(ctxt, "runtime.deferreturn", 0)
}
for { for {
loop = 0 loop := int32(0)
for i = 0; i < len(s.R); i++ { for i := range s.R {
s.R[i] = obj.Reloc{} s.R[i] = obj.Reloc{}
} }
s.R = s.R[:0] s.R = s.R[:0]
s.P = s.P[:0] s.P = s.P[:0]
c = 0 c = 0
for p = s.Text; p != nil; p = p.Link { for p := s.Text; p != nil; p = p.Link {
if ctxt.Headtype == obj.Hnacl && p.Isize > 0 { if ctxt.Headtype == obj.Hnacl && p.Isize > 0 {
var deferreturn *obj.LSym
if deferreturn == nil {
deferreturn = obj.Linklookup(ctxt, "runtime.deferreturn", 0)
}
// pad everything to avoid crossing 32-byte boundary // pad everything to avoid crossing 32-byte boundary
if c>>5 != (c+int32(p.Isize)-1)>>5 { if c>>5 != (c+int32(p.Isize)-1)>>5 {
...@@ -1881,7 +1875,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) { ...@@ -1881,7 +1875,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) {
if (p.Back&4 != 0) && c&(LoopAlign-1) != 0 { if (p.Back&4 != 0) && c&(LoopAlign-1) != 0 {
// pad with NOPs // pad with NOPs
v = -c & (LoopAlign - 1) v := -c & (LoopAlign - 1)
if v <= MaxLoopPad { if v <= MaxLoopPad {
obj.Symgrow(ctxt, s, int64(c)+int64(v)) obj.Symgrow(ctxt, s, int64(c)+int64(v))
...@@ -1894,7 +1888,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) { ...@@ -1894,7 +1888,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) {
// process forward jumps to p // process forward jumps to p
for q = p.Rel; q != nil; q = q.Forwd { for q = p.Rel; q != nil; q = q.Forwd {
v = int32(p.Pc - (q.Pc + int64(q.Isize))) v := int32(p.Pc - (q.Pc + int64(q.Isize)))
if q.Back&2 != 0 { // short if q.Back&2 != 0 { // short
if v > 127 { if v > 127 {
loop++ loop++
...@@ -1907,14 +1901,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) { ...@@ -1907,14 +1901,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) {
s.P[q.Pc+1] = byte(v) s.P[q.Pc+1] = byte(v)
} }
} else { } else {
bp = s.P[q.Pc+int64(q.Isize)-4:] binary.LittleEndian.PutUint32(s.P[q.Pc+int64(q.Isize)-4:], uint32(v))
bp[0] = byte(v)
bp = bp[1:]
bp[0] = byte(v >> 8)
bp = bp[1:]
bp[0] = byte(v >> 16)
bp = bp[1:]
bp[0] = byte(v >> 24)
} }
} }
...@@ -1922,7 +1909,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) { ...@@ -1922,7 +1909,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) {
p.Pc = int64(c) p.Pc = int64(c)
asmins(ctxt, p) asmins(ctxt, p)
m = -cap(ctxt.Andptr) + cap(ctxt.And[:]) m := -cap(ctxt.Andptr) + cap(ctxt.And[:])
if int(p.Isize) != m { if int(p.Isize) != m {
p.Isize = uint8(m) p.Isize = uint8(m)
loop++ loop++
...@@ -1952,7 +1939,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) { ...@@ -1952,7 +1939,7 @@ func span6(ctxt *obj.Link, s *obj.LSym) {
// Pad functions with trap instruction, to catch invalid jumps // Pad functions with trap instruction, to catch invalid jumps
if c&(FuncAlign-1) != 0 { if c&(FuncAlign-1) != 0 {
v = -c & (FuncAlign - 1) v := -c & (FuncAlign - 1)
obj.Symgrow(ctxt, s, int64(c)+int64(v)) obj.Symgrow(ctxt, s, int64(c)+int64(v))
for i := c; i < c+v; i++ { for i := c; i < c+v; i++ {
// 0xCC is INT $3 - breakpoint instruction // 0xCC is INT $3 - breakpoint instruction
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment