Bug 1896414 - Move MOZ_ASAN checks from old.configure to moz.configure r=glandium,geckoview-reviewers,m_kato

Also improve detection of runtime libraries as a side effect.

Differential Revision: https://phabricator.services.mozilla.com/D210196
This commit is contained in:
serge-sans-paille 2024-06-18 14:44:40 +00:00
parent 66625946be
commit c7d66816f8
9 changed files with 84 additions and 61 deletions

1
aclocal.m4 vendored
View File

@ -12,7 +12,6 @@ builtin(include, build/autoconf/mozheader.m4)dnl
builtin(include, build/autoconf/compiler-opts.m4)dnl builtin(include, build/autoconf/compiler-opts.m4)dnl
builtin(include, build/autoconf/arch.m4)dnl builtin(include, build/autoconf/arch.m4)dnl
builtin(include, build/autoconf/clang-plugin.m4)dnl builtin(include, build/autoconf/clang-plugin.m4)dnl
builtin(include, build/autoconf/sanitize.m4)dnl
MOZ_PROG_CHECKMSYS() MOZ_PROG_CHECKMSYS()

View File

@ -1,44 +0,0 @@
dnl This Source Code Form is subject to the terms of the Mozilla Public
dnl License, v. 2.0. If a copy of the MPL was not distributed with this
dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
AC_DEFUN([MOZ_CONFIG_SANITIZE], [
dnl ========================================================
dnl = Use Address Sanitizer
dnl ========================================================
if test -n "$MOZ_ASAN"; then
if test "$CC_TYPE" = clang-cl ; then
# Look for the ASan runtime binary
if test "$TARGET_CPU" = "x86_64"; then
MOZ_CLANG_RT_ASAN_LIB=clang_rt.asan_dynamic-x86_64.dll
else
MOZ_CLANG_RT_ASAN_LIB=clang_rt.asan_dynamic-i386.dll
fi
# We use MOZ_PATH_PROG in order to get a Windows style path.
MOZ_PATH_PROG(MOZ_CLANG_RT_ASAN_LIB_PATH, $MOZ_CLANG_RT_ASAN_LIB)
if test -z "$MOZ_CLANG_RT_ASAN_LIB_PATH"; then
AC_MSG_ERROR([Couldn't find $MOZ_CLANG_RT_ASAN_LIB. It should be available in the same location as clang-cl.])
fi
AC_SUBST(MOZ_CLANG_RT_ASAN_LIB_PATH)
# Suppressing errors in recompiled code.
if test "$OS_ARCH" = "WINNT"; then
CFLAGS="-fsanitize-blacklist=$_topsrcdir/build/sanitizers/asan_blacklist_win.txt $CFLAGS"
CXXFLAGS="-fsanitize-blacklist=$_topsrcdir/build/sanitizers/asan_blacklist_win.txt $CXXFLAGS"
fi
fi
ASAN_FLAG="-fsanitize=address"
CFLAGS="$ASAN_FLAG $CFLAGS"
CXXFLAGS="$ASAN_FLAG $CXXFLAGS"
if test "$CC_TYPE" != clang-cl ; then
LDFLAGS="$ASAN_FLAG -rdynamic $LDFLAGS"
fi
fi
dnl ========================================================
dnl = Test for whether the compiler is compatible with the
dnl = given sanitize options.
dnl ========================================================
AC_TRY_LINK(,,,AC_MSG_ERROR([compiler is incompatible with sanitize options]))
])

View File

@ -2427,6 +2427,86 @@ def asan():
return True return True
with only_when(asan):
option(
env="MOZ_CLANG_RT_ASAN_LIB_PATH",
nargs=1,
help="Path to clang runtime asan library",
)
@depends(
c_compiler,
target,
"MOZ_CLANG_RT_ASAN_LIB_PATH",
)
@imports("os")
@imports("glob")
def clang_rt_asan_lib_path(c_compiler, target, clang_rt_asan_lib):
if clang_rt_asan_lib:
if os.path.exists(clang_rt_asan_lib[0]):
return clang_rt_asan_lib[0]
else:
die(
f"Specified MOZ_CLANG_RT_ASAN_LIB_PATH value '{clang_rt_asan_lib}' doesn't exist. "
)
# Look for the ASan runtime binary
if c_compiler.type == "clang-cl":
cpu = {"x86": "i386"}.get(target.cpu, target.cpu)
clang_rt_asan_lib = f"clang_rt.asan_dynamic-{target.cpu}.dll"
subdir = "windows"
elif target.os == "Android":
cpu = {"x86": "i686"}.get(target.cpu, target.cpu)
clang_rt_asan_lib = f"libclang_rt.asan-{cpu}-android.so"
subdir = "linux"
else:
return
search_path = os.path.join(
os.path.dirname(c_compiler.compiler),
"..",
"lib",
"clang",
"*",
"lib",
subdir,
clang_rt_asan_lib,
)
if candidates := glob.glob(search_path):
return candidates[0]
die(
f"Couldn't find {clang_rt_asan_lib}. "
f"It should be available in the same location as {c_compiler.type}."
)
set_config("MOZ_CLANG_RT_ASAN_LIB_PATH", clang_rt_asan_lib_path)
@depends(
c_compiler,
target,
compilation_flags,
linker_flags,
build_environment,
when=asan,
)
def asan_flags(c_compiler, target, compilation_flags, linker_flags, build_env):
if c_compiler.type == "clang-cl":
# Suppressing errors in recompiled code.
if target.os == "WINNT":
flag = f"-fsanitize-blacklist={build_env.topsrcdir}/build/sanitizers/asan_blacklist_win.txt"
compilation_flags.cflags.append(flag)
compilation_flags.cxxflags.append(flag)
asan_flag = "-fsanitize=address"
compilation_flags.cflags.append(asan_flag)
compilation_flags.cxxflags.append(asan_flag)
if c_compiler.type != "clang-cl":
linker_flags.ldflags.extend([asan_flag, "-rdynamic"])
add_old_configure_assignment("MOZ_ASAN", asan) add_old_configure_assignment("MOZ_ASAN", asan)
set_define("MOZ_ASAN", True, when=asan) set_define("MOZ_ASAN", True, when=asan)
set_config("MOZ_ASAN", True, when=asan) set_config("MOZ_ASAN", True, when=asan)
@ -2631,6 +2711,7 @@ any_ubsan = ubsan | ub_signed_overflow_san | ub_unsigned_overflow_san
set_define("MOZ_UBSAN", True, when=any_ubsan) set_define("MOZ_UBSAN", True, when=any_ubsan)
set_config("MOZ_UBSAN", any_ubsan) set_config("MOZ_UBSAN", any_ubsan)
# Security Hardening # Security Hardening
# ============================================================== # ==============================================================

View File

@ -7,7 +7,6 @@ if [ -d "$MOZ_FETCHES_DIR/clang" ]; then
export MOZ_COPY_PDBS=1 export MOZ_COPY_PDBS=1
export LLVM_SYMBOLIZER="$MOZ_FETCHES_DIR/llvm-symbolizer/bin/llvm-symbolizer.exe" export LLVM_SYMBOLIZER="$MOZ_FETCHES_DIR/llvm-symbolizer/bin/llvm-symbolizer.exe"
export MOZ_CLANG_RT_ASAN_LIB_PATH="${CLANG_LIB_DIR}/clang_rt.asan_dynamic-x86_64.dll"
fi fi
# Enable ASan specific code and build workarounds # Enable ASan specific code and build workarounds

1
js/src/aclocal.m4 vendored
View File

@ -12,7 +12,6 @@ builtin(include, ../../build/autoconf/mozheader.m4)dnl
builtin(include, ../../build/autoconf/compiler-opts.m4)dnl builtin(include, ../../build/autoconf/compiler-opts.m4)dnl
builtin(include, ../../build/autoconf/arch.m4)dnl builtin(include, ../../build/autoconf/arch.m4)dnl
builtin(include, ../../build/autoconf/clang-plugin.m4)dnl builtin(include, ../../build/autoconf/clang-plugin.m4)dnl
builtin(include, ../../build/autoconf/sanitize.m4)dnl
define([__MOZ_AC_INIT_PREPARE], defn([AC_INIT_PREPARE])) define([__MOZ_AC_INIT_PREPARE], defn([AC_INIT_PREPARE]))
define([AC_INIT_PREPARE], define([AC_INIT_PREPARE],

View File

@ -162,8 +162,6 @@ dnl Configure platform-specific CPU architecture compiler options.
dnl ============================================================== dnl ==============================================================
MOZ_ARCH_OPTS MOZ_ARCH_OPTS
MOZ_CONFIG_SANITIZE
dnl ======================================================== dnl ========================================================
dnl GNU specific defaults dnl GNU specific defaults
dnl ======================================================== dnl ========================================================

View File

@ -17,8 +17,9 @@
* 2) They implement this functionality *safely*, without invoking signed * 2) They implement this functionality *safely*, without invoking signed
* integer overflow that has undefined behavior in C++. * integer overflow that has undefined behavior in C++.
* 3) They play nice with compiler-based integer-overflow sanitizers (see * 3) They play nice with compiler-based integer-overflow sanitizers (see
* build/autoconf/sanitize.m4), that in appropriately configured builds * build/moz.configure/toolchain.configure), that in appropriately
* verify at runtime that integral arithmetic doesn't overflow. * configured builds verify at runtime that integral arithmetic doesn't
* overflow.
*/ */
#ifndef mozilla_WrappingOperations_h #ifndef mozilla_WrappingOperations_h

