blob: 267c920f3e95647db5cfcacc71204cc0ab82eda8 [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) {
Ben Murdoch61f157c2016-09-16 13:49:30 +0100504 cflags += [ "--target=arm-linux-gnueabihf" ]
505 ldflags += [ "--target=arm-linux-gnueabihf" ]
Ben Murdoch097c5b22016-05-18 11:27:45 +0100506 }
507 if (!is_nacl) {
508 cflags += [
509 "-march=$arm_arch",
510 "-mfloat-abi=$arm_float_abi",
511 ]
512 if (arm_use_thumb) {
513 cflags += [ "-mthumb" ]
514 if (is_android && !is_clang) {
515 # Clang doesn't support this option.
516 cflags += [ "-mthumb-interwork" ]
517 }
518 }
519 }
520 if (arm_tune != "") {
521 cflags += [ "-mtune=$arm_tune" ]
522 }
523 } else if (current_cpu == "mipsel") {
524 if (mips_arch_variant == "r6") {
525 if (is_clang) {
526 cflags += [
Ben Murdoch61f157c2016-09-16 13:49:30 +0100527 "--target=mipsel-linux-gnu",
Ben Murdoch097c5b22016-05-18 11:27:45 +0100528 "-march=mips32r6",
529 ]
Ben Murdoch61f157c2016-09-16 13:49:30 +0100530 ldflags += [ "--target=mipsel-linux-gnu" ]
Ben Murdoch097c5b22016-05-18 11:27:45 +0100531 } else {
532 cflags += [
533 "-mips32r6",
534 "-Wa,-mips32r6",
535 ]
536 if (is_android) {
537 ldflags += [
538 "-mips32r6",
539 "-Wl,-melf32ltsmip",
540 ]
541 }
542 }
543 } else if (mips_arch_variant == "r2") {
544 if (is_clang) {
545 if (is_android) {
546 cflags += [
Ben Murdoch61f157c2016-09-16 13:49:30 +0100547 "--target=mipsel-linux-android",
Ben Murdoch097c5b22016-05-18 11:27:45 +0100548 "-march=mipsel",
549 "-mcpu=mips32r2",
550 ]
Ben Murdoch61f157c2016-09-16 13:49:30 +0100551 ldflags += [ "--target=mipsel-linux-android" ]
Ben Murdoch097c5b22016-05-18 11:27:45 +0100552 } else {
553 cflags += [
Ben Murdoch61f157c2016-09-16 13:49:30 +0100554 "--target=mipsel-linux-gnu",
Ben Murdoch097c5b22016-05-18 11:27:45 +0100555 "-march=mipsel",
556 "-mcpu=mips32r2",
557 ]
Ben Murdoch61f157c2016-09-16 13:49:30 +0100558 ldflags += [ "--target=mipsel-linux-gnu" ]
Ben Murdoch097c5b22016-05-18 11:27:45 +0100559 }
560 } else {
561 cflags += [
562 "-mips32r2",
563 "-Wa,-mips32r2",
564 ]
565 if (mips_float_abi == "hard" && mips_fpu_mode != "") {
566 cflags += [ "-m$mips_fpu_mode" ]
567 }
568 }
569 } else if (mips_arch_variant == "r1") {
570 if (is_clang) {
571 if (is_android) {
572 cflags += [
Ben Murdoch61f157c2016-09-16 13:49:30 +0100573 "--target=mipsel-linux-android",
Ben Murdoch097c5b22016-05-18 11:27:45 +0100574 "-march=mipsel",
575 "-mcpu=mips32",
576 ]
Ben Murdoch61f157c2016-09-16 13:49:30 +0100577 ldflags += [ "--target=mipsel-linux-android" ]
Ben Murdoch097c5b22016-05-18 11:27:45 +0100578 } else {
579 cflags += [
Ben Murdoch61f157c2016-09-16 13:49:30 +0100580 "--target=mipsel-linux-gnu",
Ben Murdoch097c5b22016-05-18 11:27:45 +0100581 "-march=mipsel",
582 "-mcpu=mips32",
583 ]
Ben Murdoch61f157c2016-09-16 13:49:30 +0100584 ldflags += [ "--target=mipsel-linux-gnu" ]
Ben Murdoch097c5b22016-05-18 11:27:45 +0100585 }
586 } else {
587 cflags += [
588 "-mips32",
589 "-Wa,-mips32",
590 ]
591 }
592 }
593
594 if (mips_dsp_rev == 1) {
595 cflags += [ "-mdsp" ]
596 } else if (mips_dsp_rev == 2) {
597 cflags += [ "-mdspr2" ]
598 }
599
600 cflags += [ "-m${mips_float_abi}-float" ]
601 } else if (current_cpu == "mips64el") {
602 if (mips_arch_variant == "r6") {
603 cflags += [
604 "-mips64r6",
605 "-Wa,-mips64r6",
606 ]
607 ldflags += [ "-mips64r6" ]
608 } else if (mips_arch_variant == "r2") {
609 cflags += [
610 "-mips64r2",
611 "-Wa,-mips64r2",
612 ]
613 ldflags += [ "-mips64r2" ]
614 }
615 } else if (current_cpu == "pnacl" && is_nacl_nonsfi) {
616 if (target_cpu == "x86" || target_cpu == "x64") {
617 cflags += [
618 "-arch",
619 "x86-32-nonsfi",
620 "--pnacl-bias=x86-32-nonsfi",
621 "--target=i686-unknown-nacl",
622 ]
623 ldflags += [
624 "-arch",
625 "x86-32-nonsfi",
626 "--target=i686-unknown-nacl",
627 ]
628 } else if (target_cpu == "arm") {
629 cflags += [
630 "-arch",
631 "arm-nonsfi",
632 "--pnacl-bias=arm-nonsfi",
633 "--target=armv7-unknown-nacl-gnueabihf",
634 ]
635 ldflags += [
636 "-arch",
637 "arm-nonsfi",
638 "--target=armv7-unknown-nacl-gnueabihf",
639 ]
640 }
641 }
642 }
643
644 asmflags = cflags
645}
646
647# This provides options to tweak code generation that are necessary
648# for particular Chromium code or for working around particular
649# compiler bugs (or the combination of the two).
650config("compiler_codegen") {
651 configs = []
652 cflags = []
653
654 if (is_nacl) {
655 configs += [ "//build/config/nacl:compiler_codegen" ]
656 } else if (is_posix && !is_mac && !is_ios) {
657 if (current_cpu == "x86") {
658 if (is_clang) {
659 cflags += [
660 # Else building libyuv gives clang's register allocator issues,
661 # see llvm.org/PR15798 / crbug.com/233709
662 "-momit-leaf-frame-pointer",
663 ]
664 }
665 } else if (current_cpu == "arm") {
666 if (is_android && !is_clang) {
667 # Clang doesn't support these flags.
668 cflags += [
669 # The tree-sra optimization (scalar replacement for
670 # aggregates enabling subsequent optimizations) leads to
671 # invalid code generation when using the Android NDK's
672 # compiler (r5-r7). This can be verified using
673 # webkit_unit_tests' WTF.Checked_int8_t test.
674 "-fno-tree-sra",
675
676 # The following option is disabled to improve binary
677 # size and performance in gcc 4.9.
678 "-fno-caller-saves",
679 ]
680 }
681 }
682 }
683
684 asmflags = cflags
685}
686
687# This is separate from :compiler_codegen (and not even a sub-config there)
688# so that some targets can remove it from the list with:
689# configs -= [ "//build/config/compiler:clang_stackrealign" ]
690# See https://crbug.com/556393 for details of where it must be avoided.
691config("clang_stackrealign") {
692 if (is_clang && current_cpu == "x86" && is_linux) {
693 cflags = [
694 # Align the stack on 16-byte boundaries, http://crbug.com/418554.
695 "-mstack-alignment=16",
696 "-mstackrealign",
697 ]
698 }
699}
700
701config("compiler_arm_fpu") {
702 if (current_cpu == "arm" && !is_ios && !is_nacl) {
703 cflags = [ "-mfpu=$arm_fpu" ]
704 asmflags = cflags
705 } else if (current_cpu == "arm64" && !is_ios && !is_nacl) {
706 cflags = [ "-mcpu=$arm_fpu" ]
707 asmflags = cflags
708 }
709}
710
711# runtime_library -------------------------------------------------------------
712#
713# Sets the runtime library and associated options.
714#
715# How do you determine what should go in here vs. "compiler" above? Consider if
716# a target might choose to use a different runtime library (ignore for a moment
717# if this is possible or reasonable on your system). If such a target would want
718# to change or remove your option, put it in the runtime_library config. If a
719# target wants the option regardless, put it in the compiler config.
720
721config("runtime_library") {
722 defines = []
723 configs = []
724
725 # System-specific flags. If your compiler flags apply to one of the
726 # categories here, add it to the associated file to keep this shared config
727 # smaller.
728 if (is_win) {
729 configs += [ "//build/config/win:runtime_library" ]
730 } else if (is_linux) {
731 configs += [ "//build/config/linux:runtime_library" ]
732 } else if (is_ios) {
733 configs += [ "//build/config/ios:runtime_library" ]
734 } else if (is_mac) {
735 configs += [ "//build/config/mac:runtime_library" ]
736 } else if (is_android) {
737 configs += [ "//build/config/android:runtime_library" ]
738 }
739
740 if (is_posix) {
741 configs += [ "//build/config/posix:runtime_library" ]
742 }
743
744 if (is_component_build) {
745 defines += [ "COMPONENT_BUILD" ]
746 }
747}
748
749# default_warnings ------------------------------------------------------------
750#
751# Collects all warning flags that are used by default. This is used as a
752# subconfig of both chromium_code and no_chromium_code. This way these
753# flags are guaranteed to appear on the compile command line after -Wall.
754config("default_warnings") {
755 cflags = []
756 cflags_cc = []
757
758 if (is_win) {
759 if (treat_warnings_as_errors) {
760 cflags += [ "/WX" ]
761 }
762
763 cflags += [
764 # Warnings permanently disabled:
765
766 # C4091: 'typedef ': ignored on left of 'X' when no variable is
767 # declared.
768 # This happens in a number of Windows headers. Dumb.
769 "/wd4091",
770
771 # C4127: conditional expression is constant
772 # This warning can in theory catch dead code and other problems, but
773 # triggers in far too many desirable cases where the conditional
774 # expression is either set by macros or corresponds some legitimate
775 # compile-time constant expression (due to constant template args,
776 # conditionals comparing the sizes of different types, etc.). Some of
777 # these can be worked around, but it's not worth it.
778 "/wd4127",
779
780 # C4251: 'identifier' : class 'type' needs to have dll-interface to be
781 # used by clients of class 'type2'
782 # This is necessary for the shared library build.
783 "/wd4251",
784
785 # C4351: new behavior: elements of array 'array' will be default
786 # initialized
787 # This is a silly "warning" that basically just alerts you that the
788 # compiler is going to actually follow the language spec like it's
789 # supposed to, instead of not following it like old buggy versions did.
790 # There's absolutely no reason to turn this on.
791 "/wd4351",
792
793 # C4355: 'this': used in base member initializer list
794 # It's commonly useful to pass |this| to objects in a class' initializer
795 # list. While this warning can catch real bugs, most of the time the
796 # constructors in question don't attempt to call methods on the passed-in
797 # pointer (until later), and annotating every legit usage of this is
798 # simply more hassle than the warning is worth.
799 "/wd4355",
800
801 # C4503: 'identifier': decorated name length exceeded, name was
802 # truncated
803 # This only means that some long error messages might have truncated
804 # identifiers in the presence of lots of templates. It has no effect on
805 # program correctness and there's no real reason to waste time trying to
806 # prevent it.
807 "/wd4503",
808
809 # Warning C4589 says: "Constructor of abstract class ignores
810 # initializer for virtual base class." Disable this warning because it
811 # is flaky in VS 2015 RTM. It triggers on compiler generated
812 # copy-constructors in some cases.
813 "/wd4589",
814
815 # C4611: interaction between 'function' and C++ object destruction is
816 # non-portable
817 # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN
818 # suggests using exceptions instead of setjmp/longjmp for C++, but
819 # Chromium code compiles without exception support. We therefore have to
820 # use setjmp/longjmp for e.g. JPEG decode error handling, which means we
821 # have to turn off this warning (and be careful about how object
822 # destruction happens in such cases).
823 "/wd4611",
824
825 # Warnings to evaluate and possibly fix/reenable later:
826
827 "/wd4100", # Unreferenced formal function parameter.
828 "/wd4121", # Alignment of a member was sensitive to packing.
829 "/wd4244", # Conversion: possible loss of data.
830 "/wd4505", # Unreferenced local function has been removed.
831 "/wd4510", # Default constructor could not be generated.
832 "/wd4512", # Assignment operator could not be generated.
833 "/wd4610", # Class can never be instantiated, constructor required.
834 "/wd4838", # Narrowing conversion. Doesn't seem to be very useful.
835 "/wd4995", # 'X': name was marked as #pragma deprecated
836 "/wd4996", # Deprecated function warning.
837
838 # These are variable shadowing warnings that are new in VS2015. We
839 # should work through these at some point -- they may be removed from
840 # the RTM release in the /W4 set.
841 "/wd4456",
842 "/wd4457",
843 "/wd4458",
844 "/wd4459",
845 ]
846
847 if (visual_studio_version == "2015") {
848 cflags += [
849 # C4312 is a VS 2015 64-bit warning for integer to larger pointer.
850 # TODO(brucedawson): fix warnings, crbug.com/554200
851 "/wd4312",
852
853 # TODO(brucedawson): http://crbug.com/593448 - C4595 is an 'illegal
854 # inline operator new' warning that is new in VS 2015 Update 2.
855 # This is equivalent to clang's no-inline-new-delete warning.
856 # See http://bugs.icu-project.org/trac/ticket/11122
857 "/wd4595",
858 ]
859
860 if (current_cpu == "x86") {
861 cflags += [
862 # VC++ 2015 changes 32-bit size_t truncation warnings from 4244 to
863 # 4267. Example: short TruncTest(size_t x) { return x; }
864 # Since we disable 4244 we need to disable 4267 during migration.
865 # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
866 "/wd4267",
867 ]
868 }
869 }
870
871 # VS xtree header file needs to be patched or 4702 (unreachable code
872 # warning) is reported if _HAS_EXCEPTIONS=0. Disable the warning if xtree is
873 # not patched.
874 if (!msvs_xtree_patched &&
875 exec_script("../../win_is_xtree_patched.py", [], "value") == 0) {
876 cflags += [ "/wd4702" ] # Unreachable code.
877 }
878
879 # Building with Clang on Windows is a work in progress and very
880 # experimental. See crbug.com/82385.
881 # Keep this in sync with the similar block in build/common.gypi
882 if (is_clang) {
883 cflags += [
884 # TODO(hans): Make this list shorter eventually, http://crbug.com/504657
885 "-Wno-microsoft-enum-value", # http://crbug.com/505296
886 "-Wno-unknown-pragmas", # http://crbug.com/505314
887 "-Wno-microsoft-cast", # http://crbug.com/550065
888 ]
889 }
890 } else {
891 if (is_mac && !is_nacl) {
892 # When compiling Objective-C, warns if a method is used whose
893 # availability is newer than the deployment target. This is not
894 # required when compiling Chrome for iOS.
895 cflags += [ "-Wpartial-availability" ]
896 }
897
898 # Suppress warnings about ABI changes on ARM (Clang doesn't give this
899 # warning).
900 if (current_cpu == "arm" && !is_clang) {
901 cflags += [ "-Wno-psabi" ]
902 }
903
904 if (!is_clang) {
905 cflags_cc += [
906 # See comment for -Wno-c++11-narrowing.
907 "-Wno-narrowing",
908 ]
909
910 # Don't warn about the "typedef 'foo' locally defined but not used"
911 # for gcc 4.8.
912 # TODO: remove this flag once all builds work. See crbug.com/227506
913 cflags += [ "-Wno-unused-local-typedefs" ]
914
915 # Don't warn about "maybe" uninitialized. Clang doesn't include this
916 # in -Wall but gcc does, and it gives false positives.
917 cflags += [ "-Wno-maybe-uninitialized" ]
918 }
919 }
920
921 # Common Clang and GCC warning setup.
922 if (!is_win || is_clang) {
923 cflags += [
924 # Disables.
925 "-Wno-missing-field-initializers", # "struct foo f = {0};"
926 "-Wno-unused-parameter", # Unused function parameters.
927 ]
928 }
929
930 if (is_chromeos) {
931 # TODO(thakis): Remove, http://crbug.com/263960
932 if (is_clang) {
933 cflags_cc += [ "-Wno-reserved-user-defined-literal" ]
934 } else {
935 cflags_cc += [ "-Wno-literal-suffix" ]
936 }
937 }
938
939 if (is_clang) {
940 cflags += [
941 # TODO(thakis): Consider -Wloop-analysis (turns on
942 # -Wrange-loop-analysis too).
943
944 # This warns on using ints as initializers for floats in
945 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
946 # which happens in several places in chrome code. Not sure if
947 # this is worth fixing.
948 "-Wno-c++11-narrowing",
949
950 # Warns on switches on enums that cover all enum values but
951 # also contain a default: branch. Chrome is full of that.
952 "-Wno-covered-switch-default",
953
954 # Clang considers the `register` keyword as deprecated, but e.g.
955 # code generated by flex (used in angle) contains that keyword.
956 # http://crbug.com/255186
957 "-Wno-deprecated-register",
958
959 # TODO(thakis): This used to be implied by -Wno-unused-function,
960 # which we no longer use. Check if it makes sense to remove
961 # this as well. http://crbug.com/316352
962 "-Wno-unneeded-internal-declaration",
963
964 # TODO(hans): Get this cleaned up, http://crbug.com/428099
965 "-Wno-inconsistent-missing-override",
966 ]
967
968 # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost
969 # always have different versions. Certain flags may not be recognized by
970 # one version or the other.
971 if (!is_nacl) {
972 # Flags NaCl (Clang 3.7) does not recognize.
973 cflags += [
974 # TODO(thakis): Enable this, crbug.com/507717
975 "-Wno-shift-negative-value",
976
977 # TODO(thakis): https://crbug.com/604888
978 "-Wno-undefined-var-template",
979 ]
980 }
981 }
982}
983
984# chromium_code ---------------------------------------------------------------
985#
986# Toggles between higher and lower warnings for code that is (or isn't)
987# part of Chromium.
988
989config("chromium_code") {
990 if (is_win) {
991 cflags = [ "/W4" ] # Warning level 4.
992 } else {
993 cflags = [ "-Wall" ]
994 if (treat_warnings_as_errors) {
995 cflags += [ "-Werror" ]
996 }
997 if (is_clang) {
998 # Enable -Wextra for chromium_code when we control the compiler.
999 cflags += [ "-Wextra" ]
1000 }
1001
1002 # In Chromium code, we define __STDC_foo_MACROS in order to get the
1003 # C99 macros on Mac and Linux.
1004 defines = [
1005 "__STDC_CONSTANT_MACROS",
1006 "__STDC_FORMAT_MACROS",
1007 ]
1008
1009 if (!is_debug && !using_sanitizer &&
1010 (!is_linux || !is_clang || is_official_build)) {
1011 # _FORTIFY_SOURCE isn't really supported by Clang now, see
1012 # http://llvm.org/bugs/show_bug.cgi?id=16821.
1013 # It seems to work fine with Ubuntu 12 headers though, so use it in
1014 # official builds.
1015 #
1016 # Non-chromium code is not guaranteed to compile cleanly with
1017 # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are
1018 # disabled, so only do that for Release build.
1019 defines += [ "_FORTIFY_SOURCE=2" ]
1020 }
1021 }
1022
1023 configs = [ ":default_warnings" ]
1024}
1025
1026config("no_chromium_code") {
1027 cflags = []
1028 cflags_cc = []
1029 defines = []
1030
1031 if (is_win) {
1032 cflags += [
1033 "/W3", # Warning level 3.
1034 "/wd4800", # Disable warning when forcing value to bool.
1035 "/wd4267", # TODO(jschuh): size_t to int.
1036 "/wd4996", # Deprecated function warning.
1037 ]
1038 defines += [
1039 "_CRT_NONSTDC_NO_WARNINGS",
1040 "_CRT_NONSTDC_NO_DEPRECATE",
1041 ]
1042 } else {
1043 # GCC may emit unsuppressible warnings so don't add -Werror for no chromium
1044 # code. crbug.com/589724
1045 if (treat_warnings_as_errors && is_clang) {
1046 cflags += [ "-Werror" ]
1047 }
1048 if (is_clang && !is_nacl) {
1049 # TODO(thakis): Remove !is_nacl once
1050 # https://codereview.webrtc.org/1552863002/ made its way into chromium.
1051 cflags += [ "-Wall" ]
1052 }
1053 }
1054
1055 if (is_clang) {
1056 cflags += [
1057 # Lots of third-party libraries have unused variables. Instead of
1058 # suppressing them individually, we just blanket suppress them here.
1059 "-Wno-unused-variable",
1060 ]
1061 }
1062
1063 if (is_linux || is_android) {
1064 cflags_cc += [
1065 # Don't warn about hash_map in third-party code.
1066 "-Wno-deprecated",
1067 ]
1068 }
1069
1070 configs = [ ":default_warnings" ]
1071}
1072
1073# rtti ------------------------------------------------------------------------
1074#
1075# Allows turning Run-Time Type Identification on or off.
1076
1077config("rtti") {
1078 if (is_win) {
1079 cflags_cc = [ "/GR" ]
1080 }
1081}
1082config("no_rtti") {
1083 # CFI diagnostics and UBsan vptr require RTTI.
1084 if (!use_cfi_diag && !is_ubsan_vptr) {
1085 if (is_win) {
1086 cflags_cc = [ "/GR-" ]
1087 } else {
1088 cflags_cc = [ "-fno-rtti" ]
1089 cflags_objcc = cflags_cc
1090 }
1091 }
1092}
1093
1094# Warnings ---------------------------------------------------------------------
1095
1096# This will generate warnings when using Clang if code generates exit-time
1097# destructors, which will slow down closing the program.
1098# TODO(thakis): Make this a blacklist instead, http://crbug.com/101600
1099config("wexit_time_destructors") {
1100 # TODO: Enable on Windows too, http://crbug.com/404525
1101 if (is_clang && !is_win) {
1102 cflags = [ "-Wexit-time-destructors" ]
1103 }
1104}
1105
1106# On Windows compiling on x64, VC will issue a warning when converting
1107# size_t to int because it will truncate the value. Our code should not have
1108# these warnings and one should use a static_cast or a checked_cast for the
1109# conversion depending on the case. However, a lot of code still needs to be
1110# fixed. Apply this config to such targets to disable the warning.
1111#
1112# Note that this can be applied regardless of platform and architecture to
1113# clean up the call sites. This will only apply the flag when necessary.
1114#
1115# TODO(jschuh): crbug.com/167187 fix this and delete this config.
1116config("no_size_t_to_int_warning") {
1117 if (is_win && current_cpu == "x64") {
1118 cflags = [ "/wd4267" ]
1119 }
1120}
1121
1122# Some code presumes that pointers to structures/objects are compatible
1123# regardless of whether what they point to is already known to be valid.
1124# gcc 4.9 and earlier had no way of suppressing this warning without
1125# supressing the rest of them. Here we centralize the identification of
1126# the gcc 4.9 toolchains.
1127config("no_incompatible_pointer_warnings") {
1128 cflags = []
1129 if (is_clang) {
1130 cflags += [ "-Wno-incompatible-pointer-types" ]
1131 } else if (current_cpu == "mipsel") {
1132 cflags += [ "-w" ]
1133 } else if (is_chromeos && current_cpu == "arm") {
1134 cflags += [ "-w" ]
1135 }
1136}
1137
1138# Optimization -----------------------------------------------------------------
1139#
1140# The BUILDCONFIG file sets the "default_optimization" config on targets by
1141# default. It will be equivalent to either "optimize" (release) or
1142# "no_optimize" (debug) optimization configs.
1143#
1144# You can override the optimization level on a per-target basis by removing the
1145# default config and then adding the named one you want:
1146#
1147# configs -= [ "//build/config/compiler:default_optimization" ]
1148# configs += [ "//build/config/compiler:optimize_max" ]
1149
1150# Shared settings for both "optimize" and "optimize_max" configs.
1151# IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags.
1152if (is_win) {
1153 common_optimize_on_cflags = [
1154 "/Ob2", # Both explicit and auto inlining.
1155 "/Oy-", # Disable omitting frame pointers, must be after /O2.
1156 "/d2Zi+", # Improve debugging of optimized code.
1157 "/Zc:inline", # Remove unreferenced COMDAT (faster links).
1158 ]
1159 if (!is_asan) {
1160 common_optimize_on_cflags += [
1161 # Put data in separate COMDATs. This allows the linker
1162 # to put bit-identical constants at the same address even if
1163 # they're unrelated constants, which saves binary size.
1164 # This optimization can't be used when ASan is enabled because
1165 # it is not compatible with the ASan ODR checker.
1166 "/Gw",
1167 ]
1168 }
1169 common_optimize_on_ldflags = [ "/OPT:ICF" ] # Redundant COMDAT folding.
1170 if (is_official_build) {
1171 common_optimize_on_ldflags += [
1172 "/OPT:REF", # Remove unreferenced data.
1173 "/LTCG", # Link-time code generation.
1174
1175 # Set the number of LTCG code-gen threads to eight. The default is four.
1176 # This gives a 5-10% link speedup.
1177 "/cgthreads:8",
1178 ]
1179 }
1180} else {
1181 common_optimize_on_cflags = [
1182 # Don't emit the GCC version ident directives, they just end up in the
1183 # .comment section taking up binary size.
1184 "-fno-ident",
1185
1186 # Put data and code in their own sections, so that unused symbols
1187 # can be removed at link time with --gc-sections.
1188 "-fdata-sections",
1189 "-ffunction-sections",
1190 ]
1191 common_optimize_on_ldflags = []
1192
1193 if (is_android) {
1194 # We don't omit frame pointers on arm64 since they are required
1195 # to correctly unwind stackframes which contain system library
1196 # function frames (crbug.com/391706).
1197 if (!using_sanitizer && !enable_profiling && target_cpu != "arm64") {
1198 common_optimize_on_cflags += [ "-fomit-frame-pointer" ]
1199 }
1200
1201 # TODO(jdduke) Re-enable on mips after resolving linking
1202 # issues with libc++ (crbug.com/456380).
1203 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
1204 common_optimize_on_ldflags += [
1205 # Warn in case of text relocations.
1206 "-Wl,--warn-shared-textrel",
1207 ]
1208 }
1209 }
1210
1211 if (is_mac || is_ios) {
1212 if (symbol_level == 2) {
1213 # Mac dead code stripping requires symbols.
1214 common_optimize_on_ldflags += [ "-Wl,-dead_strip" ]
1215 }
1216 } else {
1217 # Non-Mac Posix linker flags.
1218 common_optimize_on_ldflags += [
1219 # Specifically tell the linker to perform optimizations.
1220 # See http://lwn.net/Articles/192624/ .
1221 "-Wl,-O1",
1222 "-Wl,--gc-sections",
1223 ]
1224
1225 if (!using_sanitizer) {
1226 # Functions interposed by the sanitizers can make ld think
1227 # that some libraries aren't needed when they actually are,
1228 # http://crbug.com/234010. As workaround, disable --as-needed.
1229 common_optimize_on_ldflags += [ "-Wl,--as-needed" ]
1230 }
1231 }
1232}
1233
1234# Default "optimization on" config.
1235config("optimize") {
1236 if (is_win) {
1237 if (is_official_build && full_wpo_on_official) {
1238 common_optimize_on_cflags += [ "/GL" ]
1239 }
1240
1241 # Favor size over speed, /O1 must be before the common flags. The GYP
1242 # build also specifies /Os and /GF but these are implied by /O1.
1243 cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
1244 } else if (optimize_for_size) {
1245 # Favor size over speed.
1246 cflags = [ "-Os" ] + common_optimize_on_cflags
1247 } else {
1248 cflags = [ "-O2" ] + common_optimize_on_cflags
1249 }
1250 ldflags = common_optimize_on_ldflags
1251}
1252
1253# Same config as 'optimize' but without the WPO flag.
1254config("optimize_no_wpo") {
1255 if (is_win) {
1256 # Favor size over speed, /O1 must be before the common flags. The GYP
1257 # build also specifies /Os and /GF but these are implied by /O1.
1258 cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
1259 } else if (optimize_for_size) {
1260 # Favor size over speed.
1261 cflags = [ "-Os" ] + common_optimize_on_cflags
1262 } else {
1263 cflags = [ "-O2" ] + common_optimize_on_cflags
1264 }
1265 ldflags = common_optimize_on_ldflags
1266}
1267
1268# Turn off optimizations.
1269config("no_optimize") {
1270 if (is_win) {
1271 cflags = [
1272 "/Od", # Disable optimization.
1273 "/Ob0", # Disable all inlining (on by default).
1274 ]
1275 } else if (is_android && !android_full_debug) {
1276 # On Android we kind of optimize some things that don't affect debugging
1277 # much even when optimization is disabled to get the binary size down.
1278 cflags = [
1279 "-Os",
1280 "-fdata-sections",
1281 "-ffunction-sections",
1282 ]
1283
1284 # We don't omit frame pointers on arm64 since they are required
1285 # to correctly unwind stackframes which contain system library
1286 # function frames (crbug.com/391706).
1287 if (!using_sanitizer && !enable_profiling && target_cpu != "arm64") {
1288 cflags += [ "-fomit-frame-pointer" ]
1289 }
1290
1291 # Don't use gc-sections since it can cause links to succeed when they
1292 # actually shouldn't. http://crbug.com/159847
1293 ldflags = common_optimize_on_ldflags - [ "-Wl,--gc-sections" ]
1294 } else {
1295 cflags = [ "-O0" ]
1296 ldflags = []
1297 }
1298}
1299
1300# Turns up the optimization level. On Windows, this implies whole program
1301# optimization and link-time code generation which is very expensive and should
1302# be used sparingly.
1303config("optimize_max") {
1304 if (is_nacl_irt) {
1305 # The NaCl IRT is a special case and always wants its own config.
1306 # Various components do:
1307 # if (!is_debug) {
1308 # configs -= [ "//build/config/compiler:default_optimization" ]
1309 # configs += [ "//build/config/compiler:optimize_max" ]
1310 # }
1311 # So this config has to have the selection logic just like
1312 # "default_optimization", below.
1313 configs = [ "//build/config/nacl:irt_optimize" ]
1314 } else {
1315 ldflags = common_optimize_on_ldflags
1316 if (is_win) {
1317 # Favor speed over size, /O2 must be before the common flags. The GYP
1318 # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2.
1319 cflags = [ "/O2" ] + common_optimize_on_cflags
1320
1321 # TODO(thakis): Remove is_clang here, https://crbug.com/598772
1322 if (is_official_build && !is_clang) {
1323 cflags += [
1324 "/GL", # Whole program optimization.
1325
1326 # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds.
1327 # Probably anything that this would catch that wouldn't be caught in a
1328 # normal build isn't going to actually be a bug, so the incremental
1329 # value of C4702 for PGO builds is likely very small.
1330 "/wd4702",
1331 ]
1332 }
1333 } else {
1334 cflags = [ "-O2" ] + common_optimize_on_cflags
1335 }
1336 }
1337}
1338
1339# The default optimization applied to all targets. This will be equivalent to
1340# either "optimize" or "no_optimize", depending on the build flags.
1341config("default_optimization") {
1342 if (is_nacl_irt) {
1343 # The NaCl IRT is a special case and always wants its own config.
1344 # It gets optimized the same way regardless of the type of build.
1345 configs = [ "//build/config/nacl:irt_optimize" ]
1346 } else if (is_debug) {
1347 configs = [ ":no_optimize" ]
1348 } else {
1349 configs = [ ":optimize" ]
1350 }
1351}
1352
1353# Symbols ----------------------------------------------------------------------
1354
1355# The BUILDCONFIG file sets the "default_symbols" config on targets by
1356# default. It will be equivalent to one the three specific symbol levels.
1357#
1358# You can override the symbol level on a per-target basis by removing the
1359# default config and then adding the named one you want:
1360#
1361# configs -= [ "//build/config/compiler:default_symbols" ]
1362# configs += [ "//build/config/compiler:symbols" ]
1363
1364# Full symbols.
1365config("symbols") {
1366 if (is_win) {
1367 import("//build/toolchain/goma.gni")
1368 if (use_goma) {
1369 cflags = [ "/Z7" ] # No PDB file
1370 } else {
1371 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
1372 }
1373 if (is_win_fastlink && visual_studio_version != "2013") {
1374 # Tell VS 2015+ to create a PDB that references debug
1375 # information in .obj and .lib files instead of copying
1376 # it all. This flag is incompatible with /PROFILE
1377 ldflags = [ "/DEBUG:FASTLINK" ]
1378 } else {
1379 ldflags = [ "/DEBUG" ]
1380 }
1381 } else {
1382 if (is_ios) {
1383 cflags = [ "-gdwarf-2" ]
1384 } else {
1385 cflags = [ "-g2" ]
1386 }
1387 if (use_debug_fission) {
1388 cflags += [ "-gsplit-dwarf" ]
1389 }
1390 asmflags = cflags
1391 ldflags = []
1392 }
1393}
1394
1395# Minimal symbols.
1396config("minimal_symbols") {
1397 if (is_win) {
1398 # Linker symbols for backtraces only.
1399 cflags = []
1400 if (is_win_fastlink && visual_studio_version != "2013") {
1401 # Tell VS 2015+ to create a PDB that references debug
1402 # information in .obj and .lib files instead of copying
1403 # it all. This flag is incompatible with /PROFILE
1404 ldflags = [ "/DEBUG:FASTLINK" ]
1405 } else {
1406 ldflags = [ "/DEBUG" ]
1407 }
1408 } else {
1409 cflags = [ "-g1" ]
1410 if (use_debug_fission) {
1411 cflags += [ "-gsplit-dwarf" ]
1412 }
1413 asmflags = cflags
1414 ldflags = []
1415 }
1416}
1417
1418# No symbols.
1419config("no_symbols") {
1420 if (!is_win) {
1421 cflags = [ "-g0" ]
1422 asmflags = cflags
1423 }
1424}
1425
1426# Default symbols.
1427config("default_symbols") {
1428 if (symbol_level == 0) {
1429 configs = [ ":no_symbols" ]
1430 } else if (symbol_level == 1) {
1431 configs = [ ":minimal_symbols" ]
1432 } else if (symbol_level == 2) {
1433 configs = [ ":symbols" ]
1434 } else {
1435 assert(false)
1436 }
1437}
1438
1439if (is_ios || is_mac) {
1440 # On Mac and iOS, this enables support for ARC (automatic ref-counting).
1441 # See http://clang.llvm.org/docs/AutomaticReferenceCounting.html.
1442 config("enable_arc") {
1443 common_flags = [ "-fobjc-arc" ]
1444 cflags_objc = common_flags
1445 cflags_objcc = common_flags
1446 }
1447}