Skip to content

Commit

Permalink
btf: synthesise instruction comments into line info
Browse files Browse the repository at this point in the history
When an asm.Comment is added to an instruction, existing source
information like btf.Line will be replaced. But in some cases,
instructions without line information won't pass the verifier. The
expected behavior would be, that the comment gets synthesized into a
line info where everything but the line string is zero. This commit
implements this.

Fixes #1413

Signed-off-by: Marcus Wichelmann <mail@marcusw.de>
  • Loading branch information
MarcusWichelmann authored and lmb committed Apr 8, 2024
1 parent 0ec5f53 commit bfbf391
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions btf/ext_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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,
Expand Down

0 comments on commit bfbf391

Please sign in to comment.