Skip to content

Commit 7cf6126

Browse files
committed
elf_reader: don't panic if ex.extInfo is nil
When the ELF has no BTF, ex.extInfo will be nil. This was overlooked in a recent refactor. Signed-off-by: Timo Beckers <timo@isovalent.com>
1 parent 3609a64 commit 7cf6126

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

btf/ext_info.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ type ExtInfos struct {
2121
CORERelos map[string]CORERelocationOffsets
2222
}
2323

24+
// Section returns the FuncOffsets, LineOffsets and CORERelocationOffsets for
25+
// the given section name. Returns all nils if ExtInfos is nil, or individual
26+
// nils if there is no metadata of that type for the section.
27+
func (ei *ExtInfos) Section(name string) (FuncOffsets, LineOffsets, CORERelocationOffsets) {
28+
if ei == nil {
29+
return nil, nil, nil
30+
}
31+
32+
return ei.Funcs[name], ei.Lines[name], ei.CORERelos[name]
33+
}
34+
2435
// loadExtInfosFromELF parses ext infos from the .BTF.ext section in an ELF.
2536
//
2637
// Returns an error wrapping ErrNotFound if no ext infos are present.

elf_reader.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,7 @@ func (ec *elfCode) loadFunctions(sec *elfSection) (map[string]asm.Instructions,
439439

440440
// Pull out ExtInfos once per section to avoid map lookups on every
441441
// instruction.
442-
fo := ec.extInfo.Funcs[sec.Name]
443-
lo := ec.extInfo.Lines[sec.Name]
444-
ro := ec.extInfo.CORERelos[sec.Name]
442+
fo, lo, ro := ec.extInfo.Section(sec.Name)
445443

446444
// Raw instruction count since start of the section. ExtInfos point at raw
447445
// insn offsets and ignore the gaps between symbols in case of linked objects.

0 commit comments

Comments
 (0)