Prior to this CL, flags such as NOSPLIT
on ATEXT Progs were stored in From3.Offset.
Some but not all of those flags were also
duplicated into From.Sym.Attribute.
This CL migrates all of those flags into
From.Sym.Attribute and stops creating a From3.
A side-effect of this is that printing an
ATEXT Prog can no longer simply dump From3.Offset.
That's kind of good, since the raw flag value
wasn't very informative anyway, but it did
necessitate a bunch of updates to the cmd/asm tests.
The reason I'm doing this work now is that
avoiding storing flags in both From.Sym and From3.Offset
simplifies some other changes to fix the data
race first described in CL 40254.
This CL almost passes toolstash-check -all.
The only changes are in cases where the assembler
has decided that a function's flags may be altered,
e.g. to make a function with no calls in it NOSPLIT.
Prior to this CL, that information was not printed.
Sample before:
"".Ctz64 t=1 size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·
f207267fbf96a0178e8758c6e3e0ce28(SB)
Sample after:
"".Ctz64 t=1 nosplit size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), NOSPLIT, $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·
f207267fbf96a0178e8758c6e3e0ce28(SB)
Observe the additional "nosplit" in the first line
and the additional "NOSPLIT" in the second line.
Updates #15756
Change-Id: I5c59bd8f3bdc7c780361f801d94a261f0aef3d13
Reviewed-on: https://go-review.googlesource.com/40495
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
regexp
testdata
+
+ runtime
+ textflag.h
strconv
testdata
+
As: obj.ATEXT,
Pos: p.pos(),
From: nameAddr,
- From3: &obj.Addr{
- Type: obj.TYPE_CONST,
- Offset: flag,
- },
To: obj.Addr{
Type: obj.TYPE_TEXTSIZE,
Offset: frameSize,
},
}
prog.To.Val = int32(argSize)
- p.ctxt.InitTextSym(prog)
+ p.ctxt.InitTextSym(prog, int(flag))
p.append(prog, "", true)
}
for _, line := range lines {
lineno++
+ // Ignore include of textflag.h.
+ if strings.HasPrefix(line, "#include ") {
+ continue
+ }
+
// The general form of a test input line is:
// // comment
// INST args [// printed form] [// hex encoding]
// the old assembler's (8a's) grammar and hand-writing complete
// instructions for each rule, to guarantee we cover the same space.
-TEXT foo(SB), 7, $0
+#include "../../../../../runtime/textflag.h"
+
+TEXT foo(SB), DUPOK|NOSPLIT, $0
// LTYPE1 nonrem { outcode(int($1), &$2); }
SETCC AX
// the old assembler's (6a's) grammar and hand-writing complete
// instructions for each rule, to guarantee we cover the same space.
-TEXT foo(SB), 7, $0
+#include "../../../../../runtime/textflag.h"
+
+TEXT foo(SB), DUPOK|NOSPLIT, $0
// LTYPE1 nonrem { outcode($1, &$2); }
NEGQ R11
// generated by x86test -amd64
// DO NOT EDIT
-TEXT asmtest(SB),7,$0
+#include "../../../../../runtime/textflag.h"
+
+TEXT asmtest(SB),DUPOK|NOSPLIT,$0
ADCB $7, AL // 1407
ADCW $61731, AX // 661523f1
ADCL $4045620583, AX // 15674523f1
// the old assembler's (5a's) grammar and hand-writing complete
// instructions for each rule, to guarantee we cover the same space.
-TEXT foo(SB), 7, $0
+#include "../../../../../runtime/textflag.h"
+
+TEXT foo(SB), DUPOK|NOSPLIT, $0
// ADD
//
// the old assembler's (7a's) grammar and hand-writing complete
// instructions for each rule, to guarantee we cover the same space.
-TEXT foo(SB), 7, $-8
+#include "../../../../../runtime/textflag.h"
+
+TEXT foo(SB), DUPOK|NOSPLIT, $-8
//
// ADD
// This input was created by taking the mips64 testcase and modified
// by hand.
-TEXT foo(SB),7,$0
+#include "../../../../../runtime/textflag.h"
+
+TEXT foo(SB),DUPOK|NOSPLIT,$0
//inst:
//
// This input was created by taking the ppc64 testcase and modified
// by hand.
-TEXT foo(SB),7,$0
+#include "../../../../../runtime/textflag.h"
+
+TEXT foo(SB),DUPOK|NOSPLIT,$0
//inst:
//
// the old assembler's (9a's) grammar and hand-writing complete
// instructions for each rule, to guarantee we cover the same space.
-TEXT foo(SB),7,$0
+#include "../../../../../runtime/textflag.h"
+
+TEXT foo(SB),DUPOK|NOSPLIT,$0
//inst:
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-TEXT main·foo(SB),7,$16-0 // TEXT main.foo(SB), 7, $16-0
+#include "../../../../../runtime/textflag.h"
+
+TEXT main·foo(SB),DUPOK|NOSPLIT,$16-0 // TEXT main.foo(SB), DUPOK|NOSPLIT, $16-0
MOVD R1, R2 // b9040021
MOVW R3, R4 // b9140043
MOVH R5, R6 // b9070065
RET
-TEXT main·init(SB),7,$0 // TEXT main.init(SB), 7, $0
+TEXT main·init(SB),DUPOK|NOSPLIT,$0 // TEXT main.init(SB), DUPOK|NOSPLIT, $0
RET
-TEXT main·main(SB),7,$0 // TEXT main.main(SB), 7, $0
+TEXT main·main(SB),DUPOK|NOSPLIT,$0 // TEXT main.main(SB), DUPOK|NOSPLIT, $0
BL main·foo(SB) // CALL main.foo(SB)
RET
}
}
- ptxt.From3 = new(obj.Addr)
+ var flag int
if fn.Func.Dupok() {
- ptxt.From3.Offset |= obj.DUPOK
+ flag |= obj.DUPOK
}
if fn.Func.Wrapper() {
- ptxt.From3.Offset |= obj.WRAPPER
+ flag |= obj.WRAPPER
}
if fn.Func.NoFramePointer() {
- ptxt.From3.Offset |= obj.NOFRAME
+ flag |= obj.NOFRAME
}
if fn.Func.Needctxt() {
- ptxt.From3.Offset |= obj.NEEDCTXT
+ flag |= obj.NEEDCTXT
}
if fn.Func.Pragma&Nosplit != 0 {
- ptxt.From3.Offset |= obj.NOSPLIT
+ flag |= obj.NOSPLIT
}
if fn.Func.ReflectMethod() {
- ptxt.From3.Offset |= obj.REFLECTMETHOD
+ flag |= obj.REFLECTMETHOD
}
// Clumsy but important.
if myimportpath == "reflect" {
switch fn.Func.Nname.Sym.Name {
case "callReflect", "callMethod":
- ptxt.From3.Offset |= obj.WRAPPER
+ flag |= obj.WRAPPER
}
}
- Ctxt.InitTextSym(ptxt)
+ Ctxt.InitTextSym(ptxt, flag)
pp.Text = ptxt
}
}
}
- if p.From3.Offset&obj.NOSPLIT == 0 {
+ if !p.From.Sym.NoSplit() {
p = c.stacksplit(p, autosize) // emit split check
}
p.To.Reg = REGSP
p.Spadj = autosize
- if cursym.Text.From3.Offset&obj.WRAPPER != 0 {
+ if cursym.Text.From.Sym.Wrapper() {
// if(g->panic != nil && g->panic->argp == FP) g->panic->argp = bottom-of-frame
//
// MOVW g_panic(g), R1
}
case ADIV, ADIVU, AMOD, AMODU:
- if cursym.Text.From3.Offset&obj.NOSPLIT != 0 {
+ if cursym.Text.From.Sym.NoSplit() {
ctxt.Diag("cannot divide in NOSPLIT function")
}
const debugdivmod = false
switch {
case c.cursym.CFunc():
morestack = "runtime.morestackc"
- case c.cursym.Text.From3.Offset&obj.NEEDCTXT == 0:
+ case !c.cursym.Text.From.Sym.NeedCtxt():
morestack = "runtime.morestack_noctxt"
}
call.To.Sym = c.ctxt.Lookup(morestack, 0)
switch {
case c.cursym.CFunc():
morestack = "runtime.morestackc"
- case c.cursym.Text.From3.Offset&obj.NEEDCTXT == 0:
+ case !c.cursym.Text.From.Sym.NeedCtxt():
morestack = "runtime.morestack_noctxt"
}
call.To.Sym = c.ctxt.Lookup(morestack, 0)
c.cursym.Text.Mark |= LEAF
}
- if !(p.From3.Offset&obj.NOSPLIT != 0) {
+ if !p.From.Sym.NoSplit() {
p = c.stacksplit(p, c.autosize) // emit split check
}
q1.Spadj = aoffset
}
- if c.cursym.Text.From3.Offset&obj.WRAPPER != 0 {
+ if c.cursym.Text.From.Sym.Wrapper() {
// if(g->panic != nil && g->panic->argp == FP) g->panic->argp = bottom-of-frame
//
// MOV g_panic(g), R1
return p.From3.Type
}
-// From3Offset returns From3.Offset, or 0 when From3 is nil.
-func (p *Prog) From3Offset() int64 {
- if p.From3 == nil {
- return 0
- }
- return p.From3.Offset
-}
-
// An As denotes an assembler opcode.
// There are some portable opcodes, declared here in package obj,
// that are common to all architectures.
AttrCFunc
AttrNoSplit
AttrLeaf
+ AttrWrapper
+ AttrNeedCtxt
+ AttrNoFrame
AttrSeenGlobl
AttrOnList
func (a Attribute) OnList() bool { return a&AttrOnList != 0 }
func (a Attribute) ReflectMethod() bool { return a&AttrReflectMethod != 0 }
func (a Attribute) Local() bool { return a&AttrLocal != 0 }
+func (a Attribute) Wrapper() bool { return a&AttrWrapper != 0 }
+func (a Attribute) NeedCtxt() bool { return a&AttrNeedCtxt != 0 }
+func (a Attribute) NoFrame() bool { return a&AttrNoFrame != 0 }
func (a *Attribute) Set(flag Attribute, value bool) {
if value {
}
}
+var textAttrStrings = [...]struct {
+ bit Attribute
+ s string
+}{
+ {bit: AttrDuplicateOK, s: "DUPOK"},
+ {bit: AttrMakeTypelink, s: ""},
+ {bit: AttrCFunc, s: "CFUNC"},
+ {bit: AttrNoSplit, s: "NOSPLIT"},
+ {bit: AttrLeaf, s: "LEAF"},
+ {bit: AttrSeenGlobl, s: ""},
+ {bit: AttrOnList, s: ""},
+ {bit: AttrReflectMethod, s: "REFLECTMETHOD"},
+ {bit: AttrLocal, s: "LOCAL"},
+ {bit: AttrWrapper, s: "WRAPPER"},
+ {bit: AttrNeedCtxt, s: "NEEDCTXT"},
+ {bit: AttrNoFrame, s: "NOFRAME"},
+}
+
+// TextAttrString formats a for printing in as part of a TEXT prog.
+func (a Attribute) TextAttrString() string {
+ var s string
+ for _, x := range textAttrStrings {
+ if a&x.bit != 0 {
+ if x.s != "" {
+ s += x.s + "|"
+ }
+ a &^= x.bit
+ }
+ }
+ if a != 0 {
+ s += fmt.Sprintf("UnknownAttribute(%d)|", a)
+ }
+ // Chop off trailing |, if present.
+ if len(s) > 0 {
+ s = s[:len(s)-1]
+ }
+ return s
+}
+
// The compiler needs LSym to satisfy fmt.Stringer, because it stores
// an LSym in ssa.ExternSymbol.
func (s *LSym) String() string {
p.To.Offset = int64(autosize) - ctxt.FixedFrameSize()
- if p.From3.Offset&obj.NOSPLIT == 0 {
+ if !p.From.Sym.NoSplit() {
p = c.stacksplit(p, autosize) // emit split check
}
q.To.Reg = REGSP
q.Spadj = +autosize
} else if c.cursym.Text.Mark&LEAF == 0 {
- if c.cursym.Text.From3.Offset&obj.NOSPLIT != 0 {
+ if c.cursym.Text.From.Sym.NoSplit() {
if ctxt.Debugvlog {
ctxt.Logf("save suppressed in: %s\n", c.cursym.Name)
}
break
}
- if c.cursym.Text.From3.Offset&obj.WRAPPER != 0 {
+ if c.cursym.Text.From.Sym.Wrapper() {
// if(g->panic != nil && g->panic->argp == FP) g->panic->argp = bottom-of-frame
//
// MOV g_panic(g), R1
p.To.Type = obj.TYPE_BRANCH
if c.cursym.CFunc() {
p.To.Sym = c.ctxt.Lookup("runtime.morestackc", 0)
- } else if c.cursym.Text.From3.Offset&obj.NEEDCTXT == 0 {
+ } else if !c.cursym.Text.From.Sym.NeedCtxt() {
p.To.Sym = c.ctxt.Lookup("runtime.morestack_noctxt", 0)
} else {
p.To.Sym = c.ctxt.Lookup("runtime.morestack", 0)
ctxt.Text = append(ctxt.Text, text...)
}
-func (ctxt *Link) InitTextSym(p *Prog) {
+func (ctxt *Link) InitTextSym(p *Prog, flag int) {
if p.As != ATEXT {
ctxt.Diag("InitTextSym non-ATEXT: %v", p)
}
ctxt.Diag("symbol %s listed multiple times", s.Name)
}
s.Set(AttrOnList, true)
- flag := int(p.From3Offset())
- if flag&DUPOK != 0 {
- s.Set(AttrDuplicateOK, true)
- }
- if flag&NOSPLIT != 0 {
- s.Set(AttrNoSplit, true)
- }
- if flag&REFLECTMETHOD != 0 {
- s.Set(AttrReflectMethod, true)
- }
+ s.Set(AttrDuplicateOK, flag&DUPOK != 0)
+ s.Set(AttrNoSplit, flag&NOSPLIT != 0)
+ s.Set(AttrReflectMethod, flag&REFLECTMETHOD != 0)
+ s.Set(AttrWrapper, flag&WRAPPER != 0)
+ s.Set(AttrNeedCtxt, flag&NEEDCTXT != 0)
+ s.Set(AttrNoFrame, flag&NOFRAME != 0)
s.Type = STEXT
s.Text = p
}
textstksiz := p.To.Offset
if textstksiz == -8 {
// Compatibility hack.
- p.From3.Offset |= obj.NOFRAME
+ p.From.Sym.Set(obj.AttrNoFrame, true)
textstksiz = 0
}
if textstksiz%8 != 0 {
c.ctxt.Diag("frame size %d not a multiple of 8", textstksiz)
}
- if p.From3.Offset&obj.NOFRAME != 0 {
+ if p.From.Sym.NoFrame() {
if textstksiz != 0 {
c.ctxt.Diag("NOFRAME functions must have a frame size of 0, not %d", textstksiz)
}
if p.Mark&LEAF != 0 && autosize == 0 {
// A leaf function with no locals has no frame.
- p.From3.Offset |= obj.NOFRAME
+ p.From.Sym.Set(obj.AttrNoFrame, true)
}
- if p.From3.Offset&obj.NOFRAME == 0 {
+ if !p.From.Sym.NoFrame() {
// If there is a stack frame at all, it includes
// space to save the LR.
autosize += int32(c.ctxt.FixedFrameSize())
if p.Mark&LEAF != 0 && autosize < obj.StackSmall {
// A leaf function with a small stack can be marked
// NOSPLIT, avoiding a stack check.
- p.From3.Offset |= obj.NOSPLIT
+ p.From.Sym.Set(obj.AttrNoSplit, true)
}
p.To.Offset = int64(autosize)
rel.Type = obj.R_ADDRPOWER_PCREL
}
- if c.cursym.Text.From3.Offset&obj.NOSPLIT == 0 {
+ if !c.cursym.Text.From.Sym.NoSplit() {
q = c.stacksplit(q, autosize) // emit split check
}
q.To.Offset = 24
}
- if c.cursym.Text.From3.Offset&obj.WRAPPER != 0 {
+ if c.cursym.Text.From.Sym.Wrapper() {
// if(g->panic != nil && g->panic->argp == FP) g->panic->argp = bottom-of-frame
//
// MOVD g_panic(g), R3
var morestacksym *obj.LSym
if c.cursym.CFunc() {
morestacksym = c.ctxt.Lookup("runtime.morestackc", 0)
- } else if c.cursym.Text.From3.Offset&obj.NEEDCTXT == 0 {
+ } else if !c.cursym.Text.From.Sym.NeedCtxt() {
morestacksym = c.ctxt.Lookup("runtime.morestack_noctxt", 0)
} else {
morestacksym = c.ctxt.Lookup("runtime.morestack", 0)
textstksiz := p.To.Offset
if textstksiz == -8 {
// Compatibility hack.
- p.From3.Offset |= obj.NOFRAME
+ p.From.Sym.Set(obj.AttrNoFrame, true)
textstksiz = 0
}
if textstksiz%8 != 0 {
c.ctxt.Diag("frame size %d not a multiple of 8", textstksiz)
}
- if p.From3.Offset&obj.NOFRAME != 0 {
+ if p.From.Sym.NoFrame() {
if textstksiz != 0 {
c.ctxt.Diag("NOFRAME functions must have a frame size of 0, not %d", textstksiz)
}
if p.Mark&LEAF != 0 && autosize == 0 {
// A leaf function with no locals has no frame.
- p.From3.Offset |= obj.NOFRAME
+ p.From.Sym.Set(obj.AttrNoFrame, true)
}
- if p.From3.Offset&obj.NOFRAME == 0 {
+ if !p.From.Sym.NoFrame() {
// If there is a stack frame at all, it includes
// space to save the LR.
autosize += int32(c.ctxt.FixedFrameSize())
if p.Mark&LEAF != 0 && autosize < obj.StackSmall {
// A leaf function with a small stack can be marked
// NOSPLIT, avoiding a stack check.
- p.From3.Offset |= obj.NOSPLIT
+ p.From.Sym.Set(obj.AttrNoSplit, true)
}
p.To.Offset = int64(autosize)
q := p
- if p.From3.Offset&obj.NOSPLIT == 0 {
+ if !p.From.Sym.NoSplit() {
p, pPreempt = c.stacksplitPre(p, autosize) // emit pre part of split check
pPre = p
wasSplit = true //need post part of split
break
}
- if c.cursym.Text.From3.Offset&obj.WRAPPER != 0 {
+ if c.cursym.Text.From.Sym.Wrapper() {
// if(g->panic != nil && g->panic->argp == FP) g->panic->argp = bottom-of-frame
//
// MOVD g_panic(g), R3
p.To.Type = obj.TYPE_BRANCH
if c.cursym.CFunc() {
p.To.Sym = c.ctxt.Lookup("runtime.morestackc", 0)
- } else if c.cursym.Text.From3.Offset&obj.NEEDCTXT == 0 {
+ } else if !c.cursym.Text.From.Sym.NeedCtxt() {
p.To.Sym = c.ctxt.Lookup("runtime.morestack_noctxt", 0)
} else {
p.To.Sym = c.ctxt.Lookup("runtime.morestack", 0)
sep = ", "
}
if p.From3Type() != TYPE_NONE {
- if p.From3.Type == TYPE_CONST && p.As == ATEXT {
- // Special case - omit $.
- fmt.Fprintf(&buf, "%s%d", sep, p.From3.Offset)
- } else if quadOpAmd64 {
+ if quadOpAmd64 {
fmt.Fprintf(&buf, "%s%v", sep, Rconv(int(p.From3.Reg)))
} else {
fmt.Fprintf(&buf, "%s%v", sep, Dconv(p, p.From3))
}
sep = ", "
}
+ if p.As == ATEXT {
+ // If there are attributes, print them. Otherwise, skip the comma.
+ // In short, print one of these two:
+ // TEXT foo(SB), DUPOK|NOSPLIT, $0
+ // TEXT foo(SB), $0
+ s := p.From.Sym.Attribute.TextAttrString()
+ if s != "" {
+ fmt.Fprintf(&buf, "%s%s", sep, s)
+ sep = ", "
+ }
+ }
if p.To.Type != TYPE_NONE {
fmt.Fprintf(&buf, "%s%v", sep, Dconv(p, &p.To))
}
var bpsize int
if ctxt.Arch.Family == sys.AMD64 && ctxt.Framepointer_enabled &&
- p.From3.Offset&obj.NOFRAME == 0 && // (1) below
- !(autoffset == 0 && p.From3.Offset&obj.NOSPLIT != 0) && // (2) below
+ !p.From.Sym.NoFrame() && // (1) below
+ !(autoffset == 0 && p.From.Sym.NoSplit()) && // (2) below
!(autoffset == 0 && !hasCall) { // (3) below
// Make room to save a base pointer.
// There are 2 cases we must avoid:
}
// TODO(rsc): Remove 'ctxt.Arch.Family == sys.AMD64 &&'.
- if ctxt.Arch.Family == sys.AMD64 && autoffset < obj.StackSmall && p.From3Offset()&obj.NOSPLIT == 0 {
+ if ctxt.Arch.Family == sys.AMD64 && autoffset < obj.StackSmall && !p.From.Sym.NoSplit() {
leaf := true
LeafSearch:
for q := p; q != nil; q = q.Link {
}
if leaf {
- p.From3.Offset |= obj.NOSPLIT
+ p.From.Sym.Set(obj.AttrNoSplit, true)
}
}
- if p.From3Offset()&obj.NOSPLIT == 0 || p.From3Offset()&obj.WRAPPER != 0 {
+ if !p.From.Sym.NoSplit() || p.From.Sym.Wrapper() {
p = obj.Appendp(p, newprog)
p = load_g_cx(ctxt, p, newprog) // load g into CX
}
- if cursym.Text.From3Offset()&obj.NOSPLIT == 0 {
+ if !cursym.Text.From.Sym.NoSplit() {
p = stacksplit(ctxt, cursym, p, newprog, autoffset, int32(textarg)) // emit split check
}
p.To.Reg = REG_BP
}
- if cursym.Text.From3Offset()&obj.WRAPPER != 0 {
+ if cursym.Text.From.Sym.Wrapper() {
// if g._panic != nil && g._panic.argp == FP {
// g._panic.argp = bottom-of-frame
// }
switch {
case cursym.CFunc():
morestack = "runtime.morestackc"
- case cursym.Text.From3Offset()&obj.NEEDCTXT == 0:
+ case !cursym.Text.From.Sym.NeedCtxt():
morestack = "runtime.morestack_noctxt"
}
call.To.Sym = ctxt.Lookup(morestack, 0)