Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: build/config/sanitizers/BUILD.gn

Issue 1839763006: Add support for the Windows ASan configuration to the gn build (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/config/win/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import("//build/config/chrome_build.gni") 5 import("//build/config/chrome_build.gni")
6 import("//build/config/chromecast_build.gni") 6 import("//build/config/chromecast_build.gni")
7 import("//build/config/sanitizers/sanitizers.gni") 7 import("//build/config/sanitizers/sanitizers.gni")
8 8
9 # Contains the dependencies needed for sanitizers to link into executables and 9 # Contains the dependencies needed for sanitizers to link into executables and
10 # shared_libraries. Unconditionally depend upon this target as it is empty if 10 # shared_libraries. Unconditionally depend upon this target as it is empty if
(...skipping 18 matching lines...) Expand all
29 if (use_custom_libcxx) { 29 if (use_custom_libcxx) {
30 deps += [ "//buildtools/third_party/libc++:libcxx_proxy" ] 30 deps += [ "//buildtools/third_party/libc++:libcxx_proxy" ]
31 if (is_mac) { 31 if (is_mac) {
32 deps += [ ":copy_libclang_rt_dyn" ] 32 deps += [ ":copy_libclang_rt_dyn" ]
33 } 33 }
34 } 34 }
35 } 35 }
36 } 36 }
37 37
38 config("sanitizer_options_link_helper") { 38 config("sanitizer_options_link_helper") {
39 if (!is_mac) { 39 if (!is_mac && !is_win) {
40 ldflags = [ "-Wl,-u_sanitizer_options_link_helper" ] 40 ldflags = [ "-Wl,-u_sanitizer_options_link_helper" ]
41 } 41 }
42 } 42 }
43 43
44 source_set("options_sources") { 44 source_set("options_sources") {
45 visibility = [ 45 visibility = [
46 ":deps", 46 ":deps",
47 "//:gn_visibility", 47 "//:gn_visibility",
48 ] 48 ]
49 sources = [ 49 sources = [
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 # removes this config, executables & shared libraries should still depend on 145 # removes this config, executables & shared libraries should still depend on
146 # :deps if any of their dependencies have not opted out of sanitizers. 146 # :deps if any of their dependencies have not opted out of sanitizers.
147 config("default_sanitizer_flags") { 147 config("default_sanitizer_flags") {
148 cflags = [] 148 cflags = []
149 cflags_cc = [] 149 cflags_cc = []
150 defines = [] 150 defines = []
151 configs = [ ":default_sanitizer_ldflags" ] 151 configs = [ ":default_sanitizer_ldflags" ]
152 152
153 # Sanitizers need line table info for stack traces. They don't need type info 153 # Sanitizers need line table info for stack traces. They don't need type info
154 # or variable info, so we can leave that out to speed up the build. 154 # or variable info, so we can leave that out to speed up the build.
155 if (is_clang && using_sanitizer) { 155 if (using_sanitizer) {
156 assert(is_clang, "sanitizers only supported with clang")
156 cflags += [ "-gline-tables-only" ] 157 cflags += [ "-gline-tables-only" ]
157 } 158 }
158 159
159 # Only works on Posix-like platforms. 160 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer,
160 # FIXME: this is not true, remove the conditional. 161 # MemorySanitizer and non-official CFI builds.
161 if (is_posix) { 162 if (using_sanitizer || (is_lto && !is_official_build)) {
162 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer, 163 if (is_posix) {
163 # MemorySanitizer and non-official CFI builds.
164 if (using_sanitizer || (is_lto && !is_official_build)) {
165 cflags += [ "-fno-omit-frame-pointer" ] 164 cflags += [ "-fno-omit-frame-pointer" ]
165 } else {
166 cflags += [ "/Oy-" ]
166 } 167 }
167 if (is_asan) { 168 }
168 asan_blacklist_path = 169 if (is_asan) {
169 rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir) 170 cflags += [ "-fsanitize=address" ]
171 if (is_android) {
172 # Android build relies on -Wl,--gc-sections removing unreachable code.
173 # ASan instrumentation for globals inhibits this and results in a
174 # library with unresolvable relocations.
175 # TODO(eugenis): find a way to reenable this.
170 cflags += [ 176 cflags += [
171 "-fsanitize=address", 177 "-mllvm",
172 "-fsanitize-blacklist=$asan_blacklist_path", 178 "-asan-globals=0",
Nico 2016/03/31 02:09:32 It looks like the only reason we don't pass this i
Reid Kleckner 2016/03/31 16:39:15 The blacklist file is empty, though. I think we sh
Nico 2016/03/31 16:53:54 Ok, but that shouldn't be in a "asan in gn for Win
173 ] 179 ]
174 if (is_android) { 180 } else if (is_mac) {
175 # Android build relies on -Wl,--gc-sections removing unreachable code. 181 # http://crbug.com/352073
176 # ASan instrumentation for globals inhibits this and results in a 182 cflags += [
177 # library with unresolvable relocations. 183 "-mllvm",
178 # TODO(eugenis): find a way to reenable this. 184 "-asan-globals=0",
179 cflags += [ 185 ]
180 "-mllvm", 186 libs = [ "clang_rt.asan_osx_dynamic" ]
181 "-asan-globals=0", 187
188 # TODO(GYP): deal with mac_bundles.
189 } else if (is_win) {
190 assert(target_cpu == "x86", "WinASan is 32-bit only currently")
191
192 # We still need a blacklist on Windows.
193 cflags += [ "-fsanitize-blacklist=" +
194 rebase_path("//tools/memory/asan/blacklist_win.txt",
195 root_build_dir) ]
196 if (is_component_build) {
197 libs = [
198 "clang_rt.asan_dynamic-i386.lib",
199 "clang_rt.asan_dynamic_runtime_thunk-i386.lib",
182 ] 200 ]
183 } else if (is_mac) { 201 } else {
184 # http://crbug.com/352073 202 # TODO(rnk): DLLs in the non-component build should link against
185 cflags += [ 203 # clang_rt.asan_dll_thunk-i386.lib instead.
Nico 2016/03/31 02:09:32 Dirk: is there some easy way in gn to check "is th
Dirk Pranke 2016/03/31 02:28:39 Nope. However, if what you want is some settings
Reid Kleckner 2016/03/31 16:39:15 Yep, I figured the logic would have to move. Anywa
186 "-mllvm", 204 libs = [ "clang_rt.asan-i386.lib" ]
187 "-asan-globals=0",
188 ]
189 # TODO(GYP): deal with mac_bundles.
190 } 205 }
191 } 206 }
192 if (is_lsan) { 207 }
193 cflags += [ "-fsanitize=leak" ] 208 if (is_lsan) {
194 } 209 cflags += [ "-fsanitize=leak" ]
195 if (is_tsan) { 210 }
196 tsan_blacklist_path = 211 if (is_tsan) {
197 rebase_path("//tools/memory/tsan_v2/ignores.txt", root_build_dir) 212 assert(is_linux, "tsan only supported on linux x86_64")
213 tsan_blacklist_path =
214 rebase_path("//tools/memory/tsan_v2/ignores.txt", root_build_dir)
215 cflags += [
216 "-fsanitize=thread",
217 "-fsanitize-blacklist=$tsan_blacklist_path",
218 ]
219 }
220 if (is_msan) {
221 assert(is_linux, "msan only supported on linux x86_64")
222 msan_blacklist_path =
223 rebase_path("//tools/msan/blacklist.txt", root_build_dir)
224 cflags += [
225 "-fsanitize=memory",
226 "-fsanitize-memory-track-origins=$msan_track_origins",
227 "-fsanitize-blacklist=$msan_blacklist_path",
228 ]
229 }
230 if (is_ubsan) {
231 ubsan_blacklist_path =
232 rebase_path("//tools/ubsan/blacklist.txt", root_build_dir)
233 cflags += [
234 # Yasm dies with an "Illegal instruction" error when bounds checking is
235 # enabled. See http://crbug.com/489901
236 # "-fsanitize=bounds",
237 "-fsanitize=float-divide-by-zero",
238 "-fsanitize=integer-divide-by-zero",
239 "-fsanitize=null",
240 "-fsanitize=object-size",
241 "-fsanitize=return",
242 "-fsanitize=returns-nonnull-attribute",
243 "-fsanitize=shift-exponent",
244 "-fsanitize=signed-integer-overflow",
245 "-fsanitize=unreachable",
246 "-fsanitize=vla-bound",
247 "-fsanitize-blacklist=$ubsan_blacklist_path",
248 ]
249
250 # Chromecast ubsan builds fail to compile with these
251 # experimental flags, so only add them to non-chromecast ubsan builds.
Nico 2016/03/31 02:09:32 Huh? (not your code, only talking to myself)
252 if (!is_chromecast) {
198 cflags += [ 253 cflags += [
199 "-fsanitize=thread", 254 # Employ the experimental PBQP register allocator to avoid slow
200 "-fsanitize-blacklist=$tsan_blacklist_path", 255 # compilation on files with too many basic blocks.
201 ] 256 # See http://crbug.com/426271.
202 } 257 "-mllvm",
203 if (is_msan) { 258 "-regalloc=pbqp",
204 msan_blacklist_path =
205 rebase_path("//tools/msan/blacklist.txt", root_build_dir)
206 cflags += [
207 "-fsanitize=memory",
208 "-fsanitize-memory-track-origins=$msan_track_origins",
209 "-fsanitize-blacklist=$msan_blacklist_path",
210 ]
211 }
212 if (is_ubsan) {
213 ubsan_blacklist_path =
214 rebase_path("//tools/ubsan/blacklist.txt", root_build_dir)
215 cflags += [
216 # Yasm dies with an "Illegal instruction" error when bounds checking is
217 # enabled. See http://crbug.com/489901
218 # "-fsanitize=bounds",
219 "-fsanitize=float-divide-by-zero",
220 "-fsanitize=integer-divide-by-zero",
221 "-fsanitize=null",
222 "-fsanitize=object-size",
223 "-fsanitize=return",
224 "-fsanitize=returns-nonnull-attribute",
225 "-fsanitize=shift-exponent",
226 "-fsanitize=signed-integer-overflow",
227 "-fsanitize=unreachable",
228 "-fsanitize=vla-bound",
229 "-fsanitize-blacklist=$ubsan_blacklist_path",
230 ]
231 259
232 # Chromecast ubsan builds fail to compile with these 260 # Speculatively use coalescing to slightly improve the code generated
233 # experimental flags, so only add them to non-chromecast ubsan builds. 261 # by PBQP regallocator. May increase compile time.
234 if (!is_chromecast) { 262 "-mllvm",
235 cflags += [ 263 "-pbqp-coalescing",
236 # Employ the experimental PBQP register allocator to avoid slow
237 # compilation on files with too many basic blocks.
238 # See http://crbug.com/426271.
239 "-mllvm",
240 "-regalloc=pbqp",
241
242 # Speculatively use coalescing to slightly improve the code generated
243 # by PBQP regallocator. May increase compile time.
244 "-mllvm",
245 "-pbqp-coalescing",
246 ]
247 }
248 }
249 if (is_ubsan_vptr) {
250 ubsan_vptr_blacklist_path =
251 rebase_path("//tools/ubsan/vptr_blacklist.txt", root_build_dir)
252 cflags += [
253 "-fsanitize=vptr",
254 "-fsanitize-blacklist=$ubsan_vptr_blacklist_path",
255 ]
256 }
257 if (is_ubsan_security) {
258 ubsan_blacklist_path =
259 rebase_path("//tools/ubsan/blacklist.txt", root_build_dir)
260 cflags += [
261 "-fsanitize=signed-integer-overflow",
262 "-fsanitize-blacklist=$ubsan_blacklist_path",
263 ]
264 }
265 if (is_lto && !is_nacl) {
266 cflags += [ "-flto" ]
267
268 if (is_cfi) {
269 cfi_blacklist_path =
270 rebase_path("//tools/cfi/blacklist.txt", root_build_dir)
271 cflags += [
272 "-fsanitize=cfi-vcall",
273 "-fsanitize=cfi-derived-cast",
274 "-fsanitize=cfi-unrelated-cast",
275 "-fsanitize-blacklist=$cfi_blacklist_path",
276 ]
277 }
278
279 if (use_cfi_diag) {
280 cflags += [
281 "-fno-sanitize-trap=cfi",
282 "-fsanitize-recover=cfi",
283 "-fno-inline-functions",
284 "-fno-inline",
285 "-fno-omit-frame-pointer",
286 "-O1",
287 ]
288 } else {
289 defines += [ "CFI_ENFORCEMENT" ]
290 }
291 }
292
293 if (use_custom_libcxx) {
294 prefix = "//buildtools/third_party"
295 include = "trunk/include"
296 cflags_cc += [
297 "-nostdinc++",
298 "-isystem" + rebase_path("$prefix/libc++/$include", root_build_dir),
299 "-isystem" + rebase_path("$prefix/libc++abi/$include", root_build_dir),
300 ] 264 ]
301 } 265 }
302 } 266 }
267 if (is_ubsan_vptr) {
268 ubsan_vptr_blacklist_path =
269 rebase_path("//tools/ubsan/vptr_blacklist.txt", root_build_dir)
270 cflags += [
271 "-fsanitize=vptr",
272 "-fsanitize-blacklist=$ubsan_vptr_blacklist_path",
273 ]
274 }
275 if (is_ubsan_security) {
276 ubsan_blacklist_path =
277 rebase_path("//tools/ubsan/blacklist.txt", root_build_dir)
278 cflags += [
279 "-fsanitize=signed-integer-overflow",
280 "-fsanitize-blacklist=$ubsan_blacklist_path",
281 ]
282 }
283 if (is_lto && !is_nacl) {
284 cflags += [ "-flto" ]
303 285
304 if (is_mac && is_asan) { 286 if (is_cfi) {
305 libs = [ "clang_rt.asan_osx_dynamic" ] 287 cfi_blacklist_path =
288 rebase_path("//tools/cfi/blacklist.txt", root_build_dir)
289 cflags += [
290 "-fsanitize=cfi-vcall",
291 "-fsanitize=cfi-derived-cast",
292 "-fsanitize=cfi-unrelated-cast",
293 "-fsanitize-blacklist=$cfi_blacklist_path",
294 ]
295 }
296
297 if (use_cfi_diag) {
298 cflags += [
299 "-fno-sanitize-trap=cfi",
300 "-fsanitize-recover=cfi",
301 "-fno-inline-functions",
302 "-fno-inline",
303 "-fno-omit-frame-pointer",
304 "-O1",
305 ]
306 } else {
307 defines += [ "CFI_ENFORCEMENT" ]
308 }
309 }
310
311 if (use_custom_libcxx) {
312 prefix = "//buildtools/third_party"
313 include = "trunk/include"
314 cflags_cc += [
315 "-nostdinc++",
316 "-isystem" + rebase_path("$prefix/libc++/$include", root_build_dir),
317 "-isystem" + rebase_path("$prefix/libc++abi/$include", root_build_dir),
318 ]
306 } 319 }
307 } 320 }
308 321
309 config("default_sanitizer_coverage_flags") { 322 config("default_sanitizer_coverage_flags") {
310 cflags = [] 323 cflags = []
311 324
312 if (use_sanitizer_coverage) { 325 if (use_sanitizer_coverage) {
313 # FIXME: make this configurable. 326 # FIXME: make this configurable.
314 cflags += [ 327 cflags += [
315 "-fsanitize-coverage=edge,indirect-calls,8bit-counters", 328 "-fsanitize-coverage=edge,indirect-calls,8bit-counters",
316 "-mllvm", 329 "-mllvm",
317 "-sanitizer-coverage-prune-blocks=1", 330 "-sanitizer-coverage-prune-blocks=1",
318 ] 331 ]
319 } 332 }
320 } 333 }
321 334
322 # Copy dynamic clang_rt sanitizer libraries to output directory. 335 # Copy dynamic clang_rt sanitizer libraries to output directory.
323 if (is_mac) { 336 if (is_mac) {
324 copy("copy_libclang_rt_dyn") { 337 copy("copy_libclang_rt_dyn") {
325 sources = [ 338 sources = [
326 "//third_party/llvm-build/Release+Asserts/compiler-rt/lib/darwin/libclang_ rt.asan_osx_dynamic.dylib", 339 "//third_party/llvm-build/Release+Asserts/compiler-rt/lib/darwin/libclang_ rt.asan_osx_dynamic.dylib",
327 "//third_party/llvm-build/Release+Asserts/compiler-rt/lib/darwin/libclang_ rt.tsan_osx_dynamic.dylib", 340 "//third_party/llvm-build/Release+Asserts/compiler-rt/lib/darwin/libclang_ rt.tsan_osx_dynamic.dylib",
328 "//third_party/llvm-build/Release+Asserts/compiler-rt/lib/darwin/libclang_ rt.ubsan_osx_dynamic.dylib", 341 "//third_party/llvm-build/Release+Asserts/compiler-rt/lib/darwin/libclang_ rt.ubsan_osx_dynamic.dylib",
329 ] 342 ]
330 outputs = [ 343 outputs = [
331 "$root_build_dir/{{source_file_part}}", 344 "$root_build_dir/{{source_file_part}}",
332 ] 345 ]
333 } 346 }
334 } 347 }
OLDNEW
« no previous file with comments | « no previous file | build/config/win/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698