1
0
mirror of https://github.com/golang/go synced 2024-11-22 18:54:44 -07:00

cmd/internal/obj: replace AGLOBL with (*Link).Globl

Replace the AGLOBL pseudo-op with a method to directly register an
LSym as a global. Similar to how we previously already replaced the
ADATA pseudo-op with directly writing out data bytes.

Passes toolstash -cmp.

Change-Id: I3631af0a2ab5798152d0c26b833dc309dbec5772
Reviewed-on: https://go-review.googlesource.com/29366
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2016-09-16 15:31:04 -07:00
parent a1bf203b57
commit 6fe1febc86
9 changed files with 42 additions and 112 deletions

View File

@ -269,17 +269,7 @@ func (p *Parser) asmGlobl(word string, operands [][]lex.Token) {
}
// log.Printf("GLOBL %s %d, $%d", name, flag, size)
prog := &obj.Prog{
Ctxt: p.ctxt,
As: obj.AGLOBL,
Lineno: p.histLineNum,
From: nameAddr,
From3: &obj.Addr{
Offset: flag,
},
To: addr,
}
p.append(prog, "", false)
p.ctxt.Globl(nameAddr.Sym, addr.Offset, int(flag))
}
// asmPCData assembles a PCDATA pseudo-op.

View File

@ -1268,7 +1268,6 @@ func funccompile(n *Node) {
// If we have compile errors, ignore any assembler/linker errors.
Ctxt.DiagFunc = func(string, ...interface{}) {}
}
flushdata()
obj.Flushplist(Ctxt) // convert from Prog list to machine code
}

View File

