* [PATCH] libbpf: skip empty sections in bpf_object__init_global_data_maps
@ 2022-07-31 23:26 James Hilliard
2022-08-01 20:24 ` Jiri Olsa
2022-08-04 21:50 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 5+ messages in thread
From: James Hilliard @ 2022-07-31 23:26 UTC (permalink / raw)
To: bpf
Cc: James Hilliard, Jose E . Marchesi, Alexei Starovoitov,
Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Nathan Chancellor, Nick Desaulniers, Tom Rix,
linux-kernel, llvm
The GNU assembler generates an empty .bss section. This is a well
established behavior in GAS that happens in all supported targets.
The LLVM assembler doesn't generate an empty .bss section.
bpftool chokes on the empty .bss section.
Additionally in bpf_object__elf_collect the sec_desc->data is not
initialized when a section is not recognized. In this case, this
happens with .comment.
So we must check that sec_desc->data is initialized before checking
if the size is 0.
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Cc: Jose E. Marchesi <jose.marchesi@oracle.com>
---
tools/lib/bpf/libbpf.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 50d41815f431..77e3797cf75a 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1642,6 +1642,10 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj)
for (sec_idx = 1; sec_idx < obj->efile.sec_cnt; sec_idx++) {
sec_desc = &obj->efile.secs[sec_idx];
+ /* Skip recognized sections with size 0. */
+ if (sec_desc->data && sec_desc->data->d_size == 0)
+ continue;
+
switch (sec_desc->sec_type) {
case SEC_DATA:
sec_name = elf_sec_name(obj, elf_sec_by_idx(obj, sec_idx));
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] libbpf: skip empty sections in bpf_object__init_global_data_maps
2022-07-31 23:26 [PATCH] libbpf: skip empty sections in bpf_object__init_global_data_maps James Hilliard
@ 2022-08-01 20:24 ` Jiri Olsa
2022-08-01 22:21 ` David Faust
2022-08-04 21:50 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 5+ messages in thread
From: Jiri Olsa @ 2022-08-01 20:24 UTC (permalink / raw)
To: James Hilliard
Cc: bpf, Jose E . Marchesi, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo,
Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, llvm,
David Faust
On Sun, Jul 31, 2022 at 05:26:49PM -0600, James Hilliard wrote:
> The GNU assembler generates an empty .bss section. This is a well
> established behavior in GAS that happens in all supported targets.
>
> The LLVM assembler doesn't generate an empty .bss section.
>
> bpftool chokes on the empty .bss section.
>
> Additionally in bpf_object__elf_collect the sec_desc->data is not
> initialized when a section is not recognized. In this case, this
> happens with .comment.
>
> So we must check that sec_desc->data is initialized before checking
> if the size is 0.
oops David send same change but I asked him to move the check
to bpf_object__elf_collect [1] .. but with your explanation this
fix actualy looks fine to me
jirka
[1] https://lore.kernel.org/bpf/YuKaFiZ+ksB5f0Ye@krava/
>
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> Cc: Jose E. Marchesi <jose.marchesi@oracle.com>
> ---
> tools/lib/bpf/libbpf.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 50d41815f431..77e3797cf75a 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -1642,6 +1642,10 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj)
> for (sec_idx = 1; sec_idx < obj->efile.sec_cnt; sec_idx++) {
> sec_desc = &obj->efile.secs[sec_idx];
>
> + /* Skip recognized sections with size 0. */
> + if (sec_desc->data && sec_desc->data->d_size == 0)
> + continue;
> +
> switch (sec_desc->sec_type) {
> case SEC_DATA:
> sec_name = elf_sec_name(obj, elf_sec_by_idx(obj, sec_idx));
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libbpf: skip empty sections in bpf_object__init_global_data_maps
2022-08-01 20:24 ` Jiri Olsa
@ 2022-08-01 22:21 ` David Faust
2022-08-02 8:52 ` Jiri Olsa
0 siblings, 1 reply; 5+ messages in thread
From: David Faust @ 2022-08-01 22:21 UTC (permalink / raw)
To: Jiri Olsa, James Hilliard
Cc: bpf, Jose E . Marchesi, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo,
Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, llvm
On 8/1/22 13:24, Jiri Olsa wrote:
> On Sun, Jul 31, 2022 at 05:26:49PM -0600, James Hilliard wrote:
>> The GNU assembler generates an empty .bss section. This is a well
>> established behavior in GAS that happens in all supported targets.
>>
>> The LLVM assembler doesn't generate an empty .bss section.
>>
>> bpftool chokes on the empty .bss section.
>>
>> Additionally in bpf_object__elf_collect the sec_desc->data is not
>> initialized when a section is not recognized. In this case, this
>> happens with .comment.
>>
>> So we must check that sec_desc->data is initialized before checking
>> if the size is 0.
>
> oops David send same change but I asked him to move the check
> to bpf_object__elf_collect [1] .. but with your explanation this
> fix actualy looks fine to me
FWIW, I only just got back to actually making that change. This
patch has a much better explanation than the one I sent so +1 from
me also
David
>
> jirka
>
>
> [1] https://lore.kernel.org/bpf/YuKaFiZ+ksB5f0Ye@krava/
>
>>
>> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
>> Cc: Jose E. Marchesi <jose.marchesi@oracle.com>
>> ---
>> tools/lib/bpf/libbpf.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index 50d41815f431..77e3797cf75a 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -1642,6 +1642,10 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj)
>> for (sec_idx = 1; sec_idx < obj->efile.sec_cnt; sec_idx++) {
>> sec_desc = &obj->efile.secs[sec_idx];
>>
>> + /* Skip recognized sections with size 0. */
>> + if (sec_desc->data && sec_desc->data->d_size == 0)
>> + continue;
>> +
>> switch (sec_desc->sec_type) {
>> case SEC_DATA:
>> sec_name = elf_sec_name(obj, elf_sec_by_idx(obj, sec_idx));
>> --
>> 2.34.1
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libbpf: skip empty sections in bpf_object__init_global_data_maps
2022-08-01 22:21 ` David Faust
@ 2022-08-02 8:52 ` Jiri Olsa
0 siblings, 0 replies; 5+ messages in thread
From: Jiri Olsa @ 2022-08-02 8:52 UTC (permalink / raw)
To: David Faust
Cc: Jiri Olsa, James Hilliard, bpf, Jose E . Marchesi,
Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Nathan Chancellor,
Nick Desaulniers, Tom Rix, linux-kernel, llvm
On Mon, Aug 01, 2022 at 03:21:58PM -0700, David Faust wrote:
>
>
> On 8/1/22 13:24, Jiri Olsa wrote:
> > On Sun, Jul 31, 2022 at 05:26:49PM -0600, James Hilliard wrote:
> >> The GNU assembler generates an empty .bss section. This is a well
> >> established behavior in GAS that happens in all supported targets.
> >>
> >> The LLVM assembler doesn't generate an empty .bss section.
> >>
> >> bpftool chokes on the empty .bss section.
> >>
> >> Additionally in bpf_object__elf_collect the sec_desc->data is not
> >> initialized when a section is not recognized. In this case, this
> >> happens with .comment.
> >>
> >> So we must check that sec_desc->data is initialized before checking
> >> if the size is 0.
> >
> > oops David send same change but I asked him to move the check
> > to bpf_object__elf_collect [1] .. but with your explanation this
> > fix actualy looks fine to me
>
> FWIW, I only just got back to actually making that change. This
> patch has a much better explanation than the one I sent so +1 from
> me also
thanks, I'm acking this one then
Acked-by: Jiri Olsa <jolsa@kernel.org>
jirka
>
> David
>
> >
> > jirka
> >
> >
> > [1] https://lore.kernel.org/bpf/YuKaFiZ+ksB5f0Ye@krava/
> >
> >>
> >> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> >> Cc: Jose E. Marchesi <jose.marchesi@oracle.com>
> >> ---
> >> tools/lib/bpf/libbpf.c | 4 ++++
> >> 1 file changed, 4 insertions(+)
> >>
> >> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> >> index 50d41815f431..77e3797cf75a 100644
> >> --- a/tools/lib/bpf/libbpf.c
> >> +++ b/tools/lib/bpf/libbpf.c
> >> @@ -1642,6 +1642,10 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj)
> >> for (sec_idx = 1; sec_idx < obj->efile.sec_cnt; sec_idx++) {
> >> sec_desc = &obj->efile.secs[sec_idx];
> >>
> >> + /* Skip recognized sections with size 0. */
> >> + if (sec_desc->data && sec_desc->data->d_size == 0)
> >> + continue;
> >> +
> >> switch (sec_desc->sec_type) {
> >> case SEC_DATA:
> >> sec_name = elf_sec_name(obj, elf_sec_by_idx(obj, sec_idx));
> >> --
> >> 2.34.1
> >>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libbpf: skip empty sections in bpf_object__init_global_data_maps
2022-07-31 23:26 [PATCH] libbpf: skip empty sections in bpf_object__init_global_data_maps James Hilliard
2022-08-01 20:24 ` Jiri Olsa
@ 2022-08-04 21:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-08-04 21:50 UTC (permalink / raw)
To: James Hilliard
Cc: bpf, jose.marchesi, ast, daniel, andrii, martin.lau, song, yhs,
john.fastabend, kpsingh, sdf, haoluo, jolsa, nathan,
ndesaulniers, trix, linux-kernel, llvm
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Sun, 31 Jul 2022 17:26:49 -0600 you wrote:
> The GNU assembler generates an empty .bss section. This is a well
> established behavior in GAS that happens in all supported targets.
>
> The LLVM assembler doesn't generate an empty .bss section.
>
> bpftool chokes on the empty .bss section.
>
> [...]
Here is the summary with links:
- libbpf: skip empty sections in bpf_object__init_global_data_maps
https://git.kernel.org/bpf/bpf-next/c/47ea7417b074
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-08-04 21:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-31 23:26 [PATCH] libbpf: skip empty sections in bpf_object__init_global_data_maps James Hilliard
2022-08-01 20:24 ` Jiri Olsa
2022-08-01 22:21 ` David Faust
2022-08-02 8:52 ` Jiri Olsa
2022-08-04 21:50 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).