On Tue, Nov 26, 2024 at 11:31 AM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote: > > On Tue, 2024-11-26 at 11:26 -0800, Andrii Nakryiko wrote: > > 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 I tried 'data->d_type = ELF_T_WORD' + gelf_xlatetom() snippet > suggested by Tony Ambardar some time ago, I got a write protection error. > Concluded that this is so, because file is opened in O_RDONLY mode. Ok, maybe don't follow my words *exactly*, just in spirit ;) I see there is elf_getdata_rawchunk() API in libelf, which seems useful: /* Get data translated from a chunk of the file contents as section data would be for TYPE. The resulting Elf_Data pointer is valid until elf_end (ELF) is called. */ extern Elf_Data *elf_getdata_rawchunk (Elf *__elf, int64_t __offset, size_t __size, Elf_Type __type); I don't know the surrounding code, I was just hoping to leverage libelf's byte swapping support (which I think I learned from Tony as well). But if it's too inconvenient, so be it. > > (Also please note v2 of this patch). > > [...] >