summaryrefslogtreecommitdiffstats
path: root/samples/bpf
diff options
context:
space:
mode:
authorRuowen Qin <ruowenq2@illinois.edu>2023-09-26 23:50:30 -0500
committerAndrii Nakryiko <andrii@kernel.org>2023-09-28 09:31:05 -0700
commit9e09b75079e229b08f12a732712100fdb9af8cab (patch)
treeb12d556d10ab041bfa4b9e19f9befa31137a7dfd /samples/bpf
parent0e73ef1d8c09a1f21ca2b19684819dbbcdce00f9 (diff)
downloadlinux-stable-9e09b75079e229b08f12a732712100fdb9af8cab.tar.gz
linux-stable-9e09b75079e229b08f12a732712100fdb9af8cab.tar.bz2
linux-stable-9e09b75079e229b08f12a732712100fdb9af8cab.zip
samples/bpf: Add -fsanitize=bounds to userspace programs
The sanitizer flag, which is supported by both clang and gcc, would make it easier to debug array index out-of-bounds problems in these programs. Make the Makfile smarter to detect ubsan support from the compiler and add the '-fsanitize=bounds' accordingly. Suggested-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Jinghao Jia <jinghao@linux.ibm.com> Signed-off-by: Jinghao Jia <jinghao7@illinois.edu> Signed-off-by: Ruowen Qin <ruowenq2@illinois.edu> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Tested-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Jiri Olsa <jolsa@kernel.org> Link: https://lore.kernel.org/bpf/20230927045030.224548-2-ruowenq2@illinois.edu
Diffstat (limited to 'samples/bpf')
-rw-r--r--samples/bpf/Makefile3
1 files changed, 3 insertions, 0 deletions
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 6c707ebcebb9..90af76fa9dd8 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -169,6 +169,9 @@ endif
TPROGS_CFLAGS += -Wall -O2
TPROGS_CFLAGS += -Wmissing-prototypes
TPROGS_CFLAGS += -Wstrict-prototypes
+TPROGS_CFLAGS += $(call try-run,\
+ printf "int main() { return 0; }" |\
+ $(CC) -Werror -fsanitize=bounds -x c - -o "$$TMP",-fsanitize=bounds,)
TPROGS_CFLAGS += -I$(objtree)/usr/include
TPROGS_CFLAGS += -I$(srctree)/tools/testing/selftests/bpf/