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.
5 import("//build/config/android/config.gni")
6 if (current_cpu == "arm") {
7 import("//build/config/arm.gni")
9 if (current_cpu == "mipsel" || current_cpu == "mips64el") {
10 import("//build/config/mips.gni")
13 import("//build/config/gcc/gcc_version.gni")
16 import("//build/toolchain/ccache.gni")
19 # Normally, Android builds are lightly optimized, even for debug builds, to
20 # keep binary size down. Setting this flag to true disables such optimization
21 android_full_debug = false
23 # Whether to use the binary binutils checked into third_party/binutils.
24 # These are not multi-arch so cannot be used except on x86 and x86-64 (the
25 # only two architectures that are currently checked in). Turn this off when
26 # you are using a custom toolchain and need to control -B in cflags.
27 linux_use_bundled_binutils = is_linux && current_cpu == "x64"
29 # Compile in such a way as to enable profiling of the generated code. For
30 # example, don't omit the frame pointer and leave in symbols.
31 enable_profiling = false
33 # Compile in such a way as to make it possible for the profiler to unwind full
34 # stack frames. Setting this flag has a large effect on the performance of the
35 # generated code than just setting profiling, but gives the profiler more
36 # information to analyze.
37 # Requires profiling to be set to true.
38 enable_full_stack_frames_for_profiling = false
40 # Use gold for linking on 64-bit Linux only (on 32-bit it runs out of
41 # address space, and it doesn't support cross-compiling).
42 use_gold = is_linux && current_cpu == "x64"
44 # use_debug_fission: whether to use split DWARF debug info
45 # files. This can reduce link time significantly, but is incompatible
46 # with some utilities such as icecc and ccache. Requires gold and
47 # gcc >= 4.8 or clang.
48 # http://gcc.gnu.org/wiki/DebugFission
50 !is_win && use_gold && linux_use_bundled_binutils && !use_ccache
53 # default_include_dirs ---------------------------------------------------------
55 # This is a separate config so that third_party code (which would not use the
56 # source root and might have conflicting versions of some headers) can remove
57 # this and specify their own include paths.
58 config("default_include_dirs") {
65 # TODO(GYP): is_ubsan, is_ubsan_vptr
67 using_sanitizer = is_asan || is_lsan || is_tsan || is_msan
70 # compiler ---------------------------------------------------------------------
72 # Base compiler configuration.
74 # See also "runtime_library" below for related stuff and a discusison about
75 # where stuff should go. Put warning related stuff in the "warnings" config.
84 # In general, Windows is totally different, but all the other builds share
85 # some common GCC configuration. This section sets up Windows and the common
86 # GCC flags, and then we handle the other non-Windows platforms specifically
89 # Windows compiler flags setup.
90 # -----------------------------
92 "/Gy", # Enable function-level linking.
93 "/GS", # Enable buffer security checking.
94 "/FS", # Preserve previous PDB behavior.
96 if (is_component_build) {
97 cflags += [ "/EHsc" ] # Assume C functions can't throw exceptions and don't catch
98 # structured exceptions (only C++ ones).
101 # Common GCC compiler flags setup.
102 # --------------------------------
103 cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204
105 "-fno-threadsafe-statics",
107 # Not exporting C++ inline functions can generally be applied anywhere
108 # so we do so here. Normal function visibility is controlled by
109 # //build/config/gcc:symbol_visibility_hidden.
110 "-fvisibility-inlines-hidden",
115 cflags += [ "-fstack-protector-all" ]
116 } else if (is_linux) {
119 "--param=ssp-buffer-size=4",
124 if (!(is_chromeos && current_cpu == "arm") && !is_mac) {
125 # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580
126 ldflags += [ "-Wl,--fatal-warnings" ]
129 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer and
131 if (using_sanitizer) {
133 "-fno-omit-frame-pointer",
134 "-gline-tables-only",
138 cflags += [ "-fsanitize=address" ]
140 cflags += [ "-mllvm -asan-globals=0" ] # http://crbug.com/352073
141 # TODO(GYP): deal with mac_bundles.
146 if (is_clang && is_debug) {
147 # Allow comparing the address of references and 'this' against 0
148 # in debug builds. Technically, these can never be null in
149 # well-defined C/C++ and Clang can optimize such checks away in
150 # release builds, but they may be used in asserts in debug builds.
152 "-Wno-undefined-bool-conversion",
153 "-Wno-tautological-undefined-compare",
157 if (is_clang && !is_win) {
158 # This is here so that all files get recompiled after a clang roll and
159 # when turning clang on or off. (defines are passed via the command line,
160 # and build system rebuild things when their commandline changes). Nothing
161 # should ever read this define.
162 defines += [ "CR_CLANG_REVISION=" +
163 exec_script("//tools/clang/scripts/posix-print-revision.py",
168 # Mac-specific compiler flags setup.
169 # ----------------------------------
170 if (is_mac || is_ios) {
171 # These flags are shared between the C compiler and linker.
172 common_mac_flags = []
175 if (current_cpu == "x64") {
176 common_mac_flags += [
180 } else if (current_cpu == "x86") {
181 common_mac_flags += [
187 cflags += common_mac_flags
189 # Without this, the constructors and destructors of a C++ object inside
190 # an Objective C struct won't be called, which is very bad.
191 cflags_objcc = [ "-fobjc-call-cxx-cdtors" ]
193 cflags_c += [ "-std=c99" ]
194 cflags_cc += [ "-std=gnu++11" ]
196 ldflags += common_mac_flags
197 } else if (is_posix) {
198 # Non-Mac Posix compiler flags setup.
199 # -----------------------------------
200 if (gcc_version >= 48) {
201 cflags_cc += [ "-std=gnu++11" ]
204 if (enable_profiling && !is_debug) {
205 # The GYP build spams this define into every compilation unit, as we do
206 # here, but it only appears to be used in base and a couple other places.
207 # TODO(abarth): Should we move this define closer to where it's used?
208 defines += [ "ENABLE_PROFILING" ]
211 "-fno-omit-frame-pointer",
215 if (enable_full_stack_frames_for_profiling) {
218 "-fno-optimize-sibling-calls",
223 # CPU architecture. We may or may not be doing a cross compile now, so for
224 # simplicity we always explicitly set the architecture.
225 if (current_cpu == "x64") {
230 ldflags += [ "-m64" ]
231 } else if (current_cpu == "x86") {
233 ldflags += [ "-m32" ]
236 # Else building libyuv gives clang's register allocator issues,
237 # see llvm.org/PR15798 / crbug.com/233709
238 "-momit-leaf-frame-pointer",
240 # Align the stack on 16-byte boundaries, http://crbug.com/418554.
241 "-mstack-alignment=16",
245 } else if (current_cpu == "arm") {
246 # Don't set the compiler flags for the WebView build. These will come
247 # from the Android build system.
248 if (!is_android_webview_build) {
251 "-mfloat-abi=$arm_float_abi",
253 if (arm_tune != "") {
254 cflags += [ "-mtune=$arm_tune" ]
257 cflags += [ "-mthumb" ]
258 if (is_android && !is_clang) { # Clang doesn't support this option.
259 cflags += [ "-mthumb-interwork" ]
263 # Clang doesn't support these flags.
265 # The tree-sra optimization (scalar replacement for
266 # aggregates enabling subsequent optimizations) leads to
267 # invalid code generation when using the Android NDK's
268 # compiler (r5-r7). This can be verified using
269 # webkit_unit_tests' WTF.Checked_int8_t test.
272 # The following option is disabled to improve binary
273 # size and performance in gcc 4.9.
278 } else if (current_cpu == "mipsel") {
279 # Don't set the compiler flags for the WebView build. These will come
280 # from the Android build system.
281 if (!is_android_webview_build) {
282 if (mips_arch_variant == "r6") {
293 } else if (mips_arch_variant == "r2") {
298 if (mips_fpu_mode != "") {
299 cflags += [ "-m$mips_fpu_mode" ]
301 } else if (mips_arch_variant == "r1") {
308 if (mips_dsp_rev == 1) {
309 cflags += [ "-mdsp" ]
310 } else if (mips_dsp_rev == 2) {
311 cflags += [ "-mdspr2" ]
314 cflags += [ "-m${mips_float_abi}-float" ]
316 } else if (current_cpu == "mips64el") {
317 # Don't set the compiler flags for the WebView build. These will come
318 # from the Android build system.
319 if (!is_android_webview_build) {
320 if (mips_arch_variant == "r6") {
325 ldflags += [ "-mips64r6" ]
326 } else if (mips_arch_variant == "r2") {
331 ldflags += [ "-mips64r2" ]
336 defines += [ "_FILE_OFFSET_BITS=64" ]
338 # Omit unwind support in official builds to save space. We can use breakpad
340 if (is_chrome_branded && is_official_build) {
342 "-fno-unwind-tables",
343 "-fno-asynchronous-unwind-tables",
346 cflags += [ "-funwind-tables" ]
350 # Linux/Android common flags setup.
351 # ---------------------------------
352 if (is_linux || is_android) {
355 "-pipe", # Use pipes for communicating between sub-processes. Faster.
360 "-Wl,-z,noexecstack",
364 if (!using_sanitizer) {
365 ldflags += [ "-Wl,-z,defs" ]
369 # Linux-specific compiler flags setup.
370 # ------------------------------------
372 cflags += [ "-pthread" ]
373 ldflags += [ "-pthread" ]
376 gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
381 # Newer gccs and clangs support -fuse-ld, use the flag to force gold
383 # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html
386 # TODO(brettw) common.gypi has this only for target toolset.
389 # Experimentation found that using four linking threads
390 # saved ~20% of link time.
391 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
392 # Only apply this to the target linker, since the host
393 # linker might not be gold, but isn't used much anyway.
394 # TODO(raymes): Disable threading because gold is frequently
395 # crashing on the bots: crbug.com/161942.
397 #"-Wl,--thread-count=4",
401 if (linux_use_bundled_binutils) {
402 binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
404 cflags += [ "-B$binutils_path" ]
407 # Clang-specific compiler flags setup.
408 # ------------------------------------
410 cflags += [ "-fcolor-diagnostics" ]
411 cflags_cc += [ "-std=gnu++11" ]
414 # Android-specific flags setup.
415 # -----------------------------
418 "-ffunction-sections",
423 # Clang doesn't support these flags.
424 cflags += [ "-finline-limit=64" ]
426 if (is_android_webview_build) {
427 # Android predefines this as 1; undefine it here so Chromium can redefine
428 # it later to be 2 for chromium code and unset for third party code. This
429 # works because cflags are added before defines.
430 # TODO(brettw) the above comment seems incorrect. We specify defines
431 # before cflags on our compiler command lines.
432 cflags += [ "-U_FORTIFY_SOURCE" ]
436 # Android build relies on -Wl,--gc-sections removing unreachable code.
437 # ASan instrumentation for globals inhibits this and results in a library
438 # with unresolvable relocations.
439 # TODO(eugenis): find a way to reenable this.
440 cflags += [ "-mllvm -asan-globals=0" ]
443 defines += [ "ANDROID" ]
444 if (!is_android_webview_build) {
445 # The NDK has these things, but doesn't define the constants
446 # to say that it does. Define them here instead.
447 defines += [ "HAVE_SYS_UIO_H" ]
450 # Use gold for Android for most CPU architectures.
451 if (current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm") {
452 ldflags += [ "-fuse-ld=gold" ]
454 # Let clang find the ld.gold in the NDK.
455 ldflags += [ "--gcc-toolchain=" +
456 rebase_path(android_toolchain_root, root_build_dir) ]
461 "-Wl,--no-undefined",
463 # Don't allow visible symbols from libgcc or stlport to be
465 "-Wl,--exclude-libs=libgcc.a",
466 "-Wl,--exclude-libs=libstlport_static.a",
468 # Don't allow visible symbols from libraries that contain
469 # assembly code with symbols that aren't hidden properly.
470 # http://crbug.com/448386
471 "-Wl,--exclude-libs=libvpx_assembly_arm.a",
473 if (current_cpu == "arm") {
475 # Enable identical code folding to reduce size.
481 if (current_cpu == "arm") {
482 cflags += [ "-target arm-linux-androideabi" ]
483 ldflags += [ "-target arm-linux-androideabi" ]
484 } else if (current_cpu == "x86") {
485 cflags += [ "-target x86-linux-androideabi" ]
486 ldflags += [ "-target x86-linux-androideabi" ]
492 config("compiler_arm_fpu") {
493 if (current_cpu == "arm" && !is_android_webview_build) {
494 cflags = [ "-mfpu=$arm_fpu" ]
498 # runtime_library -------------------------------------------------------------
500 # Sets the runtime library and associated options.
502 # How do you determine what should go in here vs. "compiler" above? Consider if
503 # a target might choose to use a different runtime library (ignore for a moment
504 # if this is possible or reasonable on your system). If such a target would want
505 # to change or remove your option, put it in the runtime_library config. If a
506 # target wants the option regardless, put it in the compiler config.
508 config("runtime_library") {
515 if (is_component_build) {
516 # Component mode: dynamic CRT.
517 defines += [ "COMPONENT_BUILD" ]
519 # Since the library is shared, it requires exceptions or will give errors
520 # about things not matching, so keep exceptions on.
530 # We don't use exceptions, and when we link statically we can just get
531 # rid of them entirely.
532 defines += [ "_HAS_EXCEPTIONS=0" ]
544 "__STDC_CONSTANT_MACROS",
545 "__STDC_FORMAT_MACROS",
547 "_CRT_SECURE_NO_DEPRECATE",
548 "_SCL_SECURE_NO_DEPRECATE",
552 # Stlport setup. Android uses a different (smaller) version of the STL.
555 # Work around incompatibilities between bionic and clang headers.
557 "__compiler_offsetof=__builtin_offsetof",
564 "_STLP_USE_PTR_SPECIALIZATIONS=1",
565 "__GNU_SOURCE=1", # Necessary for clone().
568 # TODO(jdduke) Re-enable on mips after resolving linking
569 # issues with libc++ (crbug.com/456380).
570 if (cpu_arch != "mipsel" && cpu_arch != "mips64el") {
571 ldflags += [ "-Wl,--warn-shared-textrel" ]
573 ldflags += [ "-nostdlib" ]
575 # NOTE: The stlport header include paths below are specified in cflags
576 # rather than include_dirs because they need to come after include_dirs.
577 # Think of them like system headers, but don't use '-isystem' because the
578 # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit
579 # strange errors. The include ordering here is important; change with
581 android_stlport_root = "$android_ndk_root/sources/cxx-stl/stlport"
583 cflags += [ "-isystem" +
584 rebase_path("$android_stlport_root/stlport", root_build_dir) ]
585 lib_dirs += [ "$android_stlport_root/libs/$android_app_abi" ]
587 if (component_mode == "shared_library") {
588 libs += [ "stlport_shared" ]
590 libs += [ "stlport_static" ]
593 if (current_cpu == "mipsel") {
595 # ld linker is used for mips Android, and ld does not accept library
596 # absolute path prefixed by "-l"; Since libgcc does not exist in mips
597 # sysroot the proper library will be linked.
598 # TODO(gordanac): Remove once gold linker is used for mips Android.
603 # Manually link the libgcc.a that the cross compiler uses. This is
604 # absolute because the linker will look inside the sysroot if it's not.
605 rebase_path(android_libgcc_file),
617 # chromium_code ---------------------------------------------------------------
619 # Toggles between higher and lower warnings for code that is (or isn't)
622 config("chromium_code") {
624 cflags = [ "/W4" ] # Warning level 4.
629 # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't,
630 # so we specify it explicitly.
631 # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it.
632 # http://code.google.com/p/chromium/issues/detail?id=90453
636 # In Chromium code, we define __STDC_foo_MACROS in order to get the
637 # C99 macros on Mac and Linux.
639 "__STDC_CONSTANT_MACROS",
640 "__STDC_FORMAT_MACROS",
644 config("no_chromium_code") {
651 "/W3", # Warning level 3.
652 "/wd4800", # Disable warning when forcing value to bool.
653 "/wd4267", # TODO(jschuh): size_t to int.
654 "/wd4996", # Deprecated function warning.
657 "_CRT_NONSTDC_NO_WARNINGS",
658 "_CRT_NONSTDC_NO_DEPRECATE",
663 # Don't warn about ignoring the return value from e.g. close(). This is
664 # off by default in some gccs but on by default in others. BSD systems do
665 # not support this option, since they are usually using gcc 4.2.1, which
666 # does not have this flag yet.
667 cflags += [ "-Wno-unused-result" ]
670 if (is_linux || is_android) {
672 # Don't warn about printf format problems. This is off by default in gcc
673 # but on in Ubuntu's gcc(!).
677 # Don't warn about hash_map in third-party code.
682 if (is_android_webview_build) {
683 # There is a class of warning which:
684 # 1) Android always enables and also treats as errors
685 # 2) Chromium ignores in third party code
686 # So we re-enable those warnings when building Android.
689 "-Wno-format-security",
691 "-Wno-sequence-point",
693 cflags_cc += [ "-Wno-non-virtual-dtor" ]
697 # rtti ------------------------------------------------------------------------
699 # Allows turning Run-Time Type Identification on or off.
703 cflags_cc = [ "/GR" ]
708 cflags_cc = [ "/GR-" ]
710 cflags_cc = [ "-fno-rtti" ]
714 # Warnings ---------------------------------------------------------------------
716 # This is where we disable various warnings that we've decided aren't
717 # worthwhile, and enable special warnings.
719 config("default_warnings") {
722 "/WX", # Treat warnings as errors.
724 # Warnings permanently disabled:
726 # TODO(GYP) The GYP build doesn't have this globally enabled but disabled
727 # for a bunch of individual targets. Re-enable this globally when those
729 "/wd4018", # Comparing signed and unsigned values.
731 # C4127: conditional expression is constant
732 # This warning can in theory catch dead code and other problems, but
733 # triggers in far too many desirable cases where the conditional
734 # expression is either set by macros or corresponds some legitimate
735 # compile-time constant expression (due to constant template args,
736 # conditionals comparing the sizes of different types, etc.). Some of
737 # these can be worked around, but it's not worth it.
740 # C4251: 'identifier' : class 'type' needs to have dll-interface to be
741 # used by clients of class 'type2'
742 # This is necessary for the shared library build.
745 # C4351: new behavior: elements of array 'array' will be default
747 # This is a silly "warning" that basically just alerts you that the
748 # compiler is going to actually follow the language spec like it's
749 # supposed to, instead of not following it like old buggy versions did.
750 # There's absolutely no reason to turn this on.
753 # C4355: 'this': used in base member initializer list
754 # It's commonly useful to pass |this| to objects in a class' initializer
755 # list. While this warning can catch real bugs, most of the time the
756 # constructors in question don't attempt to call methods on the passed-in
757 # pointer (until later), and annotating every legit usage of this is
758 # simply more hassle than the warning is worth.
761 # C4503: 'identifier': decorated name length exceeded, name was
763 # This only means that some long error messages might have truncated
764 # identifiers in the presence of lots of templates. It has no effect on
765 # program correctness and there's no real reason to waste time trying to
769 # C4611: interaction between 'function' and C++ object destruction is
771 # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN
772 # suggests using exceptions instead of setjmp/longjmp for C++, but
773 # Chromium code compiles without exception support. We therefore have to
774 # use setjmp/longjmp for e.g. JPEG decode error handling, which means we
775 # have to turn off this warning (and be careful about how object
776 # destruction happens in such cases).
779 # Warnings to evaluate and possibly fix/reenable later:
781 "/wd4100", # Unreferenced formal function parameter.
782 "/wd4121", # Alignment of a member was sensitive to packing.
783 "/wd4244", # Conversion: possible loss of data.
784 "/wd4481", # Nonstandard extension: override specifier.
785 "/wd4505", # Unreferenced local function has been removed.
786 "/wd4510", # Default constructor could not be generated.
787 "/wd4512", # Assignment operator could not be generated.
788 "/wd4610", # Class can never be instantiated, constructor required.
789 "/wd4996", # Deprecated function warning.
792 # Common GCC warning setup.
795 "-Wendif-labels", # Weird old-style text after an #endif.
796 "-Werror", # Warnings as errors.
799 "-Wno-missing-field-initializers", # "struct foo f = {0};"
800 "-Wno-unused-parameter", # Unused function parameters.
805 cflags += [ "-Wnewline-eof" ]
810 # This warns on using ints as initializers for floats in
811 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
812 # which happens in several places in chrome code. Not sure if
813 # this is worth fixing.
814 "-Wno-c++11-narrowing",
816 # Don't die on dtoa code that uses a char as an array index.
817 # This is required solely for base/third_party/dmg_fp/dtoa.cc.
818 # TODO(brettw) move this to that project then!
819 "-Wno-char-subscripts",
821 # Warns on switches on enums that cover all enum values but
822 # also contain a default: branch. Chrome is full of that.
823 "-Wno-covered-switch-default",
825 # Clang considers the `register` keyword as deprecated, but e.g.
826 # code generated by flex (used in angle) contains that keyword.
827 # http://crbug.com/255186
828 "-Wno-deprecated-register",
830 # TODO(thakis): This used to be implied by -Wno-unused-function,
831 # which we no longer use. Check if it makes sense to remove
832 # this as well. http://crbug.com/316352
833 "-Wno-unneeded-internal-declaration",
835 # TODO(thakis): Remove, http://crbug.com/263960
836 "-Wno-reserved-user-defined-literal",
839 # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost
840 # always have different versions. Certain flags may not be recognized by
841 # one version or the other.
843 # Flags NaCl does not recognize.
845 # TODO(hans): Get this cleaned up.
846 "-Wno-inconsistent-missing-override",
850 if (gcc_version >= 48) {
852 # See comment for -Wno-c++11-narrowing.
855 # TODO(thakis): Remove, http://crbug.com/263960
856 "-Wno-literal-suffix",
860 # Suppress warnings about ABI changes on ARM (Clang doesn't give this
862 if (current_cpu == "arm" && !is_clang) {
863 cflags += [ "-Wno-psabi" ]
867 # Disable any additional warnings enabled by the Android build system but
868 # which chromium does not build cleanly with (when treating warning as
872 "-Wno-ignored-qualifiers",
876 # Disabling c++0x-compat should be handled in WebKit, but
877 # this currently doesn't work because gcc_version is not set
878 # correctly when building with the Android build system.
879 # TODO(torne): Fix this in WebKit.
880 "-Wno-error=c++0x-compat",
882 # Other things unrelated to -Wextra:
883 "-Wno-non-virtual-dtor",
888 if (gcc_version >= 48) {
889 # Don't warn about the "typedef 'foo' locally defined but not used"
891 # TODO: remove this flag once all builds work. See crbug.com/227506
892 cflags += [ "-Wno-unused-local-typedefs" ]
897 # This will generate warnings when using Clang if code generates exit-time
898 # destructors, which will slow down closing the program.
899 # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600
900 config("wexit_time_destructors") {
902 cflags = [ "-Wexit-time-destructors" ]
906 # On Windows compiling on x64, VC will issue a warning when converting
907 # size_t to int because it will truncate the value. Our code should not have
908 # these warnings and one should use a static_cast or a checked_cast for the
909 # conversion depending on the case. However, a lot of code still needs to be
910 # fixed. Apply this config to such targets to disable the warning.
912 # Note that this can be applied regardless of platform and architecture to
913 # clean up the call sites. This will only apply the flag when necessary.
914 config("no_size_t_to_int_warning") {
915 if (is_win && current_cpu == "x64") {
916 cflags = [ "/wd4267" ]
920 # Optimization -----------------------------------------------------------------
922 # Note that BUILDCONFIG.gn sets up a variable "default_optimization_config"
923 # which it will assign to the config it implicitly applies to every target. If
924 # you want to override the optimization level for your target, remove this
925 # config (which will expand differently for debug or release builds), and then
926 # add back the one you want to override it with:
928 # configs -= default_optimization_config
929 # configs += [ "//build/config/compiler/optimize_max" ]
931 # Shared settings for both "optimize" and "optimize_max" configs.
933 common_optimize_on_cflags = [
935 "/Ob2", # both explicit and auto inlining.
936 "/Oy-", # disable omitting frame pointers, must be after /o2.
937 "/Os", # favor size over speed.
940 common_optimize_on_cflags += [
941 # Put data in separate COMDATs. This allows the linker
942 # to put bit-identical constants at the same address even if
943 # they're unrelated constants, which saves binary size.
944 # This optimization can't be used when ASan is enabled because
945 # it is not compatible with the ASan ODR checker.
949 common_optimize_on_ldflags = [ "/OPT:REF" ]
951 common_optimize_on_cflags = [
952 # Don't emit the GCC version ident directives, they just end up in the
953 # .comment section taking up binary size.
956 # Put data and code in their own sections, so that unused symbols
957 # can be removed at link time with --gc-sections.
959 "-ffunction-sections",
961 common_optimize_on_ldflags = []
964 if (!using_sanitizer) {
965 common_optimize_on_cflags += [ "-fomit-frame-pointer" ]
968 # TODO(jdduke) Re-enable on mips after resolving linking
969 # issues with libc++ (crbug.com/456380).
970 if (cpu_arch != "mipsel" && cpu_arch != "mips64el") {
971 common_optimize_on_ldflags += [
972 # Warn in case of text relocations.
973 "-Wl,--warn-shared-textrel",
979 if (symbol_level == 2) {
980 # Mac dead code stripping requires symbols.
981 common_optimize_on_ldflags += [ "-Wl,-dead_strip" ]
984 # Non-Mac Posix linker flags.
985 common_optimize_on_ldflags += [
986 # Specifically tell the linker to perform optimizations.
987 # See http://lwn.net/Articles/192624/ .
992 if (!using_sanitizer) {
993 # Functions interposed by the sanitizers can make ld think
994 # that some libraries aren't needed when they actually are,
995 # http://crbug.com/234010. As workaround, disable --as-needed.
996 common_optimize_on_ldflags += [ "-Wl,--as-needed" ]
1001 # Default "optimization on" config. On Windows, this favors size over speed.
1002 config("optimize") {
1003 cflags = common_optimize_on_cflags
1004 ldflags = common_optimize_on_ldflags
1006 cflags += [ "/Os" ] # favor size over speed.
1007 } else if (is_android || is_ios) {
1008 cflags += [ "-Os" ] # Favor size over speed.
1014 # Turn off optimizations.
1015 config("no_optimize") {
1018 "/Od", # Disable optimization.
1019 "/Ob0", # Disable all inlining (on by default).
1020 "/RTC1", # Runtime checks for stack frame and uninitialized variables.
1022 } else if (is_android && !android_full_debug) {
1023 # On Android we kind of optimize some things that don't affect debugging
1024 # much even when optimization is disabled to get the binary size down.
1028 "-ffunction-sections",
1030 if (!using_sanitizer) {
1031 cflags += [ "-fomit-frame-pointer" ]
1033 ldflags = common_optimize_on_ldflags
1039 # Turns up the optimization level. On Windows, this implies whole program
1040 # optimization and link-time code generation which is very expensive and should
1041 # be used sparingly.
1042 config("optimize_max") {
1043 cflags = common_optimize_on_cflags
1044 ldflags = common_optimize_on_ldflags
1047 cflags += [ "/Ot" ] # Favor speed over size.
1048 if (is_official_build) {
1049 # TODO(GYP): TODO(dpranke): Should these only be on in an official
1050 # build, or on all the time? For now we'll require official build so
1051 # that the compile is clean.
1053 "/GL", # Whole program optimization.
1055 # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds.
1056 # Probably anything that this would catch that wouldn't be caught in a
1057 # normal build isn't going to actually be a bug, so the incremental
1058 # value of C4702 for PGO builds is likely very small.
1061 ldflags += [ "/LTCG" ]
1068 # Symbols ----------------------------------------------------------------------
1072 import("//build/toolchain/goma.gni")
1074 cflags = [ "/Z7" ] # No PDB file
1076 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
1078 ldflags = [ "/DEBUG" ]
1081 if (use_debug_fission) {
1082 cflags += [ "-gsplit-dwarf" ]
1087 config("minimal_symbols") {
1089 # Linker symbols for backtraces only.
1090 ldflags = [ "/DEBUG" ]
1093 if (use_debug_fission) {
1094 cflags += [ "-gsplit-dwarf" ]
1099 config("no_symbols") {