Skip to content

Commit

Permalink
linker: do not copy instructions when there is no reference
Browse files Browse the repository at this point in the history
When resolving the bpf-to-bpf calls we need to copy the
instructions from the program to flatten the references.

But when there is no reference there is nothing to do so we
can skip the copy operation altogether.
  • Loading branch information
paulcacheux committed Jan 20, 2025
1 parent fd1fe1b commit 8056168
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,19 @@ func flattenPrograms(progs map[string]*ProgramSpec, names []string) {
// dependencies of each program.
func flattenInstructions(name string, progs map[string]*ProgramSpec, refs map[*ProgramSpec][]string) asm.Instructions {
prog := progs[name]
progRefs := refs[prog]

if len(progRefs) == 0 {
// No references, nothing to do.
return prog.Instructions
}

insns := make(asm.Instructions, len(prog.Instructions))
copy(insns, prog.Instructions)

// Add all direct references of prog to the list of to be linked programs.
pending := make([]string, len(refs[prog]))
copy(pending, refs[prog])
pending := make([]string, len(progRefs))
copy(pending, progRefs)

// All references for which we've appended instructions.
linked := make(map[string]bool)
Expand Down

0 comments on commit 8056168

Please sign in to comment.