I have discovered an issue with this approach. If you minimize the vmlinux file first, then it can remove/renumber types that are referenced from the module BTF. This causes bpftool to fail to parse the module BTF file. Likewise, if you minimize the vmlinux second, then the minimized module BTF will reference invalid vmlinux type IDs because they have been renumbered/removed. We essentially need to minimize all the modules and the vmlinux at the same time. On Wed, Jan 31, 2024 at 4:54 PM Quentin Monnet <quentin@xxxxxxxxxxxxx> wrote: > > 2024-01-30 23:05 UTC+0000 ~ Bryce Kahle <git@xxxxxxxxxxxxxx> > > From: Bryce Kahle <bryce.kahle@xxxxxxxxxxxxx> > > > > Enables a user to generate minimized kernel module BTF. > > > > If an eBPF program probes a function within a kernel module or uses > > types that come from a kernel module, split BTF is required. The split > > module BTF contains only the BTF types that are unique to the module. > > It will reference the base/vmlinux BTF types and always starts its type > > IDs at X+1 where X is the largest type ID in the base BTF. > > > > Minimization allows a user to ship only the types necessary to do > > relocations for the program(s) in the provided eBPF object file(s). A > > minimized module BTF will still not contain vmlinux BTF types, so you > > should always minimize the vmlinux file first, and then minimize the > > kernel module file. > > > > Example: > > > > bpftool gen min_core_btf vmlinux.btf vm-min.btf prog.bpf.o > > bpftool -B vm-min.btf gen min_core_btf mod.btf mod-min.btf prog.bpf.o > > > > v3->v4: > > - address style nit about start_id initialization > > - rename base to src_base_btf (base_btf is a global var) > > - copy src_base_btf so new BTF is not modifying original vmlinux BTF > > > > Signed-off-by: Bryce Kahle <bryce.kahle@xxxxxxxxxxxxx> > > Looks good, thank you! > > Reviewed-by: Quentin Monnet <quentin@xxxxxxxxxxxxx> >