From 9e09b75079e229b08f12a732712100fdb9af8cab Mon Sep 17 00:00:00 2001 From: Ruowen Qin Date: Tue, 26 Sep 2023 23:50:30 -0500 Subject: 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 Signed-off-by: Jinghao Jia Signed-off-by: Jinghao Jia Signed-off-by: Ruowen Qin Signed-off-by: Andrii Nakryiko Tested-by: Jiri Olsa Acked-by: Jiri Olsa Link: https://lore.kernel.org/bpf/20230927045030.224548-2-ruowenq2@illinois.edu --- samples/bpf/Makefile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'samples') 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/ -- cgit v1.2.3