• Hengqi Chen's avatar
    libbpf: Support static initialization of BPF_MAP_TYPE_PROG_ARRAY · 341ac5ff
    Hengqi Chen authored
    Support static initialization of BPF_MAP_TYPE_PROG_ARRAY with a
    syntax similar to map-in-map initialization ([0]):
    
        SEC("socket")
        int tailcall_1(void *ctx)
        {
            return 0;
        }
    
        struct {
            __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
            __uint(max_entries, 2);
            __uint(key_size, sizeof(__u32));
            __array(values, int (void *));
        } prog_array_init SEC(".maps") = {
            .values = {
                [1] = (void *)&tailcall_1,
            },
        };
    
    Here's the relevant part of libbpf debug log showing what's
    going on with prog-array initialization:
    
    libbpf: sec '.relsocket': collecting relocation for section(3) 'socket'
    libbpf: sec '.relsocket': relo #0: insn #2 against 'prog_array_init'
    libbpf: prog 'entry': found map 0 (prog_array_init, sec 4, off 0) for insn #0
    libbpf: .maps relo #0: for 3 value 0 rel->r_offset 32 name 53 ('tailcall_1')
    libbpf: .maps relo #0: map 'prog_array_init' slot [1] points to prog 'tailcall_1'
    libbpf: map 'prog_array_init': created successfully, fd=5
    libbpf: map 'prog_array_init': slot [1] set to prog 'tailcall_1' fd=6
    
      [0] Closes: https://github.com/libbpf/libbpf/issues/354Signed-off-by: default avatarHengqi Chen <hengqi.chen@gmail.com>
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20211128141633.502339-2-hengqi.chen@gmail.com
    341ac5ff
libbpf.c 303 KB