1. 30 Jan, 2024 2 commits
    • Jose E. Marchesi's avatar
      bpf: Generate const static pointers for kernel helpers · ff2071a7
      Jose E. Marchesi authored
      The generated bpf_helper_defs.h file currently contains definitions
      like this for the kernel helpers, which are static objects:
      
        static void *(*bpf_map_lookup_elem)(void *map, const void *key) = (void *) 1;
      
      These work well in both clang and GCC because both compilers do
      constant propagation with -O1 and higher optimization, resulting in
      `call 1' BPF instructions being generated, which are calls to kernel
      helpers.
      
      However, there is a discrepancy on how the -Wunused-variable
      warning (activated by -Wall) is handled in these compilers:
      
      - clang will not emit -Wunused-variable warnings for static variables
        defined in C header files, be them constant or not constant.
      
      - GCC will not emit -Wunused-variable warnings for _constant_ static
        variables defined in header files, but it will emit warnings for
        non-constant static variables defined in header files.
      
      There is no reason for these bpf_helpers_def.h pointers to not be
      declared constant, and it is actually desirable to do so, since their
      values are not to be changed.  So this patch modifies bpf_doc.py to
      generate prototypes like:
      
        static void *(* const bpf_map_lookup_elem)(void *map, const void *key) = (void *) 1;
      
      This allows GCC to not error while compiling BPF programs with `-Wall
      -Werror', while still being able to detect and error on legitimate
      unused variables in the program themselves.
      
      This change doesn't impact the desired constant propagation in neither
      Clang nor GCC with -O1 and higher.  On the contrary, being declared as
      constant may increase the odds they get constant folded when
      used/referred to in certain circumstances.
      
      Tested in bpf-next master.
      No regressions.
      Signed-off-by: default avatarJose E. Marchesi <jose.marchesi@oracle.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
      Link: https://lore.kernel.org/bpf/20240127185031.29854-1-jose.marchesi@oracle.com
      ff2071a7
    • Ian Rogers's avatar
      libbpf: Add some details for BTF parsing failures · f2e4040c
      Ian Rogers authored
      As CONFIG_DEBUG_INFO_BTF is default off the existing "failed to find
      valid kernel BTF" message makes diagnosing the kernel build issue somewhat
      cryptic. Add a little more detail with the hope of helping users.
      
      Before:
      ```
      libbpf: failed to find valid kernel BTF
      libbpf: Error loading vmlinux BTF: -3
      ```
      
      After not accessible:
      ```
      libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
      libbpf: failed to find valid kernel BTF
      libbpf: Error loading vmlinux BTF: -3
      ```
      
      After not readable:
      ```
      libbpf: failed to read kernel BTF from (/sys/kernel/btf/vmlinux): -1
      ```
      
      Closes: https://lore.kernel.org/bpf/CAP-5=fU+DN_+Y=Y4gtELUsJxKNDDCOvJzPHvjUVaUoeFAzNnig@mail.gmail.com/Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20240125231840.1647951-1-irogers@google.com
      f2e4040c
  2. 29 Jan, 2024 34 commits
  3. 27 Jan, 2024 4 commits