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

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

Issue 1324623005: Move sanitizer and symbol flags out of BUILDCONFIG (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 | « build/config/BUILDCONFIG.gn ('k') | build/config/compiler/compiler.gni » ('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 (c) 2013 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2013 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/android/config.gni") 5 import("//build/config/android/config.gni")
6 import("//build/config/chrome_build.gni") 6 import("//build/config/chrome_build.gni")
7 import("//build/config/compiler/compiler.gni")
8 import("//build/toolchain/ccache.gni")
9
7 if (current_cpu == "arm") { 10 if (current_cpu == "arm") {
8 import("//build/config/arm.gni") 11 import("//build/config/arm.gni")
9 } 12 }
10 if (current_cpu == "mipsel" || current_cpu == "mips64el") { 13 if (current_cpu == "mipsel" || current_cpu == "mips64el") {
11 import("//build/config/mips.gni") 14 import("//build/config/mips.gni")
12 } 15 }
13 if (is_posix) { 16 if (is_posix) {
14 import("//build/config/gcc/gcc_version.gni") 17 import("//build/config/gcc/gcc_version.gni")
15 } 18 }
16 if (is_win) { 19 if (is_win) {
17 import("//build/config/win/visual_studio_version.gni") 20 import("//build/config/win/visual_studio_version.gni")
18 } 21 }
19 22
20 import("//build/toolchain/ccache.gni")
21 import("//build/config/sanitizers/sanitizers.gni")
22
23 declare_args() { 23 declare_args() {
24 # Normally, Android builds are lightly optimized, even for debug builds, to 24 # Normally, Android builds are lightly optimized, even for debug builds, to
25 # keep binary size down. Setting this flag to true disables such optimization 25 # keep binary size down. Setting this flag to true disables such optimization
26 android_full_debug = false 26 android_full_debug = false
27 27
28 # Whether to use the binary binutils checked into third_party/binutils. 28 # Whether to use the binary binutils checked into third_party/binutils.
29 # These are not multi-arch so cannot be used except on x86 and x86-64 (the 29 # These are not multi-arch so cannot be used except on x86 and x86-64 (the
30 # only two architectures that are currently checked in). Turn this off when 30 # only two architectures that are currently checked in). Turn this off when
31 # you are using a custom toolchain and need to control -B in cflags. 31 # you are using a custom toolchain and need to control -B in cflags.
32 linux_use_bundled_binutils = is_linux && current_cpu == "x64" 32 linux_use_bundled_binutils = is_linux && current_cpu == "x64"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 # This is a separate config so that third_party code (which would not use the 77 # This is a separate config so that third_party code (which would not use the
78 # source root and might have conflicting versions of some headers) can remove 78 # source root and might have conflicting versions of some headers) can remove
79 # this and specify their own include paths. 79 # this and specify their own include paths.
80 config("default_include_dirs") { 80 config("default_include_dirs") {
81 include_dirs = [ 81 include_dirs = [
82 "//", 82 "//",
83 root_gen_dir, 83 root_gen_dir,
84 ] 84 ]
85 } 85 }
86 86
87 # TODO(GYP) bug 527515: is_ubsan, is_ubsan_vptr
88 if (!is_win) {
89 using_sanitizer = is_asan || is_lsan || is_tsan || is_msan
90 }
91
92 # compiler --------------------------------------------------------------------- 87 # compiler ---------------------------------------------------------------------
93 # 88 #
94 # Base compiler configuration. 89 # Base compiler configuration.
95 # 90 #
96 # See also "runtime_library" below for related stuff and a discussion about 91 # See also "runtime_library" below for related stuff and a discussion about
97 # where stuff should go. Put warning related stuff in the "warnings" config. 92 # where stuff should go. Put warning related stuff in the "warnings" config.
98 93
99 config("compiler") { 94 config("compiler") {
100 cflags = [] 95 cflags = []
101 cflags_c = [] 96 cflags_c = []
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 cflags += [ "-Wno-incompatible-pointer-types" ] 1199 cflags += [ "-Wno-incompatible-pointer-types" ]
1205 } else if (current_cpu == "mipsel") { 1200 } else if (current_cpu == "mipsel") {
1206 cflags += [ "-w" ] 1201 cflags += [ "-w" ]
1207 } else if (is_chromeos && current_cpu == "arm") { 1202 } else if (is_chromeos && current_cpu == "arm") {
1208 cflags += [ "-w" ] 1203 cflags += [ "-w" ]
1209 } 1204 }
1210 } 1205 }
1211 1206
1212 # Optimization ----------------------------------------------------------------- 1207 # Optimization -----------------------------------------------------------------
1213 # 1208 #
1214 # Note that BUILDCONFIG.gn sets up a variable "default_optimization_config" 1209 # The BUILDCONFIG file sets the "default_optimization" config on targets by
1215 # which it will assign to the config it implicitly applies to every target. If 1210 # default. It will be equivalent to either "optimize" (release) or
1216 # you want to override the optimization level for your target, remove this 1211 # "no_optimize" (debug) optimization configs.
1217 # config (which will expand differently for debug or release builds), and then
1218 # add back the one you want to override it with:
1219 # 1212 #
1220 # configs -= default_optimization_config 1213 # You can override the optimization level on a per-target basis by removing the
1221 # configs += [ "//build/config/compiler/optimize_max" ] 1214 # default config and then adding the named one you want:
1215 #
1216 # configs -= [ "//build/config/compiler:default_optimization" ]
1217 # configs += [ "//build/config/compiler:optimize_max" ]
1222 1218
1223 # Shared settings for both "optimize" and "optimize_max" configs. 1219 # Shared settings for both "optimize" and "optimize_max" configs.
1224 # IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags. 1220 # IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags.
1225 if (is_win) { 1221 if (is_win) {
1226 common_optimize_on_cflags = [ 1222 common_optimize_on_cflags = [
1227 "/Ob2", # Both explicit and auto inlining. 1223 "/Ob2", # Both explicit and auto inlining.
1228 "/Oy-", # Disable omitting frame pointers, must be after /O2. 1224 "/Oy-", # Disable omitting frame pointers, must be after /O2.
1229 "/d2Zi+", # Improve debugging of optimized code. 1225 "/d2Zi+", # Improve debugging of optimized code.
1230 "/Zc:inline", # Remove unreferenced COMDAT (faster links). 1226 "/Zc:inline", # Remove unreferenced COMDAT (faster links).
1231 ] 1227 ]
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 1290
1295 if (!using_sanitizer) { 1291 if (!using_sanitizer) {
1296 # Functions interposed by the sanitizers can make ld think 1292 # Functions interposed by the sanitizers can make ld think
1297 # that some libraries aren't needed when they actually are, 1293 # that some libraries aren't needed when they actually are,
1298 # http://crbug.com/234010. As workaround, disable --as-needed. 1294 # http://crbug.com/234010. As workaround, disable --as-needed.
1299 common_optimize_on_ldflags += [ "-Wl,--as-needed" ] 1295 common_optimize_on_ldflags += [ "-Wl,--as-needed" ]
1300 } 1296 }
1301 } 1297 }
1302 } 1298 }
1303 1299
1304 # Default "optimization on" config. On Windows, this favors size over speed. 1300 # Default "optimization on" config. Set up variables so the
1301 # "default_optimization" config can re-use these settings.
1302 if (is_win) {
1303 # Favor size over speed, /O1 must be before the common flags. The GYP
1304 # build also specifies /Os and /GF but these are implied by /O1.
1305 optimize_cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
1306 } else if (is_android || is_ios) {
1307 # Favor size over speed.
1308 optimize_cflags = [ "-Os" ] + common_optimize_on_cflags
1309 } else {
1310 # Linux & Mac favor speed over size.
1311 # TODO(brettw) it's weird that Mac and desktop Linux are different. We should
1312 # explore favoring size over speed in this case as well.
1313 optimize_cflags = [ "-O2" ] + common_optimize_on_cflags
1314 }
1315 optimize_ldflags = common_optimize_on_ldflags
1316
1305 config("optimize") { 1317 config("optimize") {
1306 if (is_win) { 1318 cflags = optimize_cflags
1307 # Favor size over speed, /O1 must be before the common flags. The GYP 1319 ldflags = optimize_ldflags
1308 # build also specifies /Os and /GF but these are implied by /O1.
1309 cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
1310 } else if (is_android || is_ios) {
1311 cflags = [ "-Os" ] + common_optimize_on_cflags # Favor size over speed.
1312 } else {
1313 cflags = [ "-O2" ] + common_optimize_on_cflags
1314 }
1315 ldflags = common_optimize_on_ldflags
1316 } 1320 }
1317 1321
1318 # Turn off optimizations. 1322 # Turn off optimizations. Set up variables so the
1323 # "default_optimization" config can re-use these settings.
1324 if (is_win) {
1325 no_optimize_cflags = [
1326 "/Od", # Disable optimization.
1327 "/Ob0", # Disable all inlining (on by default).
1328 "/RTC1", # Runtime checks for stack frame and uninitialized variables.
1329 ]
1330 no_optimize_ldflags = []
1331 } else if (is_android && !android_full_debug) {
1332 # On Android we kind of optimize some things that don't affect debugging
1333 # much even when optimization is disabled to get the binary size down.
1334 no_optimize_cflags = [
1335 "-Os",
1336 "-fdata-sections",
1337 "-ffunction-sections",
1338 ]
1339 if (!using_sanitizer) {
1340 no_optimize_cflags += [ "-fomit-frame-pointer" ]
1341 }
1342 no_optimize_ldflags = common_optimize_on_ldflags
1343 } else {
1344 no_optimize_cflags = [ "-O0" ]
1345 no_optimize_ldflags = []
1346 }
1347
1319 config("no_optimize") { 1348 config("no_optimize") {
1320 if (is_win) { 1349 cflags = no_optimize_cflags
1321 cflags = [ 1350 ldflags = no_optimize_ldflags
1322 "/Od", # Disable optimization.
1323 "/Ob0", # Disable all inlining (on by default).
1324 "/RTC1", # Runtime checks for stack frame and uninitialized variables.
1325 ]
1326 } else if (is_android && !android_full_debug) {
1327 # On Android we kind of optimize some things that don't affect debugging
1328 # much even when optimization is disabled to get the binary size down.
1329 cflags = [
1330 "-Os",
1331 "-fdata-sections",
1332 "-ffunction-sections",
1333 ]
1334 if (!using_sanitizer) {
1335 cflags += [ "-fomit-frame-pointer" ]
1336 }
1337 ldflags = common_optimize_on_ldflags
1338 } else {
1339 cflags = [ "-O0" ]
1340 }
1341 } 1351 }
1342 1352
1343 # Turns up the optimization level. On Windows, this implies whole program 1353 # Turns up the optimization level. On Windows, this implies whole program
1344 # optimization and link-time code generation which is very expensive and should 1354 # optimization and link-time code generation which is very expensive and should
1345 # be used sparingly. 1355 # be used sparingly.
1346 config("optimize_max") { 1356 config("optimize_max") {
1347 ldflags = common_optimize_on_ldflags 1357 ldflags = common_optimize_on_ldflags
1348 if (is_win) { 1358 if (is_win) {
1349 # Favor speed over size, /O2 must be before the common flags. The GYP 1359 # Favor speed over size, /O2 must be before the common flags. The GYP
1350 # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2. 1360 # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2.
(...skipping 10 matching lines...) Expand all
1361 # normal build isn't going to actually be a bug, so the incremental 1371 # normal build isn't going to actually be a bug, so the incremental
1362 # value of C4702 for PGO builds is likely very small. 1372 # value of C4702 for PGO builds is likely very small.
1363 "/wd4702", 1373 "/wd4702",
1364 ] 1374 ]
1365 } 1375 }
1366 } else { 1376 } else {
1367 cflags = [ "-O2" ] + common_optimize_on_cflags 1377 cflags = [ "-O2" ] + common_optimize_on_cflags
1368 } 1378 }
1369 } 1379 }
1370 1380
1381 # The default optimization applied to all targets. This will be equivalent to
1382 # either "optimize" or "no_optimize", depending on the build flags.
1383 config("default_optimization") {
1384 if (is_debug) {
1385 cflags = no_optimize_cflags
1386 ldflags = no_optimize_ldflags
1387 } else {
1388 cflags = optimize_cflags
1389 ldflags = optimize_ldflags
1390 }
1391 }
1392
1371 # Symbols ---------------------------------------------------------------------- 1393 # Symbols ----------------------------------------------------------------------
1372 1394
1395 # The BUILDCONFIG file sets the "default_symbols" config on targets by
1396 # default. It will be equivalent to one the three specific symbol levels.
1397 #
1398 # You can override the symbol level on a per-target basis by removing the
1399 # default config and then adding the named one you want:
1400 #
1401 # configs -= [ "//build/config/compiler:default_symbols" ]
1402 # configs += [ "//build/config/compiler:symbols" ]
1403
1404 # Full symbols.
1405 if (is_win) {
1406 import("//build/toolchain/goma.gni")
1407 if (use_goma) {
1408 symbols_cflags = [ "/Z7" ] # No PDB file
1409 } else {
1410 symbols_cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
1411 }
1412 if (is_win_fastlink) {
1413 # Tell VS 2015+ to create a PDB that references debug
1414 # information in .obj and .lib files instead of copying
1415 # it all. This flag is incompatible with /PROFILE
1416 symbols_ldflags = [ "/DEBUG:FASTLINK" ]
1417 } else {
1418 symbols_ldflags = [ "/DEBUG" ]
1419 }
1420 } else {
1421 symbols_cflags = [ "-g2" ]
1422 if (use_debug_fission) {
1423 symbols_cflags += [ "-gsplit-dwarf" ]
1424 }
1425 symbols_ldflags = []
1426 }
1427
1373 config("symbols") { 1428 config("symbols") {
1374 if (is_win) { 1429 cflags = symbols_cflags
1375 import("//build/toolchain/goma.gni") 1430 ldflags = symbols_ldflags
1376 if (use_goma) { 1431 }
1377 cflags = [ "/Z7" ] # No PDB file 1432
1378 } else { 1433 # Minimal symbols.
1379 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue. 1434 if (is_win) {
1380 } 1435 # Linker symbols for backtraces only.
1381 if (is_win_fastlink) { 1436 minimal_symbols_cflags = []
1382 # Tell VS 2015+ to create a PDB that references debug 1437 if (is_win_fastlink) {
1383 # information in .obj and .lib files instead of copying 1438 # Tell VS 2015+ to create a PDB that references debug
1384 # it all. This flag is incompatible with /PROFILE 1439 # information in .obj and .lib files instead of copying
1385 ldflags = [ "/DEBUG:FASTLINK" ] 1440 # it all. This flag is incompatible with /PROFILE
1386 } else { 1441 minimal_symbols_ldflags = [ "/DEBUG:FASTLINK" ]
1387 ldflags = [ "/DEBUG" ]
1388 }
1389 } else { 1442 } else {
1390 cflags = [ "-g2" ] 1443 minimal_symbols_ldflags = [ "/DEBUG" ]
1391 if (use_debug_fission) {
1392 cflags += [ "-gsplit-dwarf" ]
1393 }
1394 } 1444 }
1445 } else {
1446 minimal_symbols_cflags = [ "-g1" ]
1447 if (use_debug_fission) {
1448 minimal_symbols_cflags += [ "-gsplit-dwarf" ]
1449 }
1450 minimal_symbols_ldflags = []
1395 } 1451 }
1396 1452
1397 config("minimal_symbols") { 1453 config("minimal_symbols") {
1398 if (is_win) { 1454 cflags = minimal_symbols_cflags
1399 # Linker symbols for backtraces only. 1455 ldflags = minimal_symbols_ldflags
1400 if (is_win_fastlink) { 1456 }
1401 # Tell VS 2015+ to create a PDB that references debug 1457
1402 # information in .obj and .lib files instead of copying 1458 # No symbols.
1403 # it all. This flag is incompatible with /PROFILE 1459 if (is_win) {
1404 ldflags = [ "/DEBUG:FASTLINK" ] 1460 no_symbols_cflags = []
1405 } else { 1461 } else {
1406 ldflags = [ "/DEBUG" ] 1462 no_symbols_cflags = [ "-g0" ]
1407 }
1408 } else {
1409 cflags = [ "-g1" ]
1410 if (use_debug_fission) {
1411 cflags += [ "-gsplit-dwarf" ]
1412 }
1413 }
1414 } 1463 }
1415 1464
1416 config("no_symbols") { 1465 config("no_symbols") {
1417 if (!is_win) { 1466 cflags = no_symbols_cflags
1418 cflags = [ "-g0" ] 1467 }
1468
1469 # Default symbols.
1470 config("default_symbols") {
1471 if (symbol_level == 0) {
1472 cflags = no_symbols_cflags
1473 } else if (symbol_level == 1) {
1474 cflags = minimal_symbols_cflags
1475 ldflags = minimal_symbols_ldflags
1476 } else if (symbol_level == 2) {
1477 cflags = symbols_cflags
1478 ldflags = symbols_ldflags
1479 } else {
1480 assert(false)
1419 } 1481 }
1420 } 1482 }
OLDNEW
« no previous file with comments | « build/config/BUILDCONFIG.gn ('k') | build/config/compiler/compiler.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698