libbpf: Define BTF_KIND_* constants in btf.h to avoid compilation errors
authorToke Høiland-Jørgensen <toke@redhat.com>
Tue, 18 Jan 2022 14:13:27 +0000 (15:13 +0100)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 19 Jan 2022 03:49:12 +0000 (19:49 -0800)
commiteaa266d83a3730a15de2ceebcc89e8f6290e8cf6
treed34bc90d43419a895f9634fc196737287e8a4b71
parent712d47938dcaf9973791e1f600c70dab272bed55
libbpf: Define BTF_KIND_* constants in btf.h to avoid compilation errors

The btf.h header included with libbpf contains inline helper functions to
check for various BTF kinds. These helpers directly reference the
BTF_KIND_* constants defined in the kernel header, and because the header
file is included in user applications, this happens in the user application
compile units.

This presents a problem if a user application is compiled on a system with
older kernel headers because the constants are not available. To avoid
this, add #defines of the constants directly in btf.h before using them.

Since the kernel header moved to an enum for BTF_KIND_*, the #defines can
shadow the enum values without any errors, so we only need #ifndef guards
for the constants that predates the conversion to enum. We group these so
there's only one guard for groups of values that were added together.

  [0] Closes: https://github.com/libbpf/libbpf/issues/436

Fixes: 223f903e9c83 ("bpf: Rename BTF_KIND_TAG to BTF_KIND_DECL_TAG")
Fixes: 5b84bd10363e ("libbpf: Add support for BTF_KIND_TAG")
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: https://lore.kernel.org/bpf/20220118141327.34231-1-toke@redhat.com
tools/lib/bpf/btf.h