Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: Fix incorrect traversal end type ID when marking BTF_IS_EMBEDDED

When redirecting the split BTF to the vmlinux base BTF, we need to mark
the distilled base struct/union members of split BTF structs/unions in
id_map with BTF_IS_EMBEDDED. This indicates that these types must match
both name and size later. Therefore, we need to traverse the entire
split BTF, which involves traversing type IDs from nr_dist_base_types to
nr_types. However, the current implementation uses an incorrect
traversal end type ID, so let's correct it.

Fixes: 19e00c897d50 ("libbpf: Split BTF relocation")
Signed-off-by: Pu Lehui <pulehui@huawei.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250115100241.4171581-3-pulehui@huaweicloud.com

authored by

Pu Lehui and committed by
Andrii Nakryiko
5ca681a8 5436a543

+1 -1
+1 -1
tools/lib/bpf/btf_relocate.c
··· 212 212 * need to match both name and size, otherwise embedding the base 213 213 * struct/union in the split type is invalid. 214 214 */ 215 - for (id = r->nr_dist_base_types; id < r->nr_split_types; id++) { 215 + for (id = r->nr_dist_base_types; id < r->nr_dist_base_types + r->nr_split_types; id++) { 216 216 err = btf_mark_embedded_composite_type_ids(r, id); 217 217 if (err) 218 218 goto done;