mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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:
parent
a1bf203b57
commit
6fe1febc86
9 changed files with 42 additions and 112 deletions
|
|
@ -269,17 +269,7 @@ func (p *Parser) asmGlobl(word string, operands [][]lex.Token) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// log.Printf("GLOBL %s %d, $%d", name, flag, size)
|
// log.Printf("GLOBL %s %d, $%d", name, flag, size)
|
||||||
prog := &obj.Prog{
|
p.ctxt.Globl(nameAddr.Sym, addr.Offset, int(flag))
|
||||||
Ctxt: p.ctxt,
|
|
||||||
As: obj.AGLOBL,
|
|
||||||
Lineno: p.histLineNum,
|
|
||||||
From: nameAddr,
|
|
||||||
From3: &obj.Addr{
|
|
||||||
Offset: flag,
|
|
||||||
},
|
|
||||||
To: addr,
|
|
||||||
}
|
|
||||||
p.append(prog, "", false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// asmPCData assembles a PCDATA pseudo-op.
|
// asmPCData assembles a PCDATA pseudo-op.
|
||||||
|
|
|
||||||
|
|
@ -1268,7 +1268,6 @@ func funccompile(n *Node) {
|
||||||
// If we have compile errors, ignore any assembler/linker errors.
|
// If we have compile errors, ignore any assembler/linker errors.
|
||||||
Ctxt.DiagFunc = func(string, ...interface{}) {}
|
Ctxt.DiagFunc = func(string, ...interface{}) {}
|
||||||
}
|
}
|
||||||
flushdata()
|
|
||||||
obj.Flushplist(Ctxt) // convert from Prog list to machine code
|
obj.Flushplist(Ctxt) // convert from Prog list to machine code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,33 +35,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
ddumped bool
|
|
||||||
dfirst *obj.Prog
|
|
||||||
dpc *obj.Prog
|
|
||||||
)
|
|
||||||
|
|
||||||
func Prog(as obj.As) *obj.Prog {
|
func Prog(as obj.As) *obj.Prog {
|
||||||
var p *obj.Prog
|
var p *obj.Prog
|
||||||
|
|
||||||
if as == obj.AGLOBL {
|
p = Pc
|
||||||
if ddumped {
|
Pc = Ctxt.NewProg()
|
||||||
Fatalf("already dumped data")
|
Clearp(Pc)
|
||||||
}
|
p.Link = Pc
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
if lineno == 0 && Debug['K'] != 0 {
|
if lineno == 0 && Debug['K'] != 0 {
|
||||||
Warn("prog: line 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
|
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.
|
// Fixup instructions after allocauto (formerly compactframe) has moved all autos around.
|
||||||
func fixautoused(p *obj.Prog) {
|
func fixautoused(p *obj.Prog) {
|
||||||
for lp := &p; ; {
|
for lp := &p; ; {
|
||||||
|
|
@ -160,19 +117,16 @@ func fixautoused(p *obj.Prog) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ggloblnod(nam *Node) {
|
func ggloblnod(nam *Node) {
|
||||||
p := Gins(obj.AGLOBL, nam, nil)
|
s := Linksym(nam.Sym)
|
||||||
p.Lineno = nam.Lineno
|
s.Gotype = Linksym(ngotype(nam))
|
||||||
p.From.Sym.Gotype = Linksym(ngotype(nam))
|
flags := 0
|
||||||
p.To.Sym = nil
|
|
||||||
p.To.Type = obj.TYPE_CONST
|
|
||||||
p.To.Offset = nam.Type.Width
|
|
||||||
p.From3 = new(obj.Addr)
|
|
||||||
if nam.Name.Readonly {
|
if nam.Name.Readonly {
|
||||||
p.From3.Offset = obj.RODATA
|
flags = obj.RODATA
|
||||||
}
|
}
|
||||||
if nam.Type != nil && !haspointers(nam.Type) {
|
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) {
|
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) {
|
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 {
|
if flags&obj.LOCAL != 0 {
|
||||||
p.From.Sym.Local = true
|
s.Local = true
|
||||||
flags &^= obj.LOCAL
|
flags &^= obj.LOCAL
|
||||||
}
|
}
|
||||||
p.To.Type = obj.TYPE_CONST
|
Ctxt.Globl(s, int64(width), int(flags))
|
||||||
p.To.Offset = int64(width)
|
|
||||||
p.From3 = new(obj.Addr)
|
|
||||||
p.From3.Offset = int64(flags)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func gtrack(s *Sym) {
|
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 {
|
func Gins(as obj.As, f, t *Node) *obj.Prog {
|
||||||
switch as {
|
switch as {
|
||||||
case obj.AVARKILL, obj.AVARLIVE, obj.AVARDEF, obj.ATYPE,
|
case obj.AVARKILL, obj.AVARLIVE, obj.AVARDEF, obj.ATYPE,
|
||||||
obj.ATEXT, obj.AFUNCDATA, obj.AUSEFIELD, obj.AGLOBL:
|
obj.ATEXT, obj.AFUNCDATA, obj.AUSEFIELD:
|
||||||
default:
|
default:
|
||||||
Fatalf("unhandled gins op %v", as)
|
Fatalf("unhandled gins op %v", as)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,6 @@ func dumpobj1(outfile string, mode int) {
|
||||||
ggloblsym(zero, int32(zerosize), obj.DUPOK|obj.RODATA)
|
ggloblsym(zero, int32(zerosize), obj.DUPOK|obj.RODATA)
|
||||||
}
|
}
|
||||||
|
|
||||||
dumpdata()
|
|
||||||
obj.Writeobjdirect(Ctxt, bout.Writer)
|
obj.Writeobjdirect(Ctxt, bout.Writer)
|
||||||
|
|
||||||
if writearchive {
|
if writearchive {
|
||||||
|
|
|
||||||
|
|
@ -855,7 +855,7 @@ func checkptxt(fn *Node, firstp *obj.Prog) {
|
||||||
if false {
|
if false {
|
||||||
fmt.Printf("analyzing '%v'\n", p)
|
fmt.Printf("analyzing '%v'\n", p)
|
||||||
}
|
}
|
||||||
if p.As != obj.AGLOBL && p.As != obj.ATYPE {
|
if p.As != obj.ATYPE {
|
||||||
checkprog(fn, p)
|
checkprog(fn, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -276,7 +276,6 @@ const (
|
||||||
ADUFFZERO
|
ADUFFZERO
|
||||||
AEND
|
AEND
|
||||||
AFUNCDATA
|
AFUNCDATA
|
||||||
AGLOBL
|
|
||||||
AJMP
|
AJMP
|
||||||
ANOP
|
ANOP
|
||||||
APCDATA
|
APCDATA
|
||||||
|
|
|
||||||
|
|
@ -82,34 +82,6 @@ func flushplist(ctxt *Link, freeProgs bool) {
|
||||||
curtext.Autom = a
|
curtext.Autom = a
|
||||||
continue
|
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:
|
case ATEXT:
|
||||||
s := p.From.Sym
|
s := p.From.Sym
|
||||||
if s == nil {
|
if s == nil {
|
||||||
|
|
@ -217,3 +189,29 @@ func flushplist(ctxt *Link, freeProgs bool) {
|
||||||
ctxt.freeProgs()
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ func (p *Prog) String() string {
|
||||||
sep = ", "
|
sep = ", "
|
||||||
}
|
}
|
||||||
if p.From3Type() != TYPE_NONE {
|
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 $.
|
// Special case - omit $.
|
||||||
fmt.Fprintf(&buf, "%s%d", sep, p.From3.Offset)
|
fmt.Fprintf(&buf, "%s%d", sep, p.From3.Offset)
|
||||||
} else if quadOpAmd64 {
|
} else if quadOpAmd64 {
|
||||||
|
|
@ -477,7 +477,6 @@ var Anames = []string{
|
||||||
"DUFFZERO",
|
"DUFFZERO",
|
||||||
"END",
|
"END",
|
||||||
"FUNCDATA",
|
"FUNCDATA",
|
||||||
"GLOBL",
|
|
||||||
"JMP",
|
"JMP",
|
||||||
"NOP",
|
"NOP",
|
||||||
"PCDATA",
|
"PCDATA",
|
||||||
|
|
|
||||||
|
|
@ -1148,7 +1148,6 @@ var optab =
|
||||||
{AFXSAVE, ysvrs, Pm, [23]uint8{0xae, 00, 0xae, 00}},
|
{AFXSAVE, ysvrs, Pm, [23]uint8{0xae, 00, 0xae, 00}},
|
||||||
{AFXRSTOR64, ysvrs, Pw, [23]uint8{0x0f, 0xae, 01, 0x0f, 0xae, 01}},
|
{AFXRSTOR64, ysvrs, Pw, [23]uint8{0x0f, 0xae, 01, 0x0f, 0xae, 01}},
|
||||||
{AFXSAVE64, ysvrs, Pw, [23]uint8{0x0f, 0xae, 00, 0x0f, 0xae, 00}},
|
{AFXSAVE64, ysvrs, Pw, [23]uint8{0x0f, 0xae, 00, 0x0f, 0xae, 00}},
|
||||||
{obj.AGLOBL, nil, 0, [23]uint8{}},
|
|
||||||
{AHLT, ynone, Px, [23]uint8{0xf4}},
|
{AHLT, ynone, Px, [23]uint8{0xf4}},
|
||||||
{AIDIVB, ydivb, Pb, [23]uint8{0xf6, 07}},
|
{AIDIVB, ydivb, Pb, [23]uint8{0xf6, 07}},
|
||||||
{AIDIVL, ydivl, Px, [23]uint8{0xf7, 07}},
|
{AIDIVL, ydivl, Px, [23]uint8{0xf7, 07}},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue