]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] move FuncID creation into the compiler/assembler
authorJeremy Faller <jeremy@golang.org>
Tue, 21 Jul 2020 19:53:30 +0000 (15:53 -0400)
committerJeremy Faller <jeremy@golang.org>
Mon, 3 Aug 2020 17:56:50 +0000 (17:56 +0000)
Leaving creation of the funcID till the linker requires the linker to
load the function and file names into memory. Moving these into the
compiler/assembler prevents this.

This work is a step towards moving all func metadata into the compiler.

Change-Id: Iebffdc5a909adbd03ac263fde3f4c3d492fb1eac
Reviewed-on: https://go-review.googlesource.com/c/go/+/244024
Run-TryBot: Jeremy Faller <jeremy@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Austin Clements <austin@google.com>
src/cmd/compile/internal/gc/closure.go
src/cmd/internal/goobj2/funcinfo.go
src/cmd/internal/goobj2/objfile.go
src/cmd/internal/obj/link.go
src/cmd/internal/obj/objfile.go
src/cmd/internal/obj/objfile2.go
src/cmd/internal/obj/plist.go
src/cmd/internal/objabi/funcid.go
src/cmd/link/internal/ld/pcln.go
src/cmd/link/internal/loader/loader.go

index 9d71c1e2ef2dddb093ceb806071b9793c491d7cb..3bb7bb98345f2a7ce4bf775aeb06fe79b080dca4 100644 (file)
@@ -429,6 +429,7 @@ func typecheckpartialcall(fn *Node, sym *types.Sym) {
        // Create top-level function.
        xfunc := makepartialcall(fn, fn.Type, sym)
        fn.Func = xfunc.Func
+       fn.Func.SetWrapper(true)
        fn.Right = newname(sym)
        fn.Op = OCALLPART
        fn.Type = xfunc.Type
index 36b2de20cd40b42c4c03377214d42ee383deeee9..b525c88b1381c45576a68cb9c1297f76733100eb 100644 (file)
@@ -6,6 +6,7 @@ package goobj2
 
 import (
        "bytes"
+       "cmd/internal/objabi"
        "encoding/binary"
 )
 
@@ -16,6 +17,7 @@ import (
 type FuncInfo struct {
        Args   uint32
        Locals uint32
+       FuncID objabi.FuncID
 
        Pcsp        uint32
        Pcfile      uint32
@@ -38,6 +40,7 @@ func (a *FuncInfo) Write(w *bytes.Buffer) {
 
        writeUint32(a.Args)
        writeUint32(a.Locals)
+       writeUint32(uint32(a.FuncID))
 
        writeUint32(a.Pcsp)
        writeUint32(a.Pcfile)
@@ -72,6 +75,7 @@ func (a *FuncInfo) Read(b []byte) {
 
        a.Args = readUint32()
        a.Locals = readUint32()
+       a.FuncID = objabi.FuncID(readUint32())
 
        a.Pcsp = readUint32()
        a.Pcfile = readUint32()
@@ -120,7 +124,7 @@ type FuncInfoLengths struct {
 func (*FuncInfo) ReadFuncInfoLengths(b []byte) FuncInfoLengths {
        var result FuncInfoLengths
 
-       const numpcdataOff = 24
+       const numpcdataOff = 28
        result.NumPcdata = binary.LittleEndian.Uint32(b[numpcdataOff:])
        result.PcdataOff = numpcdataOff + 4
 
@@ -146,24 +150,26 @@ func (*FuncInfo) ReadArgs(b []byte) uint32 { return binary.LittleEndian.Uint32(b
 
 func (*FuncInfo) ReadLocals(b []byte) uint32 { return binary.LittleEndian.Uint32(b[4:]) }
 
+func (*FuncInfo) ReadFuncID(b []byte) uint32 { return binary.LittleEndian.Uint32(b[8:]) }
+
 // return start and end offsets.
 func (*FuncInfo) ReadPcsp(b []byte) (uint32, uint32) {
-       return binary.LittleEndian.Uint32(b[8:]), binary.LittleEndian.Uint32(b[12:])
+       return binary.LittleEndian.Uint32(b[12:]), binary.LittleEndian.Uint32(b[16:])
 }
 
 // return start and end offsets.
 func (*FuncInfo) ReadPcfile(b []byte) (uint32, uint32) {
-       return binary.LittleEndian.Uint32(b[12:]), binary.LittleEndian.Uint32(b[16:])
+       return binary.LittleEndian.Uint32(b[16:]), binary.LittleEndian.Uint32(b[20:])
 }
 
 // return start and end offsets.
 func (*FuncInfo) ReadPcline(b []byte) (uint32, uint32) {
-       return binary.LittleEndian.Uint32(b[16:]), binary.LittleEndian.Uint32(b[20:])
+       return binary.LittleEndian.Uint32(b[20:]), binary.LittleEndian.Uint32(b[24:])
 }
 
 // return start and end offsets.
 func (*FuncInfo) ReadPcinline(b []byte, pcdataoffset uint32) (uint32, uint32) {
-       return binary.LittleEndian.Uint32(b[20:]), binary.LittleEndian.Uint32(b[pcdataoffset:])
+       return binary.LittleEndian.Uint32(b[24:]), binary.LittleEndian.Uint32(b[pcdataoffset:])
 }
 
 // return start and end offsets.
index 4465cfd5afdb9d5dca77ee869bc96d0eb530fa75..eae9b5587c2f528c1194ac047917c4171cec0c24 100644 (file)
@@ -21,7 +21,7 @@ import (
 // New object file format.
 //
 //    Header struct {
-//       Magic       [...]byte   // "\x00go115ld"
+//       Magic       [...]byte   // "\x00go116ld"
 //       Fingerprint [8]byte
 //       Flags       uint32
 //       Offsets     [...]uint32 // byte offset of each block below
@@ -199,7 +199,7 @@ type Header struct {
        Offsets     [NBlk]uint32
 }
 
-const Magic = "\x00go115ld"
+const Magic = "\x00go116ld"
 
 func (h *Header) Write(w *Writer) {
        w.RawString(h.Magic)
index 195af8494cf044c55f46224ee8f330cbfa0805d3..8d189b71f94da7238e09ea53c46b5195337e7e36 100644 (file)
@@ -400,6 +400,7 @@ type FuncInfo struct {
        Args     int32
        Locals   int32
        Align    int32
+       FuncID   objabi.FuncID
        Text     *Prog
        Autot    map[*LSym]struct{}
        Pcln     Pcln
index c0194c5a6d193b74dc330687e773a3f5e1cd5710..2f28b6eeecebbd5b594ad690067f56592e810844 100644 (file)
@@ -40,7 +40,7 @@ func (ctxt *Link) writeSymDebugNamed(s *LSym, name string) {
        }
        fmt.Fprintf(ctxt.Bso, "size=%d", s.Size)
        if s.Type == objabi.STEXT {
-               fmt.Fprintf(ctxt.Bso, " args=%#x locals=%#x", uint64(s.Func.Args), uint64(s.Func.Locals))
+               fmt.Fprintf(ctxt.Bso, " args=%#x locals=%#x funcid=%#x", uint64(s.Func.Args), uint64(s.Func.Locals), uint64(s.Func.FuncID))
                if s.Leaf() {
                        fmt.Fprintf(ctxt.Bso, " leaf")
                }
index 6cf82779e440ed71520aa495dad3a08c54927082..988ecdf543e04e17e207b51034f30e94c6290050 100644 (file)
@@ -534,6 +534,7 @@ func genFuncInfoSyms(ctxt *Link) {
                o := goobj2.FuncInfo{
                        Args:   uint32(s.Func.Args),
                        Locals: uint32(s.Func.Locals),
+                       FuncID: objabi.FuncID(s.Func.FuncID),
                }
                pc := &s.Func.Pcln
                o.Pcsp = pcdataoff
index b27e6c163d563f983cf55ee6902915a08f77a4b4..afe0ee4ee0c12431a623b39724e830891d555516 100644 (file)
@@ -127,6 +127,8 @@ func (ctxt *Link) InitTextSym(s *LSym, flag int) {
        if s.OnList() {
                ctxt.Diag("symbol %s listed multiple times", s.Name)
        }
+       name := strings.Replace(s.Name, "\"\"", ctxt.Pkgpath, -1)
+       s.Func.FuncID = objabi.GetFuncID(name, flag&WRAPPER != 0)
        s.Set(AttrOnList, true)
        s.Set(AttrDuplicateOK, flag&DUPOK != 0)
        s.Set(AttrNoSplit, flag&NOSPLIT != 0)
index 0fda1db1789556198bc3c552e5c077376a2ee692..6c9336f31cb8081a9b8801577e8ae73e6117a41e 100644 (file)
@@ -4,11 +4,6 @@
 
 package objabi
 
-import (
-       "strconv"
-       "strings"
-)
-
 // A FuncID identifies particular functions that need to be treated
 // specially by the runtime.
 // Note that in some situations involving plugins, there may be multiple
@@ -44,7 +39,10 @@ const (
 
 // Get the function ID for the named function in the named file.
 // The function should be package-qualified.
-func GetFuncID(name, file string) FuncID {
+func GetFuncID(name string, isWrapper bool) FuncID {
+       if isWrapper {
+               return FuncID_wrapper
+       }
        switch name {
        case "runtime.main":
                return FuncID_runtime_main
@@ -98,17 +96,5 @@ func GetFuncID(name, file string) FuncID {
                // Don't show in the call stack (used when invoking defer functions)
                return FuncID_wrapper
        }
-       if file == "<autogenerated>" {
-               return FuncID_wrapper
-       }
-       if strings.HasPrefix(name, "runtime.call") {
-               if _, err := strconv.Atoi(name[12:]); err == nil {
-                       // runtime.callXX reflect call wrappers.
-                       return FuncID_wrapper
-               }
-       }
-       if strings.HasSuffix(name, "-fm") {
-               return FuncID_wrapper
-       }
        return FuncID_normal
 }
index 1b59b80e26bbc98d787f075c45016156dc1ac00b..c6174e378c5ceb84923afe65e40c25cf89a84e83 100644 (file)
@@ -297,7 +297,14 @@ func (state *oldPclnState) genInlTreeSym(fi loader.FuncInfo, arch *sys.Arch, new
                }
 
                inlTreeSym.SetUint16(arch, int64(i*20+0), uint16(call.Parent))
-               inlTreeSym.SetUint8(arch, int64(i*20+2), uint8(objabi.GetFuncID(ldr.SymName(call.Func), "")))
+               inlFunc := ldr.FuncInfo(call.Func)
+
+               var funcID objabi.FuncID
+               if inlFunc.Valid() {
+                       funcID = inlFunc.FuncID()
+               }
+               inlTreeSym.SetUint8(arch, int64(i*20+2), uint8(funcID))
+
                // byte 3 is unused
                inlTreeSym.SetUint32(arch, int64(i*20+4), uint32(val))
                inlTreeSym.SetUint32(arch, int64(i*20+8), uint32(call.Line))
@@ -610,13 +617,10 @@ func (ctxt *Link) pclntab(container loader.Bitmap) *pclntab {
                off = int32(ftab.SetUint32(ctxt.Arch, int64(off), uint32(len(pcdata))))
 
                // funcID uint8
-               var file string
-               if fi.Valid() && fi.NumFile() > 0 {
-                       filesymname := ldr.SymName(fi.File(0))
-                       file = filesymname[len(src.FileSymPrefix):]
+               var funcID objabi.FuncID
+               if fi.Valid() {
+                       funcID = fi.FuncID()
                }
-               funcID := objabi.GetFuncID(ldr.SymName(s), file)
-
                off = int32(ftab.SetUint8(ctxt.Arch, int64(off), uint8(funcID)))
 
                // unused
index 16331e08257d414418781c749fe0424e1d728135..45085f56c1fa76a6df7132b27cddaf61cbe4f656 100644 (file)
@@ -1872,6 +1872,10 @@ func (fi *FuncInfo) Locals() int {
        return int((*goobj2.FuncInfo)(nil).ReadLocals(fi.data))
 }
 
+func (fi *FuncInfo) FuncID() objabi.FuncID {
+       return objabi.FuncID((*goobj2.FuncInfo)(nil).ReadFuncID(fi.data))
+}
+
 func (fi *FuncInfo) Pcsp() []byte {
        pcsp, end := (*goobj2.FuncInfo)(nil).ReadPcsp(fi.data)
        return fi.r.BytesAt(fi.r.PcdataBase()+pcsp, int(end-pcsp))