Skip to content
Snippets Groups Projects
  • Dave Marchevsky's avatar
    Move HAVE_BUILTIN_BSWAP includes to separate header · d089013e
    Dave Marchevsky authored
    As reported in #3366, on newer kernels bcc complains about macro
    redefinition when compiling bpf programs:
    
    ```
    include/linux/compiler-clang.h:46:9: warning: '__HAVE_BUILTIN_BSWAP64__' macro redefined [-Wmacro-redefined]
    \#define __HAVE_BUILTIN_BSWAP64__
            ^
    <command line>:5:9: note: previous definition is here
    \#define __HAVE_BUILTIN_BSWAP64__ 1
    ```
    
    Since these macros are passed in as `-D` cflags, they appear first
    before any \#define statements in code. Since an [upstream kernel
    patch](https://lore.kernel.org/linux-csky/20210226161151.2629097-1-arnd@kernel.org/)
    added these defines in a kernel header, we see the warning.
    
    This patch moves these definitions to a separate 'virtual' header that's included
    after virtual_bpf.h and adds an ifndef guard. As a result, newer kernels
    with the patch will not trigger the warning, while older kernels will
    not lose the definition.
    
    This should be safe based on my digging - some existing bcc programs use
    `__builtin_bswap` methods, but without checking HAVE_BUILTIN_BSWAP.
    Macros that may be conditionally defined based on HAVE_BUILTIN_BSWAP,
    like those in `bpf_endian.h`, aren't. If a similar macro or struct def
    in virtual_bpf.h - or any header it pulls in - changes depending on
    HAVE_BUILTIN_BSWAP this could cause problems on older kernels, but I
    don't believe that this is the case, or will be based on how
    infrequently the defines are checked.
    d089013e