* [PATCH dwarves v3 0/1] btf_encoder: handle .BTF_ids section endianness
@ 2024-11-27 1:50 Eduard Zingerman
2024-11-27 1:50 ` [PATCH dwarves v3 1/1] " Eduard Zingerman
0 siblings, 1 reply; 9+ messages in thread
From: Eduard Zingerman @ 2024-11-27 1:50 UTC (permalink / raw)
To: dwarves, arnaldo.melo
Cc: bpf, kernel-team, ast, daniel, andrii, yonghong.song,
Eduard Zingerman, Alan Maguire, Daniel Xu, Jiri Olsa,
Kumar Kartikeya Dwivedi, Vadim Fedorenko
Currently, pahole does not generate kfunc declaration tags when
generating BTF for ELF files with an endianness different from the
host system. For example, this issue occurs when processing a vmlinux
built for s390 on an x86 host.
To reproduce the bug:
- follow the instructions in [0] to build an s390 vmlinux;
- generate BTF requesting declaration tags for kfuncs:
$ pahole --btf_features_strict=decl_tag_kfuncs,decl_tag \
--btf_encode_detached=test.btf vmlinux
- observe that no kfuncs are generated:
$ bpftool btf dump file test.btf format c | grep __ksym
This patch resolves the issue by adding the necessary byte-swapping
operations.
Changelog:
- v1 [1] -> v2:
- avoid modifying the 'idlist' Elf_Data object directly.
Instead, use struct local_elf_data (suggested by Jiri);
- update the description of the .BTF_ids section (suggested by Jiri).
- v2 [2] -> v3:
- use elf_getdata_rawchunk() instead of direct conversion loop
(suggested by Andrii);
- removed Jiri's acked-by and Vadim's reviewed-by,
as patch had changed significantly.
[0] https://docs.kernel.org/bpf/s390.html
[1] https://lore.kernel.org/dwarves/20241122070218.3832680-1-eddyz87@gmail.com/
[2] https://lore.kernel.org/dwarves/20241122214431.292196-1-eddyz87@gmail.com/
Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Daniel Xu <dxu@dxuuu.xyz>
Cc: Jiri Olsa <olsajiri@gmail.com>
Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: Vadim Fedorenko <vadfed@meta.com>
Eduard Zingerman (1):
btf_encoder: handle .BTF_ids section endianness
btf_encoder.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
--
2.47.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH dwarves v3 1/1] btf_encoder: handle .BTF_ids section endianness 2024-11-27 1:50 [PATCH dwarves v3 0/1] btf_encoder: handle .BTF_ids section endianness Eduard Zingerman @ 2024-11-27 1:50 ` Eduard Zingerman 2024-11-27 11:00 ` Jiri Olsa 2024-11-27 13:59 ` Vadim Fedorenko 0 siblings, 2 replies; 9+ messages in thread From: Eduard Zingerman @ 2024-11-27 1:50 UTC (permalink / raw) To: dwarves, arnaldo.melo Cc: bpf, kernel-team, ast, daniel, andrii, yonghong.song, Eduard Zingerman, Alan Maguire, Daniel Xu, Jiri Olsa, Kumar Kartikeya Dwivedi, Vadim Fedorenko btf_encoder__tag_kfuncs() reads .BTF_ids section to identify a set of kfuncs present in the ELF file being processed. This section consists of: - arrays of uint32_t elements; - arrays of records with the following structure: struct btf_id_and_flag { uint32_t id; uint32_t flags; }; When endianness of a binary operated by pahole differs from the host system's endianness, these fields require byte-swapping before use. Currently, this byte-swapping does not occur, resulting in kfuncs not being marked with declaration tags. This commit resolves the issue by using elf_getdata_rawchunk() function to read .BTF_ids section data. When called with ELF_T_WORD as 'type' parameter it does necessary byte order conversion (only if host and elf endianness do not match). Cc: Alan Maguire <alan.maguire@oracle.com> Cc: Andrii Nakryiko <andrii@kernel.org> Cc: Daniel Xu <dxu@dxuuu.xyz> Cc: Jiri Olsa <olsajiri@gmail.com> Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com> Cc: Vadim Fedorenko <vadfed@meta.com> Fixes: 72e88f29c6f7 ("pahole: Inject kfunc decl tags into BTF") Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> --- btf_encoder.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index e1adddf..3754884 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -1904,18 +1904,32 @@ static int btf_encoder__tag_kfuncs(struct btf_encoder *encoder) goto out; } - data = elf_getdata(scn, 0); - if (!data) { - elf_error("Failed to get ELF section(%d) data", i); - goto out; - } - if (shdr.sh_type == SHT_SYMTAB) { + data = elf_getdata(scn, 0); + if (!data) { + elf_error("Failed to get ELF section(%d) data", i); + goto out; + } + symbols_shndx = i; symscn = scn; symbols = data; strtabidx = shdr.sh_link; } else if (!strcmp(secname, BTF_IDS_SECTION)) { + /* .BTF_ids section consists of uint32_t elements, + * and thus might need byte order conversion. + * However, it has type PROGBITS, hence elf_getdata() + * won't automatically do the conversion. + * Use elf_getdata_rawchunk() instead, + * ELF_T_WORD tells it to do the necessary conversion. + */ + data = elf_getdata_rawchunk(elf, shdr.sh_offset, shdr.sh_size, ELF_T_WORD); + if (!data) { + elf_error("Failed to get %s ELF section(%d) data", + BTF_IDS_SECTION, i); + goto out; + } + idlist_shndx = i; idlist_addr = shdr.sh_addr; idlist = data; -- 2.47.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH dwarves v3 1/1] btf_encoder: handle .BTF_ids section endianness 2024-11-27 1:50 ` [PATCH dwarves v3 1/1] " Eduard Zingerman @ 2024-11-27 11:00 ` Jiri Olsa 2024-11-27 12:03 ` Vadim Fedorenko 2024-11-27 13:59 ` Vadim Fedorenko 1 sibling, 1 reply; 9+ messages in thread From: Jiri Olsa @ 2024-11-27 11:00 UTC (permalink / raw) To: Eduard Zingerman Cc: dwarves, arnaldo.melo, bpf, kernel-team, ast, daniel, andrii, yonghong.song, Alan Maguire, Daniel Xu, Jiri Olsa, Kumar Kartikeya Dwivedi, Vadim Fedorenko On Tue, Nov 26, 2024 at 05:50:06PM -0800, Eduard Zingerman wrote: > btf_encoder__tag_kfuncs() reads .BTF_ids section to identify a set of > kfuncs present in the ELF file being processed. > This section consists of: > - arrays of uint32_t elements; > - arrays of records with the following structure: > struct btf_id_and_flag { > uint32_t id; > uint32_t flags; > }; > > When endianness of a binary operated by pahole differs from the host > system's endianness, these fields require byte-swapping before use. > Currently, this byte-swapping does not occur, resulting in kfuncs not > being marked with declaration tags. > > This commit resolves the issue by using elf_getdata_rawchunk() > function to read .BTF_ids section data. When called with ELF_T_WORD as > 'type' parameter it does necessary byte order conversion > (only if host and elf endianness do not match). > > Cc: Alan Maguire <alan.maguire@oracle.com> > Cc: Andrii Nakryiko <andrii@kernel.org> > Cc: Daniel Xu <dxu@dxuuu.xyz> > Cc: Jiri Olsa <olsajiri@gmail.com> > Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com> > Cc: Vadim Fedorenko <vadfed@meta.com> > Fixes: 72e88f29c6f7 ("pahole: Inject kfunc decl tags into BTF") > Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> > --- > btf_encoder.c | 26 ++++++++++++++++++++------ > 1 file changed, 20 insertions(+), 6 deletions(-) > > diff --git a/btf_encoder.c b/btf_encoder.c > index e1adddf..3754884 100644 > --- a/btf_encoder.c > +++ b/btf_encoder.c > @@ -1904,18 +1904,32 @@ static int btf_encoder__tag_kfuncs(struct btf_encoder *encoder) > goto out; > } > > - data = elf_getdata(scn, 0); > - if (!data) { > - elf_error("Failed to get ELF section(%d) data", i); > - goto out; > - } > - > if (shdr.sh_type == SHT_SYMTAB) { > + data = elf_getdata(scn, 0); > + if (!data) { > + elf_error("Failed to get ELF section(%d) data", i); > + goto out; > + } > + > symbols_shndx = i; > symscn = scn; > symbols = data; > strtabidx = shdr.sh_link; > } else if (!strcmp(secname, BTF_IDS_SECTION)) { > + /* .BTF_ids section consists of uint32_t elements, > + * and thus might need byte order conversion. > + * However, it has type PROGBITS, hence elf_getdata() > + * won't automatically do the conversion. > + * Use elf_getdata_rawchunk() instead, > + * ELF_T_WORD tells it to do the necessary conversion. > + */ > + data = elf_getdata_rawchunk(elf, shdr.sh_offset, shdr.sh_size, ELF_T_WORD); looks good, I'm just curious about one thing.. so ELF_T_WORD enum has this comment: /* Elf32_Word, Elf64_Word, ... */ I did just quick check, ***so I might be easily wrong***, but I wonder the code in __elf_xfctstom (which I assume is the one called for conversion) chooses to swap 32/64 bits values based on elf->class .. so for 64bit ELF class we swap 64bit values? ... while .BTF_ids has always 32 bit values thanks, jirka > + if (!data) { > + elf_error("Failed to get %s ELF section(%d) data", > + BTF_IDS_SECTION, i); > + goto out; > + } > + > idlist_shndx = i; > idlist_addr = shdr.sh_addr; > idlist = data; > -- > 2.47.0 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH dwarves v3 1/1] btf_encoder: handle .BTF_ids section endianness 2024-11-27 11:00 ` Jiri Olsa @ 2024-11-27 12:03 ` Vadim Fedorenko 2024-11-27 12:35 ` Jiri Olsa 2024-11-27 17:53 ` Eduard Zingerman 0 siblings, 2 replies; 9+ messages in thread From: Vadim Fedorenko @ 2024-11-27 12:03 UTC (permalink / raw) To: Jiri Olsa, Eduard Zingerman Cc: dwarves, arnaldo.melo, bpf, kernel-team, ast, daniel, andrii, yonghong.song, Alan Maguire, Daniel Xu, Kumar Kartikeya Dwivedi On 27/11/2024 11:00, Jiri Olsa wrote: > On Tue, Nov 26, 2024 at 05:50:06PM -0800, Eduard Zingerman wrote: >> btf_encoder__tag_kfuncs() reads .BTF_ids section to identify a set of >> kfuncs present in the ELF file being processed. >> This section consists of: >> - arrays of uint32_t elements; >> - arrays of records with the following structure: >> struct btf_id_and_flag { >> uint32_t id; >> uint32_t flags; >> }; >> >> When endianness of a binary operated by pahole differs from the host >> system's endianness, these fields require byte-swapping before use. >> Currently, this byte-swapping does not occur, resulting in kfuncs not >> being marked with declaration tags. >> >> This commit resolves the issue by using elf_getdata_rawchunk() >> function to read .BTF_ids section data. When called with ELF_T_WORD as >> 'type' parameter it does necessary byte order conversion >> (only if host and elf endianness do not match). >> >> Cc: Alan Maguire <alan.maguire@oracle.com> >> Cc: Andrii Nakryiko <andrii@kernel.org> >> Cc: Daniel Xu <dxu@dxuuu.xyz> >> Cc: Jiri Olsa <olsajiri@gmail.com> >> Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com> >> Cc: Vadim Fedorenko <vadfed@meta.com> >> Fixes: 72e88f29c6f7 ("pahole: Inject kfunc decl tags into BTF") >> Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> >> --- >> btf_encoder.c | 26 ++++++++++++++++++++------ >> 1 file changed, 20 insertions(+), 6 deletions(-) >> >> diff --git a/btf_encoder.c b/btf_encoder.c >> index e1adddf..3754884 100644 >> --- a/btf_encoder.c >> +++ b/btf_encoder.c >> @@ -1904,18 +1904,32 @@ static int btf_encoder__tag_kfuncs(struct btf_encoder *encoder) >> goto out; >> } >> >> - data = elf_getdata(scn, 0); >> - if (!data) { >> - elf_error("Failed to get ELF section(%d) data", i); >> - goto out; >> - } >> - >> if (shdr.sh_type == SHT_SYMTAB) { >> + data = elf_getdata(scn, 0); >> + if (!data) { >> + elf_error("Failed to get ELF section(%d) data", i); >> + goto out; >> + } >> + >> symbols_shndx = i; >> symscn = scn; >> symbols = data; >> strtabidx = shdr.sh_link; >> } else if (!strcmp(secname, BTF_IDS_SECTION)) { >> + /* .BTF_ids section consists of uint32_t elements, >> + * and thus might need byte order conversion. >> + * However, it has type PROGBITS, hence elf_getdata() >> + * won't automatically do the conversion. >> + * Use elf_getdata_rawchunk() instead, >> + * ELF_T_WORD tells it to do the necessary conversion. >> + */ >> + data = elf_getdata_rawchunk(elf, shdr.sh_offset, shdr.sh_size, ELF_T_WORD); > > looks good, I'm just curious about one thing.. > > so ELF_T_WORD enum has this comment: /* Elf32_Word, Elf64_Word, ... */ > > I did just quick check, ***so I might be easily wrong***, but I wonder the > code in __elf_xfctstom (which I assume is the one called for conversion) > chooses to swap 32/64 bits values based on elf->class .. so for 64bit ELF > class we swap 64bit values? ... while .BTF_ids has always 32 bit values Well according to the doc: ELF_T_WORD Unsigned 32-bit words. ELF_T_XWORD Unsigned 64-bit words. It shouldn't use 64 bits swap: const xfct_t __elf_xfctstom[EV_NUM - 1][EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM] = .... [ELF_T_WORD] = ElfW2(Bits, cvt_Word), [ELF_T_XWORD] = ElfW2(Bits, cvt_Xword), ... Are you looking somewhere else? > > thanks, > jirka > >> + if (!data) { >> + elf_error("Failed to get %s ELF section(%d) data", >> + BTF_IDS_SECTION, i); >> + goto out; >> + } >> + >> idlist_shndx = i; >> idlist_addr = shdr.sh_addr; >> idlist = data; >> -- >> 2.47.0 >> ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH dwarves v3 1/1] btf_encoder: handle .BTF_ids section endianness 2024-11-27 12:03 ` Vadim Fedorenko @ 2024-11-27 12:35 ` Jiri Olsa 2024-11-27 17:53 ` Eduard Zingerman 1 sibling, 0 replies; 9+ messages in thread From: Jiri Olsa @ 2024-11-27 12:35 UTC (permalink / raw) To: Vadim Fedorenko Cc: Jiri Olsa, Eduard Zingerman, dwarves, arnaldo.melo, bpf, kernel-team, ast, daniel, andrii, yonghong.song, Alan Maguire, Daniel Xu, Kumar Kartikeya Dwivedi On Wed, Nov 27, 2024 at 12:03:59PM +0000, Vadim Fedorenko wrote: > On 27/11/2024 11:00, Jiri Olsa wrote: > > On Tue, Nov 26, 2024 at 05:50:06PM -0800, Eduard Zingerman wrote: > > > btf_encoder__tag_kfuncs() reads .BTF_ids section to identify a set of > > > kfuncs present in the ELF file being processed. > > > This section consists of: > > > - arrays of uint32_t elements; > > > - arrays of records with the following structure: > > > struct btf_id_and_flag { > > > uint32_t id; > > > uint32_t flags; > > > }; > > > > > > When endianness of a binary operated by pahole differs from the host > > > system's endianness, these fields require byte-swapping before use. > > > Currently, this byte-swapping does not occur, resulting in kfuncs not > > > being marked with declaration tags. > > > > > > This commit resolves the issue by using elf_getdata_rawchunk() > > > function to read .BTF_ids section data. When called with ELF_T_WORD as > > > 'type' parameter it does necessary byte order conversion > > > (only if host and elf endianness do not match). > > > > > > Cc: Alan Maguire <alan.maguire@oracle.com> > > > Cc: Andrii Nakryiko <andrii@kernel.org> > > > Cc: Daniel Xu <dxu@dxuuu.xyz> > > > Cc: Jiri Olsa <olsajiri@gmail.com> > > > Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com> > > > Cc: Vadim Fedorenko <vadfed@meta.com> > > > Fixes: 72e88f29c6f7 ("pahole: Inject kfunc decl tags into BTF") > > > Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> > > > --- > > > btf_encoder.c | 26 ++++++++++++++++++++------ > > > 1 file changed, 20 insertions(+), 6 deletions(-) > > > > > > diff --git a/btf_encoder.c b/btf_encoder.c > > > index e1adddf..3754884 100644 > > > --- a/btf_encoder.c > > > +++ b/btf_encoder.c > > > @@ -1904,18 +1904,32 @@ static int btf_encoder__tag_kfuncs(struct btf_encoder *encoder) > > > goto out; > > > } > > > - data = elf_getdata(scn, 0); > > > - if (!data) { > > > - elf_error("Failed to get ELF section(%d) data", i); > > > - goto out; > > > - } > > > - > > > if (shdr.sh_type == SHT_SYMTAB) { > > > + data = elf_getdata(scn, 0); > > > + if (!data) { > > > + elf_error("Failed to get ELF section(%d) data", i); > > > + goto out; > > > + } > > > + > > > symbols_shndx = i; > > > symscn = scn; > > > symbols = data; > > > strtabidx = shdr.sh_link; > > > } else if (!strcmp(secname, BTF_IDS_SECTION)) { > > > + /* .BTF_ids section consists of uint32_t elements, > > > + * and thus might need byte order conversion. > > > + * However, it has type PROGBITS, hence elf_getdata() > > > + * won't automatically do the conversion. > > > + * Use elf_getdata_rawchunk() instead, > > > + * ELF_T_WORD tells it to do the necessary conversion. > > > + */ > > > + data = elf_getdata_rawchunk(elf, shdr.sh_offset, shdr.sh_size, ELF_T_WORD); > > > > looks good, I'm just curious about one thing.. > > > > so ELF_T_WORD enum has this comment: /* Elf32_Word, Elf64_Word, ... */ > > > > I did just quick check, ***so I might be easily wrong***, but I wonder the > > code in __elf_xfctstom (which I assume is the one called for conversion) > > chooses to swap 32/64 bits values based on elf->class .. so for 64bit ELF > > class we swap 64bit values? ... while .BTF_ids has always 32 bit values > > Well according to the doc: > > ELF_T_WORD Unsigned 32-bit words. > ELF_T_XWORD Unsigned 64-bit words. > > It shouldn't use 64 bits swap: > > const xfct_t __elf_xfctstom[EV_NUM - 1][EV_NUM - 1][ELFCLASSNUM - > 1][ELF_T_NUM] = > .... > [ELF_T_WORD] = ElfW2(Bits, cvt_Word), > [ELF_T_XWORD] = ElfW2(Bits, cvt_Xword), > ... > > Are you looking somewhere else? nah I guess I got confused with Elf64_Word, which is still 32bits, seems fine, sorry for noise Acked-by: Jiri Olsa <jolsa@kernel.org> thanks, jirka ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH dwarves v3 1/1] btf_encoder: handle .BTF_ids section endianness 2024-11-27 12:03 ` Vadim Fedorenko 2024-11-27 12:35 ` Jiri Olsa @ 2024-11-27 17:53 ` Eduard Zingerman 1 sibling, 0 replies; 9+ messages in thread From: Eduard Zingerman @ 2024-11-27 17:53 UTC (permalink / raw) To: Vadim Fedorenko, Jiri Olsa Cc: dwarves, arnaldo.melo, bpf, kernel-team, ast, daniel, andrii, yonghong.song, Alan Maguire, Daniel Xu, Kumar Kartikeya Dwivedi On Wed, 2024-11-27 at 12:03 +0000, Vadim Fedorenko wrote: [...] > > looks good, I'm just curious about one thing.. > > > > so ELF_T_WORD enum has this comment: /* Elf32_Word, Elf64_Word, ... */ > > > > I did just quick check, ***so I might be easily wrong***, but I wonder the > > code in __elf_xfctstom (which I assume is the one called for conversion) > > chooses to swap 32/64 bits values based on elf->class .. so for 64bit ELF > > class we swap 64bit values? ... while .BTF_ids has always 32 bit values > > Well according to the doc: > > ELF_T_WORD Unsigned 32-bit words. > ELF_T_XWORD Unsigned 64-bit words. > > It shouldn't use 64 bits swap: > > const xfct_t __elf_xfctstom[EV_NUM - 1][EV_NUM - 1][ELFCLASSNUM - > 1][ELF_T_NUM] = > .... > [ELF_T_WORD] = ElfW2(Bits, cvt_Word), > [ELF_T_XWORD] = ElfW2(Bits, cvt_Xword), > ... > > Are you looking somewhere else? Right, thank you, Vadim. [...] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH dwarves v3 1/1] btf_encoder: handle .BTF_ids section endianness 2024-11-27 1:50 ` [PATCH dwarves v3 1/1] " Eduard Zingerman 2024-11-27 11:00 ` Jiri Olsa @ 2024-11-27 13:59 ` Vadim Fedorenko 2024-11-28 20:26 ` Arnaldo Carvalho de Melo 1 sibling, 1 reply; 9+ messages in thread From: Vadim Fedorenko @ 2024-11-27 13:59 UTC (permalink / raw) To: Eduard Zingerman, dwarves, arnaldo.melo Cc: bpf, kernel-team, ast, daniel, andrii, yonghong.song, Alan Maguire, Daniel Xu, Jiri Olsa, Kumar Kartikeya Dwivedi On 27/11/2024 01:50, Eduard Zingerman wrote: > btf_encoder__tag_kfuncs() reads .BTF_ids section to identify a set of > kfuncs present in the ELF file being processed. > This section consists of: > - arrays of uint32_t elements; > - arrays of records with the following structure: > struct btf_id_and_flag { > uint32_t id; > uint32_t flags; > }; > > When endianness of a binary operated by pahole differs from the host > system's endianness, these fields require byte-swapping before use. > Currently, this byte-swapping does not occur, resulting in kfuncs not > being marked with declaration tags. > > This commit resolves the issue by using elf_getdata_rawchunk() > function to read .BTF_ids section data. When called with ELF_T_WORD as > 'type' parameter it does necessary byte order conversion > (only if host and elf endianness do not match). > > Cc: Alan Maguire <alan.maguire@oracle.com> > Cc: Andrii Nakryiko <andrii@kernel.org> > Cc: Daniel Xu <dxu@dxuuu.xyz> > Cc: Jiri Olsa <olsajiri@gmail.com> > Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com> > Cc: Vadim Fedorenko <vadfed@meta.com> > Fixes: 72e88f29c6f7 ("pahole: Inject kfunc decl tags into BTF") > Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> > --- > btf_encoder.c | 26 ++++++++++++++++++++------ > 1 file changed, 20 insertions(+), 6 deletions(-) > > diff --git a/btf_encoder.c b/btf_encoder.c > index e1adddf..3754884 100644 > --- a/btf_encoder.c > +++ b/btf_encoder.c > @@ -1904,18 +1904,32 @@ static int btf_encoder__tag_kfuncs(struct btf_encoder *encoder) > goto out; > } > > - data = elf_getdata(scn, 0); > - if (!data) { > - elf_error("Failed to get ELF section(%d) data", i); > - goto out; > - } > - > if (shdr.sh_type == SHT_SYMTAB) { > + data = elf_getdata(scn, 0); > + if (!data) { > + elf_error("Failed to get ELF section(%d) data", i); > + goto out; > + } > + > symbols_shndx = i; > symscn = scn; > symbols = data; > strtabidx = shdr.sh_link; > } else if (!strcmp(secname, BTF_IDS_SECTION)) { > + /* .BTF_ids section consists of uint32_t elements, > + * and thus might need byte order conversion. > + * However, it has type PROGBITS, hence elf_getdata() > + * won't automatically do the conversion. > + * Use elf_getdata_rawchunk() instead, > + * ELF_T_WORD tells it to do the necessary conversion. > + */ > + data = elf_getdata_rawchunk(elf, shdr.sh_offset, shdr.sh_size, ELF_T_WORD); > + if (!data) { > + elf_error("Failed to get %s ELF section(%d) data", > + BTF_IDS_SECTION, i); > + goto out; > + } > + > idlist_shndx = i; > idlist_addr = shdr.sh_addr; > idlist = data; Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev> ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH dwarves v3 1/1] btf_encoder: handle .BTF_ids section endianness 2024-11-27 13:59 ` Vadim Fedorenko @ 2024-11-28 20:26 ` Arnaldo Carvalho de Melo 2024-11-28 21:14 ` Eduard Zingerman 0 siblings, 1 reply; 9+ messages in thread From: Arnaldo Carvalho de Melo @ 2024-11-28 20:26 UTC (permalink / raw) To: Vadim Fedorenko Cc: Eduard Zingerman, dwarves, arnaldo.melo, bpf, kernel-team, ast, daniel, andrii, yonghong.song, Alan Maguire, Daniel Xu, Jiri Olsa, Kumar Kartikeya Dwivedi On Wed, Nov 27, 2024 at 01:59:55PM +0000, Vadim Fedorenko wrote: > On 27/11/2024 01:50, Eduard Zingerman wrote: > > btf_encoder__tag_kfuncs() reads .BTF_ids section to identify a set of > > kfuncs present in the ELF file being processed. > > This section consists of: > > - arrays of uint32_t elements; > > - arrays of records with the following structure: > > struct btf_id_and_flag { > > uint32_t id; > > uint32_t flags; > > }; > > > > When endianness of a binary operated by pahole differs from the host > > system's endianness, these fields require byte-swapping before use. > > Currently, this byte-swapping does not occur, resulting in kfuncs not > > being marked with declaration tags. > > > > This commit resolves the issue by using elf_getdata_rawchunk() > > function to read .BTF_ids section data. When called with ELF_T_WORD as > > 'type' parameter it does necessary byte order conversion > > (only if host and elf endianness do not match). > > > > Cc: Alan Maguire <alan.maguire@oracle.com> > > Cc: Andrii Nakryiko <andrii@kernel.org> > > Cc: Daniel Xu <dxu@dxuuu.xyz> > > Cc: Jiri Olsa <olsajiri@gmail.com> > > Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com> > > Cc: Vadim Fedorenko <vadfed@meta.com> > > Fixes: 72e88f29c6f7 ("pahole: Inject kfunc decl tags into BTF") > > Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> > Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev> Tested: acme@number:~/git/pahole$ tests/tests 1: Validation of BTF encoding of functions; this may take some time: Ok 2: Default BTF on a system without BTF: Ok 3: Flexible arrays accounting: Ok 4: Pretty printing of files using DWARF type information: Ok 5: Parallel reproducible DWARF Loading/Serial BTF encoding: Ok /home/acme/git/pahole acme@number:~/git/pahole$ And applied. - Arnaldo ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH dwarves v3 1/1] btf_encoder: handle .BTF_ids section endianness 2024-11-28 20:26 ` Arnaldo Carvalho de Melo @ 2024-11-28 21:14 ` Eduard Zingerman 0 siblings, 0 replies; 9+ messages in thread From: Eduard Zingerman @ 2024-11-28 21:14 UTC (permalink / raw) To: Arnaldo Carvalho de Melo, Vadim Fedorenko Cc: dwarves, arnaldo.melo, bpf, kernel-team, ast, daniel, andrii, yonghong.song, Alan Maguire, Daniel Xu, Jiri Olsa, Kumar Kartikeya Dwivedi On Thu, 2024-11-28 at 17:26 -0300, Arnaldo Carvalho de Melo wrote: [...] > Tested: > > acme@number:~/git/pahole$ tests/tests > 1: Validation of BTF encoding of functions; this may take some time: Ok > 2: Default BTF on a system without BTF: Ok > 3: Flexible arrays accounting: Ok > 4: Pretty printing of files using DWARF type information: Ok > 5: Parallel reproducible DWARF Loading/Serial BTF encoding: Ok > /home/acme/git/pahole > acme@number:~/git/pahole$ > > And applied. Great, thank you! ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-11-28 21:14 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-11-27 1:50 [PATCH dwarves v3 0/1] btf_encoder: handle .BTF_ids section endianness Eduard Zingerman 2024-11-27 1:50 ` [PATCH dwarves v3 1/1] " Eduard Zingerman 2024-11-27 11:00 ` Jiri Olsa 2024-11-27 12:03 ` Vadim Fedorenko 2024-11-27 12:35 ` Jiri Olsa 2024-11-27 17:53 ` Eduard Zingerman 2024-11-27 13:59 ` Vadim Fedorenko 2024-11-28 20:26 ` Arnaldo Carvalho de Melo 2024-11-28 21:14 ` Eduard Zingerman
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox