On Thu, Nov 21, 2024 at 11:02 PM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote: > > btf_encoder__tag_kfuncs() reads .BTF_ids section to identify a set of > kfuncs present in the ELF being processed. This section consists of > records of the following shape: > > struct btf_id_and_flag { > uint32_t id; > uint32_t flags; > }; > Can we just set data->d_type to ELF_T_WORD and let libelf handle the byte swap? > When endianness of binary operated by pahole differs from the > host endianness these fields require byte swap before using. > > At the moment such byte swap does not happen and kfuncs are not marked > with decl tags when e.g. s390 kernel is compiled on x86. > To reproduces the bug: > - follow instructions from [0] to build an s390 vmlinux; > - execute: > pahole --btf_features_strict=decl_tag_kfuncs,decl_tag \ > --btf_encode_detached=test.btf vmlinux > - observe no kfuncs generated: > bpftool btf dump test.btf format c | grep __ksym > > This commit fixes the issue by adding an endianness conversion step > for .BTF_ids section data before main processing step, modifying the > Elf_Data object in-place. > The choice is such in order to: > - minimize changes; > - keep using Elf_Data, as it provides fields {d_size,d_off} used > by kfunc processing routines; > - avoid sprinkling bswap_32 at each 'struct btf_id_and_flag' field > access in fear of forgetting to add new ones when code is modified. > > [0] https://docs.kernel.org/bpf/s390.html > > Cc: Alan Maguire <alan.maguire@xxxxxxxxxx> > Cc: Daniel Xu <dxu@xxxxxxxxx> > Cc: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx> > Cc: Vadim Fedorenko <vadfed@xxxxxxxx> > Fixes: 72e88f29c6f7 ("pahole: Inject kfunc decl tags into BTF") > Signed-off-by: Eduard Zingerman <eddyz87@xxxxxxxxx> > --- > btf_encoder.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > lib/bpf | 2 +- > 2 files changed, 43 insertions(+), 1 deletion(-) > [...]