All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2] samples: bpf: print a warning about headers_install
@ 2019-06-05 23:47 Jakub Kicinski
  2019-06-06  0:03 ` Martin Lau
  2019-06-06  0:18 ` Daniel Borkmann
  0 siblings, 2 replies; 3+ messages in thread
From: Jakub Kicinski @ 2019-06-05 23:47 UTC (permalink / raw)
  To: alexei.starovoitov, daniel
  Cc: bpf, netdev, oss-drivers, Jakub Kicinski, Quentin Monnet

It seems like periodically someone posts patches to "fix"
header includes.  The issue is that samples expect the
include path to have the uAPI headers (from usr/) first,
and then tools/ headers, so that locally installed uAPI
headers take precedence.  This means that if users didn't
run headers_install they will see all sort of strange
compilation errors, e.g.:

  HOSTCC  samples/bpf/test_lru_dist
  samples/bpf/test_lru_dist.c:39:8: error: redefinition of ‘struct list_head’
   struct list_head {
          ^~~~~~~~~
   In file included from samples/bpf/test_lru_dist.c:9:0:
   ../tools/include/linux/types.h:69:8: note: originally defined here
    struct list_head {
           ^~~~~~~~~

Try to detect this situation, and print a helpful warning.

v2: just use HOSTCC (Jiong).

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
---
 samples/bpf/Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 253e5a2856be..4074a66a70ca 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -206,6 +206,15 @@ HOSTCC = $(CROSS_COMPILE)gcc
 CLANG_ARCH_ARGS = -target $(ARCH)
 endif
 
+HDR_PROBE := $(shell echo "\#include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
+	$(HOSTCC) $(KBUILD_HOSTCFLAGS) -x c - -o /dev/null 2>/dev/null && \
+	echo okay)
+
+ifeq ($(HDR_PROBE),)
+$(warning WARNING: Detected possible issues with include path.)
+$(warning WARNING: Please install kernel headers locally (make headers_install).)
+endif
+
 BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris)
 BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF)
 BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm')
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next v2] samples: bpf: print a warning about headers_install
  2019-06-05 23:47 [PATCH bpf-next v2] samples: bpf: print a warning about headers_install Jakub Kicinski
@ 2019-06-06  0:03 ` Martin Lau
  2019-06-06  0:18 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Martin Lau @ 2019-06-06  0:03 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: alexei.starovoitov, daniel, bpf, netdev, oss-drivers, Quentin Monnet

On Wed, Jun 05, 2019 at 04:47:22PM -0700, Jakub Kicinski wrote:
> It seems like periodically someone posts patches to "fix"
> header includes.  The issue is that samples expect the
> include path to have the uAPI headers (from usr/) first,
> and then tools/ headers, so that locally installed uAPI
> headers take precedence.  This means that if users didn't
> run headers_install they will see all sort of strange
> compilation errors, e.g.:
> 
>   HOSTCC  samples/bpf/test_lru_dist
>   samples/bpf/test_lru_dist.c:39:8: error: redefinition of ‘struct list_head’
>    struct list_head {
>           ^~~~~~~~~
>    In file included from samples/bpf/test_lru_dist.c:9:0:
>    ../tools/include/linux/types.h:69:8: note: originally defined here
>     struct list_head {
>            ^~~~~~~~~
> 
> Try to detect this situation, and print a helpful warning.
Acked-by: Martin KaFai Lau <kafai@fb.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next v2] samples: bpf: print a warning about headers_install
  2019-06-05 23:47 [PATCH bpf-next v2] samples: bpf: print a warning about headers_install Jakub Kicinski
  2019-06-06  0:03 ` Martin Lau
@ 2019-06-06  0:18 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2019-06-06  0:18 UTC (permalink / raw)
  To: Jakub Kicinski, alexei.starovoitov
  Cc: bpf, netdev, oss-drivers, Quentin Monnet

On 06/06/2019 01:47 AM, Jakub Kicinski wrote:
> It seems like periodically someone posts patches to "fix"
> header includes.  The issue is that samples expect the
> include path to have the uAPI headers (from usr/) first,
> and then tools/ headers, so that locally installed uAPI
> headers take precedence.  This means that if users didn't
> run headers_install they will see all sort of strange
> compilation errors, e.g.:
> 
>   HOSTCC  samples/bpf/test_lru_dist
>   samples/bpf/test_lru_dist.c:39:8: error: redefinition of ‘struct list_head’
>    struct list_head {
>           ^~~~~~~~~
>    In file included from samples/bpf/test_lru_dist.c:9:0:
>    ../tools/include/linux/types.h:69:8: note: originally defined here
>     struct list_head {
>            ^~~~~~~~~
> 
> Try to detect this situation, and print a helpful warning.
> 
> v2: just use HOSTCC (Jiong).
> 
> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>

Applied, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-06  0:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-05 23:47 [PATCH bpf-next v2] samples: bpf: print a warning about headers_install Jakub Kicinski
2019-06-06  0:03 ` Martin Lau
2019-06-06  0:18 ` Daniel Borkmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.