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") {
401 if (is_clang && !is_android && !is_nacl) {
404 "arm-linux-gnueabihf",
408 "arm-linux-gnueabihf",
411 # We need to disable clang's builtin assembler as it can't
412 # handle several asm files, crbug.com/124610
413 cflags += [ "-no-integrated-as" ]
418 "-mfloat-abi=$arm_float_abi",
421 cflags += [ "-mthumb" ]
422 if (is_android && !is_clang) {
423 # Clang doesn't support this option.
424 cflags += [ "-mthumb-interwork" ]
428 if (arm_tune != "") {
429 cflags += [ "-mtune=$arm_tune" ]
432 # Clang doesn't support these flags.
434 # The tree-sra optimization (scalar replacement for
435 # aggregates enabling subsequent optimizations) leads to
436 # invalid code generation when using the Android NDK's
437 # compiler (r5-r7). This can be verified using
438 # webkit_unit_tests' WTF.Checked_int8_t test.
441 # The following option is disabled to improve binary
442 # size and performance in gcc 4.9.
446 } else if (current_cpu == "mipsel") {
447 if (mips_arch_variant == "r6") {
458 } else if (mips_arch_variant == "r2") {
463 if (mips_float_abi == "hard" && mips_fpu_mode != "") {
464 cflags += [ "-m$mips_fpu_mode" ]
466 } else if (mips_arch_variant == "r1") {
473 if (mips_dsp_rev == 1) {
474 cflags += [ "-mdsp" ]
475 } else if (mips_dsp_rev == 2) {
476 cflags += [ "-mdspr2" ]
479 cflags += [ "-m${mips_float_abi}-float" ]
480 } else if (current_cpu == "mips64el") {
481 if (mips_arch_variant == "r6") {
486 ldflags += [ "-mips64r6" ]
487 } else if (mips_arch_variant == "r2") {
492 ldflags += [ "-mips64r2" ]
496 defines += [ "_FILE_OFFSET_BITS=64" ]
501 "_LARGEFILE64_SOURCE",
505 # Omit unwind support in official builds to save space. We can use breakpad
507 if (is_chrome_branded && is_official_build) {
509 "-fno-unwind-tables",
510 "-fno-asynchronous-unwind-tables",
512 defines += [ "NO_UNWIND_TABLES" ]
514 cflags += [ "-funwind-tables" ]
518 # Linux/Android common flags setup.
519 # ---------------------------------
520 if (is_linux || is_android) {
523 "-pipe", # Use pipes for communicating between sub-processes. Faster.
528 "-Wl,-z,noexecstack",
532 if (!using_sanitizer && !use_cfi_diag) {
533 ldflags += [ "-Wl,-z,defs" ]
537 # Linux-specific compiler flags setup.
538 # ------------------------------------
540 cflags += [ "-pthread" ]
541 ldflags += [ "-pthread" ]
547 # Newer gccs and clangs support -fuse-ld, use the flag to force gold
549 # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html
552 # Experimentation found that using four linking threads
553 # saved ~20% of link time.
554 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
555 # Only apply this to the target linker, since the host
556 # linker might not be gold, but isn't used much anyway.
557 # TODO(raymes): Disable threading because gold is frequently
558 # crashing on the bots: crbug.com/161942.
560 #"-Wl,--thread-count=4",
563 if (!is_asan && !is_msan && !is_lsan && !is_tsan) {
564 # TODO(brettw) common.gypi has this only for target toolset.
565 ldflags += [ "-Wl,--icf=all" ]
568 # TODO(thestig): Make this flag work with GN.
569 #if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan || is_msan)) {
571 # "-Wl,--detect-odr-violations",
576 if (linux_use_bundled_binutils) {
577 cflags += [ "-B$binutils_path" ]
580 # Clang-specific compiler flags setup.
581 # ------------------------------------
583 cflags += [ "-fcolor-diagnostics" ]
586 # C++11 compiler flags setup.
587 # ---------------------------
588 if (is_linux || is_android || (is_nacl && is_clang)) {
589 # gnu++11 instead of c++11 is needed because some code uses typeof() (a
591 # TODO(thakis): Eventually switch this to c++11 instead,
592 # http://crbug.com/427584
593 cflags_cc += [ "-std=gnu++11" ]
594 } else if (!is_win && !is_nacl) {
595 # TODO(mcgrathr) - the NaCl GCC toolchain doesn't support either gnu++11
596 # or c++11; we technically don't need this toolchain any more, but there
597 # are still a few buildbots using it, so until those are turned off
598 # we need the !is_nacl clause and the (is_nacl && is_clang) clause, above.
599 cflags_cc += [ "-std=c++11" ]
602 # Android-specific flags setup.
603 # -----------------------------
606 "-ffunction-sections",
611 # Clang doesn't support these flags.
612 cflags += [ "-finline-limit=64" ]
615 rebased_android_toolchain_root =
616 rebase_path(android_toolchain_root, root_build_dir)
617 if (current_cpu == "arm") {
619 # TODO(hans) Enable integrated-as (crbug.com/124610).
621 "-B${rebased_android_toolchain_root}/bin", # Else /usr/bin/as gets picked up.
626 # Android build relies on -Wl,--gc-sections removing unreachable code.
627 # ASan instrumentation for globals inhibits this and results in a library
628 # with unresolvable relocations.
629 # TODO(eugenis): find a way to reenable this.
630 cflags += [ "-mllvm -asan-globals=0" ]
633 defines += [ "ANDROID" ]
635 # The NDK has these things, but doesn't define the constants
636 # to say that it does. Define them here instead.
637 defines += [ "HAVE_SYS_UIO_H" ]
639 # Use gold for Android for most CPU architectures.
640 if (current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm") {
641 ldflags += [ "-fuse-ld=gold" ]
643 # Let clang find the ld.gold in the NDK.
644 ldflags += [ "--gcc-toolchain=$rebased_android_toolchain_root" ]
647 # Use -mstackrealign due to a bug on ia32 Jelly Bean.
648 # See crbug.com/521527
649 if (current_cpu == "x86") {
650 cflags += [ "-mstackrealign" ]
655 "-Wl,--no-undefined",
657 # Don't allow visible symbols from libgcc or libc++ to be
659 "-Wl,--exclude-libs=libgcc.a",
660 "-Wl,--exclude-libs=libc++_static.a",
662 # Don't allow visible symbols from libraries that contain
663 # assembly code with symbols that aren't hidden properly.
664 # http://crbug.com/448386
665 "-Wl,--exclude-libs=libvpx_assembly_arm.a",
667 if (current_cpu == "arm") {
669 # Enable identical code folding to reduce size.
675 if (current_cpu == "arm") {
676 _abi_target = "arm-linux-androideabi"
677 } else if (current_cpu == "x86") {
678 _abi_target = "i686-linux-androideabi"
679 } else if (current_cpu == "arm64") {
680 # Place holder for arm64 support, not tested.
681 _abi_target = "aarch64-linux-androideabi"
682 } else if (current_cpu == "x64") {
683 # Place holder for x64 support, not tested.
684 # TODO: Enable clang support for Android x64. http://crbug.com/346626
685 _abi_target = "x86_64-linux-androideabi"
686 } else if (current_cpu == "mipsel") {
687 # Place holder for mips support, not tested.
688 _abi_target = "mipsel-linux-androideabi"
689 } else if (current_cpu == "mips64el") {
690 # Place holder for mips64 support, not tested.
691 _abi_target = "mips64el-linux-androideabi"
693 assert(false, "Architecture not supported")
706 # Pass the same C/C++ flags to the objective C/C++ compiler.
707 cflags_objc += cflags_c
708 cflags_objcc += cflags_cc
711 config("compiler_arm_fpu") {
712 if (current_cpu == "arm" && !is_ios && !is_nacl) {
713 cflags = [ "-mfpu=$arm_fpu" ]
717 # runtime_library -------------------------------------------------------------
719 # Sets the runtime library and associated options.
721 # How do you determine what should go in here vs. "compiler" above? Consider if
722 # a target might choose to use a different runtime library (ignore for a moment
723 # if this is possible or reasonable on your system). If such a target would want
724 # to change or remove your option, put it in the runtime_library config. If a
725 # target wants the option regardless, put it in the compiler config.
727 config("runtime_library") {
734 if (is_component_build) {
735 # Component mode: dynamic CRT.
736 defines += [ "COMPONENT_BUILD" ]
738 # Since the library is shared, it requires exceptions or will give errors
739 # about things not matching, so keep exceptions on.
747 if (is_win && current_os != "win") {
748 # WindowsRT: use the dynamic CRT.
755 # Desktop Windows: static CRT.
768 "_CRT_SECURE_NO_DEPRECATE",
770 "_SCL_SECURE_NO_DEPRECATE",
774 # Android standard library setup.
777 # Work around incompatibilities between bionic and clang headers.
779 "__compiler_offsetof=__builtin_offsetof",
784 defines += [ "__GNU_SOURCE=1" ] # Necessary for clone().
786 # TODO(jdduke) Re-enable on mips after resolving linking
787 # issues with libc++ (crbug.com/456380).
788 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
789 ldflags += [ "-Wl,--warn-shared-textrel" ]
791 ldflags += [ "-nostdlib" ]
793 # NOTE: The libc++ header include paths below are specified in cflags
794 # rather than include_dirs because they need to come after include_dirs.
795 # Think of them like system headers, but don't use '-isystem' because the
796 # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit
797 # strange errors. The include ordering here is important; change with
801 rebase_path("$android_libcpp_root/libcxx/include", root_build_dir),
802 "-isystem" + rebase_path(
803 "$android_ndk_root/sources/cxx-stl/llvm-libc++abi/libcxxabi/include",
806 rebase_path("$android_ndk_root/sources/android/support/include",
810 lib_dirs += [ "$android_libcpp_root/libs/$android_app_abi" ]
811 libs += [ "$android_libcpp_library" ]
813 if (current_cpu == "mipsel") {
815 # ld linker is used for mips Android, and ld does not accept library
816 # absolute path prefixed by "-l"; Since libgcc does not exist in mips
817 # sysroot the proper library will be linked.
818 # TODO(gordanac): Remove once gold linker is used for mips Android.
823 # Manually link the libgcc.a that the cross compiler uses. This is
824 # absolute because the linker will look inside the sysroot if it's not.
825 rebase_path(android_libgcc_file),
835 # Clang with libc++ does not require an explicit atomic library reference.
842 # default_warning_flags collects all warning flags that are used by default.
843 # This is in a variable instead of a config so that it can be used in
844 # both chromium_code and no_chromium_code. This way these flags are guaranteed
845 # to appear on the compile command line after -Wall.
847 default_warning_flags = []
848 default_warning_flags_cc = []
850 default_warning_flags += [
851 # Treat warnings as errors.
854 # Warnings permanently disabled:
856 # C4127: conditional expression is constant
857 # This warning can in theory catch dead code and other problems, but
858 # triggers in far too many desirable cases where the conditional
859 # expression is either set by macros or corresponds some legitimate
860 # compile-time constant expression (due to constant template args,
861 # conditionals comparing the sizes of different types, etc.). Some of
862 # these can be worked around, but it's not worth it.
865 # C4251: 'identifier' : class 'type' needs to have dll-interface to be
866 # used by clients of class 'type2'
867 # This is necessary for the shared library build.
870 # C4351: new behavior: elements of array 'array' will be default
872 # This is a silly "warning" that basically just alerts you that the
873 # compiler is going to actually follow the language spec like it's
874 # supposed to, instead of not following it like old buggy versions did.
875 # There's absolutely no reason to turn this on.
878 # C4355: 'this': used in base member initializer list
879 # It's commonly useful to pass |this| to objects in a class' initializer
880 # list. While this warning can catch real bugs, most of the time the
881 # constructors in question don't attempt to call methods on the passed-in
882 # pointer (until later), and annotating every legit usage of this is
883 # simply more hassle than the warning is worth.
886 # C4503: 'identifier': decorated name length exceeded, name was
888 # This only means that some long error messages might have truncated
889 # identifiers in the presence of lots of templates. It has no effect on
890 # program correctness and there's no real reason to waste time trying to
894 # Warning C4589 says: "Constructor of abstract class ignores
895 # initializer for virtual base class." Disable this warning because it
896 # is flaky in VS 2015 RTM. It triggers on compiler generated
897 # copy-constructors in some cases.
900 # C4611: interaction between 'function' and C++ object destruction is
902 # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN
903 # suggests using exceptions instead of setjmp/longjmp for C++, but
904 # Chromium code compiles without exception support. We therefore have to
905 # use setjmp/longjmp for e.g. JPEG decode error handling, which means we
906 # have to turn off this warning (and be careful about how object
907 # destruction happens in such cases).
910 # Warnings to evaluate and possibly fix/reenable later:
912 "/wd4100", # Unreferenced formal function parameter.
913 "/wd4121", # Alignment of a member was sensitive to packing.
914 "/wd4244", # Conversion: possible loss of data.
915 "/wd4481", # Nonstandard extension: override specifier.
916 "/wd4505", # Unreferenced local function has been removed.
917 "/wd4510", # Default constructor could not be generated.
918 "/wd4512", # Assignment operator could not be generated.
919 "/wd4610", # Class can never be instantiated, constructor required.
920 "/wd4995", # 'X': name was marked as #pragma deprecated
921 "/wd4996", # Deprecated function warning.
924 # VS xtree header file needs to be patched or 4702 (unreachable code
925 # warning) is reported if _HAS_EXCEPTIONS=0. Disable the warning if xtree is
927 if (!msvs_xtree_patched &&
928 exec_script("../../win_is_xtree_patched.py", [], "value") == 0) {
929 default_warning_flags += [ "/wd4702" ] # Unreachable code.
932 # Building with Clang on Windows is a work in progress and very
933 # experimental. See crbug.com/82385.
934 # Keep this in sync with the similar block in build/common.gypi
936 default_warning_flags += [
937 # TODO(hans): Make this list shorter eventually, http://crbug.com/504657
938 "-Qunused-arguments", # http://crbug.com/504658
939 "-Wno-microsoft-enum-value", # http://crbug.com/505296
940 "-Wno-unknown-pragmas", # http://crbug.com/505314
941 "-Wno-unused-value", # http://crbug.com/505318
945 # Common GCC warning setup.
946 default_warning_flags += [
948 "-Wendif-labels", # Weird old-style text after an #endif.
949 "-Werror", # Warnings as errors.
952 "-Wno-missing-field-initializers", # "struct foo f = {0};"
953 "-Wno-unused-parameter", # Unused function parameters.
957 default_warning_flags += [ "-Wnewline-eof" ]
959 # When compiling Objective-C, warns if a method is used whose
960 # availability is newer than the deployment target. This is not
961 # required when compiling Chrome for iOS.
962 default_warning_flags += [ "-Wpartial-availability" ]
966 if (gcc_version >= 48) {
967 default_warning_flags_cc += [
968 # See comment for -Wno-c++11-narrowing.
972 default_warning_flags_cc += [
973 # TODO(thakis): Remove, http://crbug.com/263960
974 "-Wno-literal-suffix",
979 # Suppress warnings about ABI changes on ARM (Clang doesn't give this
981 if (current_cpu == "arm" && !is_clang) {
982 default_warning_flags += [ "-Wno-psabi" ]
986 # Disable any additional warnings enabled by the Android build system but
987 # which chromium does not build cleanly with (when treating warning as
989 default_warning_flags += [
991 "-Wno-ignored-qualifiers",
994 default_warning_flags_cc += [
995 # Disabling c++0x-compat should be handled in WebKit, but
996 # this currently doesn't work because gcc_version is not set
997 # correctly when building with the Android build system.
998 # TODO(torne): Fix this in WebKit.
999 "-Wno-error=c++0x-compat",
1001 # Other things unrelated to -Wextra:
1002 "-Wno-non-virtual-dtor",
1007 if (gcc_version >= 48) {
1008 # Don't warn about the "typedef 'foo' locally defined but not used"
1010 # TODO: remove this flag once all builds work. See crbug.com/227506
1011 default_warning_flags += [ "-Wno-unused-local-typedefs" ]
1015 default_warning_flags += [
1016 # This warns on using ints as initializers for floats in
1017 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
1018 # which happens in several places in chrome code. Not sure if
1019 # this is worth fixing.
1020 "-Wno-c++11-narrowing",
1022 # Don't die on dtoa code that uses a char as an array index.
1023 # This is required solely for base/third_party/dmg_fp/dtoa.cc.
1024 # TODO(brettw) move this to that project then!
1025 "-Wno-char-subscripts",
1027 # Warns on switches on enums that cover all enum values but
1028 # also contain a default: branch. Chrome is full of that.
1029 "-Wno-covered-switch-default",
1031 # Clang considers the `register` keyword as deprecated, but e.g.
1032 # code generated by flex (used in angle) contains that keyword.
1033 # http://crbug.com/255186
1034 "-Wno-deprecated-register",
1036 # TODO(thakis): This used to be implied by -Wno-unused-function,
1037 # which we no longer use. Check if it makes sense to remove
1038 # this as well. http://crbug.com/316352
1039 "-Wno-unneeded-internal-declaration",
1041 # TODO(hans): Get this cleaned up, http://crbug.com/428099
1042 "-Wno-inconsistent-missing-override",
1045 if (is_posix && !is_mac && !is_ios) {
1046 default_warning_flags += [
1047 # TODO(thakis): Remove, http://crbug.com/263960
1048 "-Wno-reserved-user-defined-literal",
1052 # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost
1053 # always have different versions. Certain flags may not be recognized by
1054 # one version or the other.
1056 # Flags NaCl does not recognize.
1057 default_warning_flags += [
1058 # TODO(thakis): Enable this, crbug.com/507717
1059 "-Wno-shift-negative-value",
1063 if (exec_script("//tools/clang/scripts/update.py",
1064 [ "--print-revision" ],
1065 "trim string") != "245965-1") {
1066 default_warning_flags += [
1067 # TODO(thakis): Move this into outer if once clang is rolled far enough
1068 # that the pinned clang understands this flag.
1069 # TODO(thakis): Consider enabling this?
1070 "-Wno-bitfield-width",
1075 # chromium_code ---------------------------------------------------------------
1077 # Toggles between higher and lower warnings for code that is (or isn't)
1080 config("chromium_code") {
1082 cflags = [ "/W4" ] # Warning level 4.
1087 # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't,
1088 # so we specify it explicitly.
1089 # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it.
1090 # http://code.google.com/p/chromium/issues/detail?id=90453
1094 # In Chromium code, we define __STDC_foo_MACROS in order to get the
1095 # C99 macros on Mac and Linux.
1097 "__STDC_CONSTANT_MACROS",
1098 "__STDC_FORMAT_MACROS",
1101 if (!is_debug && !using_sanitizer &&
1102 (!is_linux || !is_clang || is_official_build)) {
1103 # _FORTIFY_SOURCE isn't really supported by Clang now, see
1104 # http://llvm.org/bugs/show_bug.cgi?id=16821.
1105 # It seems to work fine with Ubuntu 12 headers though, so use it in
1108 # Non-chromium code is not guaranteed to compile cleanly with
1109 # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are
1110 # disabled, so only do that for Release build.
1111 defines += [ "_FORTIFY_SOURCE=2" ]
1114 cflags += default_warning_flags
1115 cflags_cc = default_warning_flags_cc
1117 config("no_chromium_code") {
1124 "/W3", # Warning level 3.
1125 "/wd4800", # Disable warning when forcing value to bool.
1126 "/wd4267", # TODO(jschuh): size_t to int.
1127 "/wd4996", # Deprecated function warning.
1130 "_CRT_NONSTDC_NO_WARNINGS",
1131 "_CRT_NONSTDC_NO_DEPRECATE",
1136 # Don't warn about ignoring the return value from e.g. close(). This is
1137 # off by default in some gccs but on by default in others. BSD systems do
1138 # not support this option, since they are usually using gcc 4.2.1, which
1139 # does not have this flag yet.
1140 cflags += [ "-Wno-unused-result" ]
1145 # TODO(thakis): Move this suppression into individual third-party
1146 # libraries as required. http://crbug.com/505316.
1147 "-Wno-unused-function",
1149 # Lots of third-party libraries have unused variables. Instead of
1150 # suppressing them individually, we just blanket suppress them here.
1151 "-Wno-unused-variable",
1155 if (is_linux || is_android) {
1157 # Don't warn about printf format problems. This is off by default in gcc
1158 # but on in Ubuntu's gcc(!).
1162 # Don't warn about hash_map in third-party code.
1166 cflags += default_warning_flags
1167 cflags_cc += default_warning_flags_cc
1170 # rtti ------------------------------------------------------------------------
1172 # Allows turning Run-Time Type Identification on or off.
1176 cflags_cc = [ "/GR" ]
1180 # CFI diagnostics require RTTI.
1181 if (!use_cfi_diag) {
1183 cflags_cc = [ "/GR-" ]
1185 cflags_cc = [ "-fno-rtti" ]
1186 cflags_objcc = cflags_cc
1191 # Warnings ---------------------------------------------------------------------
1193 # This will generate warnings when using Clang if code generates exit-time
1194 # destructors, which will slow down closing the program.
1195 # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600
1196 config("wexit_time_destructors") {
1197 # TODO: Enable on Windows too, http://crbug.com/404525
1198 if (is_clang && !is_win) {
1199 cflags = [ "-Wexit-time-destructors" ]
1203 # On Windows compiling on x64, VC will issue a warning when converting
1204 # size_t to int because it will truncate the value. Our code should not have
1205 # these warnings and one should use a static_cast or a checked_cast for the
1206 # conversion depending on the case. However, a lot of code still needs to be
1207 # fixed. Apply this config to such targets to disable the warning.
1209 # Note that this can be applied regardless of platform and architecture to
1210 # clean up the call sites. This will only apply the flag when necessary.
1212 # TODO(jschuh): crbug.com/167187 fix this and delete this config.
1213 config("no_size_t_to_int_warning") {
1214 if (is_win && current_cpu == "x64") {
1215 cflags = [ "/wd4267" ]
1219 # Some code presumes that pointers to structures/objects are compatible
1220 # regardless of whether what they point to is already known to be valid.
1221 # gcc 4.9 and earlier had no way of suppressing this warning without
1222 # supressing the rest of them. Here we centralize the identification of
1223 # the gcc 4.9 toolchains.
1224 config("no_incompatible_pointer_warnings") {
1227 cflags += [ "-Wno-incompatible-pointer-types" ]
1228 } else if (current_cpu == "mipsel") {
1230 } else if (is_chromeos && current_cpu == "arm") {
1235 # Optimization -----------------------------------------------------------------
1237 # The BUILDCONFIG file sets the "default_optimization" config on targets by
1238 # default. It will be equivalent to either "optimize" (release) or
1239 # "no_optimize" (debug) optimization configs.
1241 # You can override the optimization level on a per-target basis by removing the
1242 # default config and then adding the named one you want:
1244 # configs -= [ "//build/config/compiler:default_optimization" ]
1245 # configs += [ "//build/config/compiler:optimize_max" ]
1247 # Shared settings for both "optimize" and "optimize_max" configs.
1248 # IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags.
1250 common_optimize_on_cflags = [
1251 "/Ob2", # Both explicit and auto inlining.
1252 "/Oy-", # Disable omitting frame pointers, must be after /O2.
1253 "/d2Zi+", # Improve debugging of optimized code.
1254 "/Zc:inline", # Remove unreferenced COMDAT (faster links).
1257 common_optimize_on_cflags += [
1258 # Put data in separate COMDATs. This allows the linker
1259 # to put bit-identical constants at the same address even if
1260 # they're unrelated constants, which saves binary size.
1261 # This optimization can't be used when ASan is enabled because
1262 # it is not compatible with the ASan ODR checker.
1266 common_optimize_on_ldflags = [ "/OPT:ICF" ]
1267 if (is_official_build) {
1268 common_optimize_on_ldflags += [
1269 # Link-time code generation.
1272 # Set the number of LTCG code-gen threads to eight. The default is four.
1273 # This gives a 5-10% link speedup.
1278 common_optimize_on_cflags = [
1279 # Don't emit the GCC version ident directives, they just end up in the
1280 # .comment section taking up binary size.
1283 # Put data and code in their own sections, so that unused symbols
1284 # can be removed at link time with --gc-sections.
1286 "-ffunction-sections",
1288 common_optimize_on_ldflags = []
1291 if (!using_sanitizer) {
1292 common_optimize_on_cflags += [ "-fomit-frame-pointer" ]
1295 # TODO(jdduke) Re-enable on mips after resolving linking
1296 # issues with libc++ (crbug.com/456380).
1297 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
1298 common_optimize_on_ldflags += [
1299 # Warn in case of text relocations.
1300 "-Wl,--warn-shared-textrel",
1305 if (is_mac || is_ios) {
1306 if (symbol_level == 2) {
1307 # Mac dead code stripping requires symbols.
1308 common_optimize_on_ldflags += [ "-Wl,-dead_strip" ]
1311 # Non-Mac Posix linker flags.
1312 common_optimize_on_ldflags += [
1313 # Specifically tell the linker to perform optimizations.
1314 # See http://lwn.net/Articles/192624/ .
1316 "-Wl,--gc-sections",
1319 if (!using_sanitizer) {
1320 # Functions interposed by the sanitizers can make ld think
1321 # that some libraries aren't needed when they actually are,
1322 # http://crbug.com/234010. As workaround, disable --as-needed.
1323 common_optimize_on_ldflags += [ "-Wl,--as-needed" ]
1328 # Default "optimization on" config. Set up variables so the
1329 # "default_optimization" config can re-use these settings.
1331 # Favor size over speed, /O1 must be before the common flags. The GYP
1332 # build also specifies /Os and /GF but these are implied by /O1.
1333 optimize_cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
1334 } else if (is_android || is_ios) {
1335 # Favor size over speed.
1336 optimize_cflags = [ "-Os" ] + common_optimize_on_cflags
1338 # Linux & Mac favor speed over size.
1339 # TODO(brettw) it's weird that Mac and desktop Linux are different. We should
1340 # explore favoring size over speed in this case as well.
1341 optimize_cflags = [ "-O2" ] + common_optimize_on_cflags
1343 optimize_ldflags = common_optimize_on_ldflags
1345 config("optimize") {
1346 cflags = optimize_cflags
1347 ldflags = optimize_ldflags
1350 # Turn off optimizations. Set up variables so the
1351 # "default_optimization" config can re-use these settings.
1353 no_optimize_cflags = [
1354 "/Od", # Disable optimization.
1355 "/Ob0", # Disable all inlining (on by default).
1356 "/RTC1", # Runtime checks for stack frame and uninitialized variables.
1358 no_optimize_ldflags = []
1359 } else if (is_android && !android_full_debug) {
1360 # On Android we kind of optimize some things that don't affect debugging
1361 # much even when optimization is disabled to get the binary size down.
1362 no_optimize_cflags = [
1365 "-ffunction-sections",
1367 if (!using_sanitizer) {
1368 no_optimize_cflags += [ "-fomit-frame-pointer" ]
1370 no_optimize_ldflags = common_optimize_on_ldflags
1372 no_optimize_cflags = [ "-O0" ]
1373 no_optimize_ldflags = []
1376 config("no_optimize") {
1377 cflags = no_optimize_cflags
1378 ldflags = no_optimize_ldflags
1381 # Turns up the optimization level. On Windows, this implies whole program
1382 # optimization and link-time code generation which is very expensive and should
1383 # be used sparingly.
1384 config("optimize_max") {
1385 ldflags = common_optimize_on_ldflags
1387 # Favor speed over size, /O2 must be before the common flags. The GYP
1388 # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2.
1389 cflags = [ "/O2" ] + common_optimize_on_cflags
1390 if (is_official_build) {
1391 # TODO(GYP): TODO(dpranke): Should these only be on in an official
1392 # build, or on all the time? For now we'll require official build so
1393 # that the compile is clean.
1395 "/GL", # Whole program optimization.
1397 # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds.
1398 # Probably anything that this would catch that wouldn't be caught in a
1399 # normal build isn't going to actually be a bug, so the incremental
1400 # value of C4702 for PGO builds is likely very small.
1405 cflags = [ "-O2" ] + common_optimize_on_cflags
1409 # The default optimization applied to all targets. This will be equivalent to
1410 # either "optimize" or "no_optimize", depending on the build flags.
1411 config("default_optimization") {
1413 cflags = no_optimize_cflags
1414 ldflags = no_optimize_ldflags
1416 cflags = optimize_cflags
1417 ldflags = optimize_ldflags
1421 # Symbols ----------------------------------------------------------------------
1423 # The BUILDCONFIG file sets the "default_symbols" config on targets by
1424 # default. It will be equivalent to one the three specific symbol levels.
1426 # You can override the symbol level on a per-target basis by removing the
1427 # default config and then adding the named one you want:
1429 # configs -= [ "//build/config/compiler:default_symbols" ]
1430 # configs += [ "//build/config/compiler:symbols" ]
1434 import("//build/toolchain/goma.gni")
1436 symbols_cflags = [ "/Z7" ] # No PDB file
1438 symbols_cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
1440 if (is_win_fastlink) {
1441 # Tell VS 2015+ to create a PDB that references debug
1442 # information in .obj and .lib files instead of copying
1443 # it all. This flag is incompatible with /PROFILE
1444 symbols_ldflags = [ "/DEBUG:FASTLINK" ]
1446 symbols_ldflags = [ "/DEBUG" ]
1449 symbols_cflags = [ "-g2" ]
1450 if (use_debug_fission) {
1451 symbols_cflags += [ "-gsplit-dwarf" ]
1453 symbols_ldflags = []
1457 cflags = symbols_cflags
1458 ldflags = symbols_ldflags
1463 # Linker symbols for backtraces only.
1464 minimal_symbols_cflags = []
1465 if (is_win_fastlink) {
1466 # Tell VS 2015+ to create a PDB that references debug
1467 # information in .obj and .lib files instead of copying
1468 # it all. This flag is incompatible with /PROFILE
1469 minimal_symbols_ldflags = [ "/DEBUG:FASTLINK" ]
1471 minimal_symbols_ldflags = [ "/DEBUG" ]
1474 minimal_symbols_cflags = [ "-g1" ]
1475 if (use_debug_fission) {
1476 minimal_symbols_cflags += [ "-gsplit-dwarf" ]
1478 minimal_symbols_ldflags = []
1481 config("minimal_symbols") {
1482 cflags = minimal_symbols_cflags
1483 ldflags = minimal_symbols_ldflags
1488 no_symbols_cflags = []
1490 no_symbols_cflags = [ "-g0" ]
1493 config("no_symbols") {
1494 cflags = no_symbols_cflags
1498 config("default_symbols") {
1499 if (symbol_level == 0) {
1500 cflags = no_symbols_cflags
1501 } else if (symbol_level == 1) {
1502 cflags = minimal_symbols_cflags
1503 ldflags = minimal_symbols_ldflags
1504 } else if (symbol_level == 2) {
1505 cflags = symbols_cflags
1506 ldflags = symbols_ldflags