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 import("//build/config/compiler/compiler.gni")
8 import("//build/toolchain/ccache.gni")
10 if (current_cpu == "arm") {
11 import("//build/config/arm.gni")
13 if (current_cpu == "mipsel" || current_cpu == "mips64el") {
14 import("//build/config/mips.gni")
17 import("//build/config/gcc/gcc_version.gni")
20 import("//build/config/win/visual_studio_version.gni")
24 # Normally, Android builds are lightly optimized, even for debug builds, to
25 # keep binary size down. Setting this flag to true disables such optimization
26 android_full_debug = false
28 # Whether to use the binary binutils checked into third_party/binutils.
29 # These are not multi-arch so cannot be used except on x86 and x86-64 (the
30 # only two architectures that are currently checked in). Turn this off when
31 # you are using a custom toolchain and need to control -B in cflags.
32 linux_use_bundled_binutils = is_linux && current_cpu == "x64"
33 binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
36 # Compile in such a way as to enable profiling of the generated code. For
37 # example, don't omit the frame pointer and leave in symbols.
38 enable_profiling = false
40 # Compile in such a way as to make it possible for the profiler to unwind full
41 # stack frames. Setting this flag has a large effect on the performance of the
42 # generated code than just setting profiling, but gives the profiler more
43 # information to analyze.
44 # Requires profiling to be set to true.
45 enable_full_stack_frames_for_profiling = false
47 # Use 64-bit gold for linking on both 64-bit Linux and 32-bit linux;
48 # 32-bit Gold runs out of address-space on 32-bit bit builds.
49 use_gold = is_linux && (current_cpu == "x64" || current_cpu == "x86")
51 # When we are going to use gold we need to find it.
53 gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
59 # use_debug_fission: whether to use split DWARF debug info
60 # files. This can reduce link time significantly, but is incompatible
61 # with some utilities such as icecc and ccache. Requires gold and
62 # gcc >= 4.8 or clang.
63 # http://gcc.gnu.org/wiki/DebugFission
64 use_debug_fission = is_debug && !is_win && use_gold &&
65 linux_use_bundled_binutils && !use_ccache
68 # Whether the VS xtree header has been patched to disable warning 4702. If
69 # it has, then we don't need to disable 4702 (unreachable code warning).
70 # The patch is preapplied to the internal toolchain and hence all bots.
71 msvs_xtree_patched = false
75 # default_include_dirs ---------------------------------------------------------
77 # This is a separate config so that third_party code (which would not use the
78 # source root and might have conflicting versions of some headers) can remove
79 # this and specify their own include paths.
80 config("default_include_dirs") {
87 # compiler ---------------------------------------------------------------------
89 # Base compiler configuration.
91 # See also "runtime_library" below for related stuff and a discussion about
92 # where stuff should go. Put warning related stuff in the "warnings" config.
103 # In general, Windows is totally different, but all the other builds share
104 # some common GCC configuration. This section sets up Windows and the common
105 # GCC flags, and then we handle the other non-Windows platforms specifically
108 # Windows compiler flags setup.
109 # -----------------------------
111 "/Gy", # Enable function-level linking.
112 "/GS", # Enable buffer security checking.
113 "/FS", # Preserve previous PDB behavior.
114 "/bigobj", # Some of our files are bigger than the regular limits.
117 if (visual_studio_version == "2015") {
118 # Work around crbug.com/526851, bug in VS 2015 RTM compiler.
119 cflags += [ "/Zc:sizedDealloc-" ]
122 # Force C/C++ mode for the given GN detected file type. This is necessary
123 # for precompiled headers where the same source file is compiled in both
125 cflags_c += [ "/TC" ]
126 cflags_cc += [ "/TP" ]
128 # Building with Clang on Windows is a work in progress and very
129 # experimental. See crbug.com/82385.
130 # Keep this in sync with the similar block in build/common.gypi
133 # Many files use intrinsics without including this header.
134 # TODO(hans): Fix those files, or move this to sub-GYPs.
138 if (visual_studio_version == "2013") {
139 cflags += [ "-fmsc-version=1800" ]
140 } else if (visual_studio_version == "2015") {
141 cflags += [ "-fmsc-version=1900" ]
144 if (current_cpu == "x86") {
150 if (exec_script("//build/win/use_ansi_codes.py", [], "trim string") ==
153 # cmd.exe doesn't understand ANSI escape codes by default,
154 # so only enable them if something emulating them is around.
155 "-fansi-escape-codes",
161 # SyzyAsan needs /PROFILE turned on to produce appropriate pdbs.
162 assert(!is_win_fastlink, "/PROFILE and /DEBUG:FASTLINK are incompatible")
163 ldflags += [ "/PROFILE" ]
166 # Common GCC compiler flags setup.
167 # --------------------------------
168 cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204
170 "-fno-threadsafe-statics",
172 # Not exporting C++ inline functions can generally be applied anywhere
173 # so we do so here. Normal function visibility is controlled by
174 # //build/config/gcc:symbol_visibility_hidden.
175 "-fvisibility-inlines-hidden",
180 cflags += [ "-fstack-protector-all" ]
181 } else if (is_posix && !is_chromeos && !is_nacl) {
182 # TODO(phajdan.jr): Use -fstack-protector-strong when our gcc supports it.
183 cflags += [ "--param=ssp-buffer-size=4" ]
184 if (is_android && (current_cpu == "arm64" || current_cpu == "x86")) {
185 cflags += [ "-fno-stack-protector" ]
187 cflags += [ "-fstack-protector" ]
192 if (!(is_chromeos && current_cpu == "arm") && !is_mac && !is_ios) {
193 # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580
194 ldflags += [ "-Wl,--fatal-warnings" ]
197 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer,
198 # MemorySanitizer and non-official CFI builds.
199 if (using_sanitizer || (is_cfi && !is_official_build)) {
201 "-fno-omit-frame-pointer",
202 "-gline-tables-only",
206 asan_blacklist_path =
207 rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir)
209 "-fsanitize=address",
210 "-fsanitize-blacklist=$asan_blacklist_path",
213 cflags += [ "-mllvm -asan-globals=0" ] # http://crbug.com/352073
214 # TODO(GYP): deal with mac_bundles.
218 cflags += [ "-fsanitize=leak" ]
221 tsan_blacklist_path =
222 rebase_path("//tools/memory/tsan_v2/ignores.txt", root_build_dir)
225 "-fsanitize-blacklist=$tsan_blacklist_path",
229 msan_blacklist_path =
230 rebase_path("//tools/msan/blacklist.txt", root_build_dir)
233 "-fsanitize-memory-track-origins=$msan_track_origins",
234 "-fsanitize-blacklist=$msan_blacklist_path",
237 if (is_cfi && !is_nacl) {
239 rebase_path("//tools/cfi/blacklist.txt", root_build_dir)
242 "-fsanitize=cfi-vcall",
243 "-fsanitize=cfi-derived-cast",
244 "-fsanitize=cfi-unrelated-cast",
245 "-fsanitize-blacklist=$cfi_blacklist_path",
249 "-fsanitize=cfi-vcall",
250 "-fsanitize=cfi-derived-cast",
251 "-fsanitize=cfi-unrelated-cast",
254 # Apply a lower LTO optimization level in non-official builds.
255 if (!is_official_build) {
257 ldflags += [ "-Wl,-plugin-opt,O1" ]
259 ldflags += [ "-Wl,-mllvm,-O1" ]
263 # Work-around for http://openradar.appspot.com/20356002
265 ldflags += [ "-Wl,-all_load" ]
268 # Without this flag, LTO produces a .text section that is larger
269 # than the maximum call displacement, preventing the linker from
270 # relocating calls (http://llvm.org/PR22999).
271 if (current_cpu == "arm") {
272 ldflags += [ "-Wl,-plugin-opt,-function-sections" ]
277 "-fno-sanitize-trap=cfi",
278 "-fsanitize-recover=cfi",
281 "-fno-sanitize-trap=cfi",
282 "-fsanitize-recover=cfi",
285 defines += [ "CFI_ENFORCEMENT" ]
289 if (use_custom_libcxx) {
290 cflags_cc += [ "-nostdinc++" ]
292 "//buildtools/third_party/libc++/trunk/include",
293 "//buildtools/third_party/libc++abi/trunk/include",
298 if (is_clang && is_debug) {
299 # Allow comparing the address of references and 'this' against 0
300 # in debug builds. Technically, these can never be null in
301 # well-defined C/C++ and Clang can optimize such checks away in
302 # release builds, but they may be used in asserts in debug builds.
304 "-Wno-undefined-bool-conversion",
305 "-Wno-tautological-undefined-compare",
309 if (is_clang && !is_nacl) {
310 # This is here so that all files get recompiled after a clang roll and
311 # when turning clang on or off. (defines are passed via the command line,
312 # and build system rebuild things when their commandline changes). Nothing
313 # should ever read this define.
315 [ "CR_CLANG_REVISION=" + exec_script("//tools/clang/scripts/update.py",
316 [ "--print-revision" ],
320 # Mac-specific compiler flags setup.
321 # ----------------------------------
322 if (is_mac || is_ios) {
323 # These flags are shared between the C compiler and linker.
324 common_mac_flags = []
327 if (current_cpu == "x64") {
328 common_mac_flags += [
332 } else if (current_cpu == "x86") {
333 common_mac_flags += [
337 } else if (current_cpu == "arm") {
338 # TODO(GYP): we may need to distinguish between "arm64", "armv7",
339 # and "armv7s" for iOS, and hence need multiple current_cpu values
340 # rather than just "arm".
341 common_mac_flags += [
347 cflags += common_mac_flags
349 # Without this, the constructors and destructors of a C++ object inside
350 # an Objective C struct won't be called, which is very bad.
351 cflags_objcc += [ "-fobjc-call-cxx-cdtors" ]
353 cflags_c += [ "-std=c99" ]
355 ldflags += common_mac_flags
356 } else if (is_posix) {
357 # Non-Mac Posix compiler flags setup.
358 # -----------------------------------
359 if (enable_profiling && !is_debug) {
360 # The GYP build spams this define into every compilation unit, as we do
361 # here, but it only appears to be used in base and a couple other places.
362 # TODO(abarth): Should we move this define closer to where it's used?
363 defines += [ "ENABLE_PROFILING" ]
366 "-fno-omit-frame-pointer",
370 if (enable_full_stack_frames_for_profiling) {
373 "-fno-optimize-sibling-calls",
378 # CPU architecture. We may or may not be doing a cross compile now, so for
379 # simplicity we always explicitly set the architecture.
380 if (current_cpu == "x64") {
385 ldflags += [ "-m64" ]
386 } else if (current_cpu == "x86") {
388 ldflags += [ "-m32" ]
391 # Else building libyuv gives clang's register allocator issues,
392 # see llvm.org/PR15798 / crbug.com/233709
393 "-momit-leaf-frame-pointer",
395 # Align the stack on 16-byte boundaries, http://crbug.com/418554.
396 "-mstack-alignment=16",
400 } else if (current_cpu == "arm") {
404 "-mfloat-abi=$arm_float_abi",
407 cflags += [ "-mthumb" ]
408 if (is_android && !is_clang) {
409 # Clang doesn't support this option.
410 cflags += [ "-mthumb-interwork" ]
414 if (arm_tune != "") {
415 cflags += [ "-mtune=$arm_tune" ]
418 # Clang doesn't support these flags.
420 # The tree-sra optimization (scalar replacement for
421 # aggregates enabling subsequent optimizations) leads to
422 # invalid code generation when using the Android NDK's
423 # compiler (r5-r7). This can be verified using
424 # webkit_unit_tests' WTF.Checked_int8_t test.
427 # The following option is disabled to improve binary
428 # size and performance in gcc 4.9.
432 } else if (current_cpu == "mipsel") {
433 if (mips_arch_variant == "r6") {
444 } else if (mips_arch_variant == "r2") {
449 if (mips_float_abi == "hard" && mips_fpu_mode != "") {
450 cflags += [ "-m$mips_fpu_mode" ]
452 } else if (mips_arch_variant == "r1") {
459 if (mips_dsp_rev == 1) {
460 cflags += [ "-mdsp" ]
461 } else if (mips_dsp_rev == 2) {
462 cflags += [ "-mdspr2" ]
465 cflags += [ "-m${mips_float_abi}-float" ]
466 } else if (current_cpu == "mips64el") {
467 if (mips_arch_variant == "r6") {
472 ldflags += [ "-mips64r6" ]
473 } else if (mips_arch_variant == "r2") {
478 ldflags += [ "-mips64r2" ]
482 defines += [ "_FILE_OFFSET_BITS=64" ]
487 "_LARGEFILE64_SOURCE",
491 # Omit unwind support in official builds to save space. We can use breakpad
493 if (is_chrome_branded && is_official_build) {
495 "-fno-unwind-tables",
496 "-fno-asynchronous-unwind-tables",
498 defines += [ "NO_UNWIND_TABLES" ]
500 cflags += [ "-funwind-tables" ]
504 # Linux/Android common flags setup.
505 # ---------------------------------
506 if (is_linux || is_android) {
509 "-pipe", # Use pipes for communicating between sub-processes. Faster.
514 "-Wl,-z,noexecstack",
518 if (!using_sanitizer && !use_cfi_diag) {
519 ldflags += [ "-Wl,-z,defs" ]
523 # Linux-specific compiler flags setup.
524 # ------------------------------------
526 cflags += [ "-pthread" ]
527 ldflags += [ "-pthread" ]
533 # Newer gccs and clangs support -fuse-ld, use the flag to force gold
535 # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html
538 # Experimentation found that using four linking threads
539 # saved ~20% of link time.
540 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
541 # Only apply this to the target linker, since the host
542 # linker might not be gold, but isn't used much anyway.
543 # TODO(raymes): Disable threading because gold is frequently
544 # crashing on the bots: crbug.com/161942.
546 #"-Wl,--thread-count=4",
549 if (!is_asan && !is_msan && !is_lsan && !is_tsan) {
550 # TODO(brettw) common.gypi has this only for target toolset.
551 ldflags += [ "-Wl,--icf=all" ]
554 # TODO(thestig): Make this flag work with GN.
555 #if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan || is_msan)) {
557 # "-Wl,--detect-odr-violations",
562 if (linux_use_bundled_binutils) {
563 cflags += [ "-B$binutils_path" ]
566 # Clang-specific compiler flags setup.
567 # ------------------------------------
569 cflags += [ "-fcolor-diagnostics" ]
572 # C++11 compiler flags setup.
573 # ---------------------------
574 if (is_linux || is_android || (is_nacl && is_clang)) {
575 # gnu++11 instead of c++11 is needed because some code uses typeof() (a
577 # TODO(thakis): Eventually switch this to c++11 instead,
578 # http://crbug.com/427584
579 cflags_cc += [ "-std=gnu++11" ]
580 } else if (!is_win && !is_nacl) {
581 # TODO(mcgrathr) - the NaCl GCC toolchain doesn't support either gnu++11
582 # or c++11; we technically don't need this toolchain any more, but there
583 # are still a few buildbots using it, so until those are turned off
584 # we need the !is_nacl clause and the (is_nacl && is_clang) clause, above.
585 cflags_cc += [ "-std=c++11" ]
588 # Android-specific flags setup.
589 # -----------------------------
592 "-ffunction-sections",
597 # Clang doesn't support these flags.
598 cflags += [ "-finline-limit=64" ]
601 rebased_android_toolchain_root =
602 rebase_path(android_toolchain_root, root_build_dir)
603 if (current_cpu == "arm") {
605 # TODO(hans) Enable integrated-as (crbug.com/124610).
607 "-B${rebased_android_toolchain_root}/bin", # Else /usr/bin/as gets picked up.
612 # Android build relies on -Wl,--gc-sections removing unreachable code.
613 # ASan instrumentation for globals inhibits this and results in a library
614 # with unresolvable relocations.
615 # TODO(eugenis): find a way to reenable this.
616 cflags += [ "-mllvm -asan-globals=0" ]
619 defines += [ "ANDROID" ]
621 # The NDK has these things, but doesn't define the constants
622 # to say that it does. Define them here instead.
623 defines += [ "HAVE_SYS_UIO_H" ]
625 # Use gold for Android for most CPU architectures.
626 if (current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm") {
627 ldflags += [ "-fuse-ld=gold" ]
629 # Let clang find the ld.gold in the NDK.
630 ldflags += [ "--gcc-toolchain=$rebased_android_toolchain_root" ]
633 # Use -mstackrealign due to a bug on ia32 Jelly Bean.
634 # See crbug.com/521527
635 if (current_cpu == "x86") {
636 cflags += [ "-mstackrealign" ]
641 "-Wl,--no-undefined",
643 # Don't allow visible symbols from libgcc or libc++ to be
645 "-Wl,--exclude-libs=libgcc.a",
646 "-Wl,--exclude-libs=libc++_static.a",
648 # Don't allow visible symbols from libraries that contain
649 # assembly code with symbols that aren't hidden properly.
650 # http://crbug.com/448386
651 "-Wl,--exclude-libs=libvpx_assembly_arm.a",
653 if (current_cpu == "arm") {
655 # Enable identical code folding to reduce size.
661 if (current_cpu == "arm") {
662 _abi_target = "arm-linux-androideabi"
663 } else if (current_cpu == "x86") {
664 _abi_target = "i686-linux-androideabi"
665 } else if (current_cpu == "arm64") {
666 # Place holder for arm64 support, not tested.
667 _abi_target = "aarch64-linux-androideabi"
668 } else if (current_cpu == "x64") {
669 # Place holder for x64 support, not tested.
670 # TODO: Enable clang support for Android x64. http://crbug.com/346626
671 _abi_target = "x86_64-linux-androideabi"
672 } else if (current_cpu == "mipsel") {
673 # Place holder for mips support, not tested.
674 _abi_target = "mipsel-linux-androideabi"
675 } else if (current_cpu == "mips64el") {
676 # Place holder for mips64 support, not tested.
677 _abi_target = "mips64el-linux-androideabi"
679 assert(false, "Architecture not supported")
692 # Pass the same C/C++ flags to the objective C/C++ compiler.
693 cflags_objc += cflags_c
694 cflags_objcc += cflags_cc
697 config("compiler_arm_fpu") {
698 if (current_cpu == "arm" && !is_ios && !is_nacl) {
699 cflags = [ "-mfpu=$arm_fpu" ]
703 # runtime_library -------------------------------------------------------------
705 # Sets the runtime library and associated options.
707 # How do you determine what should go in here vs. "compiler" above? Consider if
708 # a target might choose to use a different runtime library (ignore for a moment
709 # if this is possible or reasonable on your system). If such a target would want
710 # to change or remove your option, put it in the runtime_library config. If a
711 # target wants the option regardless, put it in the compiler config.
713 config("runtime_library") {
720 if (is_component_build) {
721 # Component mode: dynamic CRT.
722 defines += [ "COMPONENT_BUILD" ]
724 # Since the library is shared, it requires exceptions or will give errors
725 # about things not matching, so keep exceptions on.
733 if (is_win && current_os != "win") {
734 # WindowsRT: use the dynamic CRT.
741 # Desktop Windows: static CRT.
754 "_CRT_SECURE_NO_DEPRECATE",
756 "_SCL_SECURE_NO_DEPRECATE",
760 # Android standard library setup.
763 # Work around incompatibilities between bionic and clang headers.
765 "__compiler_offsetof=__builtin_offsetof",
770 defines += [ "__GNU_SOURCE=1" ] # Necessary for clone().
772 # TODO(jdduke) Re-enable on mips after resolving linking
773 # issues with libc++ (crbug.com/456380).
774 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
775 ldflags += [ "-Wl,--warn-shared-textrel" ]
777 ldflags += [ "-nostdlib" ]
779 # NOTE: The libc++ header include paths below are specified in cflags
780 # rather than include_dirs because they need to come after include_dirs.
781 # Think of them like system headers, but don't use '-isystem' because the
782 # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit
783 # strange errors. The include ordering here is important; change with
787 rebase_path("$android_libcpp_root/libcxx/include", root_build_dir),
788 "-isystem" + rebase_path(
789 "$android_ndk_root/sources/cxx-stl/llvm-libc++abi/libcxxabi/include",
792 rebase_path("$android_ndk_root/sources/android/support/include",
796 lib_dirs += [ "$android_libcpp_root/libs/$android_app_abi" ]
797 libs += [ "$android_libcpp_library" ]
799 if (current_cpu == "mipsel") {
801 # ld linker is used for mips Android, and ld does not accept library
802 # absolute path prefixed by "-l"; Since libgcc does not exist in mips
803 # sysroot the proper library will be linked.
804 # TODO(gordanac): Remove once gold linker is used for mips Android.
809 # Manually link the libgcc.a that the cross compiler uses. This is
810 # absolute because the linker will look inside the sysroot if it's not.
811 rebase_path(android_libgcc_file),
821 # Clang with libc++ does not require an explicit atomic library reference.
828 # default_warning_flags collects all warning flags that are used by default.
829 # This is in a variable instead of a config so that it can be used in
830 # both chromium_code and no_chromium_code. This way these flags are guaranteed
831 # to appear on the compile command line after -Wall.
833 default_warning_flags = []
834 default_warning_flags_cc = []
836 default_warning_flags += [
837 # Treat warnings as errors.
840 # Warnings permanently disabled:
842 # C4127: conditional expression is constant
843 # This warning can in theory catch dead code and other problems, but
844 # triggers in far too many desirable cases where the conditional
845 # expression is either set by macros or corresponds some legitimate
846 # compile-time constant expression (due to constant template args,
847 # conditionals comparing the sizes of different types, etc.). Some of
848 # these can be worked around, but it's not worth it.
851 # C4251: 'identifier' : class 'type' needs to have dll-interface to be
852 # used by clients of class 'type2'
853 # This is necessary for the shared library build.
856 # C4351: new behavior: elements of array 'array' will be default
858 # This is a silly "warning" that basically just alerts you that the
859 # compiler is going to actually follow the language spec like it's
860 # supposed to, instead of not following it like old buggy versions did.
861 # There's absolutely no reason to turn this on.
864 # C4355: 'this': used in base member initializer list
865 # It's commonly useful to pass |this| to objects in a class' initializer
866 # list. While this warning can catch real bugs, most of the time the
867 # constructors in question don't attempt to call methods on the passed-in
868 # pointer (until later), and annotating every legit usage of this is
869 # simply more hassle than the warning is worth.
872 # C4503: 'identifier': decorated name length exceeded, name was
874 # This only means that some long error messages might have truncated
875 # identifiers in the presence of lots of templates. It has no effect on
876 # program correctness and there's no real reason to waste time trying to
880 # Warning C4589 says: "Constructor of abstract class ignores
881 # initializer for virtual base class." Disable this warning because it
882 # is flaky in VS 2015 RTM. It triggers on compiler generated
883 # copy-constructors in some cases.
886 # C4611: interaction between 'function' and C++ object destruction is
888 # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN
889 # suggests using exceptions instead of setjmp/longjmp for C++, but
890 # Chromium code compiles without exception support. We therefore have to
891 # use setjmp/longjmp for e.g. JPEG decode error handling, which means we
892 # have to turn off this warning (and be careful about how object
893 # destruction happens in such cases).
896 # Warnings to evaluate and possibly fix/reenable later:
898 "/wd4100", # Unreferenced formal function parameter.
899 "/wd4121", # Alignment of a member was sensitive to packing.
900 "/wd4244", # Conversion: possible loss of data.
901 "/wd4481", # Nonstandard extension: override specifier.
902 "/wd4505", # Unreferenced local function has been removed.
903 "/wd4510", # Default constructor could not be generated.
904 "/wd4512", # Assignment operator could not be generated.
905 "/wd4610", # Class can never be instantiated, constructor required.
906 "/wd4995", # 'X': name was marked as #pragma deprecated
907 "/wd4996", # Deprecated function warning.
910 # VS xtree header file needs to be patched or 4702 (unreachable code
911 # warning) is reported if _HAS_EXCEPTIONS=0. Disable the warning if xtree is
913 if (!msvs_xtree_patched &&
914 exec_script("../../win_is_xtree_patched.py", [], "value") == 0) {
915 default_warning_flags += [ "/wd4702" ] # Unreachable code.
918 # Building with Clang on Windows is a work in progress and very
919 # experimental. See crbug.com/82385.
920 # Keep this in sync with the similar block in build/common.gypi
922 default_warning_flags += [
923 # TODO(hans): Make this list shorter eventually, http://crbug.com/504657
924 "-Qunused-arguments", # http://crbug.com/504658
925 "-Wno-microsoft-enum-value", # http://crbug.com/505296
926 "-Wno-unknown-pragmas", # http://crbug.com/505314
927 "-Wno-unused-value", # http://crbug.com/505318
931 # Common GCC warning setup.
932 default_warning_flags += [
934 "-Wendif-labels", # Weird old-style text after an #endif.
935 "-Werror", # Warnings as errors.
938 "-Wno-missing-field-initializers", # "struct foo f = {0};"
939 "-Wno-unused-parameter", # Unused function parameters.
943 default_warning_flags += [ "-Wnewline-eof" ]
945 # When compiling Objective-C, warns if a method is used whose
946 # availability is newer than the deployment target. This is not
947 # required when compiling Chrome for iOS.
948 default_warning_flags += [ "-Wpartial-availability" ]
952 if (gcc_version >= 48) {
953 default_warning_flags_cc += [
954 # See comment for -Wno-c++11-narrowing.
958 default_warning_flags_cc += [
959 # TODO(thakis): Remove, http://crbug.com/263960
960 "-Wno-literal-suffix",
965 # Suppress warnings about ABI changes on ARM (Clang doesn't give this
967 if (current_cpu == "arm" && !is_clang) {
968 default_warning_flags += [ "-Wno-psabi" ]
972 # Disable any additional warnings enabled by the Android build system but
973 # which chromium does not build cleanly with (when treating warning as
975 default_warning_flags += [
977 "-Wno-ignored-qualifiers",
980 default_warning_flags_cc += [
981 # Disabling c++0x-compat should be handled in WebKit, but
982 # this currently doesn't work because gcc_version is not set
983 # correctly when building with the Android build system.
984 # TODO(torne): Fix this in WebKit.
985 "-Wno-error=c++0x-compat",
987 # Other things unrelated to -Wextra:
988 "-Wno-non-virtual-dtor",
993 if (gcc_version >= 48) {
994 # Don't warn about the "typedef 'foo' locally defined but not used"
996 # TODO: remove this flag once all builds work. See crbug.com/227506
997 default_warning_flags += [ "-Wno-unused-local-typedefs" ]
1001 default_warning_flags += [
1002 # This warns on using ints as initializers for floats in
1003 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
1004 # which happens in several places in chrome code. Not sure if
1005 # this is worth fixing.
1006 "-Wno-c++11-narrowing",
1008 # Don't die on dtoa code that uses a char as an array index.
1009 # This is required solely for base/third_party/dmg_fp/dtoa.cc.
1010 # TODO(brettw) move this to that project then!
1011 "-Wno-char-subscripts",
1013 # Warns on switches on enums that cover all enum values but
1014 # also contain a default: branch. Chrome is full of that.
1015 "-Wno-covered-switch-default",
1017 # Clang considers the `register` keyword as deprecated, but e.g.
1018 # code generated by flex (used in angle) contains that keyword.
1019 # http://crbug.com/255186
1020 "-Wno-deprecated-register",
1022 # TODO(thakis): This used to be implied by -Wno-unused-function,
1023 # which we no longer use. Check if it makes sense to remove
1024 # this as well. http://crbug.com/316352
1025 "-Wno-unneeded-internal-declaration",
1027 # TODO(hans): Get this cleaned up, http://crbug.com/428099
1028 "-Wno-inconsistent-missing-override",
1031 if (is_posix && !is_mac && !is_ios) {
1032 default_warning_flags += [
1033 # TODO(thakis): Remove, http://crbug.com/263960
1034 "-Wno-reserved-user-defined-literal",
1038 # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost
1039 # always have different versions. Certain flags may not be recognized by
1040 # one version or the other.
1042 # Flags NaCl does not recognize.
1043 default_warning_flags += [
1044 # TODO(thakis): Enable this, crbug.com/507717
1045 "-Wno-shift-negative-value",
1049 if (exec_script("//tools/clang/scripts/update.py",
1050 [ "--print-revision" ],
1051 "trim string") != "245965-1") {
1052 default_warning_flags += [
1053 # TODO(thakis): Move this into outer if once clang is rolled far enough
1054 # that the pinned clang understands this flag.
1055 # TODO(thakis): Consider enabling this?
1056 "-Wno-bitfield-width",
1061 # chromium_code ---------------------------------------------------------------
1063 # Toggles between higher and lower warnings for code that is (or isn't)
1066 config("chromium_code") {
1068 cflags = [ "/W4" ] # Warning level 4.
1073 # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't,
1074 # so we specify it explicitly.
1075 # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it.
1076 # http://code.google.com/p/chromium/issues/detail?id=90453
1080 # In Chromium code, we define __STDC_foo_MACROS in order to get the
1081 # C99 macros on Mac and Linux.
1083 "__STDC_CONSTANT_MACROS",
1084 "__STDC_FORMAT_MACROS",
1087 if (!is_debug && !using_sanitizer &&
1088 (!is_linux || !is_clang || is_official_build)) {
1089 # _FORTIFY_SOURCE isn't really supported by Clang now, see
1090 # http://llvm.org/bugs/show_bug.cgi?id=16821.
1091 # It seems to work fine with Ubuntu 12 headers though, so use it in
1094 # Non-chromium code is not guaranteed to compile cleanly with
1095 # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are
1096 # disabled, so only do that for Release build.
1097 defines += [ "_FORTIFY_SOURCE=2" ]
1100 cflags += default_warning_flags
1101 cflags_cc = default_warning_flags_cc
1103 config("no_chromium_code") {
1110 "/W3", # Warning level 3.
1111 "/wd4800", # Disable warning when forcing value to bool.
1112 "/wd4267", # TODO(jschuh): size_t to int.
1113 "/wd4996", # Deprecated function warning.
1116 "_CRT_NONSTDC_NO_WARNINGS",
1117 "_CRT_NONSTDC_NO_DEPRECATE",
1122 # Don't warn about ignoring the return value from e.g. close(). This is
1123 # off by default in some gccs but on by default in others. BSD systems do
1124 # not support this option, since they are usually using gcc 4.2.1, which
1125 # does not have this flag yet.
1126 cflags += [ "-Wno-unused-result" ]
1131 # TODO(thakis): Move this suppression into individual third-party
1132 # libraries as required. http://crbug.com/505316.
1133 "-Wno-unused-function",
1135 # Lots of third-party libraries have unused variables. Instead of
1136 # suppressing them individually, we just blanket suppress them here.
1137 "-Wno-unused-variable",
1141 if (is_linux || is_android) {
1143 # Don't warn about printf format problems. This is off by default in gcc
1144 # but on in Ubuntu's gcc(!).
1148 # Don't warn about hash_map in third-party code.
1152 cflags += default_warning_flags
1153 cflags_cc += default_warning_flags_cc
1156 # rtti ------------------------------------------------------------------------
1158 # Allows turning Run-Time Type Identification on or off.
1162 cflags_cc = [ "/GR" ]
1166 # CFI diagnostics require RTTI.
1167 if (!use_cfi_diag) {
1169 cflags_cc = [ "/GR-" ]
1171 cflags_cc = [ "-fno-rtti" ]
1172 cflags_objcc = cflags_cc
1177 # Warnings ---------------------------------------------------------------------
1179 # This will generate warnings when using Clang if code generates exit-time
1180 # destructors, which will slow down closing the program.
1181 # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600
1182 config("wexit_time_destructors") {
1183 # TODO: Enable on Windows too, http://crbug.com/404525
1184 if (is_clang && !is_win) {
1185 cflags = [ "-Wexit-time-destructors" ]
1189 # On Windows compiling on x64, VC will issue a warning when converting
1190 # size_t to int because it will truncate the value. Our code should not have
1191 # these warnings and one should use a static_cast or a checked_cast for the
1192 # conversion depending on the case. However, a lot of code still needs to be
1193 # fixed. Apply this config to such targets to disable the warning.
1195 # Note that this can be applied regardless of platform and architecture to
1196 # clean up the call sites. This will only apply the flag when necessary.
1198 # TODO(jschuh): crbug.com/167187 fix this and delete this config.
1199 config("no_size_t_to_int_warning") {
1200 if (is_win && current_cpu == "x64") {
1201 cflags = [ "/wd4267" ]
1205 # Some code presumes that pointers to structures/objects are compatible
1206 # regardless of whether what they point to is already known to be valid.
1207 # gcc 4.9 and earlier had no way of suppressing this warning without
1208 # supressing the rest of them. Here we centralize the identification of
1209 # the gcc 4.9 toolchains.
1210 config("no_incompatible_pointer_warnings") {
1213 cflags += [ "-Wno-incompatible-pointer-types" ]
1214 } else if (current_cpu == "mipsel") {
1216 } else if (is_chromeos && current_cpu == "arm") {
1221 # Optimization -----------------------------------------------------------------
1223 # The BUILDCONFIG file sets the "default_optimization" config on targets by
1224 # default. It will be equivalent to either "optimize" (release) or
1225 # "no_optimize" (debug) optimization configs.
1227 # You can override the optimization level on a per-target basis by removing the
1228 # default config and then adding the named one you want:
1230 # configs -= [ "//build/config/compiler:default_optimization" ]
1231 # configs += [ "//build/config/compiler:optimize_max" ]
1233 # Shared settings for both "optimize" and "optimize_max" configs.
1234 # IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags.
1236 common_optimize_on_cflags = [
1237 "/Ob2", # Both explicit and auto inlining.
1238 "/Oy-", # Disable omitting frame pointers, must be after /O2.
1239 "/d2Zi+", # Improve debugging of optimized code.
1240 "/Zc:inline", # Remove unreferenced COMDAT (faster links).
1243 common_optimize_on_cflags += [
1244 # Put data in separate COMDATs. This allows the linker
1245 # to put bit-identical constants at the same address even if
1246 # they're unrelated constants, which saves binary size.
1247 # This optimization can't be used when ASan is enabled because
1248 # it is not compatible with the ASan ODR checker.
1252 common_optimize_on_ldflags = [ "/OPT:ICF" ]
1253 if (is_official_build) {
1254 common_optimize_on_ldflags += [
1255 # Link-time code generation.
1258 # Set the number of LTCG code-gen threads to eight. The default is four.
1259 # This gives a 5-10% link speedup.
1264 common_optimize_on_cflags = [
1265 # Don't emit the GCC version ident directives, they just end up in the
1266 # .comment section taking up binary size.
1269 # Put data and code in their own sections, so that unused symbols
1270 # can be removed at link time with --gc-sections.
1272 "-ffunction-sections",
1274 common_optimize_on_ldflags = []
1277 if (!using_sanitizer) {
1278 common_optimize_on_cflags += [ "-fomit-frame-pointer" ]
1281 # TODO(jdduke) Re-enable on mips after resolving linking
1282 # issues with libc++ (crbug.com/456380).
1283 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
1284 common_optimize_on_ldflags += [
1285 # Warn in case of text relocations.
1286 "-Wl,--warn-shared-textrel",
1291 if (is_mac || is_ios) {
1292 if (symbol_level == 2) {
1293 # Mac dead code stripping requires symbols.
1294 common_optimize_on_ldflags += [ "-Wl,-dead_strip" ]
1297 # Non-Mac Posix linker flags.
1298 common_optimize_on_ldflags += [
1299 # Specifically tell the linker to perform optimizations.
1300 # See http://lwn.net/Articles/192624/ .
1302 "-Wl,--gc-sections",
1305 if (!using_sanitizer) {
1306 # Functions interposed by the sanitizers can make ld think
1307 # that some libraries aren't needed when they actually are,
1308 # http://crbug.com/234010. As workaround, disable --as-needed.
1309 common_optimize_on_ldflags += [ "-Wl,--as-needed" ]
1314 # Default "optimization on" config. Set up variables so the
1315 # "default_optimization" config can re-use these settings.
1317 # Favor size over speed, /O1 must be before the common flags. The GYP
1318 # build also specifies /Os and /GF but these are implied by /O1.
1319 optimize_cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
1320 } else if (is_android || is_ios) {
1321 # Favor size over speed.
1322 optimize_cflags = [ "-Os" ] + common_optimize_on_cflags
1324 # Linux & Mac favor speed over size.
1325 # TODO(brettw) it's weird that Mac and desktop Linux are different. We should
1326 # explore favoring size over speed in this case as well.
1327 optimize_cflags = [ "-O2" ] + common_optimize_on_cflags
1329 optimize_ldflags = common_optimize_on_ldflags
1331 config("optimize") {
1332 cflags = optimize_cflags
1333 ldflags = optimize_ldflags
1336 # Turn off optimizations. Set up variables so the
1337 # "default_optimization" config can re-use these settings.
1339 no_optimize_cflags = [
1340 "/Od", # Disable optimization.
1341 "/Ob0", # Disable all inlining (on by default).
1342 "/RTC1", # Runtime checks for stack frame and uninitialized variables.
1344 no_optimize_ldflags = []
1345 } else if (is_android && !android_full_debug) {
1346 # On Android we kind of optimize some things that don't affect debugging
1347 # much even when optimization is disabled to get the binary size down.
1348 no_optimize_cflags = [
1351 "-ffunction-sections",
1353 if (!using_sanitizer) {
1354 no_optimize_cflags += [ "-fomit-frame-pointer" ]
1356 no_optimize_ldflags = common_optimize_on_ldflags
1358 no_optimize_cflags = [ "-O0" ]
1359 no_optimize_ldflags = []
1362 config("no_optimize") {
1363 cflags = no_optimize_cflags
1364 ldflags = no_optimize_ldflags
1367 # Turns up the optimization level. On Windows, this implies whole program
1368 # optimization and link-time code generation which is very expensive and should
1369 # be used sparingly.
1370 config("optimize_max") {
1371 ldflags = common_optimize_on_ldflags
1373 # Favor speed over size, /O2 must be before the common flags. The GYP
1374 # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2.
1375 cflags = [ "/O2" ] + common_optimize_on_cflags
1376 if (is_official_build) {
1377 # TODO(GYP): TODO(dpranke): Should these only be on in an official
1378 # build, or on all the time? For now we'll require official build so
1379 # that the compile is clean.
1381 "/GL", # Whole program optimization.
1383 # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds.
1384 # Probably anything that this would catch that wouldn't be caught in a
1385 # normal build isn't going to actually be a bug, so the incremental
1386 # value of C4702 for PGO builds is likely very small.
1391 cflags = [ "-O2" ] + common_optimize_on_cflags
1395 # The default optimization applied to all targets. This will be equivalent to
1396 # either "optimize" or "no_optimize", depending on the build flags.
1397 config("default_optimization") {
1399 cflags = no_optimize_cflags
1400 ldflags = no_optimize_ldflags
1402 cflags = optimize_cflags
1403 ldflags = optimize_ldflags
1407 # Symbols ----------------------------------------------------------------------
1409 # The BUILDCONFIG file sets the "default_symbols" config on targets by
1410 # default. It will be equivalent to one the three specific symbol levels.
1412 # You can override the symbol level on a per-target basis by removing the
1413 # default config and then adding the named one you want:
1415 # configs -= [ "//build/config/compiler:default_symbols" ]
1416 # configs += [ "//build/config/compiler:symbols" ]
1420 import("//build/toolchain/goma.gni")
1422 symbols_cflags = [ "/Z7" ] # No PDB file
1424 symbols_cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
1426 if (is_win_fastlink) {
1427 # Tell VS 2015+ to create a PDB that references debug
1428 # information in .obj and .lib files instead of copying
1429 # it all. This flag is incompatible with /PROFILE
1430 symbols_ldflags = [ "/DEBUG:FASTLINK" ]
1432 symbols_ldflags = [ "/DEBUG" ]
1435 symbols_cflags = [ "-g2" ]
1436 if (use_debug_fission) {
1437 symbols_cflags += [ "-gsplit-dwarf" ]
1439 symbols_ldflags = []
1443 cflags = symbols_cflags
1444 ldflags = symbols_ldflags
1449 # Linker symbols for backtraces only.
1450 minimal_symbols_cflags = []
1451 if (is_win_fastlink) {
1452 # Tell VS 2015+ to create a PDB that references debug
1453 # information in .obj and .lib files instead of copying
1454 # it all. This flag is incompatible with /PROFILE
1455 minimal_symbols_ldflags = [ "/DEBUG:FASTLINK" ]
1457 minimal_symbols_ldflags = [ "/DEBUG" ]
1460 minimal_symbols_cflags = [ "-g1" ]
1461 if (use_debug_fission) {
1462 minimal_symbols_cflags += [ "-gsplit-dwarf" ]
1464 minimal_symbols_ldflags = []
1467 config("minimal_symbols") {
1468 cflags = minimal_symbols_cflags
1469 ldflags = minimal_symbols_ldflags
1474 no_symbols_cflags = []
1476 no_symbols_cflags = [ "-g0" ]
1479 config("no_symbols") {
1480 cflags = no_symbols_cflags
1484 config("default_symbols") {
1485 if (symbol_level == 0) {
1486 cflags = no_symbols_cflags
1487 } else if (symbol_level == 1) {
1488 cflags = minimal_symbols_cflags
1489 ldflags = minimal_symbols_ldflags
1490 } else if (symbol_level == 2) {
1491 cflags = symbols_cflags
1492 ldflags = symbols_ldflags