* [PATCH 1/1] selftests/bpf: Makefile fix "missing" headers on build with -idirafter
@ 2018-05-21 7:00 Sirio Balmelli
2018-05-23 12:44 ` Daniel Borkmann
0 siblings, 1 reply; 2+ messages in thread
From: Sirio Balmelli @ 2018-05-21 7:00 UTC (permalink / raw)
To: daniel; +Cc: netdev
Selftests fail to build on several distros/architectures because of
missing headers files.
On a Ubuntu/x86_64 some missing headers are:
asm/byteorder.h, asm/socket.h, asm/sockios.h
On a Debian/arm32 build already fails at sys/cdefs.h
In both cases, these already exist in /usr/include/<arch-specific-dir>,
but Clang does not include these when using '-target bpf' flag,
since it is no longer compiling against the host architecture.
The solution is to:
- run Clang without '-target bpf' and extract the include chain for the
current system
- add these to the bpf build with '-idirafter'
The choice of -idirafter is to catch this error without injecting
unexpected include behavior: if an arch-specific tree is built
for bpf in the future, this will be correctly found by Clang.
Signed-off-by: Sirio Balmelli <sirio@b-ad.ch>
---
tools/testing/selftests/bpf/Makefile | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 1eb0fa2aba92..e0c8d3cdc6c9 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -84,7 +84,16 @@ else
CPU ?= generic
endif
+# Get Clang's default includes on this system, as opposed to those seen by '-target bpf'.
+# This fixes "missing" files on some architectures/distros,
+#+ such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
+# Use '-idirafter': don't interfere with include mechanics
+#+ except where the build would have failed anyways.
+CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - </dev/null 2>&1 \
+ | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')
+
CLANG_FLAGS = -I. -I./include/uapi -I../../../include/uapi \
+ $(CLANG_SYS_INCLUDES) \
-Wno-compare-distinct-pointer-types
$(OUTPUT)/test_l4lb_noinline.o: CLANG_FLAGS += -fno-inline
--
2.16.2
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH 1/1] selftests/bpf: Makefile fix "missing" headers on build with -idirafter
2018-05-21 7:00 [PATCH 1/1] selftests/bpf: Makefile fix "missing" headers on build with -idirafter Sirio Balmelli
@ 2018-05-23 12:44 ` Daniel Borkmann
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Borkmann @ 2018-05-23 12:44 UTC (permalink / raw)
To: Sirio Balmelli; +Cc: netdev
On 05/21/2018 09:00 AM, Sirio Balmelli wrote:
> Selftests fail to build on several distros/architectures because of
> missing headers files.
>
> On a Ubuntu/x86_64 some missing headers are:
> asm/byteorder.h, asm/socket.h, asm/sockios.h
>
> On a Debian/arm32 build already fails at sys/cdefs.h
>
> In both cases, these already exist in /usr/include/<arch-specific-dir>,
> but Clang does not include these when using '-target bpf' flag,
> since it is no longer compiling against the host architecture.
>
> The solution is to:
>
> - run Clang without '-target bpf' and extract the include chain for the
> current system
>
> - add these to the bpf build with '-idirafter'
>
> The choice of -idirafter is to catch this error without injecting
> unexpected include behavior: if an arch-specific tree is built
> for bpf in the future, this will be correctly found by Clang.
>
> Signed-off-by: Sirio Balmelli <sirio@b-ad.ch>
Ok, I've tried this on arm64:
# clang -v -E - </dev/null 2>&1 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
-idirafter /usr/local/include
-idirafter /usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include
-idirafter /usr/include/aarch64-linux-gnu
-idirafter /usr/include
# clang -target bpf -v -E - </dev/null 2>&1 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
-idirafter /usr/local/include
-idirafter /usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include
-idirafter /usr/include
# clang -target aarch64 -v -E - </dev/null 2>&1 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
-idirafter /usr/local/include
-idirafter /usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include
-idirafter /usr/include
# clang -target aarch64-unknown-linux-gnu -v -E - </dev/null 2>&1 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
-idirafter /usr/local/include
-idirafter /usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include
-idirafter /usr/include/aarch64-linux-gnu
-idirafter /usr/include
# llc --version
LLVM (http://llvm.org/):
LLVM version 3.8.0
Optimized build.
Built Jul 9 2016 (11:22:59).
Default target: aarch64-unknown-linux-gnu
Host CPU: (unknown)
[...]
So the default target adds additionally /usr/include/aarch64-linux-gnu which is
what you're after. Seems okay if it does the trick. Worst case we can always
revert and find a different solution. I've applied it to bpf-next instead of
bpf in order to give this some time for test exposure, thanks Sirio!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-05-23 12:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-21 7:00 [PATCH 1/1] selftests/bpf: Makefile fix "missing" headers on build with -idirafter Sirio Balmelli
2018-05-23 12:44 ` Daniel Borkmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox