]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
samples/bpf: fix a build issue
authorYonghong Song <yhs@fb.com>
Mon, 10 Jul 2017 21:04:28 +0000 (14:04 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 12 Jul 2017 03:51:29 +0000 (20:51 -0700)
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>
samples/bpf/Makefile
tools/testing/selftests/bpf/Makefile
tools/testing/selftests/bpf/bpf_endian.h
tools/testing/selftests/bpf/bpf_helpers.h [moved from samples/bpf/bpf_helpers.h with 100% similarity]

index 9c650589e80f315f0425c20d7bd205c0d89770e2..87246be6feb8513b4a97e74ada1ca3f2fa72fa9d 100644 (file)
@@ -207,6 +207,7 @@ $(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
 # useless for BPF samples.
 $(obj)/%.o: $(src)/%.c
        $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
+               -I$(srctree)/tools/testing/selftests/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 \
index 2ca51a8a588c49b14f62dfbaafba253e01cf8bde..153c3a181a4cd3be3f44470275a6c284a6dfc82c 100644 (file)
@@ -37,6 +37,5 @@ CLANG ?= clang
 
 %.o: %.c
        $(CLANG) -I. -I./include/uapi -I../../../include/uapi \
-               -I../../../../samples/bpf/ \
                -Wno-compare-distinct-pointer-types \
                -O2 -target bpf -c $< -o $@
index 487cbfb89beb5012816c7e4989b3f9ff4261995d..74af266aa512baf256a33b6434b43a901612b934 100644 (file)
 # define __bpf_htons(x)                        __builtin_bswap16(x)
 # define __bpf_constant_ntohs(x)       ___constant_swab16(x)
 # define __bpf_constant_htons(x)       ___constant_swab16(x)
+# define __bpf_ntohl(x)                        __builtin_bswap32(x)
+# define __bpf_htonl(x)                        __builtin_bswap32(x)
+# define __bpf_constant_ntohl(x)       ___constant_swab32(x)
+# define __bpf_constant_htonl(x)       ___constant_swab32(x)
 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 # define __bpf_ntohs(x)                        (x)
 # define __bpf_htons(x)                        (x)
 # define __bpf_constant_ntohs(x)       (x)
 # define __bpf_constant_htons(x)       (x)
+# define __bpf_ntohl(x)                        (x)
+# define __bpf_htonl(x)                        (x)
+# define __bpf_constant_ntohl(x)       (x)
+# define __bpf_constant_htonl(x)       (x)
 #else
 # error "Fix your compiler's __BYTE_ORDER__?!"
 #endif
 #define bpf_ntohs(x)                           \
        (__builtin_constant_p(x) ?              \
         __bpf_constant_ntohs(x) : __bpf_ntohs(x))
+#define bpf_htonl(x)                           \
+       (__builtin_constant_p(x) ?              \
+        __bpf_constant_htonl(x) : __bpf_htonl(x))
+#define bpf_ntohl(x)                           \
+       (__builtin_constant_p(x) ?              \
+        __bpf_constant_ntohl(x) : __bpf_ntohl(x))
 
 #endif /* __BPF_ENDIAN__ */