View File

@ -18,12 +18,6 @@ unset ENABLE_CLANG_PLUGIN
# We don't have a native LLVM_SYMBOLIZER yet # We don't have a native LLVM_SYMBOLIZER yet
unset LLVM_SYMBOLIZER unset LLVM_SYMBOLIZER
# Add the path to the clang_rt used, so it can be packaged with the build.
if [ -d "$MOZ_FETCHES_DIR/clang" ]; then
CLANG_LIB_DIR="$(cd $MOZ_FETCHES_DIR/clang/lib/clang/*/lib/linux && pwd)"
export MOZ_CLANG_RT_ASAN_LIB_PATH="${CLANG_LIB_DIR}/libclang_rt.asan-x86_64-android.so"
fi
# Package js shell. # Package js shell.
export MOZ_PACKAGE_JSSHELL=1 export MOZ_PACKAGE_JSSHELL=1

View File

@ -164,10 +164,6 @@ if test "$COMPILE_ENVIRONMENT"; then
MOZ_ARCH_OPTS MOZ_ARCH_OPTS
fi # COMPILE_ENVIRONMENT fi # COMPILE_ENVIRONMENT
if test -n "$COMPILE_ENVIRONMENT"; then
MOZ_CONFIG_SANITIZE
fi
dnl ======================================================== dnl ========================================================
dnl GNU specific defaults dnl GNU specific defaults
dnl ======================================================== dnl ========================================================