]> 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)
commit4ba18feee42fecf10bb70d163bed09f30c21c368
treeffbd29e58a926dec56fb62ca483932521f15f2dc
parentd3da0b322d883fb8ac0378e8dec7b16678f82845
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