commit e6a5b1c759c695b57077d410ba3d149f22680fbe
parent bb0e2eb2e94ee11cdff30eb24bd0bc825352f885
Author: Mike Hommey <mh+mozilla@glandium.org>
Date: Wed, 12 Nov 2025 23:55:39 +0000
Bug 1998852 - Add extra linker flags the compiler would use if we were using the compiler as a linker. r=firefox-build-system-reviewers,sergesanspaille
While here, remove CLANG_LIB_DIR because nothing uses it anymore (last
use removed in bug 1718171).
Differential Revision: https://phabricator.services.mozilla.com/D272105
Diffstat:
4 files changed, 47 insertions(+), 10 deletions(-)
diff --git a/browser/config/mozconfigs/win64/code-coverage b/browser/config/mozconfigs/win64/code-coverage
@@ -16,12 +16,6 @@ export MOZILLA_OFFICIAL=1
# Package js shell.
export MOZ_PACKAGE_JSSHELL=1
-if [ -d "$MOZ_FETCHES_DIR/clang" ]; then
- CLANG_LIB_DIR="$(cd $MOZ_FETCHES_DIR/clang/lib/clang/* && cd lib/windows && pwd)"
-
- export LDFLAGS="clang_rt.profile-x86_64.lib"
-fi
-
export RUSTFLAGS="-Ccodegen-units=1 -Zprofile -Cpanic=abort -Zpanic_abort_tests -Coverflow-checks=off"
export RUSTDOCFLAGS="-Cpanic=abort"
diff --git a/build/moz.configure/toolchain.configure b/build/moz.configure/toolchain.configure
@@ -3947,3 +3947,50 @@ def htmlaccel_config(target, c_compiler):
set_config("HTML_ACCEL_FLAGS", htmlaccel_config)
+
+
+@depends(c_compiler, compilation_flags, coverage_cflags, linker_flags)
+@imports(_from="mozbuild.shellutil", _import="split", _as="shellsplit")
+def extra_linker_flags(compiler, compilation_flags, coverage_cflags, linker_flags):
+ if compiler.type != "clang-cl":
+ return
+ with create_temporary_file(suffix=".c") as path:
+ # On clang-cl builds only, we run the linker via separate commands rather
+ # than invoking it through the compiler. We want to figure out what flags
+ # the compiler would add to the linker command line based on the extra
+ # compiler flags we use (notably, for sanitizer)
+ # The -### argument to clang/clang-cl tells us what commands it would run
+ # internally, and the last of them is going to be the linker.
+ # What we want to do is compare the linker commands the compiler would
+ # invoke with a limited set of flags vs. all of them.
+ # Typically, that will give us some extra flags, including extra libs for
+ # the clang runtime.
+
+ path_stem = os.path.basename(path)[: -len(".c")]
+
+ def is_in_out_arg(arg):
+ return arg.startswith("-out:") or os.path.basename(arg).startswith(
+ path_stem
+ )
+
+ cmd = [
+ compiler.compiler,
+ path,
+ "-fuse-ld=lld",
+ "-MD",
+ "-###",
+ ] + compiler.flags
+ retcode, stdout, stderr = get_cmd_output(*cmd)
+ if retcode != 0:
+ die("Error while running %s:\n%s" % (" ".join(cmd), stderr))
+ linker_command = shellsplit(stderr.splitlines()[-1])
+ linker_args = set(arg for arg in linker_command if not is_in_out_arg(arg))
+ cmd += compilation_flags.cflags + (coverage_cflags or [])
+ retcode, stdout, stderr = get_cmd_output(*cmd)
+ if retcode != 0:
+ die("Error while running %s:\n%s" % (" ".join(cmd), stderr))
+ linker_flags.ldflags.extend(
+ arg
+ for arg in shellsplit(stderr.splitlines()[-1])
+ if not is_in_out_arg(arg) and arg not in linker_args
+ )
diff --git a/build/win64/mozconfig.asan b/build/win64/mozconfig.asan
@@ -1,8 +1,6 @@
. "$topsrcdir/browser/config/mozconfigs/win64/common-win64"
if [ -d "$MOZ_FETCHES_DIR/clang" ]; then
- export LDFLAGS="clang_rt.asan_dynamic-x86_64.lib clang_rt.asan_dynamic_runtime_thunk-x86_64.lib"
-
export MOZ_COPY_PDBS=1
export LLVM_SYMBOLIZER="$MOZ_FETCHES_DIR/llvm-symbolizer/bin/llvm-symbolizer.exe"
fi
diff --git a/tools/sanitizer/docs/asan.rst b/tools/sanitizer/docs/asan.rst
@@ -97,8 +97,6 @@ Run ``mach bootstrap`` to get an updated clang-cl in your
ac_add_options --enable-address-sanitizer
ac_add_options --disable-jemalloc
- export LDFLAGS="clang_rt.asan_dynamic-x86_64.lib clang_rt.asan_dynamic_runtime_thunk-x86_64.lib"
-
If you launch an ASan build under WinDbg, you may see spurious
first-chance Access Violation exceptions. These come from ASan creating
shadow memory pages on demand, and can be ignored. Run ``sxi av`` to