mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.regabi] cmd/compile: more Linksym cleanup
This largely gets rid of the remaining direct Linksym calls, hopefully enough to discourage people from following bad existing practice until Sym.Linksym can be removed entirely. Passes toolstash -cmp. Change-Id: I5d8f8f703ace7256538fc79648891ede0d879dc2 Reviewed-on: https://go-review.googlesource.com/c/go/+/280641 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
ec59b197d5
commit
a5ec920160
6 changed files with 46 additions and 66 deletions
|
|
@ -148,8 +148,8 @@ func dumpdata() {
|
||||||
dumpglobls(typecheck.Target.Externs[numExterns:])
|
dumpglobls(typecheck.Target.Externs[numExterns:])
|
||||||
|
|
||||||
if reflectdata.ZeroSize > 0 {
|
if reflectdata.ZeroSize > 0 {
|
||||||
zero := ir.Pkgs.Map.Lookup("zero")
|
zero := ir.Pkgs.Map.Lookup("zero").Linksym()
|
||||||
objw.Global(zero.Linksym(), int32(reflectdata.ZeroSize), obj.DUPOK|obj.RODATA)
|
objw.Global(zero, int32(reflectdata.ZeroSize), obj.DUPOK|obj.RODATA)
|
||||||
}
|
}
|
||||||
|
|
||||||
addGCLocals()
|
addGCLocals()
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ func Task() *ir.Name {
|
||||||
typecheck.Stmts(nf)
|
typecheck.Stmts(nf)
|
||||||
ir.CurFunc = nil
|
ir.CurFunc = nil
|
||||||
typecheck.Target.Decls = append(typecheck.Target.Decls, fn)
|
typecheck.Target.Decls = append(typecheck.Target.Decls, fn)
|
||||||
fns = append(fns, initializers.Linksym())
|
fns = append(fns, fn.Linksym())
|
||||||
}
|
}
|
||||||
if typecheck.InitTodoFunc.Dcl != nil {
|
if typecheck.InitTodoFunc.Dcl != nil {
|
||||||
// We only generate temps using initTodo if there
|
// We only generate temps using initTodo if there
|
||||||
|
|
@ -87,7 +87,7 @@ func Task() *ir.Name {
|
||||||
task.SetType(types.Types[types.TUINT8]) // fake type
|
task.SetType(types.Types[types.TUINT8]) // fake type
|
||||||
task.Class_ = ir.PEXTERN
|
task.Class_ = ir.PEXTERN
|
||||||
sym.Def = task
|
sym.Def = task
|
||||||
lsym := sym.Linksym()
|
lsym := task.Linksym()
|
||||||
ot := 0
|
ot := 0
|
||||||
ot = objw.Uintptr(lsym, ot, 0) // state: not initialized yet
|
ot = objw.Uintptr(lsym, ot, 0) // state: not initialized yet
|
||||||
ot = objw.Uintptr(lsym, ot, uint64(len(deps)))
|
ot = objw.Uintptr(lsym, ot, uint64(len(deps)))
|
||||||
|
|
|
||||||
|
|
@ -255,7 +255,7 @@ func genhash(t *types.Type) *obj.LSym {
|
||||||
|
|
||||||
// Build closure. It doesn't close over any variables, so
|
// Build closure. It doesn't close over any variables, so
|
||||||
// it contains just the function pointer.
|
// it contains just the function pointer.
|
||||||
objw.SymPtr(closure, 0, sym.Linksym(), 0)
|
objw.SymPtr(closure, 0, fn.Linksym(), 0)
|
||||||
objw.Global(closure, int32(types.PtrSize), obj.DUPOK|obj.RODATA)
|
objw.Global(closure, int32(types.PtrSize), obj.DUPOK|obj.RODATA)
|
||||||
|
|
||||||
return closure
|
return closure
|
||||||
|
|
@ -634,7 +634,7 @@ func geneq(t *types.Type) *obj.LSym {
|
||||||
typecheck.Target.Decls = append(typecheck.Target.Decls, fn)
|
typecheck.Target.Decls = append(typecheck.Target.Decls, fn)
|
||||||
|
|
||||||
// Generate a closure which points at the function we just generated.
|
// Generate a closure which points at the function we just generated.
|
||||||
objw.SymPtr(closure, 0, sym.Linksym(), 0)
|
objw.SymPtr(closure, 0, fn.Linksym(), 0)
|
||||||
objw.Global(closure, int32(types.PtrSize), obj.DUPOK|obj.RODATA)
|
objw.Global(closure, int32(types.PtrSize), obj.DUPOK|obj.RODATA)
|
||||||
return closure
|
return closure
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,13 +52,13 @@ var (
|
||||||
signatslice []*types.Type
|
signatslice []*types.Type
|
||||||
|
|
||||||
itabs []itabEntry
|
itabs []itabEntry
|
||||||
ptabs []ptabEntry
|
ptabs []*ir.Name
|
||||||
)
|
)
|
||||||
|
|
||||||
type typeSig struct {
|
type typeSig struct {
|
||||||
name *types.Sym
|
name *types.Sym
|
||||||
isym *types.Sym
|
isym *obj.LSym
|
||||||
tsym *types.Sym
|
tsym *obj.LSym
|
||||||
type_ *types.Type
|
type_ *types.Type
|
||||||
mtype *types.Type
|
mtype *types.Type
|
||||||
}
|
}
|
||||||
|
|
@ -327,21 +327,19 @@ func methods(t *types.Type) []*typeSig {
|
||||||
// generating code if necessary.
|
// generating code if necessary.
|
||||||
var ms []*typeSig
|
var ms []*typeSig
|
||||||
for _, f := range mt.AllMethods().Slice() {
|
for _, f := range mt.AllMethods().Slice() {
|
||||||
|
if f.Sym == nil {
|
||||||
|
base.Fatalf("method with no sym on %v", mt)
|
||||||
|
}
|
||||||
if !f.IsMethod() {
|
if !f.IsMethod() {
|
||||||
base.Fatalf("non-method on %v method %v %v\n", mt, f.Sym, f)
|
base.Fatalf("non-method on %v method %v %v", mt, f.Sym, f)
|
||||||
}
|
}
|
||||||
if f.Type.Recv() == nil {
|
if f.Type.Recv() == nil {
|
||||||
base.Fatalf("receiver with no type on %v method %v %v\n", mt, f.Sym, f)
|
base.Fatalf("receiver with no type on %v method %v %v", mt, f.Sym, f)
|
||||||
}
|
}
|
||||||
if f.Nointerface() {
|
if f.Nointerface() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
method := f.Sym
|
|
||||||
if method == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// get receiver type for this particular method.
|
// get receiver type for this particular method.
|
||||||
// if pointer receiver but non-pointer t and
|
// if pointer receiver but non-pointer t and
|
||||||
// this is not an embedded pointer inside a struct,
|
// this is not an embedded pointer inside a struct,
|
||||||
|
|
@ -351,29 +349,13 @@ func methods(t *types.Type) []*typeSig {
|
||||||
}
|
}
|
||||||
|
|
||||||
sig := &typeSig{
|
sig := &typeSig{
|
||||||
name: method,
|
name: f.Sym,
|
||||||
isym: ir.MethodSym(it, method),
|
isym: methodWrapper(it, f),
|
||||||
tsym: ir.MethodSym(t, method),
|
tsym: methodWrapper(t, f),
|
||||||
type_: typecheck.NewMethodType(f.Type, t),
|
type_: typecheck.NewMethodType(f.Type, t),
|
||||||
mtype: typecheck.NewMethodType(f.Type, nil),
|
mtype: typecheck.NewMethodType(f.Type, nil),
|
||||||
}
|
}
|
||||||
ms = append(ms, sig)
|
ms = append(ms, sig)
|
||||||
|
|
||||||
this := f.Type.Recv().Type
|
|
||||||
|
|
||||||
if !sig.isym.Siggen() {
|
|
||||||
sig.isym.SetSiggen(true)
|
|
||||||
if !types.Identical(this, it) {
|
|
||||||
genwrapper(it, f, sig.isym)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !sig.tsym.Siggen() {
|
|
||||||
sig.tsym.SetSiggen(true)
|
|
||||||
if !types.Identical(this, t) {
|
|
||||||
genwrapper(t, f, sig.tsym)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ms
|
return ms
|
||||||
|
|
@ -407,11 +389,7 @@ func imethods(t *types.Type) []*typeSig {
|
||||||
// IfaceType.Method is not in the reflect data.
|
// IfaceType.Method is not in the reflect data.
|
||||||
// Generate the method body, so that compiled
|
// Generate the method body, so that compiled
|
||||||
// code can refer to it.
|
// code can refer to it.
|
||||||
isym := ir.MethodSym(t, f.Sym)
|
methodWrapper(t, f)
|
||||||
if !isym.Siggen() {
|
|
||||||
isym.SetSiggen(true)
|
|
||||||
genwrapper(t, f, isym)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return methods
|
return methods
|
||||||
|
|
@ -636,8 +614,8 @@ func dextratypeData(lsym *obj.LSym, ot int, t *types.Type) int {
|
||||||
|
|
||||||
ot = objw.SymPtrOff(lsym, ot, nsym)
|
ot = objw.SymPtrOff(lsym, ot, nsym)
|
||||||
ot = dmethodptrOff(lsym, ot, WriteType(a.mtype))
|
ot = dmethodptrOff(lsym, ot, WriteType(a.mtype))
|
||||||
ot = dmethodptrOff(lsym, ot, a.isym.Linksym())
|
ot = dmethodptrOff(lsym, ot, a.isym)
|
||||||
ot = dmethodptrOff(lsym, ot, a.tsym.Linksym())
|
ot = dmethodptrOff(lsym, ot, a.tsym)
|
||||||
}
|
}
|
||||||
return ot
|
return ot
|
||||||
}
|
}
|
||||||
|
|
@ -884,7 +862,7 @@ func ITabAddr(t, itype *types.Type) *ir.AddrExpr {
|
||||||
n.Class_ = ir.PEXTERN
|
n.Class_ = ir.PEXTERN
|
||||||
n.SetTypecheck(1)
|
n.SetTypecheck(1)
|
||||||
s.Def = n
|
s.Def = n
|
||||||
itabs = append(itabs, itabEntry{t: t, itype: itype, lsym: s.Linksym()})
|
itabs = append(itabs, itabEntry{t: t, itype: itype, lsym: n.Linksym()})
|
||||||
}
|
}
|
||||||
|
|
||||||
n := typecheck.NodAddr(ir.AsNode(s.Def))
|
n := typecheck.NodAddr(ir.AsNode(s.Def))
|
||||||
|
|
@ -1281,7 +1259,7 @@ func genfun(t, it *types.Type) []*obj.LSym {
|
||||||
// so we can find the intersect in a single pass
|
// so we can find the intersect in a single pass
|
||||||
for _, m := range methods {
|
for _, m := range methods {
|
||||||
if m.name == sigs[0].name {
|
if m.name == sigs[0].name {
|
||||||
out = append(out, m.isym.Linksym())
|
out = append(out, m.isym)
|
||||||
sigs = sigs[1:]
|
sigs = sigs[1:]
|
||||||
if len(sigs) == 0 {
|
if len(sigs) == 0 {
|
||||||
break
|
break
|
||||||
|
|
@ -1390,8 +1368,12 @@ func WriteTabs() {
|
||||||
// name nameOff
|
// name nameOff
|
||||||
// typ typeOff // pointer to symbol
|
// typ typeOff // pointer to symbol
|
||||||
// }
|
// }
|
||||||
nsym := dname(p.s.Name, "", nil, true)
|
nsym := dname(p.Sym().Name, "", nil, true)
|
||||||
tsym := WriteType(p.t)
|
t := p.Type()
|
||||||
|
if p.Class_ != ir.PFUNC {
|
||||||
|
t = types.NewPtr(t)
|
||||||
|
}
|
||||||
|
tsym := WriteType(t)
|
||||||
ot = objw.SymPtrOff(s, ot, nsym)
|
ot = objw.SymPtrOff(s, ot, nsym)
|
||||||
ot = objw.SymPtrOff(s, ot, tsym)
|
ot = objw.SymPtrOff(s, ot, tsym)
|
||||||
// Plugin exports symbols as interfaces. Mark their types
|
// Plugin exports symbols as interfaces. Mark their types
|
||||||
|
|
@ -1403,7 +1385,7 @@ func WriteTabs() {
|
||||||
ot = 0
|
ot = 0
|
||||||
s = base.Ctxt.Lookup("go.plugin.exports")
|
s = base.Ctxt.Lookup("go.plugin.exports")
|
||||||
for _, p := range ptabs {
|
for _, p := range ptabs {
|
||||||
ot = objw.SymPtr(s, ot, p.s.Linksym(), 0)
|
ot = objw.SymPtr(s, ot, p.Linksym(), 0)
|
||||||
}
|
}
|
||||||
objw.Global(s, int32(ot), int16(obj.RODATA))
|
objw.Global(s, int32(ot), int16(obj.RODATA))
|
||||||
}
|
}
|
||||||
|
|
@ -1722,13 +1704,7 @@ func CollectPTabs() {
|
||||||
if s.Pkg.Name != "main" {
|
if s.Pkg.Name != "main" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if n.Type().Kind() == types.TFUNC && n.Class_ == ir.PFUNC {
|
ptabs = append(ptabs, n)
|
||||||
// function
|
|
||||||
ptabs = append(ptabs, ptabEntry{s: s, t: s.Def.Type()})
|
|
||||||
} else {
|
|
||||||
// variable
|
|
||||||
ptabs = append(ptabs, ptabEntry{s: s, t: types.NewPtr(s.Def.Type())})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1752,22 +1728,28 @@ func CollectPTabs() {
|
||||||
//
|
//
|
||||||
// rcvr - U
|
// rcvr - U
|
||||||
// method - M func (t T)(), a TFIELD type struct
|
// method - M func (t T)(), a TFIELD type struct
|
||||||
// newnam - the eventual mangled name of this function
|
func methodWrapper(rcvr *types.Type, method *types.Field) *obj.LSym {
|
||||||
func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym) {
|
newnam := ir.MethodSym(rcvr, method.Sym)
|
||||||
if false && base.Flag.LowerR != 0 {
|
lsym := newnam.Linksym()
|
||||||
fmt.Printf("genwrapper rcvrtype=%v method=%v newnam=%v\n", rcvr, method, newnam)
|
if newnam.Siggen() {
|
||||||
|
return lsym
|
||||||
|
}
|
||||||
|
newnam.SetSiggen(true)
|
||||||
|
|
||||||
|
if types.Identical(rcvr, method.Type.Recv().Type) {
|
||||||
|
return lsym
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only generate (*T).M wrappers for T.M in T's own package.
|
// Only generate (*T).M wrappers for T.M in T's own package.
|
||||||
if rcvr.IsPtr() && rcvr.Elem() == method.Type.Recv().Type &&
|
if rcvr.IsPtr() && rcvr.Elem() == method.Type.Recv().Type &&
|
||||||
rcvr.Elem().Sym() != nil && rcvr.Elem().Sym().Pkg != types.LocalPkg {
|
rcvr.Elem().Sym() != nil && rcvr.Elem().Sym().Pkg != types.LocalPkg {
|
||||||
return
|
return lsym
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only generate I.M wrappers for I in I's own package
|
// Only generate I.M wrappers for I in I's own package
|
||||||
// but keep doing it for error.Error (was issue #29304).
|
// but keep doing it for error.Error (was issue #29304).
|
||||||
if rcvr.IsInterface() && rcvr.Sym() != nil && rcvr.Sym().Pkg != types.LocalPkg && rcvr != types.ErrorType {
|
if rcvr.IsInterface() && rcvr.Sym() != nil && rcvr.Sym().Pkg != types.LocalPkg && rcvr != types.ErrorType {
|
||||||
return
|
return lsym
|
||||||
}
|
}
|
||||||
|
|
||||||
base.Pos = base.AutogeneratedPos
|
base.Pos = base.AutogeneratedPos
|
||||||
|
|
@ -1827,10 +1809,6 @@ func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if false && base.Flag.LowerR != 0 {
|
|
||||||
ir.DumpList("genwrapper body", fn.Body)
|
|
||||||
}
|
|
||||||
|
|
||||||
typecheck.FinishFuncBody()
|
typecheck.FinishFuncBody()
|
||||||
if base.Debug.DclStack != 0 {
|
if base.Debug.DclStack != 0 {
|
||||||
types.CheckDclstack()
|
types.CheckDclstack()
|
||||||
|
|
@ -1850,6 +1828,8 @@ func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym) {
|
||||||
|
|
||||||
ir.CurFunc = nil
|
ir.CurFunc = nil
|
||||||
typecheck.Target.Decls = append(typecheck.Target.Decls, fn)
|
typecheck.Target.Decls = append(typecheck.Target.Decls, fn)
|
||||||
|
|
||||||
|
return lsym
|
||||||
}
|
}
|
||||||
|
|
||||||
var ZeroSize int64
|
var ZeroSize int64
|
||||||
|
|
|
||||||
|
|
@ -4578,7 +4578,7 @@ func (s *state) openDeferExit() {
|
||||||
call = s.newValue3A(ssa.OpClosureCall, types.TypeMem, aux, codeptr, v, s.mem())
|
call = s.newValue3A(ssa.OpClosureCall, types.TypeMem, aux, codeptr, v, s.mem())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
aux := ssa.StaticAuxCall(fn.Sym().Linksym(), ACArgs, ACResults)
|
aux := ssa.StaticAuxCall(fn.(*ir.Name).Linksym(), ACArgs, ACResults)
|
||||||
if testLateExpansion {
|
if testLateExpansion {
|
||||||
callArgs = append(callArgs, s.mem())
|
callArgs = append(callArgs, s.mem())
|
||||||
call = s.newValue0A(ssa.OpStaticLECall, aux.LateExpansionResultType(), aux)
|
call = s.newValue0A(ssa.OpStaticLECall, aux.LateExpansionResultType(), aux)
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ func slicedata(pos src.XPos, s string) *ir.Name {
|
||||||
symnode := typecheck.NewName(sym)
|
symnode := typecheck.NewName(sym)
|
||||||
sym.Def = symnode
|
sym.Def = symnode
|
||||||
|
|
||||||
lsym := sym.Linksym()
|
lsym := symnode.Linksym()
|
||||||
off := dstringdata(lsym, 0, s, pos, "slice")
|
off := dstringdata(lsym, 0, s, pos, "slice")
|
||||||
objw.Global(lsym, int32(off), obj.NOPTR|obj.LOCAL)
|
objw.Global(lsym, int32(off), obj.NOPTR|obj.LOCAL)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue