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 import("//build/config/chrome_build.gni")
7 if (current_cpu == "arm") {
8 import("//build/config/arm.gni")
10 if (current_cpu == "mipsel" || current_cpu == "mips64el") {
11 import("//build/config/mips.gni")
14 import("//build/config/gcc/gcc_version.gni")
17 import("//build/toolchain/ccache.gni")
20 # Normally, Android builds are lightly optimized, even for debug builds, to
21 # keep binary size down. Setting this flag to true disables such optimization
22 android_full_debug = false
24 # Whether to use the binary binutils checked into third_party/binutils.
25 # These are not multi-arch so cannot be used except on x86 and x86-64 (the
26 # only two architectures that are currently checked in). Turn this off when
27 # you are using a custom toolchain and need to control -B in cflags.
28 linux_use_bundled_binutils = is_linux && current_cpu == "x64"
30 # Compile in such a way as to enable profiling of the generated code. For
31 # example, don't omit the frame pointer and leave in symbols.
32 enable_profiling = false
34 # Compile in such a way as to make it possible for the profiler to unwind full
35 # stack frames. Setting this flag has a large effect on the performance of the
36 # generated code than just setting profiling, but gives the profiler more
37 # information to analyze.
38 # Requires profiling to be set to true.
39 enable_full_stack_frames_for_profiling = false
41 # Use gold for linking on 64-bit Linux only (on 32-bit it runs out of
42 # address space, and it doesn't support cross-compiling).
43 use_gold = is_linux && current_cpu == "x64"
45 # use_debug_fission: whether to use split DWARF debug info
46 # files. This can reduce link time significantly, but is incompatible
47 # with some utilities such as icecc and ccache. Requires gold and
48 # gcc >= 4.8 or clang.
49 # http://gcc.gnu.org/wiki/DebugFission
51 !is_win && use_gold && linux_use_bundled_binutils && !use_ccache
54 # Whether the VS xtree header has been patched to disable warning 4702. If
55 # it has, then we don't need to disable 4702 (unreachable code warning).
56 # The patch is preapplied to the internal toolchain and hence all bots.
57 msvs_xtree_patched = false
61 # default_include_dirs ---------------------------------------------------------
63 # This is a separate config so that third_party code (which would not use the
64 # source root and might have conflicting versions of some headers) can remove
65 # this and specify their own include paths.
66 config("default_include_dirs") {
73 # TODO(GYP): is_ubsan, is_ubsan_vptr
75 using_sanitizer = is_asan || is_lsan || is_tsan || is_msan
78 # compiler ---------------------------------------------------------------------
80 # Base compiler configuration.
82 # See also "runtime_library" below for related stuff and a discussion about
83 # where stuff should go. Put warning related stuff in the "warnings" config.
92 # In general, Windows is totally different, but all the other builds share
93 # some common GCC configuration. This section sets up Windows and the common
94 # GCC flags, and then we handle the other non-Windows platforms specifically
97 # Windows compiler flags setup.
98 # -----------------------------
100 "/Gy", # Enable function-level linking.
101 "/GS", # Enable buffer security checking.
102 "/FS", # Preserve previous PDB behavior.
105 # Common GCC compiler flags setup.
106 # --------------------------------
107 cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204
109 "-fno-threadsafe-statics",
111 # Not exporting C++ inline functions can generally be applied anywhere
112 # so we do so here. Normal function visibility is controlled by
113 # //build/config/gcc:symbol_visibility_hidden.
114 "-fvisibility-inlines-hidden",
119 cflags += [ "-fstack-protector-all" ]
120 } else if (is_linux) {
123 "--param=ssp-buffer-size=4",
128 if (!(is_chromeos && current_cpu == "arm") && !is_mac) {
129 # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580
130 ldflags += [ "-Wl,--fatal-warnings" ]
133 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer and
135 if (using_sanitizer) {
137 "-fno-omit-frame-pointer",
138 "-gline-tables-only",
142 cflags += [ "-fsanitize=address" ]
144 cflags += [ "-mllvm -asan-globals=0" ] # http://crbug.com/352073
145 # TODO(GYP): deal with mac_bundles.
150 if (is_clang && is_debug) {
151 # Allow comparing the address of references and 'this' against 0
152 # in debug builds. Technically, these can never be null in
153 # well-defined C/C++ and Clang can optimize such checks away in
154 # release builds, but they may be used in asserts in debug builds.
156 "-Wno-undefined-bool-conversion",
157 "-Wno-tautological-undefined-compare",
161 if (is_clang && !is_nacl) {
162 # This is here so that all files get recompiled after a clang roll and
163 # when turning clang on or off. (defines are passed via the command line,
164 # and build system rebuild things when their commandline changes). Nothing
165 # should ever read this define.
167 [ "CR_CLANG_REVISION=" + exec_script("//tools/clang/scripts/update.py",
168 [ "--print-revision" ],
172 # Mac-specific compiler flags setup.
173 # ----------------------------------
174 if (is_mac || is_ios) {
175 # These flags are shared between the C compiler and linker.
176 common_mac_flags = []
179 if (current_cpu == "x64") {
180 common_mac_flags += [
184 } else if (current_cpu == "x86") {
185 common_mac_flags += [
191 cflags += common_mac_flags
193 # Without this, the constructors and destructors of a C++ object inside
194 # an Objective C struct won't be called, which is very bad.
195 cflags_objcc = [ "-fobjc-call-cxx-cdtors" ]
197 cflags_c += [ "-std=c99" ]
199 ldflags += common_mac_flags
200 } else if (is_posix) {
201 # Non-Mac Posix compiler flags setup.
202 # -----------------------------------
203 if (enable_profiling && !is_debug) {
204 # The GYP build spams this define into every compilation unit, as we do
205 # here, but it only appears to be used in base and a couple other places.
206 # TODO(abarth): Should we move this define closer to where it's used?
207 defines += [ "ENABLE_PROFILING" ]
210 "-fno-omit-frame-pointer",
214 if (enable_full_stack_frames_for_profiling) {
217 "-fno-optimize-sibling-calls",
222 # CPU architecture. We may or may not be doing a cross compile now, so for
223 # simplicity we always explicitly set the architecture.
224 if (current_cpu == "x64") {
229 ldflags += [ "-m64" ]
230 } else if (current_cpu == "x86") {
232 ldflags += [ "-m32" ]
235 # Else building libyuv gives clang's register allocator issues,
236 # see llvm.org/PR15798 / crbug.com/233709
237 "-momit-leaf-frame-pointer",
239 # Align the stack on 16-byte boundaries, http://crbug.com/418554.
240 "-mstack-alignment=16",
244 } else if (current_cpu == "arm") {
247 "-mfloat-abi=$arm_float_abi",
249 if (arm_tune != "") {
250 cflags += [ "-mtune=$arm_tune" ]
253 cflags += [ "-mthumb" ]
254 if (is_android && !is_clang) { # Clang doesn't support this option.
255 cflags += [ "-mthumb-interwork" ]
259 # Clang doesn't support these flags.
261 # The tree-sra optimization (scalar replacement for
262 # aggregates enabling subsequent optimizations) leads to
263 # invalid code generation when using the Android NDK's
264 # compiler (r5-r7). This can be verified using
265 # webkit_unit_tests' WTF.Checked_int8_t test.
268 # The following option is disabled to improve binary
269 # size and performance in gcc 4.9.
273 } else if (current_cpu == "mipsel") {
274 if (mips_arch_variant == "r6") {
285 } else if (mips_arch_variant == "r2") {
290 if (mips_float_abi == "hard" && mips_fpu_mode != "") {
291 cflags += [ "-m$mips_fpu_mode" ]
293 } else if (mips_arch_variant == "r1") {
300 if (mips_dsp_rev == 1) {
301 cflags += [ "-mdsp" ]
302 } else if (mips_dsp_rev == 2) {
303 cflags += [ "-mdspr2" ]
306 cflags += [ "-m${mips_float_abi}-float" ]
307 } else if (current_cpu == "mips64el") {
308 if (mips_arch_variant == "r6") {
313 ldflags += [ "-mips64r6" ]
314 } else if (mips_arch_variant == "r2") {
319 ldflags += [ "-mips64r2" ]
323 defines += [ "_FILE_OFFSET_BITS=64" ]
328 "_LARGEFILE64_SOURCE",
332 # Omit unwind support in official builds to save space. We can use breakpad
334 if (is_chrome_branded && is_official_build) {
336 "-fno-unwind-tables",
337 "-fno-asynchronous-unwind-tables",
339 defines += [ "NO_UNWIND_TABLES" ]
341 cflags += [ "-funwind-tables" ]
345 # Linux/Android common flags setup.
346 # ---------------------------------
347 if (is_linux || is_android) {
350 "-pipe", # Use pipes for communicating between sub-processes. Faster.
355 "-Wl,-z,noexecstack",
359 if (!using_sanitizer) {
360 ldflags += [ "-Wl,-z,defs" ]
364 # Linux-specific compiler flags setup.
365 # ------------------------------------
367 cflags += [ "-pthread" ]
368 ldflags += [ "-pthread" ]
371 gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
376 # Newer gccs and clangs support -fuse-ld, use the flag to force gold
378 # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html
381 # TODO(brettw) common.gypi has this only for target toolset.
384 # Experimentation found that using four linking threads
385 # saved ~20% of link time.
386 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
387 # Only apply this to the target linker, since the host
388 # linker might not be gold, but isn't used much anyway.
389 # TODO(raymes): Disable threading because gold is frequently
390 # crashing on the bots: crbug.com/161942.
392 #"-Wl,--thread-count=4",
395 # TODO(thestig): Make this flag work with GN.
396 #if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan || is_msan)) {
398 # "-Wl,--detect-odr-violations",
403 if (linux_use_bundled_binutils) {
404 binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
406 cflags += [ "-B$binutils_path" ]
409 # Clang-specific compiler flags setup.
410 # ------------------------------------
412 cflags += [ "-fcolor-diagnostics" ]
415 # C++11 compiler flags setup.
416 # ---------------------------
417 if (is_linux || is_android || is_nacl) {
418 # gnu++11 instead of c++11 is needed because some code uses typeof() (a
420 # TODO(thakis): Eventually switch this to c++11 instead,
421 # http://crbug.com/427584
422 cflags_cc += [ "-std=gnu++11" ]
423 } else if (!is_win) {
424 cflags_cc += [ "-std=c++11" ]
427 # Android-specific flags setup.
428 # -----------------------------
431 "-ffunction-sections",
436 # Clang doesn't support these flags.
437 cflags += [ "-finline-limit=64" ]
440 # Android build relies on -Wl,--gc-sections removing unreachable code.
441 # ASan instrumentation for globals inhibits this and results in a library
442 # with unresolvable relocations.
443 # TODO(eugenis): find a way to reenable this.
444 cflags += [ "-mllvm -asan-globals=0" ]
447 defines += [ "ANDROID" ]
449 # The NDK has these things, but doesn't define the constants
450 # to say that it does. Define them here instead.
451 defines += [ "HAVE_SYS_UIO_H" ]
453 # Use gold for Android for most CPU architectures.
454 if (current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm") {
455 ldflags += [ "-fuse-ld=gold" ]
457 # Let clang find the ld.gold in the NDK.
458 ldflags += [ "--gcc-toolchain=" +
459 rebase_path(android_toolchain_root, root_build_dir) ]
464 "-Wl,--no-undefined",
466 # Don't allow visible symbols from libgcc or libc++ to be
468 "-Wl,--exclude-libs=libgcc.a",
469 "-Wl,--exclude-libs=libc++_static.a",
471 # Don't allow visible symbols from libraries that contain
472 # assembly code with symbols that aren't hidden properly.
473 # http://crbug.com/448386
474 "-Wl,--exclude-libs=libvpx_assembly_arm.a",
476 if (current_cpu == "arm") {
478 # Enable identical code folding to reduce size.
484 if (current_cpu == "arm") {
485 cflags += [ "-target arm-linux-androideabi" ]
486 ldflags += [ "-target arm-linux-androideabi" ]
487 } else if (current_cpu == "x86") {
488 cflags += [ "-target x86-linux-androideabi" ]
489 ldflags += [ "-target x86-linux-androideabi" ]
495 config("compiler_arm_fpu") {
496 if (current_cpu == "arm") {
497 cflags = [ "-mfpu=$arm_fpu" ]
501 # runtime_library -------------------------------------------------------------
503 # Sets the runtime library and associated options.
505 # How do you determine what should go in here vs. "compiler" above? Consider if
506 # a target might choose to use a different runtime library (ignore for a moment
507 # if this is possible or reasonable on your system). If such a target would want
508 # to change or remove your option, put it in the runtime_library config. If a
509 # target wants the option regardless, put it in the compiler config.
511 config("runtime_library") {
518 if (is_component_build) {
519 # Component mode: dynamic CRT.
520 defines += [ "COMPONENT_BUILD" ]
522 # Since the library is shared, it requires exceptions or will give errors
523 # about things not matching, so keep exceptions on.
545 "_CRT_SECURE_NO_DEPRECATE",
547 "_SCL_SECURE_NO_DEPRECATE",
551 # Android standard library setup.
554 # Work around incompatibilities between bionic and clang headers.
556 "__compiler_offsetof=__builtin_offsetof",
561 defines += [ "__GNU_SOURCE=1" ] # Necessary for clone().
563 # TODO(jdduke) Re-enable on mips after resolving linking
564 # issues with libc++ (crbug.com/456380).
565 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
566 ldflags += [ "-Wl,--warn-shared-textrel" ]
568 ldflags += [ "-nostdlib" ]
570 # NOTE: The libc++ header include paths below are specified in cflags
571 # rather than include_dirs because they need to come after include_dirs.
572 # Think of them like system headers, but don't use '-isystem' because the
573 # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit
574 # strange errors. The include ordering here is important; change with
576 android_libcpp_root = "$android_ndk_root/sources/cxx-stl/llvm-libc++"
580 rebase_path("$android_libcpp_root/libcxx/include", root_build_dir),
581 "-isystem" + rebase_path(
582 "$android_ndk_root/sources/cxx-stl/llvm-libc++abi/libcxxabi/include",
585 rebase_path("$android_ndk_root/sources/android/support/include",
589 lib_dirs += [ "$android_libcpp_root/libs/$android_app_abi" ]
591 if (component_mode == "shared_library") {
592 android_libcpp_library = "c++_shared"
594 android_libcpp_library = "c++_static"
598 "$android_libcpp_library",
600 # Manually link the libgcc.a that the cross compiler uses. This is
601 # absolute because the linker will look inside the sysroot if it's not.
602 rebase_path(android_libgcc_file),
608 # Clang with libc++ does not require an explicit atomic library reference.
615 # chromium_code ---------------------------------------------------------------
617 # Toggles between higher and lower warnings for code that is (or isn't)
620 config("chromium_code") {
622 cflags = [ "/W4" ] # Warning level 4.
627 # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't,
628 # so we specify it explicitly.
629 # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it.
630 # http://code.google.com/p/chromium/issues/detail?id=90453
634 # In Chromium code, we define __STDC_foo_MACROS in order to get the
635 # C99 macros on Mac and Linux.
637 "__STDC_CONSTANT_MACROS",
638 "__STDC_FORMAT_MACROS",
641 if (using_sanitizer) {
642 # _FORTIFY_SOURCE isn't really supported by Clang now, see
643 # http://llvm.org/bugs/show_bug.cgi?id=16821.
644 # It seems to work fine with Ubuntu 12 headers though, so use it in
647 # Non-chromium code is not guaranteed to compile cleanly with
648 # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are
649 # disabled, so only do that for Release build.
650 defines += [ "_FORTIFY_SOURCE=2" ]
654 config("no_chromium_code") {
661 "/W3", # Warning level 3.
662 "/wd4800", # Disable warning when forcing value to bool.
663 "/wd4267", # TODO(jschuh): size_t to int.
664 "/wd4996", # Deprecated function warning.
667 "_CRT_NONSTDC_NO_WARNINGS",
668 "_CRT_NONSTDC_NO_DEPRECATE",
673 # Don't warn about ignoring the return value from e.g. close(). This is
674 # off by default in some gccs but on by default in others. BSD systems do
675 # not support this option, since they are usually using gcc 4.2.1, which
676 # does not have this flag yet.
677 cflags += [ "-Wno-unused-result" ]
680 if (is_linux || is_android) {
682 # Don't warn about printf format problems. This is off by default in gcc
683 # but on in Ubuntu's gcc(!).
687 # Don't warn about hash_map in third-party code.
693 # rtti ------------------------------------------------------------------------
695 # Allows turning Run-Time Type Identification on or off.
699 cflags_cc = [ "/GR" ]
704 cflags_cc = [ "/GR-" ]
706 cflags_cc = [ "-fno-rtti" ]
710 # Warnings ---------------------------------------------------------------------
712 # This is where we disable various warnings that we've decided aren't
713 # worthwhile, and enable special warnings.
715 config("default_warnings") {
718 "/WX", # Treat warnings as errors.
720 # Warnings permanently disabled:
722 # TODO(GYP) The GYP build doesn't have this globally enabled but disabled
723 # for a bunch of individual targets. Re-enable this globally when those
725 "/wd4018", # Comparing signed and unsigned values.
727 # C4127: conditional expression is constant
728 # This warning can in theory catch dead code and other problems, but
729 # triggers in far too many desirable cases where the conditional
730 # expression is either set by macros or corresponds some legitimate
731 # compile-time constant expression (due to constant template args,
732 # conditionals comparing the sizes of different types, etc.). Some of
733 # these can be worked around, but it's not worth it.
736 # C4251: 'identifier' : class 'type' needs to have dll-interface to be
737 # used by clients of class 'type2'
738 # This is necessary for the shared library build.
741 # C4351: new behavior: elements of array 'array' will be default
743 # This is a silly "warning" that basically just alerts you that the
744 # compiler is going to actually follow the language spec like it's
745 # supposed to, instead of not following it like old buggy versions did.
746 # There's absolutely no reason to turn this on.
749 # C4355: 'this': used in base member initializer list
750 # It's commonly useful to pass |this| to objects in a class' initializer
751 # list. While this warning can catch real bugs, most of the time the
752 # constructors in question don't attempt to call methods on the passed-in
753 # pointer (until later), and annotating every legit usage of this is
754 # simply more hassle than the warning is worth.
757 # C4503: 'identifier': decorated name length exceeded, name was
759 # This only means that some long error messages might have truncated
760 # identifiers in the presence of lots of templates. It has no effect on
761 # program correctness and there's no real reason to waste time trying to
765 # C4611: interaction between 'function' and C++ object destruction is
767 # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN
768 # suggests using exceptions instead of setjmp/longjmp for C++, but
769 # Chromium code compiles without exception support. We therefore have to
770 # use setjmp/longjmp for e.g. JPEG decode error handling, which means we
771 # have to turn off this warning (and be careful about how object
772 # destruction happens in such cases).
775 # Warnings to evaluate and possibly fix/reenable later:
777 "/wd4100", # Unreferenced formal function parameter.
778 "/wd4121", # Alignment of a member was sensitive to packing.
779 "/wd4244", # Conversion: possible loss of data.
780 "/wd4481", # Nonstandard extension: override specifier.
781 "/wd4505", # Unreferenced local function has been removed.
782 "/wd4510", # Default constructor could not be generated.
783 "/wd4512", # Assignment operator could not be generated.
784 "/wd4610", # Class can never be instantiated, constructor required.
785 "/wd4996", # Deprecated function warning.
788 # VS xtree header file needs to be patched or 4702 (unreachable code
789 # warning) is reported if _HAS_EXCEPTIONS=0. Disable the warning if xtree is
791 if (!msvs_xtree_patched &&
792 exec_script("../../win_is_xtree_patched.py", [], "value") == 0) {
793 cflags += [ "/wd4702" ] # Unreachable code.
796 # Common GCC warning setup.
799 "-Wendif-labels", # Weird old-style text after an #endif.
800 "-Werror", # Warnings as errors.
803 "-Wno-missing-field-initializers", # "struct foo f = {0};"
804 "-Wno-unused-parameter", # Unused function parameters.
809 cflags += [ "-Wnewline-eof" ]
814 # This warns on using ints as initializers for floats in
815 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
816 # which happens in several places in chrome code. Not sure if
817 # this is worth fixing.
818 "-Wno-c++11-narrowing",
820 # Don't die on dtoa code that uses a char as an array index.
821 # This is required solely for base/third_party/dmg_fp/dtoa.cc.
822 # TODO(brettw) move this to that project then!
823 "-Wno-char-subscripts",
825 # Warns on switches on enums that cover all enum values but
826 # also contain a default: branch. Chrome is full of that.
827 "-Wno-covered-switch-default",
829 # Clang considers the `register` keyword as deprecated, but e.g.
830 # code generated by flex (used in angle) contains that keyword.
831 # http://crbug.com/255186
832 "-Wno-deprecated-register",
834 # TODO(thakis): This used to be implied by -Wno-unused-function,
835 # which we no longer use. Check if it makes sense to remove
836 # this as well. http://crbug.com/316352
837 "-Wno-unneeded-internal-declaration",
839 # TODO(thakis): Remove, http://crbug.com/263960
840 "-Wno-reserved-user-defined-literal",
843 # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost
844 # always have different versions. Certain flags may not be recognized by
845 # one version or the other.
847 # Flags NaCl does not recognize.
849 # TODO(hans): Get this cleaned up.
850 "-Wno-inconsistent-missing-override",
854 if (gcc_version >= 48) {
856 # See comment for -Wno-c++11-narrowing.
859 # TODO(thakis): Remove, http://crbug.com/263960
860 "-Wno-literal-suffix",
864 # Suppress warnings about ABI changes on ARM (Clang doesn't give this
866 if (current_cpu == "arm" && !is_clang) {
867 cflags += [ "-Wno-psabi" ]
871 # Disable any additional warnings enabled by the Android build system but
872 # which chromium does not build cleanly with (when treating warning as
876 "-Wno-ignored-qualifiers",
880 # Disabling c++0x-compat should be handled in WebKit, but
881 # this currently doesn't work because gcc_version is not set
882 # correctly when building with the Android build system.
883 # TODO(torne): Fix this in WebKit.
884 "-Wno-error=c++0x-compat",
886 # Other things unrelated to -Wextra:
887 "-Wno-non-virtual-dtor",
892 if (gcc_version >= 48) {
893 # Don't warn about the "typedef 'foo' locally defined but not used"
895 # TODO: remove this flag once all builds work. See crbug.com/227506
896 cflags += [ "-Wno-unused-local-typedefs" ]
901 # This will generate warnings when using Clang if code generates exit-time
902 # destructors, which will slow down closing the program.
903 # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600
904 config("wexit_time_destructors") {
906 cflags = [ "-Wexit-time-destructors" ]
910 # On Windows compiling on x64, VC will issue a warning when converting
911 # size_t to int because it will truncate the value. Our code should not have
912 # these warnings and one should use a static_cast or a checked_cast for the
913 # conversion depending on the case. However, a lot of code still needs to be
914 # fixed. Apply this config to such targets to disable the warning.
916 # Note that this can be applied regardless of platform and architecture to
917 # clean up the call sites. This will only apply the flag when necessary.
919 # TODO(jschuh): crbug.com/167187 fix this and delete this config.
920 config("no_size_t_to_int_warning") {
921 if (is_win && current_cpu == "x64") {
922 cflags = [ "/wd4267" ]
926 # Optimization -----------------------------------------------------------------
928 # Note that BUILDCONFIG.gn sets up a variable "default_optimization_config"
929 # which it will assign to the config it implicitly applies to every target. If
930 # you want to override the optimization level for your target, remove this
931 # config (which will expand differently for debug or release builds), and then
932 # add back the one you want to override it with:
934 # configs -= default_optimization_config
935 # configs += [ "//build/config/compiler/optimize_max" ]
937 # Shared settings for both "optimize" and "optimize_max" configs.
939 common_optimize_on_cflags = [
941 "/Ob2", # both explicit and auto inlining.
942 "/Oy-", # disable omitting frame pointers, must be after /o2.
943 "/Os", # favor size over speed.
946 common_optimize_on_cflags += [
947 # Put data in separate COMDATs. This allows the linker
948 # to put bit-identical constants at the same address even if
949 # they're unrelated constants, which saves binary size.
950 # This optimization can't be used when ASan is enabled because
951 # it is not compatible with the ASan ODR checker.
955 common_optimize_on_ldflags = [ "/OPT:REF" ]
957 common_optimize_on_cflags = [
958 # Don't emit the GCC version ident directives, they just end up in the
959 # .comment section taking up binary size.
962 # Put data and code in their own sections, so that unused symbols
963 # can be removed at link time with --gc-sections.
965 "-ffunction-sections",
967 common_optimize_on_ldflags = []
970 if (!using_sanitizer) {
971 common_optimize_on_cflags += [ "-fomit-frame-pointer" ]
974 # TODO(jdduke) Re-enable on mips after resolving linking
975 # issues with libc++ (crbug.com/456380).
976 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
977 common_optimize_on_ldflags += [
978 # Warn in case of text relocations.
979 "-Wl,--warn-shared-textrel",
985 if (symbol_level == 2) {
986 # Mac dead code stripping requires symbols.
987 common_optimize_on_ldflags += [ "-Wl,-dead_strip" ]
990 # Non-Mac Posix linker flags.
991 common_optimize_on_ldflags += [
992 # Specifically tell the linker to perform optimizations.
993 # See http://lwn.net/Articles/192624/ .
998 if (!using_sanitizer) {
999 # Functions interposed by the sanitizers can make ld think
1000 # that some libraries aren't needed when they actually are,
1001 # http://crbug.com/234010. As workaround, disable --as-needed.
1002 common_optimize_on_ldflags += [ "-Wl,--as-needed" ]
1007 # Default "optimization on" config. On Windows, this favors size over speed.
1008 config("optimize") {
1009 cflags = common_optimize_on_cflags
1010 ldflags = common_optimize_on_ldflags
1012 cflags += [ "/Os" ] # favor size over speed.
1013 } else if (is_android || is_ios) {
1014 cflags += [ "-Os" ] # Favor size over speed.
1020 # Turn off optimizations.
1021 config("no_optimize") {
1024 "/Od", # Disable optimization.
1025 "/Ob0", # Disable all inlining (on by default).
1026 "/RTC1", # Runtime checks for stack frame and uninitialized variables.
1028 } else if (is_android && !android_full_debug) {
1029 # On Android we kind of optimize some things that don't affect debugging
1030 # much even when optimization is disabled to get the binary size down.
1034 "-ffunction-sections",
1036 if (!using_sanitizer) {
1037 cflags += [ "-fomit-frame-pointer" ]
1039 ldflags = common_optimize_on_ldflags
1045 # Turns up the optimization level. On Windows, this implies whole program
1046 # optimization and link-time code generation which is very expensive and should
1047 # be used sparingly.
1048 config("optimize_max") {
1049 cflags = common_optimize_on_cflags
1050 ldflags = common_optimize_on_ldflags
1053 cflags += [ "/Ot" ] # Favor speed over size.
1054 if (is_official_build) {
1055 # TODO(GYP): TODO(dpranke): Should these only be on in an official
1056 # build, or on all the time? For now we'll require official build so
1057 # that the compile is clean.
1059 "/GL", # Whole program optimization.
1061 # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds.
1062 # Probably anything that this would catch that wouldn't be caught in a
1063 # normal build isn't going to actually be a bug, so the incremental
1064 # value of C4702 for PGO builds is likely very small.
1067 ldflags += [ "/LTCG" ]
1074 # Symbols ----------------------------------------------------------------------
1078 import("//build/toolchain/goma.gni")
1080 cflags = [ "/Z7" ] # No PDB file
1082 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
1084 ldflags = [ "/DEBUG" ]
1087 if (use_debug_fission) {
1088 cflags += [ "-gsplit-dwarf" ]
1093 config("minimal_symbols") {
1095 # Linker symbols for backtraces only.
1096 ldflags = [ "/DEBUG" ]
1099 if (use_debug_fission) {
1100 cflags += [ "-gsplit-dwarf" ]
1105 config("no_symbols") {