• Yonghong Song's avatar
    samples/bpf: Remove compiler warnings · 03421a92
    Yonghong Song authored
    Commit 5fbc2208 ("tools/libpf: Add offsetof/container_of macro
    in bpf_helpers.h") added macros offsetof/container_of to
    bpf_helpers.h. Unfortunately, it caused compilation warnings
    below for a few samples/bpf programs:
      In file included from /data/users/yhs/work/net-next/samples/bpf/sockex2_kern.c:4:
      In file included from /data/users/yhs/work/net-next/include/uapi/linux/in.h:24:
      In file included from /data/users/yhs/work/net-next/include/linux/socket.h:8:
      In file included from /data/users/yhs/work/net-next/include/linux/uio.h:8:
      /data/users/yhs/work/net-next/include/linux/kernel.h:992:9: warning: 'container_of' macro redefined [-Wmacro-redefined]
              ^
      /data/users/yhs/work/net-next/tools/lib/bpf/bpf_helpers.h:46:9: note: previous definition is here
              ^
      1 warning generated.
        CLANG-bpf  samples/bpf/sockex3_kern.o
    
    In all these cases, bpf_helpers.h is included first, followed by other
    standard headers. The macro container_of is defined unconditionally
    in kernel.h, causing the compiler warning.
    
    The fix is to move bpf_helpers.h after standard headers.
    Signed-off-by: default avatarYonghong Song <yhs@fb.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
    Link: https://lore.kernel.org/bpf/20200513180223.2949987-1-yhs@fb.com
    03421a92
sockex3_kern.c 6.14 KB