cilium/cilium · error

marking branches: %w

Error message

marking branches: %w

What it means

computeBlocks starts by running markBranches, which classifies each instruction (branches, jumps, exits) and resolves each branching instruction's jump target offset. This error wraps failure to determine a jump target instruction offset, meaning the instruction stream contains a branch whose target cannot be resolved — typically a corrupt or un-finalized program.

Source

Thrown at pkg/bpf/analyze/blocks.go:657

		return blocks, nil
	}

	blocks, err := computeBlocks(insns)
	if err != nil {
		return nil, fmt.Errorf("computing blocks: %w", err)
	}

	if err := storeBlocks(insns, blocks); err != nil {
		return nil, fmt.Errorf("storing blocks: %w", err)
	}

	return blocks, nil
}

// computeBlocks computes the basic blocks from the given instruction stream.
func computeBlocks(insns asm.Instructions) (Blocks, error) {
	if err := markBranches(insns); err != nil {
		return nil, fmt.Errorf("marking branches: %w", err)
	}

	blocks, callers, err := allocateBlocks(insns)
	if err != nil {
		return nil, fmt.Errorf("allocating blocks: %w", err)
	}

	if err := connectBlocks(blocks, insns); err != nil {
		return nil, fmt.Errorf("connecting blocks: %w", err)
	}

	callers.connect(blocks)

	return blocks, nil
}

// blocksKey is used to store Blocks in an instruction's metadata.
type blocksKey struct{}

View on GitHub (pinned to ac7b90affa)

Solutions

  1. Re-run asm.Assemble on the instructions so all jump references are resolved and offsets assigned
  2. Check the wrapped error from jumpTarget for the specific instruction offset
  3. Verify no branch target exceeds len(insns)-1
  4. Inspect the instruction at the failing offset for a malformed or nil-reference jump

Example fix

// before
insns := buildInstructionsManually()
blocks, err := MakeBlocks(insns) // marking branches fails
// after
insns, err := asm.Assemble(buildInstructionsManually())
if err != nil {
    return err
}
blocks, err := MakeBlocks(insns)
Defensive patterns

Strategy: validation

Validate before calling

for i, ins := range insns {
    if ins.IsBuiltinCall() || ins.OpCode.JumpOp() != asm.Invalid { /* structurally fine */ }
    _ = i
}
// Prefer: ensure assembly already succeeded
if assembled, err := asm.Assemble(insns); err != nil {
    return fmt.Errorf("program does not assemble: %w", err)
} else { insns = assembled }

Try / catch

blocks, err := MakeBlocks(insns)
var branchErr error
if err != nil && strings.Contains(err.Error(), "marking branches") {
    branchErr = err
    return fmt.Errorf("unresolved jump in program: %w", branchErr)
}

Prevention

When it happens

Trigger: Calling computeBlocks (via MakeBlocks or benchmarks/tests) on instructions where a branch instruction has a raw offset pointing outside the instruction stream, or the instruction lacks symbol metadata needed to resolve the target.

Common situations: Manually patched jump offsets, partially assembled programs (asm.Assemble not run or failed silently), programs deserialized from a different/older ELF format.

Related errors


AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31). Data as JSON: /api/errors/2c306ffb2bdd2ded. Report an issue: GitHub.