]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: Clarify/fix unaligned data issues for btf typed dump
authorAlan Maguire <alan.maguire@oracle.com>
Fri, 16 Jul 2021 22:46:55 +0000 (23:46 +0100)
committerAndrii Nakryiko <andrii@kernel.org>
Sat, 17 Jul 2021 00:24:55 +0000 (17:24 -0700)
commit180cf3a1d31285ff108748f016f6a818ff4e9757
treeffbd29e58a926dec56fb62ca483932521f15f2dc
parent50d2a366f6dd64a8cf1f0bd87dc894056fcdbf5c
libbpf: Clarify/fix unaligned data issues for btf typed dump

If data is packed, data structures can store it outside of usual
boundaries.  For example a 4-byte int can be stored on a unaligned
boundary in a case like this:

struct s {
char f1;
int f2;
} __attribute((packed));

...the int is stored at an offset of one byte.  Some platforms have
problems dereferencing data that is not aligned with its size, and
code exists to handle most cases of this for BTF typed data display.
However pointer display was missed, and a simple function to test if
"ptr_is_aligned(data, data_sz)" would help clarify this code.

Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/1626475617-25984-2-git-send-email-alan.maguire@oracle.com
tools/lib/bpf/btf_dump.c