src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

pclntab.go (19457B)


      1 // Copyright 2009 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 /*
      6  * Line tables
      7  */
      8 
      9 package gosym
     10 
     11 import (
     12 	"bytes"
     13 	"encoding/binary"
     14 	"sort"
     15 	"sync"
     16 )
     17 
     18 // version of the pclntab
     19 type version int
     20 
     21 const (
     22 	verUnknown version = iota
     23 	ver11
     24 	ver12
     25 	ver116
     26 	ver118
     27 	ver120
     28 )
     29 
     30 // A LineTable is a data structure mapping program counters to line numbers.
     31 //
     32 // In Go 1.1 and earlier, each function (represented by a Func) had its own LineTable,
     33 // and the line number corresponded to a numbering of all source lines in the
     34 // program, across all files. That absolute line number would then have to be
     35 // converted separately to a file name and line number within the file.
     36 //
     37 // In Go 1.2, the format of the data changed so that there is a single LineTable
     38 // for the entire program, shared by all Funcs, and there are no absolute line
     39 // numbers, just line numbers within specific files.
     40 //
     41 // For the most part, LineTable's methods should be treated as an internal
     42 // detail of the package; callers should use the methods on Table instead.
     43 type LineTable struct {
     44 	Data []byte
     45 	PC   uint64
     46 	Line int
     47 
     48 	// This mutex is used to keep parsing of pclntab synchronous.
     49 	mu sync.Mutex
     50 
     51 	// Contains the version of the pclntab section.
     52 	version version
     53 
     54 	// Go 1.2/1.16/1.18 state
     55 	binary      binary.ByteOrder
     56 	quantum     uint32
     57 	ptrsize     uint32
     58 	textStart   uint64 // address of runtime.text symbol (1.18+)
     59 	funcnametab []byte
     60 	cutab       []byte
     61 	funcdata    []byte
     62 	functab     []byte
     63 	nfunctab    uint32
     64 	filetab     []byte
     65 	pctab       []byte // points to the pctables.
     66 	nfiletab    uint32
     67 	funcNames   map[uint32]string // cache the function names
     68 	strings     map[uint32]string // interned substrings of Data, keyed by offset
     69 	// fileMap varies depending on the version of the object file.
     70 	// For ver12, it maps the name to the index in the file table.
     71 	// For ver116, it maps the name to the offset in filetab.
     72 	fileMap map[string]uint32
     73 }
     74 
     75 // NOTE(rsc): This is wrong for GOARCH=arm, which uses a quantum of 4,
     76 // but we have no idea whether we're using arm or not. This only
     77 // matters in the old (pre-Go 1.2) symbol table format, so it's not worth
     78 // fixing.
     79 const oldQuantum = 1
     80 
     81 func (t *LineTable) parse(targetPC uint64, targetLine int) (b []byte, pc uint64, line int) {
     82 	// The PC/line table can be thought of as a sequence of
     83 	//  <pc update>* <line update>
     84 	// batches. Each update batch results in a (pc, line) pair,
     85 	// where line applies to every PC from pc up to but not
     86 	// including the pc of the next pair.
     87 	//
     88 	// Here we process each update individually, which simplifies
     89 	// the code, but makes the corner cases more confusing.
     90 	b, pc, line = t.Data, t.PC, t.Line
     91 	for pc <= targetPC && line != targetLine && len(b) > 0 {
     92 		code := b[0]
     93 		b = b[1:]
     94 		switch {
     95 		case code == 0:
     96 			if len(b) < 4 {
     97 				b = b[0:0]
     98 				break
     99 			}
    100 			val := binary.BigEndian.Uint32(b)
    101 			b = b[4:]
    102 			line += int(val)
    103 		case code <= 64:
    104 			line += int(code)
    105 		case code <= 128:
    106 			line -= int(code - 64)
    107 		default:
    108 			pc += oldQuantum * uint64(code-128)
    109 			continue
    110 		}
    111 		pc += oldQuantum
    112 	}
    113 	return b, pc, line
    114 }
    115 
    116 func (t *LineTable) slice(pc uint64) *LineTable {
    117 	data, pc, line := t.parse(pc, -1)
    118 	return &LineTable{Data: data, PC: pc, Line: line}
    119 }
    120 
    121 // PCToLine returns the line number for the given program counter.
    122 //
    123 // Deprecated: Use Table's PCToLine method instead.
    124 func (t *LineTable) PCToLine(pc uint64) int {
    125 	if t.isGo12() {
    126 		return t.go12PCToLine(pc)
    127 	}
    128 	_, _, line := t.parse(pc, -1)
    129 	return line
    130 }
    131 
    132 // LineToPC returns the program counter for the given line number,
    133 // considering only program counters before maxpc.
    134 //
    135 // Deprecated: Use Table's LineToPC method instead.
    136 func (t *LineTable) LineToPC(line int, maxpc uint64) uint64 {
    137 	if t.isGo12() {
    138 		return 0
    139 	}
    140 	_, pc, line1 := t.parse(maxpc, line)
    141 	if line1 != line {
    142 		return 0
    143 	}
    144 	// Subtract quantum from PC to account for post-line increment
    145 	return pc - oldQuantum
    146 }
    147 
    148 // NewLineTable returns a new PC/line table
    149 // corresponding to the encoded data.
    150 // Text must be the start address of the
    151 // corresponding text segment.
    152 func NewLineTable(data []byte, text uint64) *LineTable {
    153 	return &LineTable{Data: data, PC: text, Line: 0, funcNames: make(map[uint32]string), strings: make(map[uint32]string)}
    154 }
    155 
    156 // Go 1.2 symbol table format.
    157 // See golang.org/s/go12symtab.
    158 //
    159 // A general note about the methods here: rather than try to avoid
    160 // index out of bounds errors, we trust Go to detect them, and then
    161 // we recover from the panics and treat them as indicative of a malformed
    162 // or incomplete table.
    163 //
    164 // The methods called by symtab.go, which begin with "go12" prefixes,
    165 // are expected to have that recovery logic.
    166 
    167 // isGo12 reports whether this is a Go 1.2 (or later) symbol table.
    168 func (t *LineTable) isGo12() bool {
    169 	t.parsePclnTab()
    170 	return t.version >= ver12
    171 }
    172 
    173 const (
    174 	go12magic  = 0xfffffffb
    175 	go116magic = 0xfffffffa
    176 	go118magic = 0xfffffff0
    177 	go120magic = 0xfffffff1
    178 )
    179 
    180 // uintptr returns the pointer-sized value encoded at b.
    181 // The pointer size is dictated by the table being read.
    182 func (t *LineTable) uintptr(b []byte) uint64 {
    183 	if t.ptrsize == 4 {
    184 		return uint64(t.binary.Uint32(b))
    185 	}
    186 	return t.binary.Uint64(b)
    187 }
    188 
    189 // parsePclnTab parses the pclntab, setting the version.
    190 func (t *LineTable) parsePclnTab() {
    191 	t.mu.Lock()
    192 	defer t.mu.Unlock()
    193 	if t.version != verUnknown {
    194 		return
    195 	}
    196 
    197 	// Note that during this function, setting the version is the last thing we do.
    198 	// If we set the version too early, and parsing failed (likely as a panic on
    199 	// slice lookups), we'd have a mistaken version.
    200 	//
    201 	// Error paths through this code will default the version to 1.1.
    202 	t.version = ver11
    203 
    204 	if !disableRecover {
    205 		defer func() {
    206 			// If we panic parsing, assume it's a Go 1.1 pclntab.
    207 			_ = recover()
    208 		}()
    209 	}
    210 
    211 	// Check header: 4-byte magic, two zeros, pc quantum, pointer size.
    212 	if len(t.Data) < 16 || t.Data[4] != 0 || t.Data[5] != 0 ||
    213 		(t.Data[6] != 1 && t.Data[6] != 2 && t.Data[6] != 4) || // pc quantum
    214 		(t.Data[7] != 4 && t.Data[7] != 8) { // pointer size
    215 		return
    216 	}
    217 
    218 	var possibleVersion version
    219 	leMagic := binary.LittleEndian.Uint32(t.Data)
    220 	beMagic := binary.BigEndian.Uint32(t.Data)
    221 	switch {
    222 	case leMagic == go12magic:
    223 		t.binary, possibleVersion = binary.LittleEndian, ver12
    224 	case beMagic == go12magic:
    225 		t.binary, possibleVersion = binary.BigEndian, ver12
    226 	case leMagic == go116magic:
    227 		t.binary, possibleVersion = binary.LittleEndian, ver116
    228 	case beMagic == go116magic:
    229 		t.binary, possibleVersion = binary.BigEndian, ver116
    230 	case leMagic == go118magic:
    231 		t.binary, possibleVersion = binary.LittleEndian, ver118
    232 	case beMagic == go118magic:
    233 		t.binary, possibleVersion = binary.BigEndian, ver118
    234 	case leMagic == go120magic:
    235 		t.binary, possibleVersion = binary.LittleEndian, ver120
    236 	case beMagic == go120magic:
    237 		t.binary, possibleVersion = binary.BigEndian, ver120
    238 	default:
    239 		return
    240 	}
    241 	t.version = possibleVersion
    242 
    243 	// quantum and ptrSize are the same between 1.2, 1.16, and 1.18
    244 	t.quantum = uint32(t.Data[6])
    245 	t.ptrsize = uint32(t.Data[7])
    246 
    247 	offset := func(word uint32) uint64 {
    248 		return t.uintptr(t.Data[8+word*t.ptrsize:])
    249 	}
    250 	data := func(word uint32) []byte {
    251 		return t.Data[offset(word):]
    252 	}
    253 
    254 	switch possibleVersion {
    255 	case ver118, ver120:
    256 		t.nfunctab = uint32(offset(0))
    257 		t.nfiletab = uint32(offset(1))
    258 		t.textStart = t.PC // use the start PC instead of reading from the table, which may be unrelocated
    259 		t.funcnametab = data(3)
    260 		t.cutab = data(4)
    261 		t.filetab = data(5)
    262 		t.pctab = data(6)
    263 		t.funcdata = data(7)
    264 		t.functab = data(7)
    265 		functabsize := (int(t.nfunctab)*2 + 1) * t.functabFieldSize()
    266 		t.functab = t.functab[:functabsize]
    267 	case ver116:
    268 		t.nfunctab = uint32(offset(0))
    269 		t.nfiletab = uint32(offset(1))
    270 		t.funcnametab = data(2)
    271 		t.cutab = data(3)
    272 		t.filetab = data(4)
    273 		t.pctab = data(5)
    274 		t.funcdata = data(6)
    275 		t.functab = data(6)
    276 		functabsize := (int(t.nfunctab)*2 + 1) * t.functabFieldSize()
    277 		t.functab = t.functab[:functabsize]
    278 	case ver12:
    279 		t.nfunctab = uint32(t.uintptr(t.Data[8:]))
    280 		t.funcdata = t.Data
    281 		t.funcnametab = t.Data
    282 		t.functab = t.Data[8+t.ptrsize:]
    283 		t.pctab = t.Data
    284 		functabsize := (int(t.nfunctab)*2 + 1) * t.functabFieldSize()
    285 		fileoff := t.binary.Uint32(t.functab[functabsize:])
    286 		t.functab = t.functab[:functabsize]
    287 		t.filetab = t.Data[fileoff:]
    288 		t.nfiletab = t.binary.Uint32(t.filetab)
    289 		t.filetab = t.filetab[:t.nfiletab*4]
    290 	default:
    291 		panic("unreachable")
    292 	}
    293 }
    294 
    295 // go12Funcs returns a slice of Funcs derived from the Go 1.2+ pcln table.
    296 func (t *LineTable) go12Funcs() []Func {
    297 	// Assume it is malformed and return nil on error.
    298 	if !disableRecover {
    299 		defer func() {
    300 			_ = recover()
    301 		}()
    302 	}
    303 
    304 	ft := t.funcTab()
    305 	funcs := make([]Func, ft.Count())
    306 	syms := make([]Sym, len(funcs))
    307 	for i := range funcs {
    308 		f := &funcs[i]
    309 		f.Entry = ft.pc(i)
    310 		f.End = ft.pc(i + 1)
    311 		info := t.funcData(uint32(i))
    312 		f.LineTable = t
    313 		f.FrameSize = int(info.deferreturn())
    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)
    327 
    328 		syms[i] = Sym{
    329 			Value:     f.Entry,
    330 			Type:      'T',
    331 			Name:      t.funcName(info.nameOff()),
    332 			GoType:    0,
    333 			Func:      f,
    334 			goVersion: t.version,
    335 		}
    336 		f.Sym = &syms[i]
    337 	}
    338 	return funcs
    339 }
    340 
    341 // findFunc returns the funcData corresponding to the given program counter.
    342 func (t *LineTable) findFunc(pc uint64) funcData {
    343 	ft := t.funcTab()
    344 	if pc < ft.pc(0) || pc >= ft.pc(ft.Count()) {
    345 		return funcData{}
    346 	}
    347 	idx := sort.Search(int(t.nfunctab), func(i int) bool {
    348 		return ft.pc(i) > pc
    349 	})
    350 	idx--
    351 	return t.funcData(uint32(idx))
    352 }
    353 
    354 // readvarint reads, removes, and returns a varint from *pp.
    355 func (t *LineTable) readvarint(pp *[]byte) uint32 {
    356 	var v, shift uint32
    357 	p := *pp
    358 	for shift = 0; ; shift += 7 {
    359 		b := p[0]
    360 		p = p[1:]
    361 		v |= (uint32(b) & 0x7F) << shift
    362 		if b&0x80 == 0 {
    363 			break
    364 		}
    365 	}
    366 	*pp = p
    367 	return v
    368 }
    369 
    370 // funcName returns the name of the function found at off.
    371 func (t *LineTable) funcName(off uint32) string {
    372 	if s, ok := t.funcNames[off]; ok {
    373 		return s
    374 	}
    375 	i := bytes.IndexByte(t.funcnametab[off:], 0)
    376 	s := string(t.funcnametab[off : off+uint32(i)])
    377 	t.funcNames[off] = s
    378 	return s
    379 }
    380 
    381 // stringFrom returns a Go string found at off from a position.
    382 func (t *LineTable) stringFrom(arr []byte, off uint32) string {
    383 	if s, ok := t.strings[off]; ok {
    384 		return s
    385 	}
    386 	i := bytes.IndexByte(arr[off:], 0)
    387 	s := string(arr[off : off+uint32(i)])
    388 	t.strings[off] = s
    389 	return s
    390 }
    391 
    392 // string returns a Go string found at off.
    393 func (t *LineTable) string(off uint32) string {
    394 	return t.stringFrom(t.funcdata, off)
    395 }
    396 
    397 // functabFieldSize returns the size in bytes of a single functab field.
    398 func (t *LineTable) functabFieldSize() int {
    399 	if t.version >= ver118 {
    400 		return 4
    401 	}
    402 	return int(t.ptrsize)
    403 }
    404 
    405 // funcTab returns t's funcTab.
    406 func (t *LineTable) funcTab() funcTab {
    407 	return funcTab{LineTable: t, sz: t.functabFieldSize()}
    408 }
    409 
    410 // funcTab is memory corresponding to a slice of functab structs, followed by an invalid PC.
    411 // A functab struct is a PC and a func offset.
    412 type funcTab struct {
    413 	*LineTable
    414 	sz int // cached result of t.functabFieldSize
    415 }
    416 
    417 // Count returns the number of func entries in f.
    418 func (f funcTab) Count() int {
    419 	return int(f.nfunctab)
    420 }
    421 
    422 // pc returns the PC of the i'th func in f.
    423 func (f funcTab) pc(i int) uint64 {
    424 	u := f.uint(f.functab[2*i*f.sz:])
    425 	if f.version >= ver118 {
    426 		u += f.textStart
    427 	}
    428 	return u
    429 }
    430 
    431 // funcOff returns the funcdata offset of the i'th func in f.
    432 func (f funcTab) funcOff(i int) uint64 {
    433 	return f.uint(f.functab[(2*i+1)*f.sz:])
    434 }
    435 
    436 // uint returns the uint stored at b.
    437 func (f funcTab) uint(b []byte) uint64 {
    438 	if f.sz == 4 {
    439 		return uint64(f.binary.Uint32(b))
    440 	}
    441 	return f.binary.Uint64(b)
    442 }
    443 
    444 // funcData is memory corresponding to an _func struct.
    445 type funcData struct {
    446 	t    *LineTable // LineTable this data is a part of
    447 	data []byte     // raw memory for the function
    448 }
    449 
    450 // funcData returns the ith funcData in t.functab.
    451 func (t *LineTable) funcData(i uint32) funcData {
    452 	data := t.funcdata[t.funcTab().funcOff(int(i)):]
    453 	return funcData{t: t, data: data}
    454 }
    455 
    456 // IsZero reports whether f is the zero value.
    457 func (f funcData) IsZero() bool {
    458 	return f.t == nil && f.data == nil
    459 }
    460 
    461 // entryPC returns the func's entry PC.
    462 func (f *funcData) entryPC() uint64 {
    463 	// In Go 1.18, the first field of _func changed
    464 	// from a uintptr entry PC to a uint32 entry offset.
    465 	if f.t.version >= ver118 {
    466 		// TODO: support multiple text sections.
    467 		// See runtime/symtab.go:(*moduledata).textAddr.
    468 		return uint64(f.t.binary.Uint32(f.data)) + f.t.textStart
    469 	}
    470 	return f.t.uintptr(f.data)
    471 }
    472 
    473 func (f funcData) nameOff() uint32     { return f.field(1) }
    474 func (f funcData) deferreturn() uint32 { return f.field(3) }
    475 func (f funcData) pcfile() uint32      { return f.field(5) }
    476 func (f funcData) pcln() uint32        { return f.field(6) }
    477 func (f funcData) cuOffset() uint32    { return f.field(8) }
    478 
    479 // field returns the nth field of the _func struct.
    480 // It panics if n == 0 or n > 9; for n == 0, call f.entryPC.
    481 // Most callers should use a named field accessor (just above).
    482 func (f funcData) field(n uint32) uint32 {
    483 	if n == 0 || n > 9 {
    484 		panic("bad funcdata field")
    485 	}
    486 	// Addition: some code deleted here to support inlining.
    487 	off := f.fieldOffset(n)
    488 	data := f.data[off:]
    489 	return f.t.binary.Uint32(data)
    490 }
    491 
    492 // step advances to the next pc, value pair in the encoded table.
    493 func (t *LineTable) step(p *[]byte, pc *uint64, val *int32, first bool) bool {
    494 	uvdelta := t.readvarint(p)
    495 	if uvdelta == 0 && !first {
    496 		return false
    497 	}
    498 	if uvdelta&1 != 0 {
    499 		uvdelta = ^(uvdelta >> 1)
    500 	} else {
    501 		uvdelta >>= 1
    502 	}
    503 	vdelta := int32(uvdelta)
    504 	pcdelta := t.readvarint(p) * t.quantum
    505 	*pc += uint64(pcdelta)
    506 	*val += vdelta
    507 	return true
    508 }
    509 
    510 // pcvalue reports the value associated with the target pc.
    511 // off is the offset to the beginning of the pc-value table,
    512 // and entry is the start PC for the corresponding function.
    513 func (t *LineTable) pcvalue(off uint32, entry, targetpc uint64) int32 {
    514 	p := t.pctab[off:]
    515 
    516 	val := int32(-1)
    517 	pc := entry
    518 	for t.step(&p, &pc, &val, pc == entry) {
    519 		if targetpc < pc {
    520 			return val
    521 		}
    522 	}
    523 	return -1
    524 }
    525 
    526 // findFileLine scans one function in the binary looking for a
    527 // program counter in the given file on the given line.
    528 // It does so by running the pc-value tables mapping program counter
    529 // to file number. Since most functions come from a single file, these
    530 // are usually short and quick to scan. If a file match is found, then the
    531 // code goes to the expense of looking for a simultaneous line number match.
    532 func (t *LineTable) findFileLine(entry uint64, filetab, linetab uint32, filenum, line int32, cutab []byte) uint64 {
    533 	if filetab == 0 || linetab == 0 {
    534 		return 0
    535 	}
    536 
    537 	fp := t.pctab[filetab:]
    538 	fl := t.pctab[linetab:]
    539 	fileVal := int32(-1)
    540 	filePC := entry
    541 	lineVal := int32(-1)
    542 	linePC := entry
    543 	fileStartPC := filePC
    544 	for t.step(&fp, &filePC, &fileVal, filePC == entry) {
    545 		fileIndex := fileVal
    546 		if t.version == ver116 || t.version == ver118 || t.version == ver120 {
    547 			fileIndex = int32(t.binary.Uint32(cutab[fileVal*4:]))
    548 		}
    549 		if fileIndex == filenum && fileStartPC < filePC {
    550 			// fileIndex is in effect starting at fileStartPC up to
    551 			// but not including filePC, and it's the file we want.
    552 			// Run the PC table looking for a matching line number
    553 			// or until we reach filePC.
    554 			lineStartPC := linePC
    555 			for linePC < filePC && t.step(&fl, &linePC, &lineVal, linePC == entry) {
    556 				// lineVal is in effect until linePC, and lineStartPC < filePC.
    557 				if lineVal == line {
    558 					if fileStartPC <= lineStartPC {
    559 						return lineStartPC
    560 					}
    561 					if fileStartPC < linePC {
    562 						return fileStartPC
    563 					}
    564 				}
    565 				lineStartPC = linePC
    566 			}
    567 		}
    568 		fileStartPC = filePC
    569 	}
    570 	return 0
    571 }
    572 
    573 // go12PCToLine maps program counter to line number for the Go 1.2+ pcln table.
    574 func (t *LineTable) go12PCToLine(pc uint64) (line int) {
    575 	defer func() {
    576 		if !disableRecover && recover() != nil {
    577 			line = -1
    578 		}
    579 	}()
    580 
    581 	f := t.findFunc(pc)
    582 	if f.IsZero() {
    583 		return -1
    584 	}
    585 	entry := f.entryPC()
    586 	linetab := f.pcln()
    587 	return int(t.pcvalue(linetab, entry, pc))
    588 }
    589 
    590 // go12PCToFile maps program counter to file name for the Go 1.2+ pcln table.
    591 func (t *LineTable) go12PCToFile(pc uint64) (file string) {
    592 	defer func() {
    593 		if !disableRecover && recover() != nil {
    594 			file = ""
    595 		}
    596 	}()
    597 
    598 	f := t.findFunc(pc)
    599 	if f.IsZero() {
    600 		return ""
    601 	}
    602 	entry := f.entryPC()
    603 	filetab := f.pcfile()
    604 	fno := t.pcvalue(filetab, entry, pc)
    605 	if t.version == ver12 {
    606 		if fno <= 0 {
    607 			return ""
    608 		}
    609 		return t.string(t.binary.Uint32(t.filetab[4*fno:]))
    610 	}
    611 	// Go ≥ 1.16
    612 	if fno < 0 { // 0 is valid for ≥ 1.16
    613 		return ""
    614 	}
    615 	cuoff := f.cuOffset()
    616 	if fnoff := t.binary.Uint32(t.cutab[(cuoff+uint32(fno))*4:]); fnoff != ^uint32(0) {
    617 		return t.stringFrom(t.filetab, fnoff)
    618 	}
    619 	return ""
    620 }
    621 
    622 // go12LineToPC maps a (file, line) pair to a program counter for the Go 1.2+ pcln table.
    623 func (t *LineTable) go12LineToPC(file string, line int) (pc uint64) {
    624 	defer func() {
    625 		if !disableRecover && recover() != nil {
    626 			pc = 0
    627 		}
    628 	}()
    629 
    630 	t.initFileMap()
    631 	filenum, ok := t.fileMap[file]
    632 	if !ok {
    633 		return 0
    634 	}
    635 
    636 	// Scan all functions.
    637 	// If this turns out to be a bottleneck, we could build a map[int32][]int32
    638 	// mapping file number to a list of functions with code from that file.
    639 	var cutab []byte
    640 	for i := uint32(0); i < t.nfunctab; i++ {
    641 		f := t.funcData(i)
    642 		entry := f.entryPC()
    643 		filetab := f.pcfile()
    644 		linetab := f.pcln()
    645 		if t.version == ver116 || t.version == ver118 || t.version == ver120 {
    646 			if f.cuOffset() == ^uint32(0) {
    647 				// skip functions without compilation unit (not real function, or linker generated)
    648 				continue
    649 			}
    650 			cutab = t.cutab[f.cuOffset()*4:]
    651 		}
    652 		pc := t.findFileLine(entry, filetab, linetab, int32(filenum), int32(line), cutab)
    653 		if pc != 0 {
    654 			return pc
    655 		}
    656 	}
    657 	return 0
    658 }
    659 
    660 // initFileMap initializes the map from file name to file number.
    661 func (t *LineTable) initFileMap() {
    662 	t.mu.Lock()
    663 	defer t.mu.Unlock()
    664 
    665 	if t.fileMap != nil {
    666 		return
    667 	}
    668 	m := make(map[string]uint32)
    669 
    670 	if t.version == ver12 {
    671 		for i := uint32(1); i < t.nfiletab; i++ {
    672 			s := t.string(t.binary.Uint32(t.filetab[4*i:]))
    673 			m[s] = i
    674 		}
    675 	} else {
    676 		var pos uint32
    677 		for i := uint32(0); i < t.nfiletab; i++ {
    678 			s := t.stringFrom(t.filetab, pos)
    679 			m[s] = pos
    680 			pos += uint32(len(s) + 1)
    681 		}
    682 	}
    683 	t.fileMap = m
    684 }
    685 
    686 // go12MapFiles adds to m a key for every file in the Go 1.2 LineTable.
    687 // Every key maps to obj. That's not a very interesting map, but it provides
    688 // a way for callers to obtain the list of files in the program.
    689 func (t *LineTable) go12MapFiles(m map[string]*Obj, obj *Obj) {
    690 	if !disableRecover {
    691 		defer func() {
    692 			_ = recover()
    693 		}()
    694 	}
    695 
    696 	t.initFileMap()
    697 	for file := range t.fileMap {
    698 		m[file] = obj
    699 	}
    700 }
    701 
    702 // disableRecover causes this package not to swallow panics.
    703 // This is useful when making changes.
    704 const disableRecover = true