• W
    bpf tools: Open eBPF object file and do basic validation · 1a5e3fb1
    Wang Nan 提交于
    This patch defines basic interface of libbpf. 'struct bpf_object' will
    be the handler of each object file. Its internal structure is hide to
    user. eBPF object files are compiled by LLVM as ELF format. In this
    patch, libelf is used to open those files, read EHDR and do basic
    validation according to e_type and e_machine.
    
    All elf related staffs are grouped together and reside in efile field of
    'struct bpf_object'. bpf_object__elf_finish() is introduced to clear it.
    
    After all eBPF programs in an object file are loaded, related ELF
    information is useless. Close the object file and free those memory.
    
    The zfree() and zclose() functions are introduced to ensure setting NULL
    pointers and negative file descriptors after resources are released.
    Signed-off-by: NWang Nan <wangnan0@huawei.com>
    Acked-by: NAlexei Starovoitov <ast@plumgrid.com>
    Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
    Cc: Daniel Borkmann <daniel@iogearbox.net>
    Cc: David Ahern <dsahern@gmail.com>
    Cc: He Kuang <hekuang@huawei.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kaixu Xia <xiakaixu@huawei.com>
    Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
    Cc: Zefan Li <lizefan@huawei.com>
    Cc: pi3orama@163.com
    Link: http://lkml.kernel.org/r/1435716878-189507-6-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
    1a5e3fb1
libbpf.c 4.0 KB