]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: mark function Syms
authorAustin Clements <austin@google.com>
Thu, 1 Nov 2018 16:20:28 +0000 (12:20 -0400)
committerAustin Clements <austin@google.com>
Mon, 12 Nov 2018 20:46:50 +0000 (20:46 +0000)
In order to mark the obj.LSyms produced by the compiler with the
correct ABI, we need to know which types.Syms refer to function
symbols. This CL adds a flag to types.Syms to mark symbols for
functions, and sets this flag everywhere we create a PFUNC-class node,
and in the one place where we directly create function symbols without
always wrapping them in a PFUNC node (methodSym).

We'll use this information to construct obj.LSyms with correct ABI
information.

For #27539.

Change-Id: Ie3ac8bf3da013e449e78f6ca85546a055f275463
Reviewed-on: https://go-review.googlesource.com/c/147158
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/alg.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/iimport.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/walk.go
src/cmd/compile/internal/types/sym.go

index b112ff679723c2a1e05f8351b616910828a7e424..f52c15b1f5c3cf9714b6f82b91f200cead009323 100644 (file)
@@ -330,6 +330,7 @@ func hashfor(t *types.Type) *Node {
 
        n := newname(sym)
        n.SetClass(PFUNC)
+       n.Sym.SetFunc(true)
        n.Type = functype(nil, []*Node{
                anonfield(types.NewPtr(t)),
                anonfield(types.Types[TUINTPTR]),
index 645ba7558c1cda91866560d6c8d8f84d7589633c..d4d0708b1c876c728a961abee879ee65cea07851 100644 (file)
@@ -125,6 +125,9 @@ func declare(n *Node, ctxt Class) {
        s.Def = asTypesNode(n)
        n.Name.Vargen = int32(gen)
        n.SetClass(ctxt)
+       if ctxt == PFUNC {
+               n.Sym.SetFunc(true)
+       }
 
        autoexport(n, ctxt)
 }
@@ -801,8 +804,12 @@ func origSym(s *types.Sym) *types.Sym {
 // Method symbols can be used to distinguish the same method appearing
 // in different method sets. For example, T.M and (*T).M have distinct
 // method symbols.
+//
+// The returned symbol will be marked as a function.
 func methodSym(recv *types.Type, msym *types.Sym) *types.Sym {
-       return methodSymSuffix(recv, msym, "")
+       sym := methodSymSuffix(recv, msym, "")
+       sym.SetFunc(true)
+       return sym
 }
 
 // methodSymSuffix is like methodsym, but allows attaching a
index 85916509cb9f202acfa3618f9457d0a937c600b6..4fe1f8b95f12d81e1c9633c001062235ab3ba5ab 100644 (file)
@@ -140,6 +140,9 @@ func importobj(ipkg *types.Pkg, pos src.XPos, s *types.Sym, op Op, ctxt Class, t
        n.Op = op
        n.Pos = pos
        n.SetClass(ctxt)
+       if ctxt == PFUNC {
+               n.Sym.SetFunc(true)
+       }
        n.Type = t
        return n
 }
index 8614c7a14f3835c54df0af6d7c148870cb94c876..c9198499dd6430aac394df359081bf94f6442704 100644 (file)
@@ -334,6 +334,7 @@ func (r *importReader) doDecl(n *Node) {
                        m := newfuncnamel(mpos, methodSym(recv.Type, msym))
                        m.Type = mtyp
                        m.SetClass(PFUNC)
+                       // methodSym already marked m.Sym as a function.
 
                        // (comment from parser.go)
                        // inl.C's inlnode in on a dotmeth node expects to find the inlineable body as
index 55d6d55e6dfc886c82e77685ecc3dfeb792ad813..087371c6f6c9ca0c9b75709edd6a800dbc286432 100644 (file)
@@ -649,6 +649,11 @@ func Main(archInit func(*Arch)) {
        Curfn = nil
        peekitabs()
 
+       // The "init" function is the only user-spellable symbol that
+       // we construct later. Mark it as a function now before
+       // anything can ask for its Linksym.
+       lookup("init").SetFunc(true)
+
        // Phase 8: Compile top level functions.
        // Don't use range--walk can add functions to xtop.
        timings.Start("be", "compilefuncs")
index b0ccd01752470f1c65e106e756685b636aed0825..d43dc8e6175966a85e581e121bf1dbe745395dbb 100644 (file)
@@ -3670,6 +3670,7 @@ func (s *state) call(n *Node, k callKind) *ssa.Value {
                n2 := newnamel(fn.Pos, fn.Sym)
                n2.Name.Curfn = s.curfn
                n2.SetClass(PFUNC)
+               n2.Sym.SetFunc(true)
                n2.Pos = fn.Pos
                n2.Type = types.Types[TUINT8] // dummy type for a static closure. Could use runtime.funcval if we had it.
                closure = s.expr(n2)
index 97f7e4880d9c7cc6c8c5645274ba6993b8dc5947..53bfcba3ffc7bd2d17348c20b5d3c6b54b8e3074 100644 (file)
@@ -1619,6 +1619,7 @@ func hashmem(t *types.Type) *Node {
 
        n := newname(sym)
        n.SetClass(PFUNC)
+       n.Sym.SetFunc(true)
        n.Type = functype(nil, []*Node{
                anonfield(types.NewPtr(t)),
                anonfield(types.Types[TUINTPTR]),
index e6a8ed4bda149ae951ad8c61cf12c22a413e666e..371e0924e71551ffbeef8d945246f282fccdf571 100644 (file)
@@ -2513,6 +2513,7 @@ func typecheckMethodExpr(n *Node) (res *Node) {
        n.Type = methodfunc(m.Type, n.Left.Type)
        n.Xoffset = 0
        n.SetClass(PFUNC)
+       // methodSym already marked n.Sym as a function.
        return n
 }
 
index 37d995b1bdf8cab872e172210eb97af0a041434b..5056212984ca8caab0c43456362602287da72753 100644 (file)
@@ -3063,6 +3063,7 @@ func eqfor(t *types.Type) (n *Node, needsize bool) {
                sym := typesymprefix(".eq", t)
                n := newname(sym)
                n.SetClass(PFUNC)
+               n.Sym.SetFunc(true)
                n.Type = functype(nil, []*Node{
                        anonfield(types.NewPtr(t)),
                        anonfield(types.NewPtr(t)),
index b7fd7ae9fbbbe3f84fe148d1017ce333bcef41d8..28583378d9dbe8f616cef335fa396be98d0096dd 100644 (file)
@@ -42,6 +42,7 @@ const (
        symSiggen // type symbol has been generated
        symAsm    // on asmlist, for writing to -asmhdr
        symAlgGen // algorithm table has been generated
+       symFunc   // function symbol; uses internal ABI
 )
 
 func (sym *Sym) OnExportList() bool { return sym.flags&symOnExportList != 0 }
@@ -49,12 +50,14 @@ func (sym *Sym) Uniq() bool         { return sym.flags&symUniq != 0 }
 func (sym *Sym) Siggen() bool       { return sym.flags&symSiggen != 0 }
 func (sym *Sym) Asm() bool          { return sym.flags&symAsm != 0 }
 func (sym *Sym) AlgGen() bool       { return sym.flags&symAlgGen != 0 }
+func (sym *Sym) Func() bool         { return sym.flags&symFunc != 0 }
 
 func (sym *Sym) SetOnExportList(b bool) { sym.flags.set(symOnExportList, b) }
 func (sym *Sym) SetUniq(b bool)         { sym.flags.set(symUniq, b) }
 func (sym *Sym) SetSiggen(b bool)       { sym.flags.set(symSiggen, b) }
 func (sym *Sym) SetAsm(b bool)          { sym.flags.set(symAsm, b) }
 func (sym *Sym) SetAlgGen(b bool)       { sym.flags.set(symAlgGen, b) }
+func (sym *Sym) SetFunc(b bool)         { sym.flags.set(symFunc, b) }
 
 func (sym *Sym) IsBlank() bool {
        return sym != nil && sym.Name == "_"