]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: make funcSize a constant
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 29 Sep 2021 00:26:24 +0000 (17:26 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Wed, 29 Sep 2021 22:14:44 +0000 (22:14 +0000)
Now that it no longer depends on the size of a pointer,
we can make it a constant, which simplifies a bit of code.

Change-Id: I1b7c3b1b648da5c8960378a02b9263e2cc902441
Reviewed-on: https://go-review.googlesource.com/c/go/+/352952
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/link/internal/ld/pcln.go

index 08b33ed815759c377a5554280d70e3dc4f30e42d..5f4724970ce8dfebb64af6f9acd82ed321b34829 100644 (file)
@@ -17,11 +17,10 @@ import (
        "strings"
 )
 
+const funcSize = 10 * 4 // funcSize is the size of the _func object in runtime/runtime2.go
+
 // pclntab holds the state needed for pclntab generation.
 type pclntab struct {
-       // The size of the func object in the runtime.
-       funcSize uint32
-
        // The first and last functions found.
        firstFunc, lastFunc loader.Sym
 
@@ -69,11 +68,7 @@ func (state *pclntab) addGeneratedSym(ctxt *Link, name string, size int64, f gen
 // generate pclntab.
 func makePclntab(ctxt *Link, container loader.Bitmap) (*pclntab, []*sym.CompilationUnit, []loader.Sym) {
        ldr := ctxt.loader
-
-       state := &pclntab{
-               // This is the size of the _func object in runtime/runtime2.go.
-               funcSize: 10 * 4,
-       }
+       state := new(pclntab)
 
        // Gather some basic stats and info.
        seenCUs := make(map[*sym.CompilationUnit]struct{})
@@ -671,7 +666,7 @@ func (state pclntab) calculateFunctabSize(ctxt *Link, funcs []loader.Sym) (int64
                size = Rnd(size, int64(ctxt.Arch.PtrSize))
                startLocations[i] = uint32(size)
                fi := ldr.FuncInfo(s)
-               size += int64(state.funcSize)
+               size += funcSize
                if fi.Valid() {
                        fi.Preload()
                        numFuncData := ldr.NumFuncdata(s)
@@ -748,7 +743,7 @@ func (state *pclntab) writeFuncData(ctxt *Link, sb *loader.SymbolBuilder, funcs
                // Missing funcdata will be 0 (nil pointer).
                funcdata = funcData(ldr, s, fi, inlSyms[s], funcdata)
                if len(funcdata) > 0 {
-                       off := int64(startLocations[i] + state.funcSize + numPCData(ldr, s, fi)*4)
+                       off := int64(startLocations[i] + funcSize + numPCData(ldr, s, fi)*4)
                        off = Rnd(off, int64(ctxt.Arch.PtrSize))
                        for j := range funcdata {
                                dataoff := off + int64(ctxt.Arch.PtrSize*j)