* [PATCH bpf-next] libbpf: provide more helpful message on uninitialized global var
@ 2019-07-23 4:23 Andrii Nakryiko
2019-07-23 8:51 ` Song Liu
0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2019-07-23 4:23 UTC (permalink / raw)
To: bpf, netdev, ast, daniel; +Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko
When BPF program defines uninitialized global variable, it's put into
a special COMMON section. Libbpf will reject such programs, but will
provide very unhelpful message with garbage-looking section index.
This patch detects special section cases and gives more explicit error
message.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
tools/lib/bpf/libbpf.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 794dd5064ae8..5f9e7eedb134 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1760,15 +1760,23 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
(long long) sym.st_value, sym.st_name, name);
shdr_idx = sym.st_shndx;
+ insn_idx = rel.r_offset / sizeof(struct bpf_insn);
+ pr_debug("relocation: insn_idx=%u, shdr_idx=%u\n",
+ insn_idx, shdr_idx);
+
+ if (shdr_idx >= SHN_LORESERVE) {
+ pr_warning("relocation: not yet supported relo for non-static global \'%s\' variable "
+ "in special section (0x%x) found in insns[%d].code 0x%x\n",
+ name, shdr_idx, insn_idx,
+ insns[insn_idx].code);
+ return -LIBBPF_ERRNO__RELOC;
+ }
if (!bpf_object__relo_in_known_section(obj, shdr_idx)) {
pr_warning("Program '%s' contains unrecognized relo data pointing to section %u\n",
prog->section_name, shdr_idx);
return -LIBBPF_ERRNO__RELOC;
}
- insn_idx = rel.r_offset / sizeof(struct bpf_insn);
- pr_debug("relocation: insn_idx=%u\n", insn_idx);
-
if (insns[insn_idx].code == (BPF_JMP | BPF_CALL)) {
if (insns[insn_idx].src_reg != BPF_PSEUDO_CALL) {
pr_warning("incorrect bpf_call opcode\n");
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] libbpf: provide more helpful message on uninitialized global var
2019-07-23 4:23 [PATCH bpf-next] libbpf: provide more helpful message on uninitialized global var Andrii Nakryiko
@ 2019-07-23 8:51 ` Song Liu
2019-07-23 17:33 ` Andrii Nakryiko
0 siblings, 1 reply; 3+ messages in thread
From: Song Liu @ 2019-07-23 8:51 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: bpf, netdev, Alexei Starovoitov, daniel, andrii.nakryiko, Kernel Team
> On Jul 22, 2019, at 9:23 PM, Andrii Nakryiko <andriin@fb.com> wrote:
>
> When BPF program defines uninitialized global variable, it's put into
> a special COMMON section. Libbpf will reject such programs, but will
> provide very unhelpful message with garbage-looking section index.
>
> This patch detects special section cases and gives more explicit error
> message.
>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
> tools/lib/bpf/libbpf.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 794dd5064ae8..5f9e7eedb134 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -1760,15 +1760,23 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
> (long long) sym.st_value, sym.st_name, name);
>
> shdr_idx = sym.st_shndx;
> + insn_idx = rel.r_offset / sizeof(struct bpf_insn);
> + pr_debug("relocation: insn_idx=%u, shdr_idx=%u\n",
> + insn_idx, shdr_idx);
> +
> + if (shdr_idx >= SHN_LORESERVE) {
> + pr_warning("relocation: not yet supported relo for non-static global \'%s\' variable "
> + "in special section (0x%x) found in insns[%d].code 0x%x\n",
For easy grep, we should keep this one long long string.
Thanks,
Song
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] libbpf: provide more helpful message on uninitialized global var
2019-07-23 8:51 ` Song Liu
@ 2019-07-23 17:33 ` Andrii Nakryiko
0 siblings, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2019-07-23 17:33 UTC (permalink / raw)
To: Song Liu
Cc: Andrii Nakryiko, bpf, netdev, Alexei Starovoitov, daniel, Kernel Team
On Tue, Jul 23, 2019 at 1:51 AM Song Liu <songliubraving@fb.com> wrote:
>
>
>
> > On Jul 22, 2019, at 9:23 PM, Andrii Nakryiko <andriin@fb.com> wrote:
> >
> > When BPF program defines uninitialized global variable, it's put into
> > a special COMMON section. Libbpf will reject such programs, but will
> > provide very unhelpful message with garbage-looking section index.
> >
> > This patch detects special section cases and gives more explicit error
> > message.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > ---
> > tools/lib/bpf/libbpf.c | 14 +++++++++++---
> > 1 file changed, 11 insertions(+), 3 deletions(-)
> >
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index 794dd5064ae8..5f9e7eedb134 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
> > @@ -1760,15 +1760,23 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
> > (long long) sym.st_value, sym.st_name, name);
> >
> > shdr_idx = sym.st_shndx;
> > + insn_idx = rel.r_offset / sizeof(struct bpf_insn);
> > + pr_debug("relocation: insn_idx=%u, shdr_idx=%u\n",
> > + insn_idx, shdr_idx);
> > +
> > + if (shdr_idx >= SHN_LORESERVE) {
> > + pr_warning("relocation: not yet supported relo for non-static global \'%s\' variable "
> > + "in special section (0x%x) found in insns[%d].code 0x%x\n",
>
> For easy grep, we should keep this one long long string.
I was worried it's way too long, so split it. But yeah, I'll just
merge it back into single line, thanks!
>
> Thanks,
> Song
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-23 17:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-23 4:23 [PATCH bpf-next] libbpf: provide more helpful message on uninitialized global var Andrii Nakryiko
2019-07-23 8:51 ` Song Liu
2019-07-23 17:33 ` Andrii Nakryiko
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).