1
0
Fork 0
remarkable-linux/tools/lib/bpf
Jesper Dangaard Brouer d6b00490a0 tools/libbpf: handle issues with bpf ELF objects containing .eh_frames
[ Upstream commit e3d91b0ca5 ]

V3: More generic skipping of relo-section (suggested by Daniel)

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() skipping
some sections, and later when performing relocation it will be
pointing to a skipped section, as these sections cannot be found by
bpf_object__find_prog_by_idx() in bpf_object__collect_reloc().

This is a general issue that also occurs for other sections, like
debug sections which are also skipped and can have relo section.

As suggested by Daniel.  To avoid keeping state about all skipped
sections, instead perform a direct qlookup in the ELF object.  Lookup
the section that the relo-section points to and check if it contains
executable machine instructions (denoted by the sh_flags
SHF_EXECINSTR).  Use this check to also skip irrelevant relo-sections.

Note, for samples/bpf/ the '-target bpf' parameter to clang cannot be used
due to incompatibility with asm embedded headers, that some of the samples
include. This is explained in more details by Yonghong Song in bpf_devel_QA.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-04-26 11:02:19 +02:00
..
.gitignore tools lib bpf: Change FEATURE-DUMP to FEATURE-DUMP.libbpf 2015-11-05 12:47:51 -03:00
Build bpf tools: Add bpf.c/h for common bpf operations 2015-08-07 10:16:58 -03:00
Makefile libbpf: Makefile set specified permission mode 2018-04-26 11:02:05 +02:00
bpf.c bpf: convert sockmap field attach_bpf_fd2 to type 2017-08-28 11:13:21 -07:00
bpf.h bpf: convert sockmap field attach_bpf_fd2 to type 2017-08-28 11:13:21 -07:00
libbpf.c tools/libbpf: handle issues with bpf ELF objects containing .eh_frames 2018-04-26 11:02:19 +02:00
libbpf.h bpf: selftests add sockmap tests 2017-08-16 11:27:53 -07:00