]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: Refactor relocation handling
authorAndrii Nakryiko <andriin@fb.com>
Thu, 21 Nov 2019 07:07:41 +0000 (23:07 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 25 Nov 2019 00:58:45 +0000 (16:58 -0800)
commitfe546dbd3aabe2d63c35866f8fdcde6cd2e934b8
treeb06cb9fbde1c9a91db7429122fef164adfc10ac6
parent0764973ab3573957e9689ec3b90384b5befc5963
libbpf: Refactor relocation handling

Relocation handling code is convoluted and unnecessarily deeply nested. Split
out per-relocation logic into separate function. Also refactor the logic to be
more a sequence of per-relocation type checks and processing steps, making it
simpler to follow control flow. This makes it easier to further extends it to
new kinds of relocations (e.g., support for extern variables).

This patch also makes relocation's section verification more robust.
Previously relocations against not yet supported externs were silently ignored
because of obj->efile.text_shndx was zero, when all BPF programs had custom
section names and there was no .text section. Also, invalid LDIMM64 relocations
against non-map sections were passed through, if they were pointing to a .text
section (or 0, which is invalid section). All these bugs are fixed within this
refactoring and checks are made more appropriate for each type of relocation.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20191121070743.1309473-3-andriin@fb.com
tools/lib/bpf/libbpf.c