From: Yonghong Song <yhs@fb.com>
To: Luigi Rizzo <rizzo@iet.unipi.it>, <bpf@vger.kernel.org>,
<ppenkov@google.com>, Luigi Rizzo <lrizzo@google.com>,
<andriin@fb.com>, <sdf@google.com>
Subject: Re: libbpf/bpftool inconsistent handling og .data and .bss ?
Date: Wed, 7 Oct 2020 08:58:18 -0700 [thread overview]
Message-ID: <0b04c2f6-c9fe-0a2a-810b-bacd9b2f8478@fb.com> (raw)
In-Reply-To: <CA+hQ2+gb_y7TViv13K_JpJTP=yHFqORmY+=6PrO4eAjgrBSitw@mail.gmail.com>
On 10/7/20 7:01 AM, Luigi Rizzo wrote:
> I am experiencing some weirdness in global variables handling
> in bpftool and libbpf, as described below.
>
> This happens happen with code in foo_bpf.c compiled with
> clang-10 -O2 -Wall -Werror -target bpf ...
> and subsequently exported with
> bpftool gen skeleton ...
> (i have tried bpftool 5.8.7 and 5.9.0-rc6)
>
> 1. uninitialized globals are not recognised
> The following code in the bpf program
>
> int x;
> SEC("fentry/bar")
> int BPF_PROG(bar) { return 0;}
>
> compiles ok but bpftool then complains
>
> libbpf: prog 'bar': invalid relo against 'x' in special section
> 0xfff2; forgot to initialize global var?..
>
> The error disappears if I initialize x=0 or x=1
> (in the skeleton, x=0 ends up in .bss, x=1 ends up in .data)
Yes, this is a particular issue with llvm10 which without "=0", put
into "common" section which we do not support. The issue is correct
in llvm11 if I remember correctly. But please just use "x = 0" it works
for all versions of compilers.
>
> 2. .bss overrides from userspace are not seen in bpf at runtime
>
> In foo_bpf.c I have "int x = 0;"
> In the userspace program, before foo_bpf__load(), I do
> obj->bss->x = 1
> but after attach, the bpf code does not see the change, ie
> "if (x == 0) { .. } else { .. }"
> always takes the first branch.
>
> If I initialize "int x = 2" and then do
> obj->data->x = 1
> the update is seen correctly ie
> "if (x == 2) { .. } else { .. }"
> takes one or the other depending on whether userspace overrides
> the value before foo_bpf__load()
>
> 3. .data overrides do not seem to work for non-scalar types
> In foo_bpf.c I have
> struct one { int a; }; // type also visible to userspace
> struct one x { .a = 2 }; // avoid bugs #1 and #2
> If in userspace I do
> obj->data->x.a = 1
> the update is not seen in the kernel, ie
> "if (x.a == 2) { .. } else { .. }"
> always takes the first branch
>
> Are these known issues ?
>
> thanks
> luigi
>
next prev parent reply other threads:[~2020-10-07 15:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-07 14:01 libbpf/bpftool inconsistent handling og .data and .bss ? Luigi Rizzo
2020-10-07 15:58 ` Yonghong Song [this message]
2020-10-07 18:35 ` Andrii Nakryiko
2020-10-07 20:31 ` Luigi Rizzo
2020-10-07 20:40 ` Andrii Nakryiko
2020-10-07 21:29 ` Luigi Rizzo
2020-10-07 22:26 ` Andrii Nakryiko
2020-10-08 1:33 ` Yonghong Song
2020-10-10 22:49 ` Luigi Rizzo
2020-10-10 23:11 ` Andrii Nakryiko
2020-10-11 0:31 ` Luigi Rizzo
2020-10-11 1:36 ` Andrii Nakryiko
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=0b04c2f6-c9fe-0a2a-810b-bacd9b2f8478@fb.com \
--to=yhs@fb.com \
--cc=andriin@fb.com \
--cc=bpf@vger.kernel.org \
--cc=lrizzo@google.com \
--cc=ppenkov@google.com \
--cc=rizzo@iet.unipi.it \
--cc=sdf@google.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;
as well as URLs for NNTP newsgroup(s).