• Andrii Nakryiko's avatar
    libbpf: Refactor relocation handling · 1f8e2bcb
    Andrii Nakryiko authored
    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: default avatarAndrii Nakryiko <andriin@fb.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Link: https://lore.kernel.org/bpf/20191121070743.1309473-3-andriin@fb.com
    1f8e2bcb
libbpf.c 162 KB