libbpf: Fix dumping enum bitfields on big-endian
PATCH 1/1 libbpf: Fix dumping enum bitfields on big-endian
btf_dump_dump_type_data() reads an enum bitfield into the __s64 enum_val and passes &enum_val to btf_dump_enum_data(), where btf_dump_get_enum_value() loads t->size bytes from that address. For enums smaller than 8 bytes, those are the high-order bytes of enum_val on big-endian, so every enum bitfield is dumped with value 0.
Pass the address of the low-order t->size bytes of enum_val instead, so the value is loaded the same way on both byte orders.
--- tools/lib/bpf/btf_dump.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/lib/bpf/btf_dump.c +7 -0
@@ -2665,7 +2665,14 @@ static int btf_dump_dump_type_data(struct btf_dump *d,if (err)break ; enum_val = (__s64 )print_num; +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ err =btf_dump_enum_data (d, t, id, &enum_val); +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + err =btf_dump_enum_data (d, t, id, + (void *)&enum_val +sizeof (enum_val) - t->size); +#else +# error "Unrecognized __BYTE_ORDER__" +#endif }else err =btf_dump_enum_data (d, t, id, data);break ;
base-commit: 8dfce13340aeba06d1b68cc7648f37762244be65
Signature · 1 line
2.43.0
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Quoted 10 lines · On Wed, 25 Nov 2026 08:12:45 +0000 you wrote:
btf_dump_dump_type_data()reads an enum bitfield into the__s64enum_valand passes&enum_valtobtf_dump_enum_data(), wherebtf_dump_get_enum_value()loadst->sizebytes from that address. For enums smaller than 8 bytes, those are the high-order bytes ofenum_valon big-endian, so every enum bitfield is dumped with value 0.Pass the address of the low-order
t->sizebytes ofenum_valinstead, so the value is loaded the same way on both byte orders.[...]
Here is the summary with links:
- [bpf-next] libbpf: Fix dumping enum bitfields on big-endian
https://git.kernel.org/bpf/bpf-next/c/3cbbebf6819b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html