Skip to content

Commit be6bc7b

Browse files
committed
vulncheck/internal/gosym: sync with new version of gosym
Follows changes in https://go-review.git.corp.google.com/c/go/+/429638 Change-Id: Ic4b55f5a6f256f2aec7bad80ab390f668531fc1e Reviewed-on: https://go-review.googlesource.com/c/vuln/+/443135 Reviewed-by: Jonathan Amsterdam <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Run-TryBot: Zvonimir Pavlinovic <[email protected]>
1 parent b9c342a commit be6bc7b

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

vulncheck/internal/gosym/additions.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ const (
1717
funcdata_InlTree = 3
1818
)
1919

20-
func (f funcData) npcdata() uint32 { return f.field(7) }
21-
func (f funcData) nfuncdata() uint32 { return uint32(f.data[f.fieldOffset(9)+3]) }
22-
2320
// InlineTree returns the inline tree for Func f as a sequence of InlinedCalls.
2421
// goFuncValue is the value of the gosym.FuncSymName symbol.
2522
// baseAddr is the address of the memory region (ELF Prog) containing goFuncValue.
@@ -88,23 +85,29 @@ type rawInlinedCall112 struct {
8885
// rawInlinedCall120 is the encoding of entries in the FUNCDATA_InlTree table
8986
// from Go 1.20. It is equivalent to runtime.inlinedCall.
9087
type rawInlinedCall120 struct {
91-
FuncID uint8 // type of the called function
92-
_ [3]byte
93-
NameOff int32 // offset into pclntab for name of called function
94-
ParentPC int32 // position of an instruction whose source position is the call site (offset from entry)
88+
FuncID uint8 // type of the called function
89+
_ [3]byte
90+
NameOff int32 // offset into pclntab for name of called function
91+
ParentPC int32 // position of an instruction whose source position is the call site (offset from entry)
92+
StartLine int32 // line number of start of function (func keyword/TEXT directive)
93+
}
94+
95+
func (f funcData) npcdata() uint32 { return f.field(7) }
96+
func (f funcData) nfuncdata(numFuncFields uint32) uint32 {
97+
return uint32(f.data[f.fieldOffset(numFuncFields-1)+3])
9598
}
9699

97-
func (f funcData) funcdataOffset(i uint8) uint32 {
98-
if uint32(i) >= f.nfuncdata() {
100+
func (f funcData) funcdataOffset(i uint8, numFuncFields uint32) uint32 {
101+
if uint32(i) >= f.nfuncdata(numFuncFields) {
99102
return ^uint32(0)
100103
}
101104
var off uint32
102105
if f.t.version >= ver118 {
103-
off = f.fieldOffset(10) + // skip fixed part of _func
106+
off = f.fieldOffset(numFuncFields) + // skip fixed part of _func
104107
f.npcdata()*4 + // skip pcdata
105108
uint32(i)*4 // index of i'th FUNCDATA
106109
} else {
107-
off = f.fieldOffset(10) + // skip fixed part of _func
110+
off = f.fieldOffset(numFuncFields) + // skip fixed part of _func
108111
f.npcdata()*4
109112
off += uint32(i) * f.t.ptrsize
110113
}
@@ -121,11 +124,11 @@ func (f funcData) fieldOffset(n uint32) uint32 {
121124
return sz0 + (n-1)*4 // subsequent fields are 4 bytes each
122125
}
123126

124-
func (f funcData) pcdataOffset(i uint8) uint32 {
127+
func (f funcData) pcdataOffset(i uint8, numFuncFields uint32) uint32 {
125128
if uint32(i) >= f.npcdata() {
126129
return ^uint32(0)
127130
}
128-
off := f.fieldOffset(10) + // skip fixed part of _func
131+
off := f.fieldOffset(numFuncFields) + // skip fixed part of _func
129132
uint32(i)*4 // index of i'th PCDATA
130133
return f.t.binary.Uint32(f.data[off:])
131134
}
@@ -134,11 +137,11 @@ func (f funcData) pcdataOffset(i uint8) uint32 {
134137
// pc-value table in info. This is the only way to determine how many
135138
// IndexedCalls are in an inline tree, since the data of the tree itself is not
136139
// delimited in any way.
137-
func (t *LineTable) maxInlineTreeIndexValue(info funcData) int {
140+
func (t *LineTable) maxInlineTreeIndexValue(info funcData, numFuncFields uint32) int {
138141
if info.npcdata() <= pcdata_InlTreeIndex {
139142
return -1
140143
}
141-
off := info.pcdataOffset(pcdata_InlTreeIndex)
144+
off := info.pcdataOffset(pcdata_InlTreeIndex, numFuncFields)
142145
p := t.pctab[off:]
143146
val := int32(-1)
144147
max := int32(-1)

vulncheck/internal/gosym/pclntab.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,19 @@ func (t *LineTable) go12Funcs() []Func {
311311
info := t.funcData(uint32(i))
312312
f.LineTable = t
313313
f.FrameSize = int(info.deferreturn())
314-
f.inlineTreeOffset = info.funcdataOffset(funcdata_InlTree)
315-
f.inlineTreeCount = 1 + t.maxInlineTreeIndexValue(info)
314+
315+
// Additions.
316+
// numFuncField is the number of (32 bit) fields in _func (src/runtime/runtime2.go)
317+
// Note that the last 4 fields are 32 bits combined. This number is 11 for go1.20,
318+
// 10 for earlier versions down to go1.16, and 9 before that.
319+
var numFuncFields uint32 = 11
320+
if t.version < ver116 {
321+
numFuncFields = 9
322+
} else if t.version < ver120 {
323+
numFuncFields = 10
324+
}
325+
f.inlineTreeOffset = info.funcdataOffset(funcdata_InlTree, numFuncFields)
326+
f.inlineTreeCount = 1 + t.maxInlineTreeIndexValue(info, numFuncFields)
316327

317328
syms[i] = Sym{
318329
Value: f.Entry,

0 commit comments

Comments
 (0)