diff --git a/btf/core.go b/btf/core.go index d53cf9168..f3b7e039e 100644 --- a/btf/core.go +++ b/btf/core.go @@ -57,13 +57,9 @@ func (f *COREFixup) Apply(ins *asm.Instruction) error { // Add context to the kernel verifier output. if source := ins.Source(); source != nil { - *ins = ins.WithSource(&Line{ - line: fmt.Sprintf("instruction poisoned by CO-RE: %s", source), - }) + *ins = ins.WithSource(asm.Comment(fmt.Sprintf("instruction poisoned by CO-RE: %s", source))) } else { - *ins = ins.WithSource(&Line{ - line: "instruction poisoned by CO-RE", - }) + *ins = ins.WithSource(asm.Comment("instruction poisoned by CO-RE")) } return nil diff --git a/btf/ext_info.go b/btf/ext_info.go index d5652bad5..eb9044bad 100644 --- a/btf/ext_info.go +++ b/btf/ext_info.go @@ -142,12 +142,13 @@ func AssignMetadataToInstructions( // MarshalExtInfos encodes function and line info embedded in insns into kernel // wire format. +// +// If an instruction has an [asm.Comment], it will be synthesized into a mostly +// empty line info. func MarshalExtInfos(insns asm.Instructions, b *Builder) (funcInfos, lineInfos []byte, _ error) { iter := insns.Iterate() for iter.Next() { - _, ok := iter.Ins.Source().(*Line) - fn := FuncMetadata(iter.Ins) - if ok || fn != nil { + if iter.Ins.Source() != nil || FuncMetadata(iter.Ins) != nil { goto marshal } } @@ -167,7 +168,16 @@ marshal: } } - if line, ok := iter.Ins.Source().(*Line); ok { + if source := iter.Ins.Source(); source != nil { + var line *Line + if l, ok := source.(*Line); ok { + line = l + } else { + line = &Line{ + line: source.String(), + } + } + li := &lineInfo{ line: line, offset: iter.Offset,