blob: 5429f9ff2467a2ee38bab7db19e6fa606b3d4627 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001# 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
3# found in the LICENSE file.
4
5import("//build/config/android/config.gni")
6import("//build/config/chrome_build.gni")
7import("//build/config/compiler/compiler.gni")
8import("//build/config/nacl/config.gni")
9import("//build/toolchain/cc_wrapper.gni")
10import("//build/toolchain/toolchain.gni")
11
12if (current_cpu == "arm" || current_cpu == "arm64") {
13 import("//build/config/arm.gni")
14}
15if (current_cpu == "mipsel" || current_cpu == "mips64el") {
16 import("//build/config/mips.gni")
17}
18if (is_win) {
19 import("//build/config/win/visual_studio_version.gni")
20}
21
22declare_args() {
23 # Default to warnings as errors for default workflow, where we catch
24 # warnings with known toolchains. Allow overriding this e.g. for Chromium
25 # builds on Linux that could use a different version of the compiler.
26 # With GCC, warnings in no-Chromium code are always not treated as errors.
27 treat_warnings_as_errors = true
28
29 # Normally, Android builds are lightly optimized, even for debug builds, to
30 # keep binary size down. Setting this flag to true disables such optimization
31 android_full_debug = false
32
33 # Whether to use the binary binutils checked into third_party/binutils.
34 # These are not multi-arch so cannot be used except on x86 and x86-64 (the
35 # only two architectures that are currently checked in). Turn this off when
36 # you are using a custom toolchain and need to control -B in cflags.
37 linux_use_bundled_binutils =
38 is_linux && (current_cpu == "x64" || current_cpu == "x86")
39 binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
40 root_build_dir)
41
42 # Compile in such a way as to make it possible for the profiler to unwind full
43 # stack frames. Setting this flag has a large effect on the performance of the
44 # generated code than just setting profiling, but gives the profiler more
45 # information to analyze.
46 # Requires profiling to be set to true.
47 enable_full_stack_frames_for_profiling = false
48
49 # Whether to use the gold linker from binutils instead of lld or bfd.
50 use_gold =
51 !use_lld && is_linux &&
52 (current_cpu == "x64" || current_cpu == "x86" || current_cpu == "arm")
53
54 # When we are going to use gold we need to find it.
55 # This is initialized below, after use_gold might have been overridden.
56 gold_path = false
57
58 # use_debug_fission: whether to use split DWARF debug info
59 # files. This can reduce link time significantly, but is incompatible
60 # with some utilities such as icecc and ccache. Requires gold and
61 # gcc >= 4.8 or clang.
62 # http://gcc.gnu.org/wiki/DebugFission
63 #
64 # This is a placeholder value indicating that the code below should set
65 # the default. This is necessary to delay the evaluation of the default
66 # value expression until after its input values such as use_gold have
67 # been set, e.g. by a toolchain_args() block.
68 use_debug_fission = "default"
69
70 if (is_win) {
71 # Whether the VS xtree header has been patched to disable warning 4702. If
72 # it has, then we don't need to disable 4702 (unreachable code warning).
73 # The patch is preapplied to the internal toolchain and hence all bots.
74 msvs_xtree_patched = false
75 }
76
77 # Omit unwind support in official builds to save space.
78 # We can use breakpad for these builds.
79 exclude_unwind_tables = is_chrome_branded && is_official_build
80
81 # If true, gold linker will save symbol table inside object files.
82 # This speeds up gdb startup by 60%
83 gdb_index = false
84
85 # If true, optimize for size. Does not affect windows builds.
86 # Linux & Mac favor speed over size.
87 # TODO(brettw) it's weird that Mac and desktop Linux are different. We should
88 # explore favoring size over speed in this case as well.
89 optimize_for_size = is_android || is_ios
90
91 # If this is set to true, or if LLVM_FORCE_HEAD_REVISION is set to 1
92 # in the environment, we use the revision in the llvm repo to determine
93 # the CLANG_REVISION to use, instead of the version hard-coded into
94 # //tools/clang/scripts/update.py. This should only be used in
95 # conjunction with setting LLVM_FORCE_HEAD_REVISION in the
96 # environment when `gclient runhooks` is run as well.
97 llvm_force_head_revision = false
98}
99
100if (is_clang && !is_nacl) {
101 update_args = [ "--print-revision" ]
102 if (llvm_force_head_revision) {
103 update_args += [ "--llvm-force-head-revision" ]
104 }
105 clang_revision =
106 exec_script("//tools/clang/scripts/update.py", update_args, "trim string")
107}
108
109# Apply the default logic for these values if they were not set explicitly.
110if (gold_path == false) {
111 if (use_gold) {
112 gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
113 root_build_dir)
114 } else {
115 gold_path = ""
116 }
117}
118
119if (use_debug_fission == "default") {
120 use_debug_fission = is_debug && !is_win && use_gold &&
121 linux_use_bundled_binutils && cc_wrapper == ""
122}
123
124# default_include_dirs ---------------------------------------------------------
125#
126# This is a separate config so that third_party code (which would not use the
127# source root and might have conflicting versions of some headers) can remove
128# this and specify their own include paths.
129config("default_include_dirs") {
130 include_dirs = [
131 "//",
132 root_gen_dir,
133 ]
134}
135
136# compiler ---------------------------------------------------------------------
137#
138# Base compiler configuration.
139#
140# See also "runtime_library" below for related stuff and a discussion about
141# where stuff should go. Put warning related stuff in the "warnings" config.
142
143config("compiler") {
144 asmflags = []
145 cflags = []
146 cflags_c = []
147 cflags_cc = []
148 cflags_objc = []
149 cflags_objcc = []
150 ldflags = []
151 defines = []
152 configs = []
153
154 # System-specific flags. If your compiler flags apply to one of the
155 # categories here, add it to the associated file to keep this shared config
156 # smaller.
157 if (is_win) {
158 configs += [ "//build/config/win:compiler" ]
159 } else if (is_android) {
160 configs += [ "//build/config/android:compiler" ]
161 } else if (is_linux) {
162 configs += [ "//build/config/linux:compiler" ]
163 } else if (is_nacl) {
164 configs += [ "//build/config/nacl:compiler" ]
165 } else if (is_ios || is_mac) {
166 configs += [ "//build/config/mac:compiler" ]
167 }
168
169 # Applies to all Posix systems.
170 if (is_posix) {
171 configs += [ "//build/config/posix:compiler" ]
172 }
173
174 # See the definitions below.
175 configs += [
176 ":compiler_cpu_abi",
177 ":compiler_codegen",
178 ]
179
180 # In general, Windows is totally different, but all the other builds share
181 # some common GCC configuration.
182 if (!is_win) {
183 # Common GCC compiler flags setup.
184 # --------------------------------
185 cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204
186 cflags_cc += [
187 # If this is removed then remove the corresponding /Zc:threadSafeInit- for
188 # Windows.
189 "-fno-threadsafe-statics",
190
191 # Not exporting C++ inline functions can generally be applied anywhere
192 # so we do so here. Normal function visibility is controlled by
193 # //build/config/gcc:symbol_visibility_hidden.
194 "-fvisibility-inlines-hidden",
195 ]
196
197 # Stack protection.
198 if (is_mac) {
199 cflags += [ "-fstack-protector-all" ]
200 } else if (is_posix && !is_chromeos && !is_nacl) {
201 # TODO(phajdan.jr): Use -fstack-protector-strong when our gcc supports it.
202 cflags += [ "--param=ssp-buffer-size=4" ]
203
204 # The x86 toolchain currently has problems with stack-protector.
205 if (is_android && current_cpu == "x86") {
206 cflags += [ "-fno-stack-protector" ]
207 } else {
208 cflags += [ "-fstack-protector" ]
209 }
210 }
211
212 # Linker warnings.
213 if (!(is_chromeos && current_cpu == "arm") &&
214 !(is_android && use_order_profiling) && !is_mac && !is_ios) {
215 # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580
216 # TODO(lizeb,pasko): Fix link errors when linking with order_profiling=1
217 # crbug.com/485542
218 ldflags += [ "-Wl,--fatal-warnings" ]
219 }
220 }
221
222 if (is_clang && is_debug) {
223 # Allow comparing the address of references and 'this' against 0
224 # in debug builds. Technically, these can never be null in
225 # well-defined C/C++ and Clang can optimize such checks away in
226 # release builds, but they may be used in asserts in debug builds.
227 cflags_cc += [
228 "-Wno-undefined-bool-conversion",
229 "-Wno-tautological-undefined-compare",
230 ]
231 }
232
233 if (is_clang && !is_nacl) {
234 # This is here so that all files get recompiled after a clang roll and
235 # when turning clang on or off. (defines are passed via the command line,
236 # and build system rebuild things when their commandline changes). Nothing
237 # should ever read this define.
238 defines += [ "CR_CLANG_REVISION=$clang_revision" ]
239 }
240
241 # Non-Mac Posix compiler flags setup.
242 # -----------------------------------
243 if (is_posix && !(is_mac || is_ios)) {
244 if (enable_profiling) {
245 # Explicitly ask for frame pointers. Otherwise they are omitted when
246 # any optimization level is used (and Android debug builds use -Os).
247 cflags += [ "-fno-omit-frame-pointer" ]
248 if (!is_debug) {
249 cflags += [ "-g" ]
250
251 if (enable_full_stack_frames_for_profiling) {
252 cflags += [
253 "-fno-inline",
254 "-fno-optimize-sibling-calls",
255 ]
256 }
257 }
258 }
259
260 defines += [ "_FILE_OFFSET_BITS=64" ]
261
262 if (!is_android) {
263 defines += [
264 "_LARGEFILE_SOURCE",
265 "_LARGEFILE64_SOURCE",
266 ]
267 }
268
269 if (!is_nacl) {
270 if (exclude_unwind_tables) {
271 cflags += [
272 "-fno-unwind-tables",
273 "-fno-asynchronous-unwind-tables",
274 ]
275 defines += [ "NO_UNWIND_TABLES" ]
276 } else {
277 cflags += [ "-funwind-tables" ]
278 }
279 }
280 }
281
282 # Linux/Android common flags setup.
283 # ---------------------------------
284 if (is_linux || is_android) {
285 cflags += [
286 "-fPIC",
287 "-pipe", # Use pipes for communicating between sub-processes. Faster.
288 ]
289
290 ldflags += [
291 "-fPIC",
292 "-Wl,-z,noexecstack",
293 "-Wl,-z,now",
294 "-Wl,-z,relro",
295 ]
296 if (!using_sanitizer && !use_cfi_diag) {
297 ldflags += [ "-Wl,-z,defs" ]
298 }
299 }
300
301 # Linux-specific compiler flags setup.
302 # ------------------------------------
303 if (is_posix && use_lld && !is_nacl) {
304 ldflags += [ "-fuse-ld=lld" ]
305 } else if (use_gold) {
306 ldflags += [
307 "-B$gold_path",
308
309 # Newer gccs and clangs support -fuse-ld, use the flag to force gold
310 # selection.
311 # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html
312 "-fuse-ld=gold",
313
314 # Experimentation found that using four linking threads
315 # saved ~20% of link time.
316 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
317 # Only apply this to the target linker, since the host
318 # linker might not be gold, but isn't used much anyway.
319 # TODO(raymes): Disable threading because gold is frequently
320 # crashing on the bots: crbug.com/161942.
321 #"-Wl,--threads",
322 #"-Wl,--thread-count=4",
323 ]
324
325 if (gdb_index) {
326 ldflags += [ "-Wl,--gdb-index" ]
327 }
328
329 # TODO(thestig): Make this flag work with GN.
330 #if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan || is_msan)) {
331 # ldflags += [
332 # "-Wl,--detect-odr-violations",
333 # ]
334 #}
335 } else if (linux_use_bundled_binutils) {
336 # Gold is the default linker for the bundled binutils so we explicitly
337 # enable the bfd linker when use_gold is not set.
338 ldflags += [ "-fuse-ld=bfd" ]
339 }
340
341 if (is_posix && (use_gold || (use_lld && !is_nacl)) && !using_sanitizer &&
342 !(is_android && use_order_profiling)) {
343 # TODO(crbug.com/576197) - gcc on x86 platforms + gold + icf=all
344 # doesn't currently work. Once it does, use icf=all everywhere.
345 if (is_clang || (target_cpu != "x86" && target_cpu != "x64")) {
346 ldflags += [ "-Wl,--icf=all" ]
347 } else {
348 ldflags += [ "-Wl,--icf=safe" ]
349 }
350 }
351
352 if (linux_use_bundled_binutils) {
353 cflags += [ "-B$binutils_path" ]
354 }
355
356 # Clang-specific compiler flags setup.
357 # ------------------------------------
358 if (is_clang) {
359 cflags += [ "-fcolor-diagnostics" ]
360 }
361
362 # Makes builds independent of absolute file path.
363 # clang-cl (used if is_win) doesn't expose this flag.
364 # Currently disabled for nacl since its toolchain lacks this flag (too old).
365 # TODO(zforman): Once nacl's toolchain is updated, remove check.
366 if (is_clang && is_linux) {
367 absolute_path = rebase_path("//.")
368 cflags += [ "-fdebug-prefix-map=$absolute_path=." ]
369 }
370
371 # C++11 compiler flags setup.
372 # ---------------------------
373 if (is_linux || is_android || (is_nacl && is_clang)) {
374 # gnu++11 instead of c++11 is needed because some code uses typeof() (a
375 # GNU extension).
376 # TODO(thakis): Eventually switch this to c++11 instead,
377 # http://crbug.com/427584
378 cflags_cc += [ "-std=gnu++11" ]
379 } else if (!is_win && !is_nacl) {
380 # TODO(mcgrathr) - the NaCl GCC toolchain doesn't support either gnu++11
381 # or c++11; we technically don't need this toolchain any more, but there
382 # are still a few buildbots using it, so until those are turned off
383 # we need the !is_nacl clause and the (is_nacl && is_clang) clause, above.
384 cflags_cc += [ "-std=c++11" ]
385 }
386
387 if (is_mac) {
388 # Tell the compiler to use libc++'s headers and the linker to link
389 # against libc++. The latter part normally requires OS X 10.7,
390 # but we still support running on 10.6. How does this work? Two
391 # parts:
392 # 1. Chromium's clang doesn't error on -mmacosx-version-min=10.6
393 # combined with -stdlib=libc++ (it normally silently produced a
394 # binary that doesn't run on 10.6)
395 # 2. Further down, library_dirs is set to
396 # third_party/libc++-static, which contains a static
397 # libc++.a library. The linker then links against that instead
398 # of against /usr/lib/libc++.dylib when it sees the -lc++ flag
399 # added by the driver.
400 #
401 # In component builds, just link to the system libc++. This has
402 # the effect of making everything depend on libc++, which means
403 # component-build binaries won't run on 10.6 (no libc++ there),
404 # but for a developer-only configuration that's ok. (We don't
405 # want to raise the deployment target yet so that official and
406 # dev builds have the same deployment target. This affects
407 # things like which functions are considered deprecated.)
408 cflags_cc += [ "-stdlib=libc++" ]
409 ldflags += [ "-stdlib=libc++" ]
410 if (!is_component_build && !is_asan) {
411 ldflags += [
412 "-L",
413 rebase_path("//third_party/libc++-static", root_build_dir),
414 ]
415 }
416 }
417
418 # Add flags for link-time optimization. These flags enable
419 # optimizations/transformations that require whole-program visibility at link
420 # time, so they need to be applied to all translation units, and we may end up
421 # with miscompiles if only part of the program is compiled with LTO flags. For
422 # that reason, we cannot allow targets to enable or disable these flags, for
423 # example by disabling the optimize configuration.
424 # TODO(pcc): Make this conditional on is_official_build rather than on gn
425 # flags for specific features.
426 if (!is_debug && (allow_posix_link_time_opt || is_cfi) && !is_nacl) {
427 cflags += [ "-flto" ]
428 ldflags += [ "-flto" ]
429
430 # Apply a lower LTO optimization level as the default is too slow.
431 if (is_linux) {
432 if (use_lld) {
433 ldflags += [ "-Wl,--lto-O1" ]
434 } else {
435 ldflags += [ "-Wl,-plugin-opt,O1" ]
436 }
437 } else if (is_mac) {
438 ldflags += [ "-Wl,-mllvm,-O1" ]
439 }
440
441 # Work-around for http://openradar.appspot.com/20356002
442 if (is_mac) {
443 ldflags += [ "-Wl,-all_load" ]
444 }
445
446 # Allows the linker to apply ICF to the LTO object file. Also, when
447 # targeting ARM, without this flag, LTO produces a .text section that is
448 # larger than the maximum call displacement, preventing the linker from
449 # relocating calls (http://llvm.org/PR22999).
450 if (is_linux) {
451 ldflags += [ "-Wl,-plugin-opt,-function-sections" ]
452 }
453
454 # TODO(pcc): Make these flags work correctly with CFI.
455 if (!is_cfi) {
456 cflags += [ "-fwhole-program-vtables" ]
457 ldflags += [ "-fwhole-program-vtables" ]
458 }
459 }
460
461 # Pass the same C/C++ flags to the objective C/C++ compiler.
462 cflags_objc += cflags_c
463 cflags_objcc += cflags_cc
464
465 # Assign any flags set for the C compiler to asmflags so that they are sent
466 # to the assembler. The Windows assembler takes different types of flags
467 # so only do so for posix platforms.
468 if (is_posix) {
469 asmflags += cflags
470 asmflags += cflags_c
471 }
472}
473
474# This provides the basic options to select the target CPU and ABI.
475# It is factored out of "compiler" so that special cases can use this
476# without using everything that "compiler" brings in. Options that
477# tweak code generation for a particular CPU do not belong here!
478# See "compiler_codegen", below.
479config("compiler_cpu_abi") {
480 cflags = []
481 ldflags = []
482
483 if (is_posix && !(is_mac || is_ios)) {
484 # CPU architecture. We may or may not be doing a cross compile now, so for
485 # simplicity we always explicitly set the architecture.
486 if (current_cpu == "x64") {
487 cflags += [
488 "-m64",
489 "-march=x86-64",
490 ]
491 ldflags += [ "-m64" ]
492 } else if (current_cpu == "x86") {
493 cflags += [ "-m32" ]
494 ldflags += [ "-m32" ]
495 if (!is_nacl) {
496 cflags += [
497 "-msse2",
498 "-mfpmath=sse",
499 "-mmmx",
500 ]
501 }
502 } else if (current_cpu == "arm") {
503 if (is_clang && !is_android && !is_nacl) {
504 cflags += [
505 "-target",
506 "arm-linux-gnueabihf",
507 ]
508 ldflags += [
509 "-target",
510 "arm-linux-gnueabihf",
511 ]
512 }
513 if (!is_nacl) {
514 cflags += [
515 "-march=$arm_arch",
516 "-mfloat-abi=$arm_float_abi",
517 ]
518 if (arm_use_thumb) {
519 cflags += [ "-mthumb" ]
520 if (is_android && !is_clang) {
521 # Clang doesn't support this option.
522 cflags += [ "-mthumb-interwork" ]
523 }
524 }
525 }
526 if (arm_tune != "") {
527 cflags += [ "-mtune=$arm_tune" ]
528 }
529 } else if (current_cpu == "mipsel") {
530 if (mips_arch_variant == "r6") {
531 if (is_clang) {
532 cflags += [
533 "-target",
534 "mipsel-linux-gnu",
535 "-march=mips32r6",
536 ]
537 ldflags += [
538 "-target",
539 "mipsel-linux-gnu",
540 ]
541 } else {
542 cflags += [
543 "-mips32r6",
544 "-Wa,-mips32r6",
545 ]
546 if (is_android) {
547 ldflags += [
548 "-mips32r6",
549 "-Wl,-melf32ltsmip",
550 ]
551 }
552 }
553 } else if (mips_arch_variant == "r2") {
554 if (is_clang) {
555 if (is_android) {
556 cflags += [
557 "-target",
558 "mipsel-linux-android",
559 "-march=mipsel",
560 "-mcpu=mips32r2",
561 ]
562 ldflags += [
563 "-target",
564 "mipsel-linux-android",
565 ]
566 } else {
567 cflags += [
568 "-target",
569 "mipsel-linux-gnu",
570 "-march=mipsel",
571 "-mcpu=mips32r2",
572 ]
573 ldflags += [
574 "-target",
575 "mipsel-linux-gnu",
576 ]
577 }
578 } else {
579 cflags += [
580 "-mips32r2",
581 "-Wa,-mips32r2",
582 ]
583 if (mips_float_abi == "hard" && mips_fpu_mode != "") {
584 cflags += [ "-m$mips_fpu_mode" ]
585 }
586 }
587 } else if (mips_arch_variant == "r1") {
588 if (is_clang) {
589 if (is_android) {
590 cflags += [
591 "-target",
592 "mipsel-linux-android",
593 "-march=mipsel",
594 "-mcpu=mips32",
595 ]
596 ldflags += [
597 "-target",
598 "mipsel-linux-android",
599 ]
600 } else {
601 cflags += [
602 "-target",
603 "mipsel-linux-gnu",
604 "-march=mipsel",
605 "-mcpu=mips32",
606 ]
607 ldflags += [
608 "-target",
609 "mipsel-linux-gnu",
610 ]
611 }
612 } else {
613 cflags += [
614 "-mips32",
615 "-Wa,-mips32",
616 ]
617 }
618 }
619
620 if (mips_dsp_rev == 1) {
621 cflags += [ "-mdsp" ]
622 } else if (mips_dsp_rev == 2) {
623 cflags += [ "-mdspr2" ]
624 }
625
626 cflags += [ "-m${mips_float_abi}-float" ]
627 } else if (current_cpu == "mips64el") {
628 if (mips_arch_variant == "r6") {
629 cflags += [
630 "-mips64r6",
631 "-Wa,-mips64r6",
632 ]
633 ldflags += [ "-mips64r6" ]
634 } else if (mips_arch_variant == "r2") {
635 cflags += [
636 "-mips64r2",
637 "-Wa,-mips64r2",
638 ]
639 ldflags += [ "-mips64r2" ]
640 }
641 } else if (current_cpu == "pnacl" && is_nacl_nonsfi) {
642 if (target_cpu == "x86" || target_cpu == "x64") {
643 cflags += [
644 "-arch",
645 "x86-32-nonsfi",
646 "--pnacl-bias=x86-32-nonsfi",
647 "--target=i686-unknown-nacl",
648 ]
649 ldflags += [
650 "-arch",
651 "x86-32-nonsfi",
652 "--target=i686-unknown-nacl",
653 ]
654 } else if (target_cpu == "arm") {
655 cflags += [
656 "-arch",
657 "arm-nonsfi",
658 "--pnacl-bias=arm-nonsfi",
659 "--target=armv7-unknown-nacl-gnueabihf",
660 ]
661 ldflags += [
662 "-arch",
663 "arm-nonsfi",
664 "--target=armv7-unknown-nacl-gnueabihf",
665 ]
666 }
667 }
668 }
669
670 asmflags = cflags
671}
672
673# This provides options to tweak code generation that are necessary
674# for particular Chromium code or for working around particular
675# compiler bugs (or the combination of the two).
676config("compiler_codegen") {
677 configs = []
678 cflags = []
679
680 if (is_nacl) {
681 configs += [ "//build/config/nacl:compiler_codegen" ]
682 } else if (is_posix && !is_mac && !is_ios) {
683 if (current_cpu == "x86") {
684 if (is_clang) {
685 cflags += [
686 # Else building libyuv gives clang's register allocator issues,
687 # see llvm.org/PR15798 / crbug.com/233709
688 "-momit-leaf-frame-pointer",
689 ]
690 }
691 } else if (current_cpu == "arm") {
692 if (is_android && !is_clang) {
693 # Clang doesn't support these flags.
694 cflags += [
695 # The tree-sra optimization (scalar replacement for
696 # aggregates enabling subsequent optimizations) leads to
697 # invalid code generation when using the Android NDK's
698 # compiler (r5-r7). This can be verified using
699 # webkit_unit_tests' WTF.Checked_int8_t test.
700 "-fno-tree-sra",
701
702 # The following option is disabled to improve binary
703 # size and performance in gcc 4.9.
704 "-fno-caller-saves",
705 ]
706 }
707 }
708 }
709
710 asmflags = cflags
711}
712
713# This is separate from :compiler_codegen (and not even a sub-config there)
714# so that some targets can remove it from the list with:
715# configs -= [ "//build/config/compiler:clang_stackrealign" ]
716# See https://crbug.com/556393 for details of where it must be avoided.
717config("clang_stackrealign") {
718 if (is_clang && current_cpu == "x86" && is_linux) {
719 cflags = [
720 # Align the stack on 16-byte boundaries, http://crbug.com/418554.
721 "-mstack-alignment=16",
722 "-mstackrealign",
723 ]
724 }
725}
726
727config("compiler_arm_fpu") {
728 if (current_cpu == "arm" && !is_ios && !is_nacl) {
729 cflags = [ "-mfpu=$arm_fpu" ]
730 asmflags = cflags
731 } else if (current_cpu == "arm64" && !is_ios && !is_nacl) {
732 cflags = [ "-mcpu=$arm_fpu" ]
733 asmflags = cflags
734 }
735}
736
737# runtime_library -------------------------------------------------------------
738#
739# Sets the runtime library and associated options.
740#
741# How do you determine what should go in here vs. "compiler" above? Consider if
742# a target might choose to use a different runtime library (ignore for a moment
743# if this is possible or reasonable on your system). If such a target would want
744# to change or remove your option, put it in the runtime_library config. If a
745# target wants the option regardless, put it in the compiler config.
746
747config("runtime_library") {
748 defines = []
749 configs = []
750
751 # System-specific flags. If your compiler flags apply to one of the
752 # categories here, add it to the associated file to keep this shared config
753 # smaller.
754 if (is_win) {
755 configs += [ "//build/config/win:runtime_library" ]
756 } else if (is_linux) {
757 configs += [ "//build/config/linux:runtime_library" ]
758 } else if (is_ios) {
759 configs += [ "//build/config/ios:runtime_library" ]
760 } else if (is_mac) {
761 configs += [ "//build/config/mac:runtime_library" ]
762 } else if (is_android) {
763 configs += [ "//build/config/android:runtime_library" ]
764 }
765
766 if (is_posix) {
767 configs += [ "//build/config/posix:runtime_library" ]
768 }
769
770 if (is_component_build) {
771 defines += [ "COMPONENT_BUILD" ]
772 }
773}
774
775# default_warnings ------------------------------------------------------------
776#
777# Collects all warning flags that are used by default. This is used as a
778# subconfig of both chromium_code and no_chromium_code. This way these
779# flags are guaranteed to appear on the compile command line after -Wall.
780config("default_warnings") {
781 cflags = []
782 cflags_cc = []
783
784 if (is_win) {
785 if (treat_warnings_as_errors) {
786 cflags += [ "/WX" ]
787 }
788
789 cflags += [
790 # Warnings permanently disabled:
791
792 # C4091: 'typedef ': ignored on left of 'X' when no variable is
793 # declared.
794 # This happens in a number of Windows headers. Dumb.
795 "/wd4091",
796
797 # C4127: conditional expression is constant
798 # This warning can in theory catch dead code and other problems, but
799 # triggers in far too many desirable cases where the conditional
800 # expression is either set by macros or corresponds some legitimate
801 # compile-time constant expression (due to constant template args,
802 # conditionals comparing the sizes of different types, etc.). Some of
803 # these can be worked around, but it's not worth it.
804 "/wd4127",
805
806 # C4251: 'identifier' : class 'type' needs to have dll-interface to be
807 # used by clients of class 'type2'
808 # This is necessary for the shared library build.
809 "/wd4251",
810
811 # C4351: new behavior: elements of array 'array' will be default
812 # initialized
813 # This is a silly "warning" that basically just alerts you that the
814 # compiler is going to actually follow the language spec like it's
815 # supposed to, instead of not following it like old buggy versions did.
816 # There's absolutely no reason to turn this on.
817 "/wd4351",
818
819 # C4355: 'this': used in base member initializer list
820 # It's commonly useful to pass |this| to objects in a class' initializer
821 # list. While this warning can catch real bugs, most of the time the
822 # constructors in question don't attempt to call methods on the passed-in
823 # pointer (until later), and annotating every legit usage of this is
824 # simply more hassle than the warning is worth.
825 "/wd4355",
826
827 # C4503: 'identifier': decorated name length exceeded, name was
828 # truncated
829 # This only means that some long error messages might have truncated
830 # identifiers in the presence of lots of templates. It has no effect on
831 # program correctness and there's no real reason to waste time trying to
832 # prevent it.
833 "/wd4503",
834
835 # Warning C4589 says: "Constructor of abstract class ignores
836 # initializer for virtual base class." Disable this warning because it
837 # is flaky in VS 2015 RTM. It triggers on compiler generated
838 # copy-constructors in some cases.
839 "/wd4589",
840
841 # C4611: interaction between 'function' and C++ object destruction is
842 # non-portable
843 # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN
844 # suggests using exceptions instead of setjmp/longjmp for C++, but
845 # Chromium code compiles without exception support. We therefore have to
846 # use setjmp/longjmp for e.g. JPEG decode error handling, which means we
847 # have to turn off this warning (and be careful about how object
848 # destruction happens in such cases).
849 "/wd4611",
850
851 # Warnings to evaluate and possibly fix/reenable later:
852
853 "/wd4100", # Unreferenced formal function parameter.
854 "/wd4121", # Alignment of a member was sensitive to packing.
855 "/wd4244", # Conversion: possible loss of data.
856 "/wd4505", # Unreferenced local function has been removed.
857 "/wd4510", # Default constructor could not be generated.
858 "/wd4512", # Assignment operator could not be generated.
859 "/wd4610", # Class can never be instantiated, constructor required.
860 "/wd4838", # Narrowing conversion. Doesn't seem to be very useful.
861 "/wd4995", # 'X': name was marked as #pragma deprecated
862 "/wd4996", # Deprecated function warning.
863
864 # These are variable shadowing warnings that are new in VS2015. We
865 # should work through these at some point -- they may be removed from
866 # the RTM release in the /W4 set.
867 "/wd4456",
868 "/wd4457",
869 "/wd4458",
870 "/wd4459",
871 ]
872
873 if (visual_studio_version == "2015") {
874 cflags += [
875 # C4312 is a VS 2015 64-bit warning for integer to larger pointer.
876 # TODO(brucedawson): fix warnings, crbug.com/554200
877 "/wd4312",
878
879 # TODO(brucedawson): http://crbug.com/593448 - C4595 is an 'illegal
880 # inline operator new' warning that is new in VS 2015 Update 2.
881 # This is equivalent to clang's no-inline-new-delete warning.
882 # See http://bugs.icu-project.org/trac/ticket/11122
883 "/wd4595",
884 ]
885
886 if (current_cpu == "x86") {
887 cflags += [
888 # VC++ 2015 changes 32-bit size_t truncation warnings from 4244 to
889 # 4267. Example: short TruncTest(size_t x) { return x; }
890 # Since we disable 4244 we need to disable 4267 during migration.
891 # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
892 "/wd4267",
893 ]
894 }
895 }
896
897 # VS xtree header file needs to be patched or 4702 (unreachable code
898 # warning) is reported if _HAS_EXCEPTIONS=0. Disable the warning if xtree is
899 # not patched.
900 if (!msvs_xtree_patched &&
901 exec_script("../../win_is_xtree_patched.py", [], "value") == 0) {
902 cflags += [ "/wd4702" ] # Unreachable code.
903 }
904
905 # Building with Clang on Windows is a work in progress and very
906 # experimental. See crbug.com/82385.
907 # Keep this in sync with the similar block in build/common.gypi
908 if (is_clang) {
909 cflags += [
910 # TODO(hans): Make this list shorter eventually, http://crbug.com/504657
911 "-Wno-microsoft-enum-value", # http://crbug.com/505296
912 "-Wno-unknown-pragmas", # http://crbug.com/505314
913 "-Wno-microsoft-cast", # http://crbug.com/550065
914 ]
915 }
916 } else {
917 if (is_mac && !is_nacl) {
918 # When compiling Objective-C, warns if a method is used whose
919 # availability is newer than the deployment target. This is not
920 # required when compiling Chrome for iOS.
921 cflags += [ "-Wpartial-availability" ]
922 }
923
924 # Suppress warnings about ABI changes on ARM (Clang doesn't give this
925 # warning).
926 if (current_cpu == "arm" && !is_clang) {
927 cflags += [ "-Wno-psabi" ]
928 }
929
930 if (!is_clang) {
931 cflags_cc += [
932 # See comment for -Wno-c++11-narrowing.
933 "-Wno-narrowing",
934 ]
935
936 # Don't warn about the "typedef 'foo' locally defined but not used"
937 # for gcc 4.8.
938 # TODO: remove this flag once all builds work. See crbug.com/227506
939 cflags += [ "-Wno-unused-local-typedefs" ]
940
941 # Don't warn about "maybe" uninitialized. Clang doesn't include this
942 # in -Wall but gcc does, and it gives false positives.
943 cflags += [ "-Wno-maybe-uninitialized" ]
944 }
945 }
946
947 # Common Clang and GCC warning setup.
948 if (!is_win || is_clang) {
949 cflags += [
950 # Disables.
951 "-Wno-missing-field-initializers", # "struct foo f = {0};"
952 "-Wno-unused-parameter", # Unused function parameters.
953 ]
954 }
955
956 if (is_chromeos) {
957 # TODO(thakis): Remove, http://crbug.com/263960
958 if (is_clang) {
959 cflags_cc += [ "-Wno-reserved-user-defined-literal" ]
960 } else {
961 cflags_cc += [ "-Wno-literal-suffix" ]
962 }
963 }
964
965 if (is_clang) {
966 cflags += [
967 # TODO(thakis): Consider -Wloop-analysis (turns on
968 # -Wrange-loop-analysis too).
969
970 # This warns on using ints as initializers for floats in
971 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
972 # which happens in several places in chrome code. Not sure if
973 # this is worth fixing.
974 "-Wno-c++11-narrowing",
975
976 # Warns on switches on enums that cover all enum values but
977 # also contain a default: branch. Chrome is full of that.
978 "-Wno-covered-switch-default",
979
980 # Clang considers the `register` keyword as deprecated, but e.g.
981 # code generated by flex (used in angle) contains that keyword.
982 # http://crbug.com/255186
983 "-Wno-deprecated-register",
984
985 # TODO(thakis): This used to be implied by -Wno-unused-function,
986 # which we no longer use. Check if it makes sense to remove
987 # this as well. http://crbug.com/316352
988 "-Wno-unneeded-internal-declaration",
989
990 # TODO(hans): Get this cleaned up, http://crbug.com/428099
991 "-Wno-inconsistent-missing-override",
992 ]
993
994 # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost
995 # always have different versions. Certain flags may not be recognized by
996 # one version or the other.
997 if (!is_nacl) {
998 # Flags NaCl (Clang 3.7) does not recognize.
999 cflags += [
1000 # TODO(thakis): Enable this, crbug.com/507717
1001 "-Wno-shift-negative-value",
1002
1003 # TODO(thakis): https://crbug.com/604888
1004 "-Wno-undefined-var-template",
1005 ]
1006 }
1007 }
1008}
1009
1010# chromium_code ---------------------------------------------------------------
1011#
1012# Toggles between higher and lower warnings for code that is (or isn't)
1013# part of Chromium.
1014
1015config("chromium_code") {
1016 if (is_win) {
1017 cflags = [ "/W4" ] # Warning level 4.
1018 } else {
1019 cflags = [ "-Wall" ]
1020 if (treat_warnings_as_errors) {
1021 cflags += [ "-Werror" ]
1022 }
1023 if (is_clang) {
1024 # Enable -Wextra for chromium_code when we control the compiler.
1025 cflags += [ "-Wextra" ]
1026 }
1027
1028 # In Chromium code, we define __STDC_foo_MACROS in order to get the
1029 # C99 macros on Mac and Linux.
1030 defines = [
1031 "__STDC_CONSTANT_MACROS",
1032 "__STDC_FORMAT_MACROS",
1033 ]
1034
1035 if (!is_debug && !using_sanitizer &&
1036 (!is_linux || !is_clang || is_official_build)) {
1037 # _FORTIFY_SOURCE isn't really supported by Clang now, see
1038 # http://llvm.org/bugs/show_bug.cgi?id=16821.
1039 # It seems to work fine with Ubuntu 12 headers though, so use it in
1040 # official builds.
1041 #
1042 # Non-chromium code is not guaranteed to compile cleanly with
1043 # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are
1044 # disabled, so only do that for Release build.
1045 defines += [ "_FORTIFY_SOURCE=2" ]
1046 }
1047 }
1048
1049 configs = [ ":default_warnings" ]
1050}
1051
1052config("no_chromium_code") {
1053 cflags = []
1054 cflags_cc = []
1055 defines = []
1056
1057 if (is_win) {
1058 cflags += [
1059 "/W3", # Warning level 3.
1060 "/wd4800", # Disable warning when forcing value to bool.
1061 "/wd4267", # TODO(jschuh): size_t to int.
1062 "/wd4996", # Deprecated function warning.
1063 ]
1064 defines += [
1065 "_CRT_NONSTDC_NO_WARNINGS",
1066 "_CRT_NONSTDC_NO_DEPRECATE",
1067 ]
1068 } else {
1069 # GCC may emit unsuppressible warnings so don't add -Werror for no chromium
1070 # code. crbug.com/589724
1071 if (treat_warnings_as_errors && is_clang) {
1072 cflags += [ "-Werror" ]
1073 }
1074 if (is_clang && !is_nacl) {
1075 # TODO(thakis): Remove !is_nacl once
1076 # https://codereview.webrtc.org/1552863002/ made its way into chromium.
1077 cflags += [ "-Wall" ]
1078 }
1079 }
1080
1081 if (is_clang) {
1082 cflags += [
1083 # Lots of third-party libraries have unused variables. Instead of
1084 # suppressing them individually, we just blanket suppress them here.
1085 "-Wno-unused-variable",
1086 ]
1087 }
1088
1089 if (is_linux || is_android) {
1090 cflags_cc += [
1091 # Don't warn about hash_map in third-party code.
1092 "-Wno-deprecated",
1093 ]
1094 }
1095
1096 configs = [ ":default_warnings" ]
1097}
1098
1099# rtti ------------------------------------------------------------------------
1100#
1101# Allows turning Run-Time Type Identification on or off.
1102
1103config("rtti") {
1104 if (is_win) {
1105 cflags_cc = [ "/GR" ]
1106 }
1107}
1108config("no_rtti") {
1109 # CFI diagnostics and UBsan vptr require RTTI.
1110 if (!use_cfi_diag && !is_ubsan_vptr) {
1111 if (is_win) {
1112 cflags_cc = [ "/GR-" ]
1113 } else {
1114 cflags_cc = [ "-fno-rtti" ]
1115 cflags_objcc = cflags_cc
1116 }
1117 }
1118}
1119
1120# Warnings ---------------------------------------------------------------------
1121
1122# This will generate warnings when using Clang if code generates exit-time
1123# destructors, which will slow down closing the program.
1124# TODO(thakis): Make this a blacklist instead, http://crbug.com/101600
1125config("wexit_time_destructors") {
1126 # TODO: Enable on Windows too, http://crbug.com/404525
1127 if (is_clang && !is_win) {
1128 cflags = [ "-Wexit-time-destructors" ]
1129 }
1130}
1131
1132# On Windows compiling on x64, VC will issue a warning when converting
1133# size_t to int because it will truncate the value. Our code should not have
1134# these warnings and one should use a static_cast or a checked_cast for the
1135# conversion depending on the case. However, a lot of code still needs to be
1136# fixed. Apply this config to such targets to disable the warning.
1137#
1138# Note that this can be applied regardless of platform and architecture to
1139# clean up the call sites. This will only apply the flag when necessary.
1140#
1141# TODO(jschuh): crbug.com/167187 fix this and delete this config.
1142config("no_size_t_to_int_warning") {
1143 if (is_win && current_cpu == "x64") {
1144 cflags = [ "/wd4267" ]
1145 }
1146}
1147
1148# Some code presumes that pointers to structures/objects are compatible
1149# regardless of whether what they point to is already known to be valid.
1150# gcc 4.9 and earlier had no way of suppressing this warning without
1151# supressing the rest of them. Here we centralize the identification of
1152# the gcc 4.9 toolchains.
1153config("no_incompatible_pointer_warnings") {
1154 cflags = []
1155 if (is_clang) {
1156 cflags += [ "-Wno-incompatible-pointer-types" ]
1157 } else if (current_cpu == "mipsel") {
1158 cflags += [ "-w" ]
1159 } else if (is_chromeos && current_cpu == "arm") {
1160 cflags += [ "-w" ]
1161 }
1162}
1163
1164# Optimization -----------------------------------------------------------------
1165#
1166# The BUILDCONFIG file sets the "default_optimization" config on targets by
1167# default. It will be equivalent to either "optimize" (release) or
1168# "no_optimize" (debug) optimization configs.
1169#
1170# You can override the optimization level on a per-target basis by removing the
1171# default config and then adding the named one you want:
1172#
1173# configs -= [ "//build/config/compiler:default_optimization" ]
1174# configs += [ "//build/config/compiler:optimize_max" ]
1175
1176# Shared settings for both "optimize" and "optimize_max" configs.
1177# IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags.
1178if (is_win) {
1179 common_optimize_on_cflags = [
1180 "/Ob2", # Both explicit and auto inlining.
1181 "/Oy-", # Disable omitting frame pointers, must be after /O2.
1182 "/d2Zi+", # Improve debugging of optimized code.
1183 "/Zc:inline", # Remove unreferenced COMDAT (faster links).
1184 ]
1185 if (!is_asan) {
1186 common_optimize_on_cflags += [
1187 # Put data in separate COMDATs. This allows the linker
1188 # to put bit-identical constants at the same address even if
1189 # they're unrelated constants, which saves binary size.
1190 # This optimization can't be used when ASan is enabled because
1191 # it is not compatible with the ASan ODR checker.
1192 "/Gw",
1193 ]
1194 }
1195 common_optimize_on_ldflags = [ "/OPT:ICF" ] # Redundant COMDAT folding.
1196 if (is_official_build) {
1197 common_optimize_on_ldflags += [
1198 "/OPT:REF", # Remove unreferenced data.
1199 "/LTCG", # Link-time code generation.
1200
1201 # Set the number of LTCG code-gen threads to eight. The default is four.
1202 # This gives a 5-10% link speedup.
1203 "/cgthreads:8",
1204 ]
1205 }
1206} else {
1207 common_optimize_on_cflags = [
1208 # Don't emit the GCC version ident directives, they just end up in the
1209 # .comment section taking up binary size.
1210 "-fno-ident",
1211
1212 # Put data and code in their own sections, so that unused symbols
1213 # can be removed at link time with --gc-sections.
1214 "-fdata-sections",
1215 "-ffunction-sections",
1216 ]
1217 common_optimize_on_ldflags = []
1218
1219 if (is_android) {
1220 # We don't omit frame pointers on arm64 since they are required
1221 # to correctly unwind stackframes which contain system library
1222 # function frames (crbug.com/391706).
1223 if (!using_sanitizer && !enable_profiling && target_cpu != "arm64") {
1224 common_optimize_on_cflags += [ "-fomit-frame-pointer" ]
1225 }
1226
1227 # TODO(jdduke) Re-enable on mips after resolving linking
1228 # issues with libc++ (crbug.com/456380).
1229 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
1230 common_optimize_on_ldflags += [
1231 # Warn in case of text relocations.
1232 "-Wl,--warn-shared-textrel",
1233 ]
1234 }
1235 }
1236
1237 if (is_mac || is_ios) {
1238 if (symbol_level == 2) {
1239 # Mac dead code stripping requires symbols.
1240 common_optimize_on_ldflags += [ "-Wl,-dead_strip" ]
1241 }
1242 } else {
1243 # Non-Mac Posix linker flags.
1244 common_optimize_on_ldflags += [
1245 # Specifically tell the linker to perform optimizations.
1246 # See http://lwn.net/Articles/192624/ .
1247 "-Wl,-O1",
1248 "-Wl,--gc-sections",
1249 ]
1250
1251 if (!using_sanitizer) {
1252 # Functions interposed by the sanitizers can make ld think
1253 # that some libraries aren't needed when they actually are,
1254 # http://crbug.com/234010. As workaround, disable --as-needed.
1255 common_optimize_on_ldflags += [ "-Wl,--as-needed" ]
1256 }
1257 }
1258}
1259
1260# Default "optimization on" config.
1261config("optimize") {
1262 if (is_win) {
1263 if (is_official_build && full_wpo_on_official) {
1264 common_optimize_on_cflags += [ "/GL" ]
1265 }
1266
1267 # Favor size over speed, /O1 must be before the common flags. The GYP
1268 # build also specifies /Os and /GF but these are implied by /O1.
1269 cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
1270 } else if (optimize_for_size) {
1271 # Favor size over speed.
1272 cflags = [ "-Os" ] + common_optimize_on_cflags
1273 } else {
1274 cflags = [ "-O2" ] + common_optimize_on_cflags
1275 }
1276 ldflags = common_optimize_on_ldflags
1277}
1278
1279# Same config as 'optimize' but without the WPO flag.
1280config("optimize_no_wpo") {
1281 if (is_win) {
1282 # Favor size over speed, /O1 must be before the common flags. The GYP
1283 # build also specifies /Os and /GF but these are implied by /O1.
1284 cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
1285 } else if (optimize_for_size) {
1286 # Favor size over speed.
1287 cflags = [ "-Os" ] + common_optimize_on_cflags
1288 } else {
1289 cflags = [ "-O2" ] + common_optimize_on_cflags
1290 }
1291 ldflags = common_optimize_on_ldflags
1292}
1293
1294# Turn off optimizations.
1295config("no_optimize") {
1296 if (is_win) {
1297 cflags = [
1298 "/Od", # Disable optimization.
1299 "/Ob0", # Disable all inlining (on by default).
1300 ]
1301 } else if (is_android && !android_full_debug) {
1302 # On Android we kind of optimize some things that don't affect debugging
1303 # much even when optimization is disabled to get the binary size down.
1304 cflags = [
1305 "-Os",
1306 "-fdata-sections",
1307 "-ffunction-sections",
1308 ]
1309
1310 # We don't omit frame pointers on arm64 since they are required
1311 # to correctly unwind stackframes which contain system library
1312 # function frames (crbug.com/391706).
1313 if (!using_sanitizer && !enable_profiling && target_cpu != "arm64") {
1314 cflags += [ "-fomit-frame-pointer" ]
1315 }
1316
1317 # Don't use gc-sections since it can cause links to succeed when they
1318 # actually shouldn't. http://crbug.com/159847
1319 ldflags = common_optimize_on_ldflags - [ "-Wl,--gc-sections" ]
1320 } else {
1321 cflags = [ "-O0" ]
1322 ldflags = []
1323 }
1324}
1325
1326# Turns up the optimization level. On Windows, this implies whole program
1327# optimization and link-time code generation which is very expensive and should
1328# be used sparingly.
1329config("optimize_max") {
1330 if (is_nacl_irt) {
1331 # The NaCl IRT is a special case and always wants its own config.
1332 # Various components do:
1333 # if (!is_debug) {
1334 # configs -= [ "//build/config/compiler:default_optimization" ]
1335 # configs += [ "//build/config/compiler:optimize_max" ]
1336 # }
1337 # So this config has to have the selection logic just like
1338 # "default_optimization", below.
1339 configs = [ "//build/config/nacl:irt_optimize" ]
1340 } else {
1341 ldflags = common_optimize_on_ldflags
1342 if (is_win) {
1343 # Favor speed over size, /O2 must be before the common flags. The GYP
1344 # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2.
1345 cflags = [ "/O2" ] + common_optimize_on_cflags
1346
1347 # TODO(thakis): Remove is_clang here, https://crbug.com/598772
1348 if (is_official_build && !is_clang) {
1349 cflags += [
1350 "/GL", # Whole program optimization.
1351
1352 # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds.
1353 # Probably anything that this would catch that wouldn't be caught in a
1354 # normal build isn't going to actually be a bug, so the incremental
1355 # value of C4702 for PGO builds is likely very small.
1356 "/wd4702",
1357 ]
1358 }
1359 } else {
1360 cflags = [ "-O2" ] + common_optimize_on_cflags
1361 }
1362 }
1363}
1364
1365# The default optimization applied to all targets. This will be equivalent to
1366# either "optimize" or "no_optimize", depending on the build flags.
1367config("default_optimization") {
1368 if (is_nacl_irt) {
1369 # The NaCl IRT is a special case and always wants its own config.
1370 # It gets optimized the same way regardless of the type of build.
1371 configs = [ "//build/config/nacl:irt_optimize" ]
1372 } else if (is_debug) {
1373 configs = [ ":no_optimize" ]
1374 } else {
1375 configs = [ ":optimize" ]
1376 }
1377}
1378
1379# Symbols ----------------------------------------------------------------------
1380
1381# The BUILDCONFIG file sets the "default_symbols" config on targets by
1382# default. It will be equivalent to one the three specific symbol levels.
1383#
1384# You can override the symbol level on a per-target basis by removing the
1385# default config and then adding the named one you want:
1386#
1387# configs -= [ "//build/config/compiler:default_symbols" ]
1388# configs += [ "//build/config/compiler:symbols" ]
1389
1390# Full symbols.
1391config("symbols") {
1392 if (is_win) {
1393 import("//build/toolchain/goma.gni")
1394 if (use_goma) {
1395 cflags = [ "/Z7" ] # No PDB file
1396 } else {
1397 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
1398 }
1399 if (is_win_fastlink && visual_studio_version != "2013") {
1400 # Tell VS 2015+ to create a PDB that references debug
1401 # information in .obj and .lib files instead of copying
1402 # it all. This flag is incompatible with /PROFILE
1403 ldflags = [ "/DEBUG:FASTLINK" ]
1404 } else {
1405 ldflags = [ "/DEBUG" ]
1406 }
1407 } else {
1408 if (is_ios) {
1409 cflags = [ "-gdwarf-2" ]
1410 } else {
1411 cflags = [ "-g2" ]
1412 }
1413 if (use_debug_fission) {
1414 cflags += [ "-gsplit-dwarf" ]
1415 }
1416 asmflags = cflags
1417 ldflags = []
1418 }
1419}
1420
1421# Minimal symbols.
1422config("minimal_symbols") {
1423 if (is_win) {
1424 # Linker symbols for backtraces only.
1425 cflags = []
1426 if (is_win_fastlink && visual_studio_version != "2013") {
1427 # Tell VS 2015+ to create a PDB that references debug
1428 # information in .obj and .lib files instead of copying
1429 # it all. This flag is incompatible with /PROFILE
1430 ldflags = [ "/DEBUG:FASTLINK" ]
1431 } else {
1432 ldflags = [ "/DEBUG" ]
1433 }
1434 } else {
1435 cflags = [ "-g1" ]
1436 if (use_debug_fission) {
1437 cflags += [ "-gsplit-dwarf" ]
1438 }
1439 asmflags = cflags
1440 ldflags = []
1441 }
1442}
1443
1444# No symbols.
1445config("no_symbols") {
1446 if (!is_win) {
1447 cflags = [ "-g0" ]
1448 asmflags = cflags
1449 }
1450}
1451
1452# Default symbols.
1453config("default_symbols") {
1454 if (symbol_level == 0) {
1455 configs = [ ":no_symbols" ]
1456 } else if (symbol_level == 1) {
1457 configs = [ ":minimal_symbols" ]
1458 } else if (symbol_level == 2) {
1459 configs = [ ":symbols" ]
1460 } else {
1461 assert(false)
1462 }
1463}
1464
1465if (is_ios || is_mac) {
1466 # On Mac and iOS, this enables support for ARC (automatic ref-counting).
1467 # See http://clang.llvm.org/docs/AutomaticReferenceCounting.html.
1468 config("enable_arc") {
1469 common_flags = [ "-fobjc-arc" ]
1470 cflags_objc = common_flags
1471 cflags_objcc = common_flags
1472 }
1473}