Skip to content

Commit 0e1bd8b

Browse files
ianlancetaylorgopherbot
authored andcommitted
cmd/link, runtime: don't store text start in pcHeader
The textStart field requires a relocation, the only relocation in pclntab. And nothing uses it. So remove it. Replace it with a zero, which can itself be removed at some point in coordination with Delve. For #76038 Change-Id: I35675c0868c5d957bb375e40b804c516ae0300ca Reviewed-on: https://go-review.googlesource.com/c/go/+/717240 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
1 parent 7347b54 commit 0e1bd8b

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

src/cmd/link/internal/ld/pcln.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ func makeInlSyms(ctxt *Link, funcs []loader.Sym, nameOffsets map[loader.Sym]uint
243243
// generator to fill in its data later.
244244
func (state *pclntab) generatePCHeader(ctxt *Link) {
245245
ldr := ctxt.loader
246-
textStartOff := int64(8 + 2*ctxt.Arch.PtrSize)
247246
size := int64(8 + 8*ctxt.Arch.PtrSize)
248247
writeHeader := func(ctxt *Link, s loader.Sym) {
249248
header := ctxt.loader.MakeSymbolUpdater(s)
@@ -264,10 +263,7 @@ func (state *pclntab) generatePCHeader(ctxt *Link) {
264263
header.SetUint8(ctxt.Arch, 7, uint8(ctxt.Arch.PtrSize))
265264
off := header.SetUint(ctxt.Arch, 8, uint64(state.nfunc))
266265
off = header.SetUint(ctxt.Arch, off, uint64(state.nfiles))
267-
if off != textStartOff {
268-
panic(fmt.Sprintf("pcHeader textStartOff: %d != %d", off, textStartOff))
269-
}
270-
off += int64(ctxt.Arch.PtrSize) // skip runtimeText relocation
266+
off = header.SetUintptr(ctxt.Arch, off, 0) // unused
271267
off = writeSymOffset(off, state.funcnametab)
272268
off = writeSymOffset(off, state.cutab)
273269
off = writeSymOffset(off, state.filetab)
@@ -279,9 +275,6 @@ func (state *pclntab) generatePCHeader(ctxt *Link) {
279275
}
280276

281277
state.pcheader = state.addGeneratedSym(ctxt, "runtime.pcheader", size, writeHeader)
282-
// Create the runtimeText relocation.
283-
sb := ldr.MakeSymbolUpdater(state.pcheader)
284-
sb.SetAddr(ctxt.Arch, textStartOff, ldr.Lookup("runtime.text", 0))
285278
}
286279

287280
// walkFuncs iterates over the funcs, calling a function for each unique

src/runtime/runtime2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ const (
10091009
type _func struct {
10101010
sys.NotInHeap // Only in static data
10111011

1012-
entryOff uint32 // start pc, as offset from moduledata.text/pcHeader.textStart
1012+
entryOff uint32 // start pc, as offset from moduledata.text
10131013
nameOff int32 // function name, as index into moduledata.funcnametab.
10141014

10151015
args int32 // in/out args size

src/runtime/symtab.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,19 @@ func (f *_func) funcInfo() funcInfo {
374374

375375
// pcHeader holds data used by the pclntab lookups.
376376
type pcHeader struct {
377-
magic uint32 // 0xFFFFFFF1
378-
pad1, pad2 uint8 // 0,0
379-
minLC uint8 // min instruction size
380-
ptrSize uint8 // size of a ptr in bytes
381-
nfunc int // number of functions in the module
382-
nfiles uint // number of entries in the file tab
383-
textStart uintptr // base for function entry PC offsets in this module, equal to moduledata.text
377+
magic uint32 // 0xFFFFFFF1
378+
pad1, pad2 uint8 // 0,0
379+
minLC uint8 // min instruction size
380+
ptrSize uint8 // size of a ptr in bytes
381+
nfunc int // number of functions in the module
382+
nfiles uint // number of entries in the file tab
383+
384+
// The next field used to be textStart. This is no longer stored
385+
// as it requires a relocation. Code should use the moduledata text
386+
// field instead. This unused field can be removed in coordination
387+
// with Delve.
388+
_ uintptr
389+
384390
funcnameOffset uintptr // offset to the funcnametab variable from pcHeader
385391
cuOffset uintptr // offset to the cutab variable from pcHeader
386392
filetabOffset uintptr // offset to the filetab variable from pcHeader
@@ -618,10 +624,9 @@ func moduledataverify1(datap *moduledata) {
618624
// Check that the pclntab's format is valid.
619625
hdr := datap.pcHeader
620626
if hdr.magic != 0xfffffff1 || hdr.pad1 != 0 || hdr.pad2 != 0 ||
621-
hdr.minLC != sys.PCQuantum || hdr.ptrSize != goarch.PtrSize || hdr.textStart != datap.text {
627+
hdr.minLC != sys.PCQuantum || hdr.ptrSize != goarch.PtrSize {
622628
println("runtime: pcHeader: magic=", hex(hdr.magic), "pad1=", hdr.pad1, "pad2=", hdr.pad2,
623-
"minLC=", hdr.minLC, "ptrSize=", hdr.ptrSize, "pcHeader.textStart=", hex(hdr.textStart),
624-
"text=", hex(datap.text), "pluginpath=", datap.pluginpath)
629+
"minLC=", hdr.minLC, "ptrSize=", hdr.ptrSize, "pluginpath=", datap.pluginpath)
625630
throw("invalid function symbol table")
626631
}
627632

0 commit comments

Comments
 (0)