Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Yonghong Song and committed by
David S. Miller
53335022 1bfb1596

+15 -1
+1
samples/bpf/Makefile
··· 207 207 # useless for BPF samples. 208 208 $(obj)/%.o: $(src)/%.c 209 209 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \ 210 + -I$(srctree)/tools/testing/selftests/bpf/ \ 210 211 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \ 211 212 -Wno-compare-distinct-pointer-types \ 212 213 -Wno-gnu-variable-sized-type-not-at-end \
samples/bpf/bpf_helpers.h tools/testing/selftests/bpf/bpf_helpers.h
-1
tools/testing/selftests/bpf/Makefile
··· 37 37 38 38 %.o: %.c 39 39 $(CLANG) -I. -I./include/uapi -I../../../include/uapi \ 40 - -I../../../../samples/bpf/ \ 41 40 -Wno-compare-distinct-pointer-types \ 42 41 -O2 -target bpf -c $< -o $@
+14
tools/testing/selftests/bpf/bpf_endian.h
··· 23 23 # define __bpf_htons(x) __builtin_bswap16(x) 24 24 # define __bpf_constant_ntohs(x) ___constant_swab16(x) 25 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 30 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 27 31 # define __bpf_ntohs(x) (x) 28 32 # define __bpf_htons(x) (x) 29 33 # define __bpf_constant_ntohs(x) (x) 30 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 39 #else 32 40 # error "Fix your compiler's __BYTE_ORDER__?!" 33 41 #endif ··· 46 38 #define bpf_ntohs(x) \ 47 39 (__builtin_constant_p(x) ? \ 48 40 __bpf_constant_ntohs(x) : __bpf_ntohs(x)) 41 + #define bpf_htonl(x) \ 42 + (__builtin_constant_p(x) ? \ 43 + __bpf_constant_htonl(x) : __bpf_htonl(x)) 44 + #define bpf_ntohl(x) \ 45 + (__builtin_constant_p(x) ? \ 46 + __bpf_constant_ntohl(x) : __bpf_ntohl(x)) 49 47 50 48 #endif /* __BPF_ENDIAN__ */