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 # Whether the VS xtree header has been patched to disable warning 4702. If
54 # it has, then we don't need to disable 4702 (unreachable code warning).
55 # The patch is preapplied to the internal toolchain and hence all bots.
56 msvs_xtree_patched = false
60 # default_include_dirs ---------------------------------------------------------
62 # This is a separate config so that third_party code (which would not use the
63 # source root and might have conflicting versions of some headers) can remove
64 # this and specify their own include paths.
65 config("default_include_dirs") {
72 # TODO(GYP): is_ubsan, is_ubsan_vptr
74 using_sanitizer = is_asan || is_lsan || is_tsan || is_msan
77 # compiler ---------------------------------------------------------------------
79 # Base compiler configuration.
81 # See also "runtime_library" below for related stuff and a discussion about
82 # where stuff should go. Put warning related stuff in the "warnings" config.
91 # In general, Windows is totally different, but all the other builds share
92 # some common GCC configuration. This section sets up Windows and the common
93 # GCC flags, and then we handle the other non-Windows platforms specifically
96 # Windows compiler flags setup.
97 # -----------------------------
99 "/Gy", # Enable function-level linking.
100 "/GS", # Enable buffer security checking.
101 "/FS", # Preserve previous PDB behavior.
104 # Common GCC compiler flags setup.
105 # --------------------------------
106 cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204
108 "-fno-threadsafe-statics",
110 # Not exporting C++ inline functions can generally be applied anywhere
111 # so we do so here. Normal function visibility is controlled by
112 # //build/config/gcc:symbol_visibility_hidden.
113 "-fvisibility-inlines-hidden",
118 cflags += [ "-fstack-protector-all" ]
119 } else if (is_linux) {
122 "--param=ssp-buffer-size=4",
127 if (!(is_chromeos && current_cpu == "arm") && !is_mac) {
128 # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580
129 ldflags += [ "-Wl,--fatal-warnings" ]
132 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer and
134 if (using_sanitizer) {
136 "-fno-omit-frame-pointer",
137 "-gline-tables-only",
141 cflags += [ "-fsanitize=address" ]
143 cflags += [ "-mllvm -asan-globals=0" ] # http://crbug.com/352073
144 # TODO(GYP): deal with mac_bundles.
149 if (is_clang && is_debug) {
150 # Allow comparing the address of references and 'this' against 0
151 # in debug builds. Technically, these can never be null in
152 # well-defined C/C++ and Clang can optimize such checks away in
153 # release builds, but they may be used in asserts in debug builds.
155 "-Wno-undefined-bool-conversion",
156 "-Wno-tautological-undefined-compare",
160 if (is_clang && !is_win && !is_nacl) {
161 # This is here so that all files get recompiled after a clang roll and
162 # when turning clang on or off. (defines are passed via the command line,
163 # and build system rebuild things when their commandline changes). Nothing
164 # should ever read this define.
165 defines += [ "CR_CLANG_REVISION=" +
166 exec_script("//tools/clang/scripts/posix-print-revision.py",
171 # Mac-specific compiler flags setup.
172 # ----------------------------------
173 if (is_mac || is_ios) {
174 # These flags are shared between the C compiler and linker.
175 common_mac_flags = []
178 if (current_cpu == "x64") {
179 common_mac_flags += [
183 } else if (current_cpu == "x86") {
184 common_mac_flags += [
190 cflags += common_mac_flags
192 # Without this, the constructors and destructors of a C++ object inside
193 # an Objective C struct won't be called, which is very bad.
194 cflags_objcc = [ "-fobjc-call-cxx-cdtors" ]
196 cflags_c += [ "-std=c99" ]
197 cflags_cc += [ "-std=gnu++11" ]
199 ldflags += common_mac_flags
200 } else if (is_posix) {
201 # Non-Mac Posix compiler flags setup.
202 # -----------------------------------
203 if (gcc_version >= 48) {
204 cflags_cc += [ "-std=gnu++11" ]
207 if (enable_profiling && !is_debug) {
208 # The GYP build spams this define into every compilation unit, as we do
209 # here, but it only appears to be used in base and a couple other places.
210 # TODO(abarth): Should we move this define closer to where it's used?
211 defines += [ "ENABLE_PROFILING" ]
214 "-fno-omit-frame-pointer",
218 if (enable_full_stack_frames_for_profiling) {
221 "-fno-optimize-sibling-calls",
226 # CPU architecture. We may or may not be doing a cross compile now, so for
227 # simplicity we always explicitly set the architecture.
228 if (current_cpu == "x64") {
233 ldflags += [ "-m64" ]
234 } else if (current_cpu == "x86") {
236 ldflags += [ "-m32" ]
239 # Else building libyuv gives clang's register allocator issues,
240 # see llvm.org/PR15798 / crbug.com/233709
241 "-momit-leaf-frame-pointer",
243 # Align the stack on 16-byte boundaries, http://crbug.com/418554.
244 "-mstack-alignment=16",
248 } else if (current_cpu == "arm") {
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.
277 } else if (current_cpu == "mipsel") {
278 if (mips_arch_variant == "r6") {
289 } else if (mips_arch_variant == "r2") {
294 if (mips_float_abi == "hard" && mips_fpu_mode != "") {
295 cflags += [ "-m$mips_fpu_mode" ]
297 } else if (mips_arch_variant == "r1") {
304 if (mips_dsp_rev == 1) {
305 cflags += [ "-mdsp" ]
306 } else if (mips_dsp_rev == 2) {
307 cflags += [ "-mdspr2" ]
310 cflags += [ "-m${mips_float_abi}-float" ]
311 } else if (current_cpu == "mips64el") {
312 if (mips_arch_variant == "r6") {
317 ldflags += [ "-mips64r6" ]
318 } else if (mips_arch_variant == "r2") {
323 ldflags += [ "-mips64r2" ]
327 defines += [ "_FILE_OFFSET_BITS=64" ]
332 "_LARGEFILE64_SOURCE",
336 # Omit unwind support in official builds to save space. We can use breakpad
338 if (is_chrome_branded && is_official_build) {
340 "-fno-unwind-tables",
341 "-fno-asynchronous-unwind-tables",
344 cflags += [ "-funwind-tables" ]
348 # Linux/Android common flags setup.
349 # ---------------------------------
350 if (is_linux || is_android) {
353 "-pipe", # Use pipes for communicating between sub-processes. Faster.
358 "-Wl,-z,noexecstack",
362 if (!using_sanitizer) {
363 ldflags += [ "-Wl,-z,defs" ]
367 # Linux-specific compiler flags setup.
368 # ------------------------------------
370 cflags += [ "-pthread" ]
371 ldflags += [ "-pthread" ]
374 gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
379 # Newer gccs and clangs support -fuse-ld, use the flag to force gold
381 # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html
384 # TODO(brettw) common.gypi has this only for target toolset.
387 # Experimentation found that using four linking threads
388 # saved ~20% of link time.
389 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
390 # Only apply this to the target linker, since the host
391 # linker might not be gold, but isn't used much anyway.
392 # TODO(raymes): Disable threading because gold is frequently
393 # crashing on the bots: crbug.com/161942.
395 #"-Wl,--thread-count=4",
398 # TODO(thestig): Make this flag work with GN.
399 #if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan || is_msan)) {
401 # "-Wl,--detect-odr-violations",
406 if (linux_use_bundled_binutils) {
407 binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
409 cflags += [ "-B$binutils_path" ]
412 # Clang-specific compiler flags setup.
413 # ------------------------------------
415 cflags += [ "-fcolor-diagnostics" ]
416 cflags_cc += [ "-std=gnu++11" ]
419 # Android-specific flags setup.
420 # -----------------------------
423 "-ffunction-sections",
428 # Clang doesn't support these flags.
429 cflags += [ "-finline-limit=64" ]
432 # Android build relies on -Wl,--gc-sections removing unreachable code.
433 # ASan instrumentation for globals inhibits this and results in a library
434 # with unresolvable relocations.
435 # TODO(eugenis): find a way to reenable this.
436 cflags += [ "-mllvm -asan-globals=0" ]
439 defines += [ "ANDROID" ]
441 # The NDK has these things, but doesn't define the constants
442 # to say that it does. Define them here instead.
443 defines += [ "HAVE_SYS_UIO_H" ]
445 # Use gold for Android for most CPU architectures.
446 if (current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm") {
447 ldflags += [ "-fuse-ld=gold" ]
449 # Let clang find the ld.gold in the NDK.
450 ldflags += [ "--gcc-toolchain=" +
451 rebase_path(android_toolchain_root, root_build_dir) ]
456 "-Wl,--no-undefined",
458 # Don't allow visible symbols from libgcc or stlport to be
460 "-Wl,--exclude-libs=libgcc.a",
461 "-Wl,--exclude-libs=libstlport_static.a",
463 # Don't allow visible symbols from libraries that contain
464 # assembly code with symbols that aren't hidden properly.
465 # http://crbug.com/448386
466 "-Wl,--exclude-libs=libvpx_assembly_arm.a",
468 if (current_cpu == "arm") {
470 # Enable identical code folding to reduce size.
476 if (current_cpu == "arm") {
477 cflags += [ "-target arm-linux-androideabi" ]
478 ldflags += [ "-target arm-linux-androideabi" ]
479 } else if (current_cpu == "x86") {
480 cflags += [ "-target x86-linux-androideabi" ]
481 ldflags += [ "-target x86-linux-androideabi" ]
487 config("compiler_arm_fpu") {
488 if (current_cpu == "arm") {
489 cflags = [ "-mfpu=$arm_fpu" ]
493 # runtime_library -------------------------------------------------------------
495 # Sets the runtime library and associated options.
497 # How do you determine what should go in here vs. "compiler" above? Consider if
498 # a target might choose to use a different runtime library (ignore for a moment
499 # if this is possible or reasonable on your system). If such a target would want
500 # to change or remove your option, put it in the runtime_library config. If a
501 # target wants the option regardless, put it in the compiler config.
503 config("runtime_library") {
510 if (is_component_build) {
511 # Component mode: dynamic CRT.
512 defines += [ "COMPONENT_BUILD" ]
514 # Since the library is shared, it requires exceptions or will give errors
515 # about things not matching, so keep exceptions on.
537 "_CRT_SECURE_NO_DEPRECATE",
539 "_SCL_SECURE_NO_DEPRECATE",
543 # Stlport setup. Android uses a different (smaller) version of the STL.
546 # Work around incompatibilities between bionic and clang headers.
548 "__compiler_offsetof=__builtin_offsetof",
555 "_STLP_USE_PTR_SPECIALIZATIONS=1",
556 "__GNU_SOURCE=1", # Necessary for clone().
559 # TODO(jdduke) Re-enable on mips after resolving linking
560 # issues with libc++ (crbug.com/456380).
561 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
562 ldflags += [ "-Wl,--warn-shared-textrel" ]
564 ldflags += [ "-nostdlib" ]
566 # NOTE: The stlport header include paths below are specified in cflags
567 # rather than include_dirs because they need to come after include_dirs.
568 # Think of them like system headers, but don't use '-isystem' because the
569 # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit
570 # strange errors. The include ordering here is important; change with
572 android_stlport_root = "$android_ndk_root/sources/cxx-stl/stlport"
574 cflags += [ "-isystem" +
575 rebase_path("$android_stlport_root/stlport", root_build_dir) ]
576 lib_dirs += [ "$android_stlport_root/libs/$android_app_abi" ]
578 if (component_mode == "shared_library") {
579 libs += [ "stlport_shared" ]
581 libs += [ "stlport_static" ]
584 if (current_cpu == "mipsel") {
586 # ld linker is used for mips Android, and ld does not accept library
587 # absolute path prefixed by "-l"; Since libgcc does not exist in mips
588 # sysroot the proper library will be linked.
589 # TODO(gordanac): Remove once gold linker is used for mips Android.
594 # Manually link the libgcc.a that the cross compiler uses. This is
595 # absolute because the linker will look inside the sysroot if it's not.
596 rebase_path(android_libgcc_file),
608 # chromium_code ---------------------------------------------------------------
610 # Toggles between higher and lower warnings for code that is (or isn't)
613 config("chromium_code") {
615 cflags = [ "/W4" ] # Warning level 4.
620 # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't,
621 # so we specify it explicitly.
622 # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it.
623 # http://code.google.com/p/chromium/issues/detail?id=90453
627 # In Chromium code, we define __STDC_foo_MACROS in order to get the
628 # C99 macros on Mac and Linux.
630 "__STDC_CONSTANT_MACROS",
631 "__STDC_FORMAT_MACROS",
635 config("no_chromium_code") {
642 "/W3", # Warning level 3.
643 "/wd4800", # Disable warning when forcing value to bool.
644 "/wd4267", # TODO(jschuh): size_t to int.
645 "/wd4996", # Deprecated function warning.
648 "_CRT_NONSTDC_NO_WARNINGS",
649 "_CRT_NONSTDC_NO_DEPRECATE",
654 # Don't warn about ignoring the return value from e.g. close(). This is
655 # off by default in some gccs but on by default in others. BSD systems do
656 # not support this option, since they are usually using gcc 4.2.1, which
657 # does not have this flag yet.
658 cflags += [ "-Wno-unused-result" ]
661 if (is_linux || is_android) {
663 # Don't warn about printf format problems. This is off by default in gcc
664 # but on in Ubuntu's gcc(!).
668 # Don't warn about hash_map in third-party code.
674 # rtti ------------------------------------------------------------------------
676 # Allows turning Run-Time Type Identification on or off.
680 cflags_cc = [ "/GR" ]
685 cflags_cc = [ "/GR-" ]
687 cflags_cc = [ "-fno-rtti" ]
691 # Warnings ---------------------------------------------------------------------
693 # This is where we disable various warnings that we've decided aren't
694 # worthwhile, and enable special warnings.
696 config("default_warnings") {
699 "/WX", # Treat warnings as errors.
701 # Warnings permanently disabled:
703 # TODO(GYP) The GYP build doesn't have this globally enabled but disabled
704 # for a bunch of individual targets. Re-enable this globally when those
706 "/wd4018", # Comparing signed and unsigned values.
708 # C4127: conditional expression is constant
709 # This warning can in theory catch dead code and other problems, but
710 # triggers in far too many desirable cases where the conditional
711 # expression is either set by macros or corresponds some legitimate
712 # compile-time constant expression (due to constant template args,
713 # conditionals comparing the sizes of different types, etc.). Some of
714 # these can be worked around, but it's not worth it.
717 # C4251: 'identifier' : class 'type' needs to have dll-interface to be
718 # used by clients of class 'type2'
719 # This is necessary for the shared library build.
722 # C4351: new behavior: elements of array 'array' will be default
724 # This is a silly "warning" that basically just alerts you that the
725 # compiler is going to actually follow the language spec like it's
726 # supposed to, instead of not following it like old buggy versions did.
727 # There's absolutely no reason to turn this on.
730 # C4355: 'this': used in base member initializer list
731 # It's commonly useful to pass |this| to objects in a class' initializer
732 # list. While this warning can catch real bugs, most of the time the
733 # constructors in question don't attempt to call methods on the passed-in
734 # pointer (until later), and annotating every legit usage of this is
735 # simply more hassle than the warning is worth.
738 # C4503: 'identifier': decorated name length exceeded, name was
740 # This only means that some long error messages might have truncated
741 # identifiers in the presence of lots of templates. It has no effect on
742 # program correctness and there's no real reason to waste time trying to
746 # C4611: interaction between 'function' and C++ object destruction is
748 # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN
749 # suggests using exceptions instead of setjmp/longjmp for C++, but
750 # Chromium code compiles without exception support. We therefore have to
751 # use setjmp/longjmp for e.g. JPEG decode error handling, which means we
752 # have to turn off this warning (and be careful about how object
753 # destruction happens in such cases).
756 # Warnings to evaluate and possibly fix/reenable later:
758 "/wd4100", # Unreferenced formal function parameter.
759 "/wd4121", # Alignment of a member was sensitive to packing.
760 "/wd4244", # Conversion: possible loss of data.
761 "/wd4481", # Nonstandard extension: override specifier.
762 "/wd4505", # Unreferenced local function has been removed.
763 "/wd4510", # Default constructor could not be generated.
764 "/wd4512", # Assignment operator could not be generated.
765 "/wd4610", # Class can never be instantiated, constructor required.
766 "/wd4996", # Deprecated function warning.
769 # VS xtree header file needs to be patched or 4702 (unreachable code
770 # warning) is reported if _HAS_EXCEPTIONS=0. Disable the warning if xtree is
772 if (!msvs_xtree_patched &&
773 exec_script("../../win_is_xtree_patched.py", [], "value") == 0) {
774 cflags += [ "/wd4702" ] # Unreachable code.
777 # Common GCC warning setup.
780 "-Wendif-labels", # Weird old-style text after an #endif.
781 "-Werror", # Warnings as errors.
784 "-Wno-missing-field-initializers", # "struct foo f = {0};"
785 "-Wno-unused-parameter", # Unused function parameters.
790 cflags += [ "-Wnewline-eof" ]
795 # This warns on using ints as initializers for floats in
796 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
797 # which happens in several places in chrome code. Not sure if
798 # this is worth fixing.
799 "-Wno-c++11-narrowing",
801 # Don't die on dtoa code that uses a char as an array index.
802 # This is required solely for base/third_party/dmg_fp/dtoa.cc.
803 # TODO(brettw) move this to that project then!
804 "-Wno-char-subscripts",
806 # Warns on switches on enums that cover all enum values but
807 # also contain a default: branch. Chrome is full of that.
808 "-Wno-covered-switch-default",
810 # Clang considers the `register` keyword as deprecated, but e.g.
811 # code generated by flex (used in angle) contains that keyword.
812 # http://crbug.com/255186
813 "-Wno-deprecated-register",
815 # TODO(thakis): This used to be implied by -Wno-unused-function,
816 # which we no longer use. Check if it makes sense to remove
817 # this as well. http://crbug.com/316352
818 "-Wno-unneeded-internal-declaration",
820 # TODO(thakis): Remove, http://crbug.com/263960
821 "-Wno-reserved-user-defined-literal",
824 # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost
825 # always have different versions. Certain flags may not be recognized by
826 # one version or the other.
828 # Flags NaCl does not recognize.
830 # TODO(hans): Get this cleaned up.
831 "-Wno-inconsistent-missing-override",
835 if (gcc_version >= 48) {
837 # See comment for -Wno-c++11-narrowing.
840 # TODO(thakis): Remove, http://crbug.com/263960
841 "-Wno-literal-suffix",
845 # Suppress warnings about ABI changes on ARM (Clang doesn't give this
847 if (current_cpu == "arm" && !is_clang) {
848 cflags += [ "-Wno-psabi" ]
852 # Disable any additional warnings enabled by the Android build system but
853 # which chromium does not build cleanly with (when treating warning as
857 "-Wno-ignored-qualifiers",
861 # Disabling c++0x-compat should be handled in WebKit, but
862 # this currently doesn't work because gcc_version is not set
863 # correctly when building with the Android build system.
864 # TODO(torne): Fix this in WebKit.
865 "-Wno-error=c++0x-compat",
867 # Other things unrelated to -Wextra:
868 "-Wno-non-virtual-dtor",
873 if (gcc_version >= 48) {
874 # Don't warn about the "typedef 'foo' locally defined but not used"
876 # TODO: remove this flag once all builds work. See crbug.com/227506
877 cflags += [ "-Wno-unused-local-typedefs" ]
882 # This will generate warnings when using Clang if code generates exit-time
883 # destructors, which will slow down closing the program.
884 # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600
885 config("wexit_time_destructors") {
887 cflags = [ "-Wexit-time-destructors" ]
891 # On Windows compiling on x64, VC will issue a warning when converting
892 # size_t to int because it will truncate the value. Our code should not have
893 # these warnings and one should use a static_cast or a checked_cast for the
894 # conversion depending on the case. However, a lot of code still needs to be
895 # fixed. Apply this config to such targets to disable the warning.
897 # Note that this can be applied regardless of platform and architecture to
898 # clean up the call sites. This will only apply the flag when necessary.
900 # TODO(jschuh): crbug.com/167187 fix this and delete this config.
901 config("no_size_t_to_int_warning") {
902 if (is_win && current_cpu == "x64") {
903 cflags = [ "/wd4267" ]
907 # Optimization -----------------------------------------------------------------
909 # Note that BUILDCONFIG.gn sets up a variable "default_optimization_config"
910 # which it will assign to the config it implicitly applies to every target. If
911 # you want to override the optimization level for your target, remove this
912 # config (which will expand differently for debug or release builds), and then
913 # add back the one you want to override it with:
915 # configs -= default_optimization_config
916 # configs += [ "//build/config/compiler/optimize_max" ]
918 # Shared settings for both "optimize" and "optimize_max" configs.
920 common_optimize_on_cflags = [
922 "/Ob2", # both explicit and auto inlining.
923 "/Oy-", # disable omitting frame pointers, must be after /o2.
924 "/Os", # favor size over speed.
927 common_optimize_on_cflags += [
928 # Put data in separate COMDATs. This allows the linker
929 # to put bit-identical constants at the same address even if
930 # they're unrelated constants, which saves binary size.
931 # This optimization can't be used when ASan is enabled because
932 # it is not compatible with the ASan ODR checker.
936 common_optimize_on_ldflags = [ "/OPT:REF" ]
938 common_optimize_on_cflags = [
939 # Don't emit the GCC version ident directives, they just end up in the
940 # .comment section taking up binary size.
943 # Put data and code in their own sections, so that unused symbols
944 # can be removed at link time with --gc-sections.
946 "-ffunction-sections",
948 common_optimize_on_ldflags = []
951 if (!using_sanitizer) {
952 common_optimize_on_cflags += [ "-fomit-frame-pointer" ]
955 # TODO(jdduke) Re-enable on mips after resolving linking
956 # issues with libc++ (crbug.com/456380).
957 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
958 common_optimize_on_ldflags += [
959 # Warn in case of text relocations.
960 "-Wl,--warn-shared-textrel",
966 if (symbol_level == 2) {
967 # Mac dead code stripping requires symbols.
968 common_optimize_on_ldflags += [ "-Wl,-dead_strip" ]
971 # Non-Mac Posix linker flags.
972 common_optimize_on_ldflags += [
973 # Specifically tell the linker to perform optimizations.
974 # See http://lwn.net/Articles/192624/ .
979 if (!using_sanitizer) {
980 # Functions interposed by the sanitizers can make ld think
981 # that some libraries aren't needed when they actually are,
982 # http://crbug.com/234010. As workaround, disable --as-needed.
983 common_optimize_on_ldflags += [ "-Wl,--as-needed" ]
988 # Default "optimization on" config. On Windows, this favors size over speed.
990 cflags = common_optimize_on_cflags
991 ldflags = common_optimize_on_ldflags
993 cflags += [ "/Os" ] # favor size over speed.
994 } else if (is_android || is_ios) {
995 cflags += [ "-Os" ] # Favor size over speed.
1001 # Turn off optimizations.
1002 config("no_optimize") {
1005 "/Od", # Disable optimization.
1006 "/Ob0", # Disable all inlining (on by default).
1007 "/RTC1", # Runtime checks for stack frame and uninitialized variables.
1009 } else if (is_android && !android_full_debug) {
1010 # On Android we kind of optimize some things that don't affect debugging
1011 # much even when optimization is disabled to get the binary size down.
1015 "-ffunction-sections",
1017 if (!using_sanitizer) {
1018 cflags += [ "-fomit-frame-pointer" ]
1020 ldflags = common_optimize_on_ldflags
1026 # Turns up the optimization level. On Windows, this implies whole program
1027 # optimization and link-time code generation which is very expensive and should
1028 # be used sparingly.
1029 config("optimize_max") {
1030 cflags = common_optimize_on_cflags
1031 ldflags = common_optimize_on_ldflags
1034 cflags += [ "/Ot" ] # Favor speed over size.
1035 if (is_official_build) {
1036 # TODO(GYP): TODO(dpranke): Should these only be on in an official
1037 # build, or on all the time? For now we'll require official build so
1038 # that the compile is clean.
1040 "/GL", # Whole program optimization.
1042 # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds.
1043 # Probably anything that this would catch that wouldn't be caught in a
1044 # normal build isn't going to actually be a bug, so the incremental
1045 # value of C4702 for PGO builds is likely very small.
1048 ldflags += [ "/LTCG" ]
1055 # Symbols ----------------------------------------------------------------------
1059 import("//build/toolchain/goma.gni")
1061 cflags = [ "/Z7" ] # No PDB file
1063 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
1065 ldflags = [ "/DEBUG" ]
1068 if (use_debug_fission) {
1069 cflags += [ "-gsplit-dwarf" ]
1074 config("minimal_symbols") {
1076 # Linker symbols for backtraces only.
1077 ldflags = [ "/DEBUG" ]
1080 if (use_debug_fission) {
1081 cflags += [ "-gsplit-dwarf" ]
1086 config("no_symbols") {