Skip to content

Commit

Permalink
bpftool: Use linux/types.h from source tree for profiler build
Browse files Browse the repository at this point in the history
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 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.

Signed-off-by: Tobias Klauser <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Reviewed-by: Quentin Monnet <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
tklauser authored and borkmann committed Mar 12, 2020
1 parent 37ccc12 commit fe4eb06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
5 changes: 4 additions & 1 deletion tools/bpf/bpftool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 > $@
Expand Down
17 changes: 8 additions & 9 deletions tools/bpf/bpftool/skeleton/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit fe4eb06

Please sign in to comment.