diff options
author | Ruowen Qin <[email protected]> | 2023-09-26 23:50:30 -0500 |
---|---|---|
committer | Andrii Nakryiko <[email protected]> | 2023-09-28 09:31:05 -0700 |
commit | 9e09b75079e229b08f12a732712100fdb9af8cab (patch) | |
tree | b12d556d10ab041bfa4b9e19f9befa31137a7dfd | |
parent | 0e73ef1d8c09a1f21ca2b19684819dbbcdce00f9 (diff) |
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 <[email protected]>
Signed-off-by: Jinghao Jia <[email protected]>
Signed-off-by: Jinghao Jia <[email protected]>
Signed-off-by: Ruowen Qin <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Tested-by: Jiri Olsa <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
-rw-r--r-- | samples/bpf/Makefile | 3 |
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/ |