]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: Do not use __builtin_offsetof for offsetof
authorYonghong Song <yhs@fb.com>
Tue, 11 Aug 2020 03:08:52 +0000 (20:08 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 11 Aug 2020 13:11:07 +0000 (15:11 +0200)
commit63fe3fd393dc4e7ea3948e79947362ffbb0fd616
tree396dd9a9d0621eeeb0e919caf9c6653308b24219
parent444da3f52407d74c9aa12187ac6b01f76ee47d62
libbpf: Do not use __builtin_offsetof for offsetof

Commit 5fbc220862fc ("tools/libpf: Add offsetof/container_of macro
in bpf_helpers.h") added a macro offsetof() to get the offset of a
structure member:

   #define offsetof(TYPE, MEMBER)  ((size_t)&((TYPE *)0)->MEMBER)

In certain use cases, size_t type may not be available so
Commit da7a35062bcc ("libbpf bpf_helpers: Use __builtin_offsetof
for offsetof") changed to use __builtin_offsetof which removed
the dependency on type size_t, which I suggested.

But using __builtin_offsetof will prevent CO-RE relocation
generation in case that, e.g., TYPE is annotated with "preserve_access_info"
where a relocation is desirable in case the member offset is changed
in a different kernel version. So this patch reverted back to
the original macro but using "unsigned long" instead of "site_t".

Fixes: da7a35062bcc ("libbpf bpf_helpers: Use __builtin_offsetof for offsetof")
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/bpf/20200811030852.3396929-1-yhs@fb.com
tools/lib/bpf/bpf_helpers.h