]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: do not mark holes in functab
authorCherry Mui <cherryyz@google.com>
Fri, 8 Oct 2021 23:55:17 +0000 (19:55 -0400)
committerCherry Mui <cherryyz@google.com>
Mon, 11 Oct 2021 16:05:38 +0000 (16:05 +0000)
With multiple text sections, there may be holes (non-Go code) in
the PC range of Go code and covered by the functab. Previously, we
use a linear search with actual PCs to find the functab entry. We
need to use special entries to mark holes, so a PC in the hole can
be distinguished from the previous function.

Now, with the previous CL we find if the PC is in between of the
sections upfront in textOff. There is no need to mark holes in the
functab.

Change-Id: I22ff27279422bfc855c2ca35ba0fdfb63234c113
Reviewed-on: https://go-review.googlesource.com/c/go/+/354874
Trust: Cherry Mui <cherryyz@google.com>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/link/internal/ld/pcln.go

index 465c52b6cf07111697be5daef399fbfdbce15647..b57e212794625735471f74af83baddeefc8da0f3 100644 (file)
@@ -72,7 +72,6 @@ func makePclntab(ctxt *Link, container loader.Bitmap) (*pclntab, []*sym.Compilat
 
        // Gather some basic stats and info.
        seenCUs := make(map[*sym.CompilationUnit]struct{})
-       prevSect := ldr.SymSect(ctxt.Textp[0])
        compUnits := []*sym.CompilationUnit{}
        funcs := []loader.Sym{}
 
@@ -86,16 +85,6 @@ func makePclntab(ctxt *Link, container loader.Bitmap) (*pclntab, []*sym.Compilat
                        state.firstFunc = s
                }
                state.lastFunc = s
-               ss := ldr.SymSect(s)
-               if ss != prevSect {
-                       // With multiple text sections, the external linker may
-                       // insert functions between the sections, which are not
-                       // known by Go. This leaves holes in the PC range covered
-                       // by the func table. We need to generate an entry to mark
-                       // the hole.
-                       state.nfunc++
-                       prevSect = ss
-               }
 
                // We need to keep track of all compilation units we see. Some symbols
                // (eg, go.buildid, _cgoexp_, etc) won't have a compilation unit.
@@ -624,30 +613,14 @@ func writePCToFunc(ctxt *Link, sb *loader.SymbolBuilder, funcs []loader.Sym, sta
                }
                return uint32(off)
        }
-       var prevFunc loader.Sym
-       prevSect := ldr.SymSect(funcs[0])
-       funcIndex := 0
        for i, s := range funcs {
-               if thisSect := ldr.SymSect(s); thisSect != prevSect {
-                       // With multiple text sections, there may be a hole here in the
-                       // address space. We use an invalid funcoff value to mark the hole.
-                       // Use the end PC - 1 to distinguish the end of a section vs. the
-                       // start of the next.
-                       // See also runtime/symtab.go:findfunc
-                       prevFuncSize := uint32(ldr.SymSize(prevFunc))
-                       sb.SetUint32(ctxt.Arch, int64(funcIndex*2*4), pcOff(prevFunc)+prevFuncSize-1)
-                       sb.SetUint32(ctxt.Arch, int64((funcIndex*2+1)*4), ^uint32(0))
-                       funcIndex++
-                       prevSect = thisSect
-               }
-               prevFunc = s
-               sb.SetUint32(ctxt.Arch, int64(funcIndex*2*4), pcOff(s))
-               sb.SetUint32(ctxt.Arch, int64((funcIndex*2+1)*4), startLocations[i])
-               funcIndex++
+               sb.SetUint32(ctxt.Arch, int64(i*2*4), pcOff(s))
+               sb.SetUint32(ctxt.Arch, int64((i*2+1)*4), startLocations[i])
        }
 
        // Final entry of table is just end pc offset.
-       sb.SetUint32(ctxt.Arch, int64(funcIndex)*2*4, pcOff(prevFunc)+uint32(ldr.SymSize(prevFunc)))
+       lastFunc := funcs[len(funcs)-1]
+       sb.SetUint32(ctxt.Arch, int64(len(funcs))*2*4, pcOff(lastFunc)+uint32(ldr.SymSize(lastFunc)))
 }
 
 // writeFuncs writes the func structures and pcdata to runtime.functab.