netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <brouer@redhat.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: netdev@vger.kernel.org, Daniel Borkmann <borkmann@iogearbox.net>,
	wangnan0@huawei.com, jakub.kicinski@netronome.com, joe@ovn.org,
	acme@redhat.com, eric@regit.org, yhs@fb.com, brouer@redhat.com
Subject: Re: [bpf-next V2 PATCH 5/5] tools/libbpf: handle issues with bpf ELF objects containing .eh_frames
Date: Tue, 6 Feb 2018 18:03:48 +0100	[thread overview]
Message-ID: <20180206180348.469344b2@redhat.com> (raw)
In-Reply-To: <20180206160057.jxf7qc64jq2gmrf2@ast-mbp.dhcp.thefacebook.com>


On Tue, 6 Feb 2018 08:00:59 -0800 Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:

> On Tue, Feb 06, 2018 at 03:54:28PM +0100, Jesper Dangaard Brouer wrote:
> > If clang >= 4.0.1 is missing the option '-target bpf', it will cause
> > llc/llvm to create two ELF sections for "Exception Frames", with
> > section names '.eh_frame' and '.rel.eh_frame'.
> > 
> > The BPF ELF loader library libbpf fails when loading files with these
> > sections.  The other in-kernel BPF ELF loader in samples/bpf/bpf_load.c,
> > handle this gracefully. And iproute2 loader also seems to work with these
> > "eh" sections.
> > 
> > The issue in libbpf is caused by bpf_object__elf_collect() skip the
> > '.eh_frame' and thus doesn't create an internal data structure
> > pointing to this ELF section index.  Later when the relocation section
> > '.rel.eh_frame' is processed, it tries to find the '.eh_frame' via the
> > ELF section idx, which is that fails (in bpf_object__collect_reloc).
> > 
> > I couldn't find a way to see that the '.rel.eh_frame' was irrelevant
> > (that is only determined by looking at the section it reference, which
> > we no longer have info available on).  
> 
> but does this approach work for all extra sections and relocations emitted
> when source is compiled with -g ?

No, but I plan to follow up and do a more complete solution later. This
is a workaround to get the Suricata use-case working and also that
samples/bpf/ can be loaded.

> To address this case bpf_load.c does:
>   if (shdr.sh_type == SHT_REL) {
>           struct bpf_insn *insns;
> 
>           /* locate prog sec that need map fixup (relocations) */
>           if (get_sec(elf, shdr.sh_info, &ehdr, &shname_prog,
>                       &shdr_prog, &data_prog))
>                   continue;
> 
>           if (shdr_prog.sh_type != SHT_PROGBITS ||
>               !(shdr_prog.sh_flags & SHF_EXECINSTR))
>                   continue;
> 
> why the same approach is not applicable here?

As described above bpf_object__elf_collect() skip the "real" section
that the relo-section want to lookup (based on the same kind of
check), but libbpf is now missing the section idx in its internal
structures... and thus the relo lookup of the idx fails. (bpf_load.c
does the lookup in the ELF obj directly, thus it does not have this
problem).


> I guess we can apply this workaround as-is but it looks incomplete.

Yes, it is a workaround to move forward... it requires a larger change
to libbpf, so it stores idx'es of skipped sections.

-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer

  reply	other threads:[~2018-02-06 17:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-06 14:54 [bpf-next V2 PATCH 0/5] tools/libbpf improvements and selftests Jesper Dangaard Brouer
2018-02-06 14:54 ` [bpf-next V2 PATCH 1/5] bpf: Sync kernel ABI header with tooling header for bpf_common.h Jesper Dangaard Brouer
2018-02-06 14:54 ` [bpf-next V2 PATCH 2/5] tools/libbpf: improve the pr_debug statements to contain section numbers Jesper Dangaard Brouer
2018-02-06 14:54 ` [bpf-next V2 PATCH 3/5] selftests/bpf: add test program for loading BPF ELF files Jesper Dangaard Brouer
2018-02-06 14:54 ` [bpf-next V2 PATCH 4/5] selftests/bpf: add selftest that use test_libbpf_open Jesper Dangaard Brouer
2018-02-06 14:54 ` [bpf-next V2 PATCH 5/5] tools/libbpf: handle issues with bpf ELF objects containing .eh_frames Jesper Dangaard Brouer
2018-02-06 16:00   ` Alexei Starovoitov
2018-02-06 17:03     ` Jesper Dangaard Brouer [this message]
2018-02-06 19:05       ` Daniel Borkmann
2018-02-07 12:40         ` Jesper Dangaard Brouer
2018-02-07 13:19           ` Daniel Borkmann
2018-02-07 14:58             ` Jesper Dangaard Brouer
2018-02-07 16:18               ` Daniel Borkmann
2018-02-07 22:21               ` [suricata PATCH 0/3] Suricata cleanup makefile Jesper Dangaard Brouer
2018-02-07 22:21                 ` [suricata PATCH 1/3] suricata/ebpf: take clang -target bpf include issue of stdint.h into account Jesper Dangaard Brouer
2018-02-07 23:52                   ` Eric Leblond
2018-02-08  8:42                     ` Jesper Dangaard Brouer
2018-02-07 22:21                 ` [suricata PATCH 2/3] suricata/ebpf: compile with clang -target bpf Jesper Dangaard Brouer
2018-02-07 22:21                 ` [suricata PATCH 3/3] suricata/ebpf: improving the ebpf makefile Jesper Dangaard Brouer
2018-02-07 22:38                 ` [suricata PATCH 0/3] Suricata cleanup makefile Eric Leblond

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=20180206180348.469344b2@redhat.com \
    --to=brouer@redhat.com \
    --cc=acme@redhat.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=borkmann@iogearbox.net \
    --cc=eric@regit.org \
    --cc=jakub.kicinski@netronome.com \
    --cc=joe@ovn.org \
    --cc=netdev@vger.kernel.org \
    --cc=wangnan0@huawei.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;
as well as URLs for NNTP newsgroup(s).