From: David Faust <david.faust@oracle.com>
To: Jiri Olsa <olsajiri@gmail.com>,
James Hilliard <james.hilliard1@gmail.com>
Cc: bpf@vger.kernel.org,
"Jose E . Marchesi" <jose.marchesi@oracle.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Tom Rix <trix@redhat.com>,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH] libbpf: skip empty sections in bpf_object__init_global_data_maps
Date: Mon, 1 Aug 2022 15:21:58 -0700 [thread overview]
Message-ID: <2dbffe19-6b28-2ce6-b367-960f2250a12a@oracle.com> (raw)
In-Reply-To: <Yug2iYQyd0TNlnHW@krava>
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
>>
next prev parent reply other threads:[~2022-08-01 22:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2022-08-02 8:52 ` Jiri Olsa
2022-08-04 21:50 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2dbffe19-6b28-2ce6-b367-960f2250a12a@oracle.com \
--to=david.faust@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=james.hilliard1@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=jose.marchesi@oracle.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=martin.lau@linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=olsajiri@gmail.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=trix@redhat.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox