Skip to content

Commit da18bfa

Browse files
guidosarduccianakryiko
authored andcommitted
libbpf: Ensure new BTF objects inherit input endianness
New split BTF needs to preserve base's endianness. Similarly, when creating a distilled BTF, we need to preserve original endianness. Fix by updating libbpf's btf__distill_base() and btf_new_empty() to retain the byte order of any source BTF objects when creating new ones. Fixes: ba45136 ("libbpf: Implement basic split BTF support") Fixes: 58e185a ("libbpf: Add btf__distill_base() creating split BTF with distilled base BTF") Reported-by: Song Liu <[email protected]> Reported-by: Eduard Zingerman <[email protected]> Suggested-by: Eduard Zingerman <[email protected]> Signed-off-by: Tony Ambardar <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Tested-by: Alan Maguire <[email protected]> Acked-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]/ Link: https://lore.kernel.org/bpf/[email protected]
1 parent 65ef66d commit da18bfa

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tools/lib/bpf/btf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ static struct btf *btf_new_empty(struct btf *base_btf)
996996
btf->base_btf = base_btf;
997997
btf->start_id = btf__type_cnt(base_btf);
998998
btf->start_str_off = base_btf->hdr->str_len;
999+
btf->swapped_endian = base_btf->swapped_endian;
9991000
}
10001001

10011002
/* +1 for empty string at offset 0 */
@@ -5394,6 +5395,9 @@ int btf__distill_base(const struct btf *src_btf, struct btf **new_base_btf,
53945395
new_base = btf__new_empty();
53955396
if (!new_base)
53965397
return libbpf_err(-ENOMEM);
5398+
5399+
btf__set_endianness(new_base, btf__endianness(src_btf));
5400+
53975401
dist.id_map = calloc(n, sizeof(*dist.id_map));
53985402
if (!dist.id_map) {
53995403
err = -ENOMEM;

0 commit comments

Comments
 (0)