py/misc: Add a way to detect sanitizer builds.

Clang and gcc>=14 can use __has_feature() to detect if a sanitizer
is enabled, but older GCC has no mechanism - need to set a macro
explicitly for this to be recognised.

Necessary for increasing some resource limits in sanitizer builds.
Important not to use to avoid real issues!

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
Angus Gratton
2025-08-06 10:19:43 +10:00
parent d81d56cc4d
commit 3faf229853
2 changed files with 28 additions and 2 deletions

View File

@@ -518,12 +518,14 @@ CI_UNIX_OPTS_QEMU_RISCV64=(
)
CI_UNIX_OPTS_SANITIZE_ADDRESS=(
CFLAGS_EXTRA="-fsanitize=address --param asan-use-after-return=0"
# Macro MP_ASAN allows detecting ASan on gcc<=13
CFLAGS_EXTRA="-fsanitize=address --param asan-use-after-return=0 -DMP_ASAN=1"
LDFLAGS_EXTRA="-fsanitize=address --param asan-use-after-return=0"
)
CI_UNIX_OPTS_SANITIZE_UNDEFINED=(
CFLAGS_EXTRA="-fsanitize=undefined -fno-sanitize=nonnull-attribute"
# Macro MP_UBSAN allows detecting UBSan on gcc<=13
CFLAGS_EXTRA="-fsanitize=undefined -fno-sanitize=nonnull-attribute -DMP_UBSAN=1"
LDFLAGS_EXTRA="-fsanitize=undefined -fno-sanitize=nonnull-attribute"
)