Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btf: synthesise instruction comments into line info #1417

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions btf/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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) {
dylandreimerink marked this conversation as resolved.
Show resolved Hide resolved
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