bpftool: use linux/types.h from source tree for profiler build
PATCH 1/1 bpftool: use linux/types.h from source tree for profiler build
When compiling bpftool on a system where the /usr/include/asm symlink doesn't exist (e.g. on an Ubuntu system without gcc-multilib installed), the build fails with:
CLANG skeleton/profiler.bpf.o
In file included from skeleton/profiler.bpf.c:4:
In file included from /usr/include/linux/bpf.h:11:
/usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found
#include <asm/types.h>
^~~~~~~~~~~~~ 1 error generated.
make: *** [Makefile:123: skeleton/profiler.bpf.o] Error 1
This indicates that the build is using linux/types.h from system headers instead of source tree headers.
To fix this, adjust the clang search path to include the necessary headers from tools/testing/selftests/bpf/include/uapi and tools/include/uapi. Also undef __bitwise in skeleton/profiler.h avoid clashing with the empty definition in tools/testing/selftests/bpf/include/uapi/linux/types.h.
--- tools/bpf/bpftool/Makefile | 5 ++++- tools/bpf/bpftool/skeleton/profiler.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-)
tools/bpf/bpftool/Makefile +4 -1
@@ -120,7 +120,10 @@ $(OUTPUT)_bpftool: $(_OBJS) $(LIBBPF) $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(_OBJS) $(LIBS) skeleton/profiler.bpf.o: skeleton/profiler.bpf.c - $(QUIET_CLANG)$(CLANG) -I$(srctree)/tools/lib -g -O2 -target bpf -c $< -o $@ + $(QUIET_CLANG)$(CLANG) \ + -I$(srctree)/tools/include/uapi/ \ + -I$(srctree)/tools/testing/selftests/bpf/include/uapi \ + -I$(srctree)/tools/lib -g -O2 -target bpf -c $< -o $@ profiler.skel.h: $(OUTPUT)_bpftool skeleton/profiler.bpf.o $(QUIET_GEN)$(OUTPUT)./_bpftool gen skeleton skeleton/profiler.bpf.o > $@
tools/bpf/bpftool/skeleton/profiler.h +1 -0
@@ -27,6 +27,7 @@ enum { true = 1, }; +#undef __bitwise#ifdef __CHECKER__#define __bitwise__ __attribute__((bitwise))#else
Signature · 1 line
2.25.1
2020-03-12 11:53 UTC+0100 ~ Tobias Klauser <[email protected]>
Quoted 33 lines
When compiling bpftool on a system where the
/usr/include/asmsymlink doesn't exist (e.g. on an Ubuntu system without gcc-multilib installed), the build fails with:CLANG
skeleton/profiler.bpf.o
In file included fromskeleton/profiler.bpf.c:4:
In file included from/usr/include/linux/bpf.h:11:
/usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found#include <asm/types.h> ^~~~~~~~~~~~~1 error generated.
make: *** [Makefile:123:skeleton/profiler.bpf.o] Error 1This indicates that the build is using
linux/types.hfrom system headers instead of source tree headers.To fix this, adjust the clang search path to include the necessary headers from
tools/testing/selftests/bpf/include/uapiandtools/include/uapi. Also undef__bitwiseinskeleton/profiler.havoid clashing with the empty definition intools/testing/selftests/bpf/include/uapi/linux/types.h.Cc Daniel Borkmann <[email protected]>Cc Song Liu <[email protected]>Cc Alexei Starovoitov <[email protected]>Signed-off-by Tobias Klauser <[email protected]>tools/bpf/bpftool/skeleton/profiler.h +0
-0
tools/bpf/bpftool/skeleton/profiler.h enum { · line 33
Quoted 7 lines
tools/bpf/bpftool/skeleton/profiler.h +1
-0@@ -27,6 +27,7 @@ enum { true = 1, }; +#undef __bitwise#ifdef __CHECKER__#define __bitwise__ __attribute__((bitwise))#else
Even with the #undef above, I get warnings on __bitwise being redefined in tools/testing/selftests/bpf/include/uapi/linux/types.h. Can we maybe just find another name (or number of underscores) for the macro in skeleton/profiler.h?
Makefile change works well otherwise, thanks (tested on Ubuntu with and without gcc-multilib).
Quentin
Quoted 36 lines · Quentin Monnet
2020-03-12 11:53 UTC+0100 ~ Tobias Klauser <[email protected]>
Quoted 35 lines
When compiling bpftool on a system where the
/usr/include/asmsymlink doesn't exist (e.g. on an Ubuntu system without gcc-multilib installed), the build fails with:CLANG
skeleton/profiler.bpf.o
In file included fromskeleton/profiler.bpf.c:4:
In file included from/usr/include/linux/bpf.h:11:
/usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found#include <asm/types.h> ^~~~~~~~~~~~~1 error generated.
make: *** [Makefile:123:skeleton/profiler.bpf.o] Error 1This indicates that the build is using
linux/types.hfrom system headers instead of source tree headers.To fix this, adjust the clang search path to include the necessary headers from
tools/testing/selftests/bpf/include/uapiandtools/include/uapi. Also undef__bitwiseinskeleton/profiler.havoid clashing with the empty definition intools/testing/selftests/bpf/include/uapi/linux/types.h.Cc Daniel Borkmann <[email protected]>Cc Song Liu <[email protected]>Cc Alexei Starovoitov <[email protected]>Signed-off-by Tobias Klauser <[email protected]>tools/bpf/bpftool/skeleton/profiler.h +0
-0@@ -27,6 +27,7 @@ enum { true = 1, };
Quoted 10 lines
tools/bpf/bpftool/skeleton/profiler.h enum { · line 33
Quoted 5 lines
tools/bpf/bpftool/skeleton/profiler.h +1
-0+#undef __bitwise#ifdef __CHECKER__#define __bitwise__ __attribute__((bitwise))#else Even with the #undef above, I get warnings on
__bitwisebeing redefined intools/testing/selftests/bpf/include/uapi/linux/types.h. Can we maybe just find another name (or number of underscores) for the macro inskeleton/profiler.h?
Good point. It seems I actually didn't test this properly. Will change the typedefs to use the existing __bitwise__.
Quoted 2 lines
Makefilechange works well otherwise, thanks (tested on Ubuntu with and without gcc-multilib).
Thanks for testing.
- Tobias
PATCH v2 1/1 bpftool: use linux/types.h from source tree for profiler build
In reply to Tobias KlauserWhen compiling bpftool on a system where the /usr/include/asm symlink doesn't exist (e.g. on an Ubuntu system without gcc-multilib installed), the build fails with:
CLANG skeleton/profiler.bpf.o
In file included from skeleton/profiler.bpf.c:4:
In file included from /usr/include/linux/bpf.h:11:
/usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found
#include <asm/types.h>
^~~~~~~~~~~~~ 1 error generated.
make: *** [Makefile:123: skeleton/profiler.bpf.o] Error 1
This indicates that the build is using linux/types.h from system headers instead of source tree headers.
To fix this, adjust the clang search path to include the necessary headers from tools/testing/selftests/bpf/include/uapi and tools/include/uapi. Also use __bitwise__ instead of __bitwise in skeleton/profiler.h to avoid clashing with the definition in tools/testing/selftests/bpf/include/uapi/linux/types.h.
--- tools/bpf/bpftool/Makefile | 5 ++++- tools/bpf/bpftool/skeleton/profiler.h | 17 ++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-)
tools/bpf/bpftool/Makefile +4 -1
@@ -120,7 +120,10 @@ $(OUTPUT)_bpftool: $(_OBJS) $(LIBBPF) $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(_OBJS) $(LIBS) skeleton/profiler.bpf.o: skeleton/profiler.bpf.c - $(QUIET_CLANG)$(CLANG) -I$(srctree)/tools/lib -g -O2 -target bpf -c $< -o $@ + $(QUIET_CLANG)$(CLANG) \ + -I$(srctree)/tools/include/uapi/ \ + -I$(srctree)/tools/testing/selftests/bpf/include/uapi \ + -I$(srctree)/tools/lib -g -O2 -target bpf -c $< -o $@ profiler.skel.h: $(OUTPUT)_bpftool skeleton/profiler.bpf.o $(QUIET_GEN)$(OUTPUT)./_bpftool gen skeleton skeleton/profiler.bpf.o > $@
tools/bpf/bpftool/skeleton/profiler.h +8 -9
@@ -32,16 +32,15 @@ enum {#else #define __bitwise__#endif -#define __bitwise __bitwise__ -typedef __u16 __bitwise __le16 ; -typedef __u16 __bitwise __be16 ; -typedef __u32 __bitwise __le32 ; -typedef __u32 __bitwise __be32 ; -typedef __u64 __bitwise __le64 ; -typedef __u64 __bitwise __be64 ; +typedef __u16 __bitwise__ __le16; +typedef __u16 __bitwise__ __be16; +typedef __u32 __bitwise__ __le32; +typedef __u32 __bitwise__ __be32; +typedef __u64 __bitwise__ __le64; +typedef __u64 __bitwise__ __be64; -typedef __u16 __bitwise __sum16 ; -typedef __u32 __bitwise __wsum ; +typedef __u16 __bitwise__ __sum16; +typedef __u32 __bitwise__ __wsum;#endif /* __PROFILER_H */
Signature · 1 line
2.25.1
2020-03-12 14:03 UTC+0100 ~ Tobias Klauser <[email protected]>
Quoted 22 lines
When compiling bpftool on a system where the
/usr/include/asmsymlink doesn't exist (e.g. on an Ubuntu system without gcc-multilib installed), the build fails with:CLANG
skeleton/profiler.bpf.o
In file included fromskeleton/profiler.bpf.c:4:
In file included from/usr/include/linux/bpf.h:11:
/usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found#include <asm/types.h> ^~~~~~~~~~~~~1 error generated.
make: *** [Makefile:123:skeleton/profiler.bpf.o] Error 1This indicates that the build is using
linux/types.hfrom system headers instead of source tree headers.To fix this, adjust the clang search path to include the necessary headers from
tools/testing/selftests/bpf/include/uapiandtools/include/uapi. Also use__bitwise__instead of__bitwiseinskeleton/profiler.hto avoid clashing with the definition intools/testing/selftests/bpf/include/uapi/linux/types.h.
Quoted 5 lines
Cc Daniel Borkmann <[email protected]>Cc Song Liu <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Quentin Monnet <[email protected]>Signed-off-by Tobias Klauser <[email protected]>
Looks good, thanks!
Daniel Borkmann
maintainerQuoted 23 lines · Quentin Monnet
2020-03-12 14:03 UTC+0100 ~ Tobias Klauser <[email protected]>
Quoted 22 lines
When compiling bpftool on a system where the
/usr/include/asmsymlink doesn't exist (e.g. on an Ubuntu system without gcc-multilib installed), the build fails with:CLANG
skeleton/profiler.bpf.o
In file included fromskeleton/profiler.bpf.c:4:
In file included from/usr/include/linux/bpf.h:11:/usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found #include <asm/types.h> ^~~~~~~~~~~~~ 1 error generated. make: *** [Makefile:123: skeleton/profiler.bpf.o] Error 1This indicates that the build is using
linux/types.hfrom system headers instead of source tree headers.To fix this, adjust the clang search path to include the necessary headers from
tools/testing/selftests/bpf/include/uapiandtools/include/uapi. Also use__bitwise__instead of__bitwiseinskeleton/profiler.hto avoid clashing with the definition intools/testing/selftests/bpf/include/uapi/linux/types.h.
Quoted 8 lines
Quoted 5 lines
Cc Daniel Borkmann <[email protected]>Cc Song Liu <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Quentin Monnet <[email protected]>Signed-off-by Tobias Klauser <[email protected]>Looks good, thanks!
Reviewed-by Quentin Monnet <[email protected]>
Applied, thanks (compiles fine over here as well now)!
Quoted 38 lines · Tobias Klauser
When compiling bpftool on a system where the
/usr/include/asmsymlink doesn't exist (e.g. on an Ubuntu system without gcc-multilib installed), the build fails with:CLANG
skeleton/profiler.bpf.o
In file included fromskeleton/profiler.bpf.c:4:
In file included from/usr/include/linux/bpf.h:11:
/usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found#include <asm/types.h> ^~~~~~~~~~~~~1 error generated.
make: *** [Makefile:123:skeleton/profiler.bpf.o] Error 1This indicates that the build is using
linux/types.hfrom system headers instead of source tree headers.To fix this, adjust the clang search path to include the necessary headers from
tools/testing/selftests/bpf/include/uapiandtools/include/uapi. Also use__bitwise__instead of__bitwiseinskeleton/profiler.hto avoid clashing with the definition intools/testing/selftests/bpf/include/uapi/linux/types.h.Cc Daniel Borkmann <[email protected]>Cc Song Liu <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Quentin Monnet <[email protected]>Signed-off-by Tobias Klauser <[email protected]>--- tools/bpf/bpftool/Makefile | 5 ++++- tools/bpf/bpftool/skeleton/profiler.h | 17 ++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-)tools/bpf/bpftool/Makefile +0
-0
tools/bpf/bpftool/Makefile $(OUTPUT)_bpftool: $(_OBJS) $(LIBBPF) · line 125
Quoted 7 lines
tools/bpf/bpftool/Makefile +3
-1@@ -120,7 +120,10 @@ $(OUTPUT)_bpftool: $(_OBJS) $(LIBBPF) $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(_OBJS) $(LIBS) skeleton/profiler.bpf.o: skeleton/profiler.bpf.c - $(QUIET_CLANG)$(CLANG) -I$(srctree)/tools/lib -g -O2 -target bpf -c $< -o $@ + $(QUIET_CLANG)$(CLANG) \ + -I$(srctree)/tools/include/uapi/ \ + -I$(srctree)/tools/testing/selftests/bpf/include/uapi \
Seems like I'm spoiling all the fun today :) But why are we ok with bpftool build depending on selftests? This just makes it even harder to have a stand-alone bpftool build eventually (similar to libbpf's Github).
Quoted 36 lines
tools/bpf/bpftool/Makefile +1
-0+ -I$(srctree)/tools/lib -g -O2 -target bpf -c $< -o $@ profiler.skel.h: $(OUTPUT)_bpftool skeleton/profiler.bpf.o $(QUIET_GEN)$(OUTPUT)./_bpftool gen skeleton skeleton/profiler.bpf.o > $@tools/bpf/bpftool/skeleton/profiler.h +8
-10@@ -32,16 +32,15 @@ enum {#else #define __bitwise__#endif -#define __bitwise __bitwise__ -typedef __u16 __bitwise __le16 ; -typedef __u16 __bitwise __be16 ; -typedef __u32 __bitwise __le32 ; -typedef __u32 __bitwise __be32 ; -typedef __u64 __bitwise __le64 ; -typedef __u64 __bitwise __be64 ; +typedef __u16 __bitwise__ __le16; +typedef __u16 __bitwise__ __be16; +typedef __u32 __bitwise__ __le32; +typedef __u32 __bitwise__ __be32; +typedef __u64 __bitwise__ __le64; +typedef __u64 __bitwise__ __be64; -typedef __u16 __bitwise __sum16 ; -typedef __u32 __bitwise __wsum ; +typedef __u16 __bitwise__ __sum16; +typedef __u32 __bitwise__ __wsum;#endif /* __PROFILER_H */ --2.25.1
Daniel Borkmann
maintainerQuoted 41 lines · Andrii Nakryiko
Quoted 40 lines · Tobias Klauser
When compiling bpftool on a system where the
/usr/include/asmsymlink doesn't exist (e.g. on an Ubuntu system without gcc-multilib installed), the build fails with:CLANG
skeleton/profiler.bpf.o
In file included fromskeleton/profiler.bpf.c:4:
In file included from/usr/include/linux/bpf.h:11:/usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found #include <asm/types.h> ^~~~~~~~~~~~~ 1 error generated. make: *** [Makefile:123: skeleton/profiler.bpf.o] Error 1This indicates that the build is using
linux/types.hfrom system headers instead of source tree headers.To fix this, adjust the clang search path to include the necessary headers from
tools/testing/selftests/bpf/include/uapiandtools/include/uapi. Also use__bitwise__instead of__bitwiseinskeleton/profiler.hto avoid clashing with the definition intools/testing/selftests/bpf/include/uapi/linux/types.h.Cc Daniel Borkmann <[email protected]>Cc Song Liu <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Quentin Monnet <[email protected]>Signed-off-by Tobias Klauser <[email protected]>--- tools/bpf/bpftool/Makefile | 5 ++++- tools/bpf/bpftool/skeleton/profiler.h | 17 ++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-)tools/bpf/bpftool/Makefile +0
-0@@ -120,7 +120,10 @@ $(OUTPUT)_bpftool: $(_OBJS) $(LIBBPF) $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(_OBJS) $(LIBS)
Quoted 10 lines
tools/bpf/bpftool/Makefile $(OUTPUT)_bpftool: $(_OBJS) $(LIBBPF) · line 125
Quoted 5 lines
tools/bpf/bpftool/Makefile +3
-1skeleton/profiler.bpf.o: skeleton/profiler.bpf.c - $(QUIET_CLANG)$(CLANG) -I$(srctree)/tools/lib -g -O2 -target bpf -c $< -o $@ + $(QUIET_CLANG)$(CLANG) \ + -I$(srctree)/tools/include/uapi/ \ + -I$(srctree)/tools/testing/selftests/bpf/include/uapi \Seems like I'm spoiling all the fun today :) But why are we ok with bpftool build depending on selftests? This just makes it even harder to have a stand-alone bpftool build eventually (similar to libbpf's Github).
I suspect the Github copy of bpftool would have its own include infra like in case of libbpf [0]?
Agree in any case that it's not an optimal situation with this dependency; I suspect we might need the tools/testing/selftests/bpf/include/uapi/ under tools/include/uapi/ in a proper way.