• Andrii Nakryiko's avatar
    libbpf: Turn btf_dedup_opts into OPTS-based struct · 957d350a
    Andrii Nakryiko authored
    btf__dedup() and struct btf_dedup_opts were added before we figured out
    OPTS mechanism. As such, btf_dedup_opts is non-extensible without
    breaking an ABI and potentially crashing user application.
    
    Unfortunately, btf__dedup() and btf_dedup_opts are short and succinct
    names that would be great to preserve and use going forward. So we use
    ___libbpf_override() macro approach, used previously for bpf_prog_load()
    API, to define a new btf__dedup() variant that accepts only struct btf *
    and struct btf_dedup_opts * arguments, and rename the old btf__dedup()
    implementation into btf__dedup_deprecated(). This keeps both source and
    binary compatibility with old and new applications.
    
    The biggest problem was struct btf_dedup_opts, which wasn't OPTS-based,
    and as such doesn't have `size_t sz;` as a first field. But btf__dedup()
    is a pretty rarely used API and I believe that the only currently known
    users (besides selftests) are libbpf's own bpf_linker and pahole.
    Neither use case actually uses options and just passes NULL. So instead
    of doing extra hacks, just rewrite struct btf_dedup_opts into OPTS-based
    one, move btf_ext argument into those opts (only bpf_linker needs to
    dedup btf_ext, so it's not a typical thing to specify), and drop never
    used `dont_resolve_fwds` option (it was never used anywhere, AFAIK, it
    makes BTF dedup much less useful and efficient).
    
    Just in case, for old implementation, btf__dedup_deprecated(), detect
    non-NULL options and error out with helpful message, to help users
    migrate, if there are any user playing with btf__dedup().
    
    The last remaining piece is dedup_table_size, which is another
    anachronism from very early days of BTF dedup. Since then it has been
    reduced to the only valid value, 1, to request forced hash collisions.
    This is only used during testing. So instead introduce a bool flag to
    force collisions explicitly.
    
    This patch also adapts selftests to new btf__dedup() and btf_dedup_opts
    use to avoid selftests breakage.
    
      [0] Closes: https://github.com/libbpf/libbpf/issues/281Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Link: https://lore.kernel.org/bpf/20211111053624.190580-4-andrii@kernel.org
    957d350a
libbpf.map 8.76 KB