@@ -38,6 +38,13 @@ config("default_include_dirs") {
3838 ]
3939}
4040
41+ if (is_win && is_asan ) {
42+ copy (" copy_sanitizer_runtime" ) {
43+ sources = [ " //buildtools/win-x64/clang/lib/clang/22/lib/x86_64-pc-windows-msvc/clang_rt.asan_dynamic.dll" ]
44+ outputs = [ " $root_out_dir /{{source_file_part}}" ]
45+ }
46+ }
47+
4148# compiler ---------------------------------------------------------------------
4249#
4350# Base compiler configuration.
@@ -107,11 +114,38 @@ config("compiler") {
107114 ldflags += [ " -Wl,--fix-cortex-a53-843419" ]
108115 }
109116
110- # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer and
111- # MemorySanitizer
117+ if (use_custom_libcxx ) {
118+ cflags_cc += [ " -nostdinc++" ]
119+ include_dirs = [
120+ " //buildtools/third_party/libc++/trunk/include" ,
121+ " //buildtools/third_party/libc++abi/trunk/include" ,
122+ ]
123+ }
124+ }
125+
126+ # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer and
127+ # MemorySanitizer
128+ if (is_clang || ! is_win ) {
112129 if (is_asan ) {
113130 cflags += [ " -fsanitize=address" ]
114- ldflags += [ " -fsanitize=address" ]
131+ if (is_win ) {
132+ # Windows directly calls link.exe instead of the compiler driver when
133+ # linking. Hence, pass the runtime libraries instead of -fsanitize=address
134+ # or -fsanitize=fuzzer.
135+ _clang_lib_dir =
136+ " //buildtools/win-x64/clang/lib/clang/22/lib/x86_64-pc-windows-msvc"
137+ libs = [ " $_clang_lib_dir /clang_rt.asan_dynamic.lib" ]
138+ ldflags += [ " -libpath:" + rebase_path (" $_clang_lib_dir " ) ]
139+ if (is_shared_library ) {
140+ ldflags += [ " -wholearchive:clang_rt.asan_dynamic_runtime_thunk.lib" ]
141+ libs += [ " $_clang_lib_dir /clang_rt.asan_dynamic_runtime_thunk.lib" ]
142+ } else {
143+ ldflags += [ " -wholearchive:clang_rt.asan_static_runtime_thunk.lib" ]
144+ libs += [ " $_clang_lib_dir /clang_rt.asan_static_runtime_thunk.lib" ]
145+ }
146+ } else {
147+ ldflags += [ " -fsanitize=address" ]
148+ }
115149 }
116150 if (is_hwasan && is_android && current_cpu == " arm64" ) {
117151 cflags += [ " -fsanitize=hwaddress" ]
@@ -156,14 +190,6 @@ config("compiler") {
156190 " @loader_path/../../../../buildtools/mac-$host_cpu /clang/lib/clang/22/lib/darwin" ,
157191 ]
158192 }
159-
160- if (use_custom_libcxx ) {
161- cflags_cc += [ " -nostdinc++" ]
162- include_dirs = [
163- " //buildtools/third_party/libc++/trunk/include" ,
164- " //buildtools/third_party/libc++abi/trunk/include" ,
165- ]
166- }
167193 }
168194
169195 if (is_clang && is_debug ) {
@@ -814,6 +840,12 @@ if (is_win) {
814840 # Warning: This changes C/C++ semantics of function pointer comparison.
815841 " /OPT:ICF" ,
816842 ]
843+ if (is_clang ) {
844+ common_optimize_on_ldflags += [
845+ # This interferes with ODR violation checks in ASAN.
846+ " /OPT:NOLLDTAILMERGE" ,
847+ ]
848+ }
817849} else {
818850 common_optimize_on_cflags = [
819851 # Don't emit the GCC version ident directives, they just end up in the
0 commit comments