mirror of
https://github.com/golang/go
synced 2024-11-26 02:07:57 -07:00
[dev.regabi] cmd/compile: add Linksym helpers
Syms are meant to be just interned (pkg, name) tuples, and are a purely abstract, Go-language concept. As such, associating them with linker symbols (a low-level, implementation-oriented detail) is inappropriate. There's still work to be done before linker symbols can be directly attached to their appropriate, higher-level objects instead. But in the mean-time, we can at least add helper functions and discourage folks from using Sym.Linksym directly. The next CL will mechanically rewrite code to use these helpers where possible. Passes toolstash -cmp. Change-Id: I413bd1c80bce056304f9a7343526bd153f2b9c7d Reviewed-on: https://go-review.googlesource.com/c/go/+/280639 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
289da2b33e
commit
25c613c02d
@ -260,7 +260,7 @@ func addGCLocals() {
|
||||
}
|
||||
}
|
||||
|
||||
func ggloblnod(nam ir.Node) {
|
||||
func ggloblnod(nam *ir.Name) {
|
||||
s := nam.Sym().Linksym()
|
||||
s.Gotype = reflectdata.TypeSym(nam.Type()).Linksym()
|
||||
flags := 0
|
||||
|
@ -78,7 +78,7 @@ type Func struct {
|
||||
// Marks records scope boundary changes.
|
||||
Marks []Mark
|
||||
|
||||
FieldTrack map[*types.Sym]struct{}
|
||||
FieldTrack map[*obj.LSym]struct{}
|
||||
DebugInfo interface{}
|
||||
LSym *obj.LSym
|
||||
|
||||
@ -119,12 +119,8 @@ func (f *Func) isStmt() {}
|
||||
func (f *Func) Type() *types.Type { return f.typ }
|
||||
func (f *Func) SetType(x *types.Type) { f.typ = x }
|
||||
|
||||
func (f *Func) Sym() *types.Sym {
|
||||
if f.Nname != nil {
|
||||
return f.Nname.Sym()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (f *Func) Sym() *types.Sym { return f.Nname.Sym() }
|
||||
func (f *Func) Linksym() *obj.LSym { return f.Nname.Linksym() }
|
||||
|
||||
// An Inline holds fields used for function bodies that can be inlined.
|
||||
type Inline struct {
|
||||
|
@ -7,6 +7,7 @@ package ir
|
||||
import (
|
||||
"cmd/compile/internal/base"
|
||||
"cmd/compile/internal/types"
|
||||
"cmd/internal/obj"
|
||||
"cmd/internal/objabi"
|
||||
"cmd/internal/src"
|
||||
|
||||
@ -238,6 +239,8 @@ func (n *Name) SetFrameOffset(x int64) { n.Offset_ = x }
|
||||
func (n *Name) Iota() int64 { return n.Offset_ }
|
||||
func (n *Name) SetIota(x int64) { n.Offset_ = x }
|
||||
|
||||
func (n *Name) Linksym() *obj.LSym { return n.sym.Linksym() }
|
||||
|
||||
func (*Name) CanBeNtype() {}
|
||||
func (*Name) CanBeAnSSASym() {}
|
||||
func (*Name) CanBeAnSSAAux() {}
|
||||
|
@ -812,8 +812,8 @@ func dcommontype(lsym *obj.LSym, t *types.Type) int {
|
||||
|
||||
// TrackSym returns the symbol for tracking use of field/method f, assumed
|
||||
// to be a member of struct/interface type t.
|
||||
func TrackSym(t *types.Type, f *types.Field) *types.Sym {
|
||||
return ir.Pkgs.Track.Lookup(t.ShortString() + "." + f.Sym.Name)
|
||||
func TrackSym(t *types.Type, f *types.Field) *obj.LSym {
|
||||
return ir.Pkgs.Track.Lookup(t.ShortString() + "." + f.Sym.Name).Linksym()
|
||||
}
|
||||
|
||||
func TypeSymPrefix(prefix string, t *types.Type) *types.Sym {
|
||||
@ -845,6 +845,18 @@ func TypeSym(t *types.Type) *types.Sym {
|
||||
return s
|
||||
}
|
||||
|
||||
func TypeLinksymPrefix(prefix string, t *types.Type) *obj.LSym {
|
||||
return TypeSymPrefix(prefix, t).Linksym()
|
||||
}
|
||||
|
||||
func TypeLinksymLookup(name string) *obj.LSym {
|
||||
return types.TypeSymLookup(name).Linksym()
|
||||
}
|
||||
|
||||
func TypeLinksym(t *types.Type) *obj.LSym {
|
||||
return TypeSym(t).Linksym()
|
||||
}
|
||||
|
||||
func TypePtr(t *types.Type) *ir.AddrExpr {
|
||||
s := TypeSym(t)
|
||||
if s.Def == nil {
|
||||
|
@ -225,7 +225,7 @@ func StackOffset(slot ssa.LocalSlot) int32 {
|
||||
|
||||
// fieldtrack adds R_USEFIELD relocations to fnsym to record any
|
||||
// struct fields that it used.
|
||||
func fieldtrack(fnsym *obj.LSym, tracked map[*types.Sym]struct{}) {
|
||||
func fieldtrack(fnsym *obj.LSym, tracked map[*obj.LSym]struct{}) {
|
||||
if fnsym == nil {
|
||||
return
|
||||
}
|
||||
@ -233,24 +233,18 @@ func fieldtrack(fnsym *obj.LSym, tracked map[*types.Sym]struct{}) {
|
||||
return
|
||||
}
|
||||
|
||||
trackSyms := make([]*types.Sym, 0, len(tracked))
|
||||
trackSyms := make([]*obj.LSym, 0, len(tracked))
|
||||
for sym := range tracked {
|
||||
trackSyms = append(trackSyms, sym)
|
||||
}
|
||||
sort.Sort(symByName(trackSyms))
|
||||
sort.Slice(trackSyms, func(i, j int) bool { return trackSyms[i].Name < trackSyms[j].Name })
|
||||
for _, sym := range trackSyms {
|
||||
r := obj.Addrel(fnsym)
|
||||
r.Sym = sym.Linksym()
|
||||
r.Sym = sym
|
||||
r.Type = objabi.R_USEFIELD
|
||||
}
|
||||
}
|
||||
|
||||
type symByName []*types.Sym
|
||||
|
||||
func (a symByName) Len() int { return len(a) }
|
||||
func (a symByName) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
||||
func (a symByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
|
||||
// largeStack is info about a function whose stack frame is too large (rare).
|
||||
type largeStack struct {
|
||||
locals int64
|
||||
|
@ -2106,7 +2106,7 @@ func (s *state) expr(n ir.Node) *ssa.Value {
|
||||
return s.newValue3(ssa.OpSliceMake, n.Type(), ptr, len, len)
|
||||
case ir.OCFUNC:
|
||||
n := n.(*ir.UnaryExpr)
|
||||
aux := n.X.Sym().Linksym()
|
||||
aux := n.X.(*ir.Name).Linksym()
|
||||
return s.entryNewValue1A(ssa.OpAddr, n.Type(), aux, s.sb)
|
||||
case ir.ONAME:
|
||||
n := n.(*ir.Name)
|
||||
@ -6826,7 +6826,7 @@ func AddAux2(a *obj.Addr, v *ssa.Value, offset int64) {
|
||||
case *ir.Name:
|
||||
if n.Class_ == ir.PPARAM || n.Class_ == ir.PPARAMOUT {
|
||||
a.Name = obj.NAME_PARAM
|
||||
a.Sym = ir.Orig(n).Sym().Linksym()
|
||||
a.Sym = ir.Orig(n).(*ir.Name).Linksym()
|
||||
a.Offset += n.FrameOffset()
|
||||
break
|
||||
}
|
||||
|
@ -258,6 +258,13 @@ func FuncSym(s *types.Sym) *types.Sym {
|
||||
return sf
|
||||
}
|
||||
|
||||
func FuncLinksym(n *ir.Name) *obj.LSym {
|
||||
if n.Op() != ir.ONAME || n.Class_ != ir.PFUNC {
|
||||
base.Fatalf("expected func name: %v", n)
|
||||
}
|
||||
return FuncSym(n.Sym()).Linksym()
|
||||
}
|
||||
|
||||
// NeedFuncSym ensures that s·f is exported.
|
||||
// It is only used with -dynlink.
|
||||
// When not compiling for dynamic linking,
|
||||
|
@ -74,6 +74,10 @@ func (sym *Sym) LinksymName() string {
|
||||
return sym.Pkg.Prefix + "." + sym.Name
|
||||
}
|
||||
|
||||
// Deprecated: This method should not be used directly. Instead, use a
|
||||
// higher-level abstraction that directly returns the linker symbol
|
||||
// for a named object. For example, reflectdata.TypeLinksym(t) instead
|
||||
// of reflectdata.TypeSym(t).Linksym().
|
||||
func (sym *Sym) Linksym() *obj.LSym {
|
||||
if sym == nil {
|
||||
return nil
|
||||
|
@ -975,7 +975,7 @@ func usefield(n *ir.SelectorExpr) {
|
||||
|
||||
sym := reflectdata.TrackSym(outer, field)
|
||||
if ir.CurFunc.FieldTrack == nil {
|
||||
ir.CurFunc.FieldTrack = make(map[*types.Sym]struct{})
|
||||
ir.CurFunc.FieldTrack = make(map[*obj.LSym]struct{})
|
||||
}
|
||||
ir.CurFunc.FieldTrack[sym] = struct{}{}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user