This patch set generalizes libbpf's CO-RE relocation support. In addition to
existing field's byte offset relocation, libbpf now supports field existence
relocations, which are emitted by Clang when using
__builtin_preserve_field_info(<field>, BPF_FIELD_EXISTS). A convenience
bpf_core_field_exists() macro is added to bpf_core_read.h BPF-side header,
along the bpf_field_info_kind enum containing currently supported types of
field information libbpf supports. This list will grow as libbpf gains support
for other relo kinds.

This patch set upgrades the format of .BTF.ext's relocation record to match
latest Clang's format (12 -> 16 bytes). This is not a breaking change, as the
previous format hasn't been released yet as part of official Clang version
release.

v1->v2:
- unify bpf_field_info_kind enum and naming changes (Alexei);
- added bpf_core_field_exists() to bpf_core_read.h.

Andrii Nakryiko (5):
  libbpf: update BTF reloc support to latest Clang format
  libbpf: refactor bpf_object__open APIs to use common opts
  libbpf: add support for field existance CO-RE relocation
  libbpf: add BPF-side definitions of supported field relocation kinds
  selftests/bpf: add field existence CO-RE relocs tests

 tools/lib/bpf/bpf_core_read.h                 |  24 ++-
 tools/lib/bpf/btf.c                           |  16 +-
 tools/lib/bpf/btf.h                           |   4 +-
 tools/lib/bpf/libbpf.c                        | 169 +++++++++++-------
 tools/lib/bpf/libbpf.h                        |   4 +-
 tools/lib/bpf/libbpf_internal.h               |  25 ++-
 .../selftests/bpf/prog_tests/core_reloc.c     |  76 +++++++-
 .../bpf/progs/btf__core_reloc_existence.c     |   3 +
 ...ore_reloc_existence___err_wrong_arr_kind.c |   3 +
 ...loc_existence___err_wrong_arr_value_type.c |   3 +
 ...ore_reloc_existence___err_wrong_int_kind.c |   3 +
 ..._core_reloc_existence___err_wrong_int_sz.c |   3 +
 ...ore_reloc_existence___err_wrong_int_type.c |   3 +
 ..._reloc_existence___err_wrong_struct_type.c |   3 +
 .../btf__core_reloc_existence___minimal.c     |   3 +
 .../selftests/bpf/progs/core_reloc_types.h    |  56 ++++++
 .../bpf/progs/test_core_reloc_existence.c     |  79 ++++++++
 17 files changed, 392 insertions(+), 85 deletions(-)
 create mode 100644 
tools/testing/selftests/bpf/progs/btf__core_reloc_existence.c
 create mode 100644 
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_arr_kind.c
 create mode 100644 
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_arr_value_type.c
 create mode 100644 
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_kind.c
 create mode 100644 
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_sz.c
 create mode 100644 
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_type.c
 create mode 100644 
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_struct_type.c
 create mode 100644 
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___minimal.c
 create mode 100644 
tools/testing/selftests/bpf/progs/test_core_reloc_existence.c

-- 
2.17.1

Reply via email to