libbpf: Fail compilation if target arch is missing
authorLorenz Bauer <lmb@cloudflare.com>
Wed, 16 Jun 2021 08:36:35 +0000 (09:36 +0100)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 17 Jun 2021 03:15:30 +0000 (20:15 -0700)
commit4a638d581a7a3f00f277349903ff419b6790e2ae
tree5460fa7cb43e229c00f3669cf060d371a16fb1e3
parentdfdda1a0f4aad476ae25f2840c9426da3b99506d
libbpf: Fail compilation if target arch is missing

bpf2go is the Go equivalent of libbpf skeleton. The convention is that
the compiled BPF is checked into the repository to facilitate distributing
BPF as part of Go packages. To make this portable, bpf2go by default
generates both bpfel and bpfeb variants of the C.

Using bpf_tracing.h is inherently non-portable since the fields of
struct pt_regs differ between platforms, so CO-RE can't help us here.
The only way of working around this is to compile for each target
platform independently. bpf2go can't do this by default since there
are too many platforms.

Define the various PT_... macros when no target can be determined and
turn them into compilation failures. This works because bpf2go always
compiles for bpf targets, so the compiler fallback doesn't kick in.
Conditionally define __BPF_MISSING_TARGET so that we can inject a
more appropriate error message at build time. The user can then
choose which platform to target explicitly.

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210616083635.11434-1-lmb@cloudflare.com
tools/lib/bpf/bpf_tracing.h