in assembler.go [174:203]
func (p *Program) resolveLabel(jump JumpIf, label Label) (uint8, error) {
dest := p.labels[label]
skipN := p.computeSkipN(jump, label)
for skipN < 0 {
dest = dest[1:]
if len(dest) == 0 {
return 0, fmt.Errorf("backward jumps are not supported")
}
p.labels[label] = dest
skipN = p.computeSkipN(jump, label)
}
// BPF does not support long conditional jumps.
if skipN > math.MaxUint8 {
insertAfter := findInsertAfter(p.jumps, jump)
// If the jump destination is a return instruction, copy it and add an early return,
// if not, insert a long jump.
jumpDest := p.instructions[dest[0]]
if _, ok := jumpDest.(bpf.RetConstant); !ok {
jumpDest = bpf.Jump{Skip: uint32(skipN - int(insertAfter.index))}
}
insertIndex := p.insertAfter(insertAfter.index, jumpDest)
p.labels[label] = append([]Index{insertIndex}, dest...)
skipN = p.computeSkipN(jump, label)
}
return uint8(skipN), nil
}