bpftool: Bpf skeletons assert type sizes
authorDelyan Kratunov <delyank@fb.com>
Wed, 23 Feb 2022 22:01:58 +0000 (22:01 +0000)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 24 Feb 2022 01:33:16 +0000 (17:33 -0800)
commit08d4dba6ae77aaec0e0c79dcfcb0613cb7426b2c
treef5501de2aed87ef4183cdef0fa7fe9d815fc1515
parentc561d11063009323a0e57c528cb1d77b7d2c41e0
bpftool: Bpf skeletons assert type sizes

When emitting type declarations in skeletons, bpftool will now also emit
static assertions on the size of the data/bss/rodata/etc fields. This
ensures that in situations where userspace and kernel types have the same
name but differ in size we do not silently produce incorrect results but
instead break the build.

This was reported in [1] and as expected the repro in [2] fails to build
on the new size assert after this change.

  [1]: Closes: https://github.com/libbpf/libbpf/issues/433
  [2]: https://github.com/fuweid/iovisor-bcc-pr-3777

Signed-off-by: Delyan Kratunov <delyank@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Hengqi Chen <hengqi.chen@gmail.com>
Acked-by: Hengqi Chen <hengqi.chen@gmail.com>
Link: https://lore.kernel.org/bpf/f562455d7b3cf338e59a7976f4690ec5a0057f7f.camel@fb.com
tools/bpf/bpftool/gen.c