cmd/link: do not mark holes in functab

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>
diff --git a/src/cmd/link/internal/ld/pcln.go b/src/cmd/link/internal/ld/pcln.go
index 465c52b..b57e212 100644
--- a/src/cmd/link/internal/ld/pcln.go
+++ b/src/cmd/link/internal/ld/pcln.go
@@ -72,7 +72,6 @@
 
 	// 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 @@
 			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 @@
 		}
 		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.