On 2025/1/15 7:46, Andrii Nakryiko wrote:
On Tue, Jan 14, 2025 at 6:06 AM Pu Lehui <pulehui@xxxxxxxxxxxxxxx> wrote:
From: Pu Lehui <pulehui@xxxxxxxxxx>
When redirecting the base BTF of the split BTF from the distilled base
BTF to the vmlinux base BTF, we need to mark distilled base struct/union
members of split BTF structs/unions in id_map with BTF_IS_EMBEDDED,
which indicates that these types need to match both name and size later.
But, the current implementation uses the incorrect iter rounds, we need
to correct it to iter from nr_dist_base_types to nr_types.
It's hard to understand what this description says without looking at
the code... the "iter rounds" and "iter" is very confusing, because we
are actually dealing with type IDs? Can you please reword to make it
clearer.
Also, why don't we see this issue in our tests? Can you come up with a
simple test to demonstrate a problem?
Sure, will make description more sense and add test in next.
This looks correct, otherwise, but it would be nice for Alan to review
as well, thanks.
pw-bot: cr
Fixes: 19e00c897d50 ("libbpf: Split BTF relocation")
Signed-off-by: Pu Lehui <pulehui@xxxxxxxxxx>
---
tools/lib/bpf/btf_relocate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/lib/bpf/btf_relocate.c b/tools/lib/bpf/btf_relocate.c
index b72f83e15156..53d1f3541bce 100644
--- a/tools/lib/bpf/btf_relocate.c
+++ b/tools/lib/bpf/btf_relocate.c
@@ -212,7 +212,7 @@ static int btf_relocate_map_distilled_base(struct btf_relocate *r)
* need to match both name and size, otherwise embedding the base
* struct/union in the split type is invalid.
*/
- for (id = r->nr_dist_base_types; id < r->nr_split_types; id++) {
+ for (id = r->nr_dist_base_types; id < r->nr_dist_base_types + r->nr_split_types; id++) {
err = btf_mark_embedded_composite_type_ids(r, id);
if (err)
goto done;
--
2.34.1