@ -35,33 +35,13 @@ import (
"fmt"
)
var (
ddumped bool
dfirst *obj.Prog
dpc *obj.Prog
)
func Prog(as obj.As) *obj.Prog {
var p *obj.Prog
if as == obj.AGLOBL {
if ddumped {
Fatalf("already dumped data")
}
if dpc == nil {
dpc = Ctxt.NewProg()
dfirst = dpc
}
p = dpc
dpc = Ctxt.NewProg()
p.Link = dpc
} else {
p = Pc
Pc = Ctxt.NewProg()
Clearp(Pc)
p.Link = Pc
}
p = Pc
Pc = Ctxt.NewProg()
Clearp(Pc)
p.Link = Pc
if lineno == 0 && Debug['K'] != 0 {
Warn("prog: line 0")
@ -102,29 +82,6 @@ func Appendpp(p *obj.Prog, as obj.As, ftype obj.AddrType, freg int16, foffset in
return q
}
func dumpdata() {
ddumped = true
if dfirst == nil {
return
}
newplist()
*Pc = *dfirst
Pc = dpc
Clearp(Pc)
}
func flushdata() {
if dfirst == nil {
return
}
newplist()
*Pc = *dfirst
Pc = dpc
Clearp(Pc)
dfirst = nil
dpc = nil
}
// Fixup instructions after allocauto (formerly compactframe) has moved all autos around.
func fixautoused(p *obj.Prog) {
for lp := &p; ; {
@ -160,19 +117,16 @@ func fixautoused(p *obj.Prog) {
}
func ggloblnod(nam *Node) {
p := Gins(obj.AGLOBL, nam, nil)
p.Lineno = nam.Lineno
p.From.Sym.Gotype = Linksym(ngotype(nam))
p.To.Sym = nil
p.To.Type = obj.TYPE_CONST
p.To.Offset = nam.Type.Width
p.From3 = new(obj.Addr)
s := Linksym(nam.Sym)
s.Gotype = Linksym(ngotype(nam))
flags := 0
if nam.Name.Readonly {
p.From3.Offset = obj.RODATA
flags = obj.RODATA
}
if nam.Type != nil && !haspointers(nam.Type) {
p.From3.Offset |= obj.NOPTR
flags |= obj.NOPTR
}
Ctxt.Globl(s, nam.Type.Width, flags)
}
func ggloblsym(s *Sym, width int32, flags int16) {
@ -180,18 +134,11 @@ func ggloblsym(s *Sym, width int32, flags int16) {
}
func ggloblLSym(s *obj.LSym, width int32, flags int16) {
p := Gins(obj.AGLOBL, nil, nil)
p.From.Type = obj.TYPE_MEM
p.From.Name = obj.NAME_EXTERN
p.From.Sym = s
if flags&obj.LOCAL != 0 {
p.From.Sym.Local = true
s.Local = true
flags &^= obj.LOCAL
}
p.To.Type = obj.TYPE_CONST
p.To.Offset = int64(width)
p.From3 = new(obj.Addr)
p.From3.Offset = int64(flags)
Ctxt.Globl(s, int64(width), int(flags))
}
func gtrack(s *Sym) {
@ -450,7 +397,7 @@ func Patch(p *obj.Prog, to *obj.Prog) {
func Gins(as obj.As, f, t *Node) *obj.Prog {
switch as {
case obj.AVARKILL, obj.AVARLIVE, obj.AVARDEF, obj.ATYPE,
obj.ATEXT, obj.AFUNCDATA, obj.AUSEFIELD, obj.AGLOBL:
obj.ATEXT, obj.AFUNCDATA, obj.AUSEFIELD:
default:
Fatalf("unhandled gins op %v", as)
}

View File

@ -147,7 +147,6 @@ func dumpobj1(outfile string, mode int) {
ggloblsym(zero, int32(zerosize), obj.DUPOK|obj.RODATA)
}
dumpdata()
obj.Writeobjdirect(Ctxt, bout.Writer)
if writearchive {

View File

@ -855,7 +855,7 @@ func checkptxt(fn *Node, firstp *obj.Prog) {
if false {
fmt.Printf("analyzing '%v'\n", p)
}
if p.As != obj.AGLOBL && p.As != obj.ATYPE {
if p.As != obj.ATYPE {
checkprog(fn, p)
}
}

View File

@ -276,7 +276,6 @@ const (
ADUFFZERO
AEND
AFUNCDATA
AGLOBL
AJMP
ANOP
APCDATA

View File

@ -82,34 +82,6 @@ func flushplist(ctxt *Link, freeProgs bool) {
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 {
@ -217,3 +189,29 @@ func flushplist(ctxt *Link, freeProgs bool) {
ctxt.freeProgs()
}
}
func (ctxt *Link) Globl(s *LSym, size int64, flag int) {
if s.Seenglobl {
fmt.Printf("duplicate %v\n", s)
}
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 = size
if s.Type == 0 || s.Type == SXREF {
s.Type = SBSS
}
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
}
}

View File

@ -143,7 +143,7 @@ func (p *Prog) String() string {
sep = ", "
}
if p.From3Type() != TYPE_NONE {
if p.From3.Type == TYPE_CONST && (p.As == ATEXT || p.As == AGLOBL) {
if p.From3.Type == TYPE_CONST && p.As == ATEXT {
// Special case - omit $.
fmt.Fprintf(&buf, "%s%d", sep, p.From3.Offset)
} else if quadOpAmd64 {
@ -477,7 +477,6 @@ var Anames = []string{
"DUFFZERO",
"END",
"FUNCDATA",
"GLOBL",
"JMP",
"NOP",
"PCDATA",

View File

@ -1148,7 +1148,6 @@ var optab =
{AFXSAVE, ysvrs, Pm, [23]uint8{0xae, 00, 0xae, 00}},
{AFXRSTOR64, ysvrs, Pw, [23]uint8{0x0f, 0xae, 01, 0x0f, 0xae, 01}},
{AFXSAVE64, ysvrs, Pw, [23]uint8{0x0f, 0xae, 00, 0x0f, 0xae, 00}},
{obj.AGLOBL, nil, 0, [23]uint8{}},
{AHLT, ynone, Px, [23]uint8{0xf4}},
{AIDIVB, ydivb, Pb, [23]uint8{0xf6, 07}},
{AIDIVL, ydivl, Px, [23]uint8{0xf7, 07}},