Skip to content

Add CO-RE support for field existence relos

Andrii Nakryiko bpf netdev 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 1 replyIn review
  2. v15 patches 2 repliesSuperseded

Changes in v2 from the cover letter

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

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5libbpf: update BTF reloc support to latest Clang formattools/lib/bpf/btf.c tools/lib/bpf/btf.h tools/lib/bpf/libbpf.c +1 more+40 -290 replies
2/5libbpf: refactor bpf_object__open APIs to use common optstools/lib/bpf/libbpf.c+35 -360 replies
3/5libbpf: add support for field existance CO-RE relocationtools/lib/bpf/libbpf.c tools/lib/bpf/libbpf.h+61 -170 replies
4/5libbpf: add BPF-side definitions of supported field relocation kindstools/lib/bpf/bpf_core_read.h+23 -10 replies
5/5selftests/bpf: add field existence CO-RE relocs teststools/testing/selftests/bpf/prog_tests/core_reloc.c tools/testing/selftests/bpf/progs/btf__core_reloc_existence.c tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_arr_kind.c +8 more+233 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 bpf-next 0/5] Add CO-RE support for field existence relos

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
Signature · 1 line
2.17.1