• A
    libbpf: Support extern resolution for BTF-defined maps in .maps section · bca088f3
    Andrii Nakryiko 提交于
    mainline inclusion
    from mainline-5.13-rc1
    commit 0a342457
    category: feature
    bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
    CVE: NA
    
    Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0a342457b3bd36e6f9b558da3ff520dee35c5363
    
    -------------------------------------------------
    
    Add extra logic to handle map externs (only BTF-defined maps are supported for
    linking). Re-use the map parsing logic used during bpf_object__open(). Map
    externs are currently restricted to always match complete map definition. So
    all the specified attributes will be compared (down to pining, map_flags,
    numa_node, etc). In the future this restriction might be relaxed with no
    backwards compatibility issues. If any attribute is mismatched between extern
    and actual map definition, linker will report an error, pointing out which one
    mismatches.
    
    The original intent was to allow for extern to specify attributes that matters
    (to user) to enforce. E.g., if you specify just key information and omit
    value, then any value fits. Similarly, it should have been possible to enforce
    map_flags, pinning, and any other possible map attribute. Unfortunately, that
    means that multiple externs can be only partially overlapping with each other,
    which means linker would need to combine their type definitions to end up with
    the most restrictive and fullest map definition. This requires an extra amount
    of BTF manipulation which at this time was deemed unnecessary and would
    require further extending generic BTF writer APIs. So that is left for future
    follow ups, if there will be demand for that. But the idea seems intresting
    and useful, so I want to document it here.
    
    Weak definitions are also supported, but are pretty strict as well, just
    like externs: all weak map definitions have to match exactly. In the follow up
    patches this most probably will be relaxed, with __weak map definitions being
    able to differ between each other (with non-weak definition always winning, of
    course).
    Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
    Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
    Acked-by: NYonghong Song <yhs@fb.com>
    Link: https://lore.kernel.org/bpf/20210423181348.1801389-13-andrii@kernel.org
    (cherry picked from commit 0a342457)
    Signed-off-by: NWang Yufen <wangyufen@huawei.com>
    bca088f3
linker.c 74.7 KB