Build error in bpf bits with clang & default-enabled stack protector
hhoffstaette opened this issue · comments
When the clang compiler has stack protection default-enabed (e.g. via the new config file support in clang-15), the build fails for obvious reasons:
holger>make
lib
libxdp
CC staticobjs/libxdp.o
CC staticobjs/xsk.o
M4 xdp-dispatcher.c
CLANG xdp-dispatcher.o
LLC xdp-dispatcher.o
GEN xdp-dispatcher.embed.o
CLANG xsk_def_xdp_prog.o
LLC xsk_def_xdp_prog.o
GEN xsk_def_xdp_prog.embed.o
CLANG xsk_def_xdp_prog_5.3.o
LLC xsk_def_xdp_prog_5.3.o
error: <unknown>:0:0: in function xsk_def_prog i32 (ptr): A call to built-in function '__stack_chk_fail' is not supported.
I recently fixed the same problem in mainline bpftool; the solution is simple: add -fno-stack-protector
to the CFLAGS used with clang.
Since I found this when trying to fix the buid for xdp-tools in Gentoo, I found that BPF_CFLAGS
used by the configure script does not seem to have an inital default value, so I just added one when writing the config:
--- xdp-tools-1.2.8/configure 2022-09-18 18:49:19.000000000 +0200
+++ xdp-tools-1.2.8-nossp/configure 2023-03-04 16:06:36.158256713 +0100
@@ -258,6 +258,7 @@ EOF
echo "SYSTEM_LIBBPF:=y" >>$CONFIG
echo "LIBBPF_VERSION=$LIBBPF_VERSION" >>$CONFIG
echo 'CFLAGS += ' $LIBBPF_CFLAGS >> $CONFIG
+ echo 'BPF_CFLAGS += -fno-stack-protector' >> $CONFIG
echo 'LDLIBS += ' $LIBBPF_LDLIBS >>$CONFIG
echo 'OBJECT_LIBBPF = ' >>$CONFIG
echo "system v$LIBBPF_VERSION"
This does the trick - I couldn't find a better location to set this, but that does not mean there isn't any. :)
An alternative appoach might be to only do this in lib/libxdp, but the result would be the same. Let me know what you think.
This should go into lib/defines.mk - care to open a PR? :)
Ahh..I knew there was a better place. Will do.