libbpf: Ensure BPF prog types are set before relocations
authorAndrii Nakryiko <andrii@kernel.org>
Tue, 14 Sep 2021 01:47:31 +0000 (18:47 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 14 Sep 2021 22:49:24 +0000 (15:49 -0700)
commit91b4d1d1d54431c72f3a7ff034f30a635f787426
tree625a85f3f636516a10bbb813c9af279f78ed586f
parent53df63ccdc0258118e53089197d0428c5330cc9c
libbpf: Ensure BPF prog types are set before relocations

Refactor bpf_object__open() sequencing to perform BPF program type
detection based on SEC() definitions before we get to relocations
collection. This allows to have more information about BPF program by
the time we get to, say, struct_ops relocation gathering. This,
subsequently, simplifies struct_ops logic and removes the need to
perform extra find_sec_def() resolution.

With this patch libbpf will require all struct_ops BPF programs to be
marked with SEC("struct_ops") or SEC("struct_ops/xxx") annotations.
Real-world applications are already doing that through something like
selftests's BPF_STRUCT_OPS() macro. This change streamlines libbpf's
internal handling of SEC() definitions and is in the sprit of
upcoming libbpf-1.0 section strictness changes ([0]).

  [0] https://github.com/libbpf/libbpf/wiki/Libbpf:-the-road-to-v1.0#stricter-and-more-uniform-bpf-program-section-name-sec-handling

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20210914014733.2768-3-andrii@kernel.org
tools/lib/bpf/libbpf.c