aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2017-07-10 17:04:28 -0400
committerDavid S. Miller <davem@davemloft.net>2017-07-11 23:51:29 -0400
commit533350227d95937703aaa16414701eadd67f3ac3 (patch)
tree0fb01390f34db0ba88a21511fff195c0f06cd03d
parent1bfb159673957644951ab0a8d2aec44b93ddb1ae (diff)
samples/bpf: fix a build issue
With latest net-next: ==== clang -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/6.3.1/include -I./arch/x86/include -I./arch/x86/include/generated/uapi -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -Isamples/bpf \ -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \ -Wno-compare-distinct-pointer-types \ -Wno-gnu-variable-sized-type-not-at-end \ -Wno-address-of-packed-member -Wno-tautological-compare \ -Wno-unknown-warning-option \ -O2 -emit-llvm -c samples/bpf/tcp_synrto_kern.c -o -| llc -march=bpf -filetype=obj -o samples/bpf/tcp_synrto_kern.o samples/bpf/tcp_synrto_kern.c:20:10: fatal error: 'bpf_endian.h' file not found ^~~~~~~~~~~~~~ 1 error generated. ==== net has the same issue. Add support for ntohl and htonl in tools/testing/selftests/bpf/bpf_endian.h. Also move bpf_helpers.h from samples/bpf to selftests/bpf and change compiler include logic so that programs in samples/bpf can access the headers in selftests/bpf, but not the other way around. Signed-off-by: Yonghong Song <yhs@fb.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Lawrence Brakmo <brakmo@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--samples/bpf/Makefile1
-rw-r--r--tools/testing/selftests/bpf/Makefile1
-rw-r--r--tools/testing/selftests/bpf/bpf_endian.h14
-rw-r--r--tools/testing/selftests/bpf/bpf_helpers.h (renamed from samples/bpf/bpf_helpers.h)0
4 files changed, 15 insertions, 1 deletions
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 9c650589e80f..87246be6feb8 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -207,6 +207,7 @@ $(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
207# useless for BPF samples. 207# useless for BPF samples.
208$(obj)/%.o: $(src)/%.c 208$(obj)/%.o: $(src)/%.c
209 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \ 209 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
210 -I$(srctree)/tools/testing/selftests/bpf/ \
210 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \ 211 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
211 -Wno-compare-distinct-pointer-types \ 212 -Wno-compare-distinct-pointer-types \
212 -Wno-gnu-variable-sized-type-not-at-end \ 213 -Wno-gnu-variable-sized-type-not-at-end \
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 2ca51a8a588c..153c3a181a4c 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -37,6 +37,5 @@ CLANG ?= clang
37 37
38%.o: %.c 38%.o: %.c
39 $(CLANG) -I. -I./include/uapi -I../../../include/uapi \ 39 $(CLANG) -I. -I./include/uapi -I../../../include/uapi \
40 -I../../../../samples/bpf/ \
41 -Wno-compare-distinct-pointer-types \ 40 -Wno-compare-distinct-pointer-types \
42 -O2 -target bpf -c $< -o $@ 41 -O2 -target bpf -c $< -o $@
diff --git a/tools/testing/selftests/bpf/bpf_endian.h b/tools/testing/selftests/bpf/bpf_endian.h
index 487cbfb89beb..74af266aa512 100644
--- a/tools/testing/selftests/bpf/bpf_endian.h
+++ b/tools/testing/selftests/bpf/bpf_endian.h
@@ -23,11 +23,19 @@
23# define __bpf_htons(x) __builtin_bswap16(x) 23# define __bpf_htons(x) __builtin_bswap16(x)
24# define __bpf_constant_ntohs(x) ___constant_swab16(x) 24# define __bpf_constant_ntohs(x) ___constant_swab16(x)
25# define __bpf_constant_htons(x) ___constant_swab16(x) 25# define __bpf_constant_htons(x) ___constant_swab16(x)
26# define __bpf_ntohl(x) __builtin_bswap32(x)
27# define __bpf_htonl(x) __builtin_bswap32(x)
28# define __bpf_constant_ntohl(x) ___constant_swab32(x)
29# define __bpf_constant_htonl(x) ___constant_swab32(x)
26#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 30#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
27# define __bpf_ntohs(x) (x) 31# define __bpf_ntohs(x) (x)
28# define __bpf_htons(x) (x) 32# define __bpf_htons(x) (x)
29# define __bpf_constant_ntohs(x) (x) 33# define __bpf_constant_ntohs(x) (x)
30# define __bpf_constant_htons(x) (x) 34# define __bpf_constant_htons(x) (x)
35# define __bpf_ntohl(x) (x)
36# define __bpf_htonl(x) (x)
37# define __bpf_constant_ntohl(x) (x)
38# define __bpf_constant_htonl(x) (x)
31#else 39#else
32# error "Fix your compiler's __BYTE_ORDER__?!" 40# error "Fix your compiler's __BYTE_ORDER__?!"
33#endif 41#endif
@@ -38,5 +46,11 @@
38#define bpf_ntohs(x) \ 46#define bpf_ntohs(x) \
39 (__builtin_constant_p(x) ? \ 47 (__builtin_constant_p(x) ? \
40 __bpf_constant_ntohs(x) : __bpf_ntohs(x)) 48 __bpf_constant_ntohs(x) : __bpf_ntohs(x))
49#define bpf_htonl(x) \
50 (__builtin_constant_p(x) ? \
51 __bpf_constant_htonl(x) : __bpf_htonl(x))
52#define bpf_ntohl(x) \
53 (__builtin_constant_p(x) ? \
54 __bpf_constant_ntohl(x) : __bpf_ntohl(x))
41 55
42#endif /* __BPF_ENDIAN__ */ 56#endif /* __BPF_ENDIAN__ */
diff --git a/samples/bpf/bpf_helpers.h b/tools/testing/selftests/bpf/bpf_helpers.h
index d50ac342dc92..d50ac342dc92 100644
--- a/samples/bpf/bpf_helpers.h
+++ b/tools/testing/selftests/bpf/bpf_helpers.h