• Andrii Nakryiko's avatar
    libbpf: detect supported kernel BTF features and sanitize BTF · d7c4b398
    Andrii Nakryiko authored
    Depending on used versions of libbpf, Clang, and kernel, it's possible to
    have valid BPF object files with valid BTF information, that still won't
    load successfully due to Clang emitting newer BTF features (e.g.,
    BTF_KIND_FUNC, .BTF.ext's line_info/func_info, BTF_KIND_DATASEC, etc), that
    are not yet supported by older kernel.
    
    This patch adds detection of BTF features and sanitizes BPF object's BTF
    by substituting various supported BTF kinds, which have compatible layout:
      - BTF_KIND_FUNC -> BTF_KIND_TYPEDEF
      - BTF_KIND_FUNC_PROTO -> BTF_KIND_ENUM
      - BTF_KIND_VAR -> BTF_KIND_INT
      - BTF_KIND_DATASEC -> BTF_KIND_STRUCT
    
    Replacement is done in such a way as to preserve as much information as
    possible (names, sizes, etc) where possible without violating kernel's
    validation rules.
    
    v2->v3:
      - remove duplicate #defines from libbpf_util.h
    
    v1->v2:
      - add internal libbpf_internal.h w/ common stuff
      - switch SK storage BTF to use new libbpf__probe_raw_btf()
    Reported-by: default avatarAlexei Starovoitov <ast@fb.com>
    Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    d7c4b398
libbpf_probes.c 7.71 KB