• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/android/config.gni")
6if (cpu_arch == "arm") {
7  import("//build/config/arm.gni")
8}
9if (is_posix) {
10  import("//build/config/gcc/gcc_version.gni")
11}
12
13declare_args() {
14  # Normally, Android builds are lightly optimized, even for debug builds, to
15  # keep binary size down. Setting this flag to true disables such optimization
16  android_full_debug = false
17}
18
19# compiler ---------------------------------------------------------------------
20#
21# Base compiler configuration.
22#
23# See also "runtime_library" below for related stuff and a discusison about
24# where stuff should go. Put warning related stuff in the "warnings" config.
25
26config("compiler") {
27  cflags = []
28  cflags_c = []
29  cflags_cc = []
30  ldflags = []
31  defines = []
32  include_dirs = []
33
34  include_dirs += [ "//", root_gen_dir ]
35
36  # In general, Windows is totally different, but all the other builds share
37  # some common GCC configuration. This section sets up Windows and the common
38  # GCC flags, and then we handle the other non-Windows platforms specifically
39  # below.
40  if (is_win) {
41    # Windows compiler flags setup.
42    # -----------------------------
43    cflags += [
44      "/Gy",  # Enable function-level linking.
45      "/GS",  # Enable buffer security checking.
46      "/FS",  # Preserve previous PDB behavior.
47    ]
48    if (is_component_build) {
49      cflags += [
50        "/EHsc",  # Assume C functions can't throw exceptions and don't catch
51                  # structured exceptions (only C++ ones).
52      ]
53    }
54  } else {
55    # Common GCC compiler flags setup.
56    # --------------------------------
57    cflags += [
58      "-fno-strict-aliasing",  # See http://crbug.com/32204
59    ]
60    cflags_cc += [
61      "-fno-threadsafe-statics",
62      # Not exporting C++ inline functions can generally be applied anywhere
63      # so we do so here. Normal function visibility is controlled by
64      # //build/config/gcc:symbol_visibility_hidden.
65      "-fvisibility-inlines-hidden",
66    ]
67
68    # Stack protection.
69    if (is_mac) {
70      cflags += [ "-fstack-protector-all" ]
71    } else if (is_linux) {
72      cflags += [ "-fstack-protector", "--param=ssp-buffer-size=4" ]
73    }
74
75    # Linker warnings.
76    if (!(is_chromeos && cpu_arch == "arm") && !is_mac) {
77      # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580
78      ldflags += [ "-Wl,--fatal-warnings" ]
79    }
80  }
81
82  # Mac-specific compiler flags setup.
83  # ----------------------------------
84  if (is_mac || is_ios) {
85    # These flags are shared between the C compiler and linker.
86    common_mac_flags = []
87
88    # CPU architecture.
89    if (cpu_arch == "x64") {
90      common_mac_flags += [ "-arch", "x86_64" ]
91    } else if (cpu_arch == "x86") {
92      common_mac_flags += [ "-arch", "i386" ]
93    }
94
95    cflags += common_mac_flags
96
97    # Without this, the constructors and destructors of a C++ object inside
98    # an Objective C struct won't be called, which is very bad.
99    cflags_objcc = [ "-fobjc-call-cxx-cdtors", ]
100
101    cflags_c += [ "-std=c99" ]
102    cflags_cc += [ "-std=gnu++11" ]
103
104    ldflags += common_mac_flags
105  } else if (is_posix) {
106    # Non-Mac Posix compiler flags setup.
107    # -----------------------------------
108
109    # CPU architecture. We may or may not be doing a cross compile now, so for
110    # simplicity we always explicitly set the architecture.
111    if (cpu_arch == "x64") {
112      cflags += [ "-m64" ]
113      ldflags += [ "-m64" ]
114    } else if (cpu_arch == "x86") {
115      cflags += [ "-m32" ]
116      ldflags += [ "-m32" ]
117    } else if (cpu_arch == "arm") {
118      # Don't set the compiler flags for the WebView build. These will come
119      # from the Android build system.
120      if (!is_android_webview_build) {
121        cflags += [
122          "-march=$arm_arch",
123          "-mfpu=$arm_fpu",
124          "-mfloat-abi=$arm_float_abi",
125        ]
126        if (arm_tune != "") {
127          cflags += [ "-mtune=$arm_tune" ]
128        }
129        if (arm_use_thumb) {
130          cflags += [ "-mthumb" ]
131          if (is_android && !is_clang) {  # Clang doesn't support this option.
132            cflags += [ "-mthumb-interwork" ]
133          }
134        }
135      }
136    }
137
138    defines += [ "_FILE_OFFSET_BITS=64" ]
139
140    # Omit unwind support in official builds to save space. We can use breakpad
141    # for these builds.
142    if (is_chrome_branded && is_official_build) {
143      cflags += [
144        "-fno-unwind-tables",
145        "-fno-asynchronous-unwind-tables",
146      ]
147    } else {
148      cflags += [ "-funwind-tables" ]
149    }
150  }
151
152  # Linux/Android common flags setup.
153  # ---------------------------------
154  if (is_linux || is_android) {
155    cflags += [
156      "-fPIC",
157      "-pipe",  # Use pipes for communicating between sub-processes. Faster.
158    ]
159
160    ldflags += [
161      "-fPIC",
162      "-Wl,-z,noexecstack",
163      "-Wl,-z,now",
164      "-Wl,-z,relro",
165    ]
166  }
167
168  # Linux-specific compiler flags setup.
169  # ------------------------------------
170  if (is_linux) {
171    cflags += [ "-pthread" ]
172
173    if (cpu_arch == "x64") {
174      # Use gold for linking on 64-bit Linux only (on 32-bit it runs out of
175      # address space, and it doesn't support cross-compiling).
176      gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
177                              root_build_dir)
178      ldflags += [
179        "-B$gold_path",
180
181        # There seems to be a conflict of --icf and -pie in gold which can
182        # generate crashy binaries. As a security measure, -pie takes
183        # precedence for now.
184        # TODO(brettw) common.gypi has this only for target toolset.
185        #"-Wl,--icf=safe",
186        "-Wl,--icf=none",
187
188        # Experimentation found that using four linking threads
189        # saved ~20% of link time.
190        # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
191        # Only apply this to the target linker, since the host
192        # linker might not be gold, but isn't used much anyway.
193        # TODO(raymes): Disable threading because gold is frequently
194        # crashing on the bots: crbug.com/161942.
195        #"-Wl,--threads",
196        #"-Wl,--thread-count=4",
197      ]
198    }
199
200    ldflags += [
201      "-pthread",
202    ]
203  }
204
205  # Clang-specific compiler flags setup.
206  # ------------------------------------
207  if (is_clang) {
208    cflags += [
209      "-fcolor-diagnostics",
210    ]
211    cflags_cc += [
212      "-std=gnu++11",
213    ]
214  }
215
216  # Android-specific flags setup.
217  # -----------------------------
218  if (is_android) {
219    cflags += [
220      "-ffunction-sections",
221      "-funwind-tables",
222      "-fno-short-enums",
223    ]
224    if (!is_clang) {
225      # Clang doesn't support these flags.
226      cflags += [
227        "-finline-limit=64",
228        # The following 6 options are disabled to save on
229        # binary size in gcc 4.8.
230        # TODO(fdegans) Reevaluate when we upgrade GCC.
231        "-fno-partial-inlining",
232        "-fno-early-inlining",
233        "-fno-tree-copy-prop",
234        "-fno-tree-loop-optimize",
235        "-fno-move-loop-invariants",
236        "-fno-caller-saves",
237      ]
238    }
239    if (is_android_webview_build) {
240      # Android predefines this as 1; undefine it here so Chromium can redefine
241      # it later to be 2 for chromium code and unset for third party code. This
242      # works because cflags are added before defines.
243      # TODO(brettw) the above comment seems incorrect. We specify defines
244      # before cflags on our compiler command lines.
245      cflags += [ "-U_FORTIFY_SOURCE" ]
246    }
247
248    if (is_asan) {
249      # Android build relies on -Wl,--gc-sections removing unreachable code.
250      # ASan instrumentation for globals inhibits this and results in a library
251      # with unresolvable relocations.
252      # TODO(eugenis): find a way to reenable this.
253      cflags += [ "-mllvm -asan-globals=0" ]
254    }
255
256    defines += [ "ANDROID" ]
257    if (!is_android_webview_build) {
258      # The NDK has these things, but doesn't define the constants
259      # to say that it does. Define them here instead.
260      defines += [ "HAVE_SYS_UIO_H" ]
261    }
262
263    # Use gold for Android for most CPU architectures.
264    if (cpu_arch == "x86" || cpu_arch == "x64" || cpu_arch == "arm") {
265      if (is_clang) {
266        # Clang does not support -fuse-ld to invoke the built-in gold linker,
267        # so use the -B option which requires us to specify the path.
268        ldflags += [
269          "-B" + rebase_path("//build/android/arm-linux-androideabi-gold",
270                             root_build_dir)
271        ]
272      } else {
273        ldflags += [ "-fuse-ld=gold" ]
274      }
275    }
276
277    ldflags += [
278      "-Wl,--no-undefined",
279      # Don't export symbols from statically linked libraries.
280      "-Wl,--exclude-libs=ALL",
281    ]
282    if (cpu_arch == "arm") {
283      ldflags += [
284        # Enable identical code folding to reduce size.
285        "-Wl,--icf=safe",
286      ]
287    }
288
289    if (is_clang) {
290      if (cpu_arch == "arm") {
291        cflags += [
292          "-target arm-linux-androideabi",
293        ]
294        ldflags += [ "-target arm-linux-androideabi" ]
295      } else if (cpu_arch == "x86") {
296        cflags += [ "-target x86-linux-androideabi" ]
297        ldflags += [ "-target x86-linux-androideabi" ]
298      }
299    }
300  }
301}
302
303# runtime_library -------------------------------------------------------------
304#
305# Sets the runtime library and associated options.
306#
307# How do you determine what should go in here vs. "compiler" above? Consider if
308# a target might choose to use a different runtime library (ignore for a moment
309# if this is possible or reasonable on your system). If such a target would want
310# to change or remove your option, put it in the runtime_library config. If a
311# target wants the option regardless, put it in the compiler config.
312
313config("runtime_library") {
314  cflags = []
315  defines = []
316  ldflags = []
317  lib_dirs = []
318  libs = []
319
320  if (is_component_build) {
321    # Component mode: dynamic CRT.
322    defines += [ "COMPONENT_BUILD" ]
323    if (is_win) {
324      # Since the library is shared, it requires exceptions or will give errors
325      # about things not matching, so keep exceptions on.
326      if (is_debug) {
327        cflags += [ "/MDd" ]
328      } else {
329        cflags += [ "/MD" ]
330      }
331    }
332  } else {
333    # Static CRT.
334    if (is_win) {
335      # We don't use exceptions, and when we link statically we can just get
336      # rid of them entirely.
337      defines += [ "_HAS_EXCEPTIONS=0" ]
338      if (is_debug) {
339        cflags += [ "/MTd" ]
340      } else {
341        cflags += [ "/MT" ]
342      }
343    }
344  }
345
346  if (is_win) {
347    defines += [
348      "__STD_C",
349      "__STDC_CONSTANT_MACROS",
350      "__STDC_FORMAT_MACROS",
351      "_CRT_RAND_S",
352      "_CRT_SECURE_NO_DEPRECATE",
353      "_SCL_SECURE_NO_DEPRECATE",
354    ]
355  }
356
357  # Stlport setup. Android uses a different (smaller) version of the STL.
358  if (is_android) {
359    if (is_clang) {
360      # Work around incompatibilities between bionic and clang headers.
361      defines += [
362        "__compiler_offsetof=__builtin_offsetof",
363        "nan=__builtin_nan",
364      ]
365    }
366
367    defines += [
368      "USE_STLPORT=1",
369      "_STLP_USE_PTR_SPECIALIZATIONS=1",
370      "__GNU_SOURCE=1",  # Necessary for clone().
371    ]
372
373    ldflags += [
374      "-Wl,--warn-shared-textrel",
375      "-nostdlib",
376    ]
377
378    # NOTE: The stlport header include paths below are specified in cflags
379    # rather than include_dirs because they need to come after include_dirs.
380    # Think of them like system headers, but don't use '-isystem' because the
381    # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit
382    # strange errors. The include ordering here is important; change with
383    # caution.
384    if (use_system_stlport) {
385      cflags += [
386        # For libstdc++/include, which is used by stlport.
387        "-I" + rebase_path("$android_src/bionic", root_build_dir),
388        "-I" + rebase_path("$android_src/external/stlport/stlport",
389                           root_build_dir),
390      ]
391      libs += [
392        "stlport",
393      ]
394    } else {
395      android_stlport_root = "$android_ndk_root/sources/cxx-stl/stlport"
396
397      cflags += [
398        "-I" + rebase_path("$android_stlport_root/stlport", root_build_dir)
399      ]
400      lib_dirs += [ "$android_stlport_root/libs/$android_app_abi" ]
401
402      if (component_mode == "shared_library") {
403        libs += [ "stlport_shared" ]
404      } else {
405        libs += [ "stlport_static" ]
406      }
407    }
408
409    libs += [
410      # Manually link the libgcc.a that the cross compiler uses. This is
411      # absolute because the linker will look inside the sysroot if it's not.
412      rebase_path(android_libgcc_file),
413      "c",
414      "dl",
415      "m",
416    ]
417
418  }
419}
420
421# chromium_code ---------------------------------------------------------------
422#
423# Toggles between higher and lower warnings for code that is (or isn't)
424# part of Chromium.
425
426config("chromium_code") {
427  if (is_win) {
428    cflags = [
429      "/W4",  # Warning level 4.
430      "/WX",  # Treat warnings as errors.
431    ]
432  } else {
433    cflags = [
434      "-Wall",
435      "-Werror",
436
437      # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't,
438      # so we specify it explicitly.
439      # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it.
440      # http://code.google.com/p/chromium/issues/detail?id=90453
441      "-Wsign-compare",
442    ]
443
444    # In Chromium code, we define __STDC_foo_MACROS in order to get the
445    # C99 macros on Mac and Linux.
446    defines = [
447      "__STDC_CONSTANT_MACROS",
448      "__STDC_FORMAT_MACROS",
449    ]
450
451    # TODO(brettw) this should also be enabled on Linux but some files
452    # currently fail.
453    if (is_mac) {
454      cflags += [ "-Wextra" ]
455    }
456  }
457}
458config("no_chromium_code") {
459  cflags = []
460  cflags_cc = []
461  defines = []
462
463  if (is_win) {
464    cflags += [
465      "/W3",  # Warning level 3.
466      "/wd4800",  # Disable warning when forcing value to bool.
467    ]
468    defines += [
469      "_CRT_NONSTDC_NO_WARNINGS",
470      "_CRT_NONSTDC_NO_DEPRECATE",
471    ]
472  }
473
474  if (is_linux) {
475    # Don't warn about ignoring the return value from e.g. close(). This is
476    # off by default in some gccs but on by default in others. BSD systems do
477    # not support this option, since they are usually using gcc 4.2.1, which
478    # does not have this flag yet.
479    cflags += [ "-Wno-unused-result" ]
480  }
481
482  if (is_linux || is_android) {
483    cflags += [
484      # Don't warn about printf format problems. This is off by default in gcc
485      # but on in Ubuntu's gcc(!).
486      "-Wno-format",
487    ]
488    cflags_cc += [
489      # Don't warn about hash_map in third-party code.
490      "-Wno-deprecated",
491    ]
492  }
493
494  if (is_android_webview_build) {
495    # There is a class of warning which:
496    #  1) Android always enables and also treats as errors
497    #  2) Chromium ignores in third party code
498    # So we re-enable those warnings when building Android.
499    cflags += [
500      "-Wno-address",
501      "-Wno-format-security",
502      "-Wno-return-type",
503      "-Wno-sequence-point",
504    ]
505    cflags_cc += [ "-Wno-non-virtual-dtor" ]
506  }
507}
508
509# rtti ------------------------------------------------------------------------
510#
511# Allows turning Run-Time Type Identification on or off.
512
513config("rtti") {
514  if (is_win) {
515    cflags_cc = [ "/GR" ]
516  }
517}
518config("no_rtti") {
519  if (is_win) {
520    cflags_cc = [ "/GR-" ]
521  } else {
522    cflags_cc = [ "-fno-rtti" ]
523  }
524}
525
526# Warnings ---------------------------------------------------------------------
527#
528# This is where we disable various warnings that we've decided aren't
529# worthwhile, and enable special warnings.
530
531config("default_warnings") {
532  if (is_win) {
533    # Please keep ordered and add names if you add more.
534    cflags = [
535      "/wd4018",  # Comparing signed and unsigned values.
536      "/wd4100",  # Unreferenced formal function parameter.
537      "/wd4121",  # Alignment of a member was sensitive to packing.
538      "/wd4125",  # Decimal digit terminates octal escape sequence.
539      "/wd4127",  # Conditional expression is constant.
540      "/wd4130",  # Logical operation on address of string constant.
541      "/wd4189",  # A variable was declared and initialized but never used.
542      "/wd4201",  # Nonstandard extension used: nameless struct/union.
543      "/wd4238",  # Nonstandard extension used: class rvalue used as lvalue.
544      "/wd4244",  # Conversion: possible loss of data.
545      "/wd4245",  # Conversion: signed/unsigned mismatch,
546      "/wd4251",  # Class needs to have dll-interface.
547      "/wd4310",  # Cast truncates constant value.
548      "/wd4351",  # Elements of array will be default initialized.
549      "/wd4355",  # 'this' used in base member initializer list.
550      "/wd4396",  # Inline friend template thing.
551      "/wd4428",  # Universal character name encountered in source.
552      "/wd4481",  # Nonstandard extension: override specifier.
553      "/wd4503",  # Decorated name length exceeded, name was truncated.
554      "/wd4505",  # Unreferenced local function has been removed.
555      "/wd4510",  # Default constructor could not be generated.
556      "/wd4512",  # Assignment operator could not be generated.
557      "/wd4530",  # Exception handler used, but unwind semantics not enabled.
558      "/wd4610",  # Class can never be instantiated, constructor required.
559      "/wd4611",  # C++ object destruction and 'catch'.
560      "/wd4701",  # Potentially uninitialized local variable name used.
561      "/wd4702",  # Unreachable code.
562      "/wd4706",  # Assignment within conditional expression.
563      "/wd4819",  # Character not in the current code page.
564    ]
565  } else {
566    # Common GCC warning setup.
567    cflags = [
568      # Enables.
569      "-Wendif-labels",  # Weird old-style text after an #endif.
570
571      # Disables.
572      "-Wno-missing-field-initializers",  # "struct foo f = {0};"
573      "-Wno-unused-parameter",  # Unused function parameters.
574    ]
575
576    if (is_mac) {
577      cflags += [
578        "-Wnewline-eof",
579      ]
580    }
581
582    if (is_clang) {
583      cflags += [
584        # This warns on using ints as initializers for floats in
585        # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
586        # which happens in several places in chrome code. Not sure if
587        # this is worth fixing.
588        "-Wno-c++11-narrowing",
589
590        # Don't die on dtoa code that uses a char as an array index.
591        # This is required solely for base/third_party/dmg_fp/dtoa.cc.
592        # TODO(brettw) move this to that project then!
593        "-Wno-char-subscripts",
594
595        # Warns on switches on enums that cover all enum values but
596        # also contain a default: branch. Chrome is full of that.
597        "-Wno-covered-switch-default",
598
599        # Clang considers the `register` keyword as deprecated, but e.g.
600        # code generated by flex (used in angle) contains that keyword.
601        # http://crbug.com/255186
602        "-Wno-deprecated-register",
603
604        # Clang spots more unused functions.
605        "-Wno-unused-function",
606      ]
607    }
608
609    # Suppress warnings about ABI changes on ARM (Clang doesn't give this
610    # warning).
611    if (cpu_arch == "arm" && !is_clang) {
612      cflags += [ "-Wno-psabi" ]
613    }
614
615    if (is_android) {
616      # Disable any additional warnings enabled by the Android build system but
617      # which chromium does not build cleanly with (when treating warning as
618      # errors).
619      cflags += [
620        "-Wno-extra",
621        "-Wno-ignored-qualifiers",
622        "-Wno-type-limits",
623      ]
624      cflags_cc = [
625        # Disabling c++0x-compat should be handled in WebKit, but
626        # this currently doesn't work because gcc_version is not set
627        # correctly when building with the Android build system.
628        # TODO(torne): Fix this in WebKit.
629        "-Wno-error=c++0x-compat",
630        # Other things unrelated to -Wextra:
631        "-Wno-non-virtual-dtor",
632        "-Wno-sign-promo",
633      ]
634    }
635
636    if (gcc_version >= 48) {
637      # Don't warn about the "typedef 'foo' locally defined but not used"
638      # for gcc 4.8.
639      # TODO: remove this flag once all builds work. See crbug.com/227506
640      cflags += [
641        "-Wno-unused-local-typedefs",
642      ]
643    }
644  }
645}
646
647# This will generate warnings when using Clang if code generates exit-time
648# destructors, which will slow down closing the program.
649# TODO(thakis): Make this a blacklist instead, http://crbug.com/101600
650config("wexit_time_destructors") {
651  if (is_clang) {
652    cflags = [ "-Wexit-time-destructors" ]
653  }
654}
655
656# Optimization -----------------------------------------------------------------
657#
658# Note that BUILDCONFIG.gn sets up a variable "default_optimization_config"
659# which it will assign to the config it implicitly applies to every target. If
660# you want to override the optimization level for your target, remove this
661# config (which will expand differently for debug or release builds), and then
662# add back the one you want to override it with:
663#
664#   configs -= default_optimization_config
665#   configs += [ "//build/config/compiler/optimize_max" ]
666
667# Shared settings for both "optimize" and "optimize_max" configs.
668if (is_win) {
669  common_optimize_on_cflags = [
670    "/O2",
671    "/Ob2",  # both explicit and auto inlining.
672    "/Oy-",  # disable omitting frame pointers, must be after /o2.
673    "/Os",   # favor size over speed.
674  ]
675  common_optimize_on_ldflags = []
676} else {
677  common_optimize_on_cflags = [
678    # Don't emit the GCC version ident directives, they just end up in the
679    # .comment section taking up binary size.
680    "-fno-ident",
681    # Put data and code in their own sections, so that unused symbols
682    # can be removed at link time with --gc-sections.
683    "-fdata-sections",
684    "-ffunction-sections",
685  ]
686  common_optimize_on_ldflags = []
687
688  if (is_android) {
689    common_optimize_on_cflags += [
690      "-fomit-frame-pointer",
691    ]
692    common_optimize_on_ldflags += [
693      # Warn in case of text relocations.
694      "-Wl,--warn-shared-textrel",
695    ]
696  }
697
698  if (is_mac) {
699    if (symbol_level == 2) {
700      # Mac dead code stripping requires symbols.
701      common_optimize_on_ldflags += [
702        "-Wl,-dead_strip",
703      ]
704    }
705  } else {
706    # Non-Mac Posix linker flags.
707    common_optimize_on_ldflags += [
708      # Specifically tell the linker to perform optimizations.
709      # See http://lwn.net/Articles/192624/ .
710      "-Wl,-O1",
711      "-Wl,--as-needed",
712      "-Wl,--gc-sections",
713    ]
714  }
715}
716
717# Default "optimization on" config. On Windows, this favors size over speed.
718config("optimize") {
719  cflags = common_optimize_on_cflags
720  ldflags = common_optimize_on_ldflags
721  if (is_win) {
722    cflags += [
723      "/Os",   # favor size over speed.
724    ]
725  } else if (is_android || is_ios) {
726    cflags += [
727      "-Os",  # Favor size over speed.
728    ]
729  } else {
730    cflags += [
731      "-O2",
732    ]
733  }
734}
735
736# Turn off optimizations.
737config("no_optimize") {
738  if (is_win) {
739    cflags = [
740      "/Od",  # Disable optimization.
741      "/Ob0",  # Disable all inlining (on by default).
742      "/RTC1",  # Runtime checks for stack frame and uninitialized variables.
743    ]
744  } else if (is_android && !android_full_debug) {
745    # On Android we kind of optimize some things that don't affect debugging
746    # much even when optimization is disabled to get the binary size down.
747    cflags = [
748      "-Os",
749      "-fomit-frame-pointer",
750      "-fdata-sections",
751      "-ffunction-sections",
752    ]
753    ldflags = common_optimize_on_ldflags
754  } else {
755    cflags = [ "-O0" ]
756  }
757}
758
759# On Windows, turns up the optimization level. This implies whole program
760# optimization and link-time code generation which is very expensive and should
761# be used sparingly. For non-Windows, this is the same as "optimize".
762config("optimize_max") {
763  cflags = common_optimize_on_cflags
764  ldflags = common_optimize_on_ldflags
765  if (is_win) {
766    cflags += [
767      "/Ot",   # Favor speed over size.
768      "/GL",   # Whole program optimization.
769      # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds.
770      # Probably anything that this would catch that wouldn't be caught in a
771      # normal build isn't going to actually be a bug, so the incremental value
772      # of C4702 for PGO builds is likely very small.
773      "/wd4702",
774    ]
775  } else {
776    cflags += [
777      "-O2",
778    ]
779  }
780}
781
782# Symbols ----------------------------------------------------------------------
783
784config("symbols") {
785  if (is_win) {
786    cflags = [ "/Zi" ]  # Produce PDB file, no edit and continue.
787    ldflags = [ "/DEBUG" ]
788  } else {
789    cflags = [ "-g2" ]
790  }
791}
792
793config("minimal_symbols") {
794  if (is_win) {
795    # Linker symbols for backtraces only.
796    ldflags = [ "/DEBUG" ]
797  } else {
798    cflags = [ "-g1" ]
799  }
800}
801
802config("no_symbols") {
803  if (!is_win) {
804    cflags = [ "-g0" ]
805  }
806}
807