Bug 1896411 - Move MOZ_UBSAN checks from old.configure to moz.configure r=glandium

Differential Revision: https://phabricator.services.mozilla.com/D210193
This commit is contained in:
serge-sans-paille 2024-05-31 06:02:53 +00:00
parent 79a4dcbb7a
commit b73661a986
2 changed files with 30 additions and 16 deletions

View File

@ -42,20 +42,6 @@ if test -n "$MOZ_ASAN"; then
fi
fi
dnl ========================================================
dnl = Use UndefinedBehavior Sanitizer (with custom checks)
dnl ========================================================
if test -n "$MOZ_UBSAN_CHECKS"; then
UBSAN_TXT="$_objdir/ubsan_blacklist.txt"
cat $_topsrcdir/build/sanitizers/ubsan_*_blacklist.txt > $UBSAN_TXT
UBSAN_FLAGS="-fsanitize=$MOZ_UBSAN_CHECKS -fno-sanitize-recover=$MOZ_UBSAN_CHECKS -fsanitize-blacklist=$UBSAN_TXT"
CFLAGS="$UBSAN_FLAGS $CFLAGS"
CXXFLAGS="$UBSAN_FLAGS $CXXFLAGS"
if test -z "$CLANG_CL"; then
LDFLAGS="-fsanitize=undefined -rdynamic $LDFLAGS"
fi
fi
dnl ========================================================
dnl = Use UndefinedBehavior Sanitizer to find integer overflows
dnl ========================================================

View File

@ -2510,10 +2510,38 @@ def ubsan(options, optimize):
checks = options if len(options) else default_checks
return ",".join(checks)
return checks
add_old_configure_assignment("MOZ_UBSAN_CHECKS", ubsan)
@depends(
ubsan, c_compiler, compilation_flags, linker_flags, build_environment, when=ubsan
)
@imports(_from="__builtin__", _import="open")
@imports(_from="glob", _import="glob")
@imports("shutil")
def ubsan_flags(ubsan_checks, c_compiler, compilation_flags, linker_flags, build_env):
ubsan_txt = os.path.join(build_env.topobjdir, "ubsan_blacklist.txt")
with open(ubsan_txt, "w") as out_fd:
for blacklist in glob(
os.path.join(
build_env.topsrcdir, "build", "sanitizers", "ubsan_*_blacklist.txt"
)
):
with open(blacklist) as in_fd:
shutil.copyfileobj(in_fd, out_fd)
joined_ubsan_checks = ",".join(ubsan_checks)
flags = [
f"-fsanitize={joined_ubsan_checks}",
f"-fno-sanitize-recover={joined_ubsan_checks}",
f"-fsanitize-blacklist={ubsan_txt}",
]
compilation_flags.cflags.extend(flags)
compilation_flags.cxxflags.extend(flags)
if c_compiler.type != "clang-cl":
linker_flags.ldflags.extend(["-fsanitize=undefined", "-rdynamic"])
option(
"--enable-signed-overflow-sanitizer",