OSDN Git Service

libbpf: Implement enum value-based CO-RE relocations
authorAndrii Nakryiko <andriin@fb.com>
Wed, 19 Aug 2020 19:45:18 +0000 (12:45 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 19 Aug 2020 21:19:39 +0000 (14:19 -0700)
commiteacaaed784e2c9da69dea3030c81062c1fd66a37
treeb720446ede6b0e701fc5543c3aca6e69c7c6d6a9
parent4836bf5e2ec6e410c7f0c044402951484901a676
libbpf: Implement enum value-based CO-RE relocations

Implement two relocations of a new enumerator value-based CO-RE relocation
kind: ENUMVAL_EXISTS and ENUMVAL_VALUE.

First, ENUMVAL_EXISTS, allows to detect the presence of a named enumerator
value in the target (kernel) BTF. This is useful to do BPF helper/map/program
type support detection from BPF program side. bpf_core_enum_value_exists()
macro helper is provided to simplify built-in usage.

Second, ENUMVAL_VALUE, allows to capture enumerator integer value and relocate
it according to the target BTF, if it changes. This is useful to have
a guarantee against intentional or accidental re-ordering/re-numbering of some
of the internal (non-UAPI) enumerations, where kernel developers don't care
about UAPI backwards compatiblity concerns. bpf_core_enum_value() allows to
capture this succinctly and use correct enum values in code.

LLVM uses ldimm64 instruction to capture enumerator value-based relocations,
so add support for ldimm64 instruction patching as well.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20200819194519.3375898-5-andriin@fb.com
tools/lib/bpf/bpf_core_read.h
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf_internal.h