Skip to content

Commit 9e09b75

Browse files
chinrwanakryiko
authored andcommitted
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
1 parent 0e73ef1 commit 9e09b75

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

samples/bpf/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ endif
169169
TPROGS_CFLAGS += -Wall -O2
170170
TPROGS_CFLAGS += -Wmissing-prototypes
171171
TPROGS_CFLAGS += -Wstrict-prototypes
172+
TPROGS_CFLAGS += $(call try-run,\
173+
printf "int main() { return 0; }" |\
174+
$(CC) -Werror -fsanitize=bounds -x c - -o "$$TMP",-fsanitize=bounds,)
172175

173176
TPROGS_CFLAGS += -I$(objtree)/usr/include
174177
TPROGS_CFLAGS += -I$(srctree)/tools/testing/selftests/bpf/

0 commit comments

Comments
 (0)