1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import("//build/config/android/config.gni")
6 import("//build/config/chrome_build.gni")
7 if (current_cpu == "arm") {
8 import("//build/config/arm.gni")
10 if (current_cpu == "mipsel" || current_cpu == "mips64el") {
11 import("//build/config/mips.gni")
14 import("//build/config/gcc/gcc_version.gni")
17 import("//build/config/win/visual_studio_version.gni")
20 import("//build/toolchain/ccache.gni")
21 import("//build/config/sanitizers/sanitizers.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 gold for linking on 64-bit Linux only (on 32-bit it runs out of
48 # address space, and it doesn't support cross-compiling).
49 use_gold = is_linux && current_cpu == "x64"
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 # TODO(GYP): is_ubsan, is_ubsan_vptr
89 using_sanitizer = is_asan || is_lsan || is_tsan || is_msan
92 # compiler ---------------------------------------------------------------------
94 # Base compiler configuration.
96 # See also "runtime_library" below for related stuff and a discussion about
97 # where stuff should go. Put warning related stuff in the "warnings" config.
108 # In general, Windows is totally different, but all the other builds share
109 # some common GCC configuration. This section sets up Windows and the common
110 # GCC flags, and then we handle the other non-Windows platforms specifically
113 # Windows compiler flags setup.
114 # -----------------------------
116 "/Gy", # Enable function-level linking.
117 "/GS", # Enable buffer security checking.
118 "/FS", # Preserve previous PDB behavior.
121 # Force C/C++ mode for the given GN detected file type. This is necessary
122 # for precompiled headers where the same source file is compiled in both
124 cflags_c += [ "/TC" ]
125 cflags_cc += [ "/TP" ]
127 # Building with Clang on Windows is a work in progress and very
128 # experimental. See crbug.com/82385.
129 # Keep this in sync with the similar block in build/common.gypi
132 # Many files use intrinsics without including this header.
133 # TODO(hans): Fix those files, or move this to sub-GYPs.
137 if (visual_studio_version == "2013") {
138 cflags += [ "-fmsc-version=1800" ]
139 } else if (visual_studio_version == "2015") {
140 cflags += [ "-fmsc-version=1900" ]
143 if (current_cpu == "x86") {
149 if (exec_script("//build/win/use_ansi_codes.py", [], "trim string") ==
152 # cmd.exe doesn't understand ANSI escape codes by default,
153 # so only enable them if something emulating them is around.
154 "-fansi-escape-codes",
160 # SyzyAsan needs /PROFILE turned on to produce appropriate pdbs.
161 assert(!is_win_fastlink, "/PROFILE and /DEBUG:FASTLINK are incompatible")
162 ldflags += [ "/PROFILE" ]
165 # Common GCC compiler flags setup.
166 # --------------------------------
167 cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204
169 "-fno-threadsafe-statics",
171 # Not exporting C++ inline functions can generally be applied anywhere
172 # so we do so here. Normal function visibility is controlled by
173 # //build/config/gcc:symbol_visibility_hidden.
174 "-fvisibility-inlines-hidden",
179 cflags += [ "-fstack-protector-all" ]
180 } else if (is_linux) {
183 "--param=ssp-buffer-size=4",
188 if (!(is_chromeos && current_cpu == "arm") && !is_mac && !is_ios) {
189 # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580
190 ldflags += [ "-Wl,--fatal-warnings" ]
193 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer and
195 if (using_sanitizer) {
197 "-fno-omit-frame-pointer",
198 "-gline-tables-only",
202 asan_blacklist_path =
203 rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir)
205 "-fsanitize=address",
206 "-fsanitize-blacklist=$asan_blacklist_path",
209 cflags += [ "-mllvm -asan-globals=0" ] # http://crbug.com/352073
210 # TODO(GYP): deal with mac_bundles.
214 cflags += [ "-fsanitize=leak" ]
217 tsan_blacklist_path =
218 rebase_path("//tools/memory/tsan_v2/ignores.txt", root_build_dir)
221 "-fsanitize-blacklist=$tsan_blacklist_path",
225 msan_blacklist_path =
226 rebase_path("//tools/msan/blacklist.txt", root_build_dir)
229 "-fsanitize-memory-track-origins=$msan_track_origins",
230 "-fsanitize-blacklist=$msan_blacklist_path",
234 if (use_custom_libcxx) {
235 cflags_cc += [ "-nostdinc++" ]
237 "//buildtools/third_party/libc++/trunk/include",
238 "//buildtools/third_party/libc++abi/trunk/include",
243 if (is_clang && is_debug) {
244 # Allow comparing the address of references and 'this' against 0
245 # in debug builds. Technically, these can never be null in
246 # well-defined C/C++ and Clang can optimize such checks away in
247 # release builds, but they may be used in asserts in debug builds.
249 "-Wno-undefined-bool-conversion",
250 "-Wno-tautological-undefined-compare",
254 if (is_clang && !is_nacl) {
255 # This is here so that all files get recompiled after a clang roll and
256 # when turning clang on or off. (defines are passed via the command line,
257 # and build system rebuild things when their commandline changes). Nothing
258 # should ever read this define.
260 [ "CR_CLANG_REVISION=" + exec_script("//tools/clang/scripts/update.py",
261 [ "--print-revision" ],
265 # Mac-specific compiler flags setup.
266 # ----------------------------------
267 if (is_mac || is_ios) {
268 # These flags are shared between the C compiler and linker.
269 common_mac_flags = []
272 if (current_cpu == "x64") {
273 common_mac_flags += [
277 } else if (current_cpu == "x86") {
278 common_mac_flags += [
282 } else if (current_cpu == "arm") {
283 common_mac_flags += [
289 cflags += common_mac_flags
291 # Without this, the constructors and destructors of a C++ object inside
292 # an Objective C struct won't be called, which is very bad.
293 cflags_objcc += [ "-fobjc-call-cxx-cdtors" ]
295 cflags_c += [ "-std=c99" ]
297 ldflags += common_mac_flags
298 } else if (is_posix) {
299 # Non-Mac Posix compiler flags setup.
300 # -----------------------------------
301 if (enable_profiling && !is_debug) {
302 # The GYP build spams this define into every compilation unit, as we do
303 # here, but it only appears to be used in base and a couple other places.
304 # TODO(abarth): Should we move this define closer to where it's used?
305 defines += [ "ENABLE_PROFILING" ]
308 "-fno-omit-frame-pointer",
312 if (enable_full_stack_frames_for_profiling) {
315 "-fno-optimize-sibling-calls",
320 # CPU architecture. We may or may not be doing a cross compile now, so for
321 # simplicity we always explicitly set the architecture.
322 if (current_cpu == "x64") {
327 ldflags += [ "-m64" ]
328 } else if (current_cpu == "x86") {
330 ldflags += [ "-m32" ]
333 # Else building libyuv gives clang's register allocator issues,
334 # see llvm.org/PR15798 / crbug.com/233709
335 "-momit-leaf-frame-pointer",
337 # Align the stack on 16-byte boundaries, http://crbug.com/418554.
338 "-mstack-alignment=16",
342 } else if (current_cpu == "arm") {
345 "-mfloat-abi=$arm_float_abi",
347 if (arm_tune != "") {
348 cflags += [ "-mtune=$arm_tune" ]
351 cflags += [ "-mthumb" ]
352 if (is_android && !is_clang) { # Clang doesn't support this option.
353 cflags += [ "-mthumb-interwork" ]
357 # Clang doesn't support these flags.
359 # The tree-sra optimization (scalar replacement for
360 # aggregates enabling subsequent optimizations) leads to
361 # invalid code generation when using the Android NDK's
362 # compiler (r5-r7). This can be verified using
363 # webkit_unit_tests' WTF.Checked_int8_t test.
366 # The following option is disabled to improve binary
367 # size and performance in gcc 4.9.
371 } else if (current_cpu == "mipsel") {
372 if (mips_arch_variant == "r6") {
383 } else if (mips_arch_variant == "r2") {
388 if (mips_float_abi == "hard" && mips_fpu_mode != "") {
389 cflags += [ "-m$mips_fpu_mode" ]
391 } else if (mips_arch_variant == "r1") {
398 if (mips_dsp_rev == 1) {
399 cflags += [ "-mdsp" ]
400 } else if (mips_dsp_rev == 2) {
401 cflags += [ "-mdspr2" ]
404 cflags += [ "-m${mips_float_abi}-float" ]
405 } else if (current_cpu == "mips64el") {
406 if (mips_arch_variant == "r6") {
411 ldflags += [ "-mips64r6" ]
412 } else if (mips_arch_variant == "r2") {
417 ldflags += [ "-mips64r2" ]
421 defines += [ "_FILE_OFFSET_BITS=64" ]
426 "_LARGEFILE64_SOURCE",
430 # Omit unwind support in official builds to save space. We can use breakpad
432 if (is_chrome_branded && is_official_build) {
434 "-fno-unwind-tables",
435 "-fno-asynchronous-unwind-tables",
437 defines += [ "NO_UNWIND_TABLES" ]
439 cflags += [ "-funwind-tables" ]
443 # Linux/Android common flags setup.
444 # ---------------------------------
445 if (is_linux || is_android) {
448 "-pipe", # Use pipes for communicating between sub-processes. Faster.
453 "-Wl,-z,noexecstack",
457 if (!using_sanitizer) {
458 ldflags += [ "-Wl,-z,defs" ]
462 # Linux-specific compiler flags setup.
463 # ------------------------------------
465 cflags += [ "-pthread" ]
466 ldflags += [ "-pthread" ]
472 # Newer gccs and clangs support -fuse-ld, use the flag to force gold
474 # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html
477 # Experimentation found that using four linking threads
478 # saved ~20% of link time.
479 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
480 # Only apply this to the target linker, since the host
481 # linker might not be gold, but isn't used much anyway.
482 # TODO(raymes): Disable threading because gold is frequently
483 # crashing on the bots: crbug.com/161942.
485 #"-Wl,--thread-count=4",
488 if (!is_asan && !is_msan && !is_lsan && !is_tsan) {
489 # TODO(brettw) common.gypi has this only for target toolset.
490 ldflags += [ "-Wl,--icf=all" ]
493 # TODO(thestig): Make this flag work with GN.
494 #if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan || is_msan)) {
496 # "-Wl,--detect-odr-violations",
501 if (linux_use_bundled_binutils) {
502 cflags += [ "-B$binutils_path" ]
505 # Clang-specific compiler flags setup.
506 # ------------------------------------
508 cflags += [ "-fcolor-diagnostics" ]
511 # C++11 compiler flags setup.
512 # ---------------------------
513 if (is_linux || is_android || is_nacl) {
514 # gnu++11 instead of c++11 is needed because some code uses typeof() (a
516 # TODO(thakis): Eventually switch this to c++11 instead,
517 # http://crbug.com/427584
518 cflags_cc += [ "-std=gnu++11" ]
519 } else if (!is_win) {
520 cflags_cc += [ "-std=c++11" ]
523 # Android-specific flags setup.
524 # -----------------------------
527 "-ffunction-sections",
532 # Clang doesn't support these flags.
533 cflags += [ "-finline-limit=64" ]
536 # Android build relies on -Wl,--gc-sections removing unreachable code.
537 # ASan instrumentation for globals inhibits this and results in a library
538 # with unresolvable relocations.
539 # TODO(eugenis): find a way to reenable this.
540 cflags += [ "-mllvm -asan-globals=0" ]
543 defines += [ "ANDROID" ]
545 # The NDK has these things, but doesn't define the constants
546 # to say that it does. Define them here instead.
547 defines += [ "HAVE_SYS_UIO_H" ]
549 # Use gold for Android for most CPU architectures.
550 if (current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm") {
551 ldflags += [ "-fuse-ld=gold" ]
553 # Let clang find the ld.gold in the NDK.
554 ldflags += [ "--gcc-toolchain=" +
555 rebase_path(android_toolchain_root, root_build_dir) ]
560 "-Wl,--no-undefined",
562 # Don't allow visible symbols from libgcc or libc++ to be
564 "-Wl,--exclude-libs=libgcc.a",
565 "-Wl,--exclude-libs=libc++_static.a",
567 # Don't allow visible symbols from libraries that contain
568 # assembly code with symbols that aren't hidden properly.
569 # http://crbug.com/448386
570 "-Wl,--exclude-libs=libvpx_assembly_arm.a",
572 if (current_cpu == "arm") {
574 # Enable identical code folding to reduce size.
580 if (current_cpu == "arm") {
581 cflags += [ "-target arm-linux-androideabi" ]
582 ldflags += [ "-target arm-linux-androideabi" ]
583 } else if (current_cpu == "x86") {
584 cflags += [ "-target i686-linux-androideabi" ]
585 ldflags += [ "-target i686-linux-androideabi" ]
590 # Pass the same C/C++ flags to the objective C/C++ compiler.
591 cflags_objc += cflags_c
592 cflags_objcc += cflags_cc
595 config("compiler_arm_fpu") {
596 if (current_cpu == "arm" && !is_ios) {
597 cflags = [ "-mfpu=$arm_fpu" ]
601 # runtime_library -------------------------------------------------------------
603 # Sets the runtime library and associated options.
605 # How do you determine what should go in here vs. "compiler" above? Consider if
606 # a target might choose to use a different runtime library (ignore for a moment
607 # if this is possible or reasonable on your system). If such a target would want
608 # to change or remove your option, put it in the runtime_library config. If a
609 # target wants the option regardless, put it in the compiler config.
611 config("runtime_library") {
618 if (is_component_build) {
619 # Component mode: dynamic CRT.
620 defines += [ "COMPONENT_BUILD" ]
622 # Since the library is shared, it requires exceptions or will give errors
623 # about things not matching, so keep exceptions on.
631 if (is_win && current_os != "win") {
632 # WindowsRT: use the dynamic CRT.
639 # Desktop Windows: static CRT.
652 "_CRT_SECURE_NO_DEPRECATE",
654 "_SCL_SECURE_NO_DEPRECATE",
658 # Android standard library setup.
661 # Work around incompatibilities between bionic and clang headers.
663 "__compiler_offsetof=__builtin_offsetof",
668 defines += [ "__GNU_SOURCE=1" ] # Necessary for clone().
670 # TODO(jdduke) Re-enable on mips after resolving linking
671 # issues with libc++ (crbug.com/456380).
672 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
673 ldflags += [ "-Wl,--warn-shared-textrel" ]
675 ldflags += [ "-nostdlib" ]
677 # NOTE: The libc++ header include paths below are specified in cflags
678 # rather than include_dirs because they need to come after include_dirs.
679 # Think of them like system headers, but don't use '-isystem' because the
680 # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit
681 # strange errors. The include ordering here is important; change with
685 rebase_path("$android_libcpp_root/libcxx/include", root_build_dir),
686 "-isystem" + rebase_path(
687 "$android_ndk_root/sources/cxx-stl/llvm-libc++abi/libcxxabi/include",
690 rebase_path("$android_ndk_root/sources/android/support/include",
694 lib_dirs += [ "$android_libcpp_root/libs/$android_app_abi" ]
695 libs += [ "$android_libcpp_library" ]
697 if (current_cpu == "mipsel") {
699 # ld linker is used for mips Android, and ld does not accept library
700 # absolute path prefixed by "-l"; Since libgcc does not exist in mips
701 # sysroot the proper library will be linked.
702 # TODO(gordanac): Remove once gold linker is used for mips Android.
707 # Manually link the libgcc.a that the cross compiler uses. This is
708 # absolute because the linker will look inside the sysroot if it's not.
709 rebase_path(android_libgcc_file),
719 # Clang with libc++ does not require an explicit atomic library reference.
726 # default_warning_flags collects all warning flags that are used by default.
727 # This is in a variable instead of a config so that it can be used in
728 # both chromium_code and no_chromium_code. This way these flags are guaranteed
729 # to appear on the compile command line after -Wall.
731 default_warning_flags = []
732 default_warning_flags_cc = []
734 default_warning_flags += [
735 # Treat warnings as errors.
738 # Warnings permanently disabled:
740 # C4127: conditional expression is constant
741 # This warning can in theory catch dead code and other problems, but
742 # triggers in far too many desirable cases where the conditional
743 # expression is either set by macros or corresponds some legitimate
744 # compile-time constant expression (due to constant template args,
745 # conditionals comparing the sizes of different types, etc.). Some of
746 # these can be worked around, but it's not worth it.
749 # C4251: 'identifier' : class 'type' needs to have dll-interface to be
750 # used by clients of class 'type2'
751 # This is necessary for the shared library build.
754 # C4351: new behavior: elements of array 'array' will be default
756 # This is a silly "warning" that basically just alerts you that the
757 # compiler is going to actually follow the language spec like it's
758 # supposed to, instead of not following it like old buggy versions did.
759 # There's absolutely no reason to turn this on.
762 # C4355: 'this': used in base member initializer list
763 # It's commonly useful to pass |this| to objects in a class' initializer
764 # list. While this warning can catch real bugs, most of the time the
765 # constructors in question don't attempt to call methods on the passed-in
766 # pointer (until later), and annotating every legit usage of this is
767 # simply more hassle than the warning is worth.
770 # C4503: 'identifier': decorated name length exceeded, name was
772 # This only means that some long error messages might have truncated
773 # identifiers in the presence of lots of templates. It has no effect on
774 # program correctness and there's no real reason to waste time trying to
778 # Warning C4589 says: "Constructor of abstract class ignores
779 # initializer for virtual base class." Disable this warning because it
780 # is flaky in VS 2015 RTM. It triggers on compiler generated
781 # copy-constructors in some cases.
784 # C4611: interaction between 'function' and C++ object destruction is
786 # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN
787 # suggests using exceptions instead of setjmp/longjmp for C++, but
788 # Chromium code compiles without exception support. We therefore have to
789 # use setjmp/longjmp for e.g. JPEG decode error handling, which means we
790 # have to turn off this warning (and be careful about how object
791 # destruction happens in such cases).
794 # Warnings to evaluate and possibly fix/reenable later:
796 "/wd4100", # Unreferenced formal function parameter.
797 "/wd4121", # Alignment of a member was sensitive to packing.
798 "/wd4244", # Conversion: possible loss of data.
799 "/wd4481", # Nonstandard extension: override specifier.
800 "/wd4505", # Unreferenced local function has been removed.
801 "/wd4510", # Default constructor could not be generated.
802 "/wd4512", # Assignment operator could not be generated.
803 "/wd4610", # Class can never be instantiated, constructor required.
804 "/wd4995", # 'X': name was marked as #pragma deprecated
805 "/wd4996", # Deprecated function warning.
808 # VS xtree header file needs to be patched or 4702 (unreachable code
809 # warning) is reported if _HAS_EXCEPTIONS=0. Disable the warning if xtree is
811 if (!msvs_xtree_patched &&
812 exec_script("../../win_is_xtree_patched.py", [], "value") == 0) {
813 default_warning_flags += [ "/wd4702" ] # Unreachable code.
816 # Building with Clang on Windows is a work in progress and very
817 # experimental. See crbug.com/82385.
818 # Keep this in sync with the similar block in build/common.gypi
820 default_warning_flags += [
821 # TODO(hans): Make this list shorter eventually, http://crbug.com/504657
822 "-Qunused-arguments", # http://crbug.com/504658
823 "-Wno-microsoft", # http://crbug.com/505296
824 "-Wno-switch", # http://crbug.com/505308
825 "-Wno-unknown-pragmas", # http://crbug.com/505314
826 "-Wno-unused-function", # http://crbug.com/505316
827 "-Wno-unused-value", # http://crbug.com/505318
831 # Common GCC warning setup.
832 default_warning_flags += [
834 "-Wendif-labels", # Weird old-style text after an #endif.
835 "-Werror", # Warnings as errors.
838 "-Wno-missing-field-initializers", # "struct foo f = {0};"
839 "-Wno-unused-parameter", # Unused function parameters.
843 default_warning_flags += [ "-Wnewline-eof" ]
845 # When compiling Objective-C, warns if a method is used whose
846 # availability is newer than the deployment target. This is not
847 # required when compiling Chrome for iOS.
848 default_warning_flags += [ "-Wpartial-availability" ]
852 if (gcc_version >= 48) {
853 default_warning_flags_cc += [
854 # See comment for -Wno-c++11-narrowing.
857 # TODO(thakis): Remove, http://crbug.com/263960
858 "-Wno-literal-suffix",
862 # Suppress warnings about ABI changes on ARM (Clang doesn't give this
864 if (current_cpu == "arm" && !is_clang) {
865 default_warning_flags += [ "-Wno-psabi" ]
869 # Disable any additional warnings enabled by the Android build system but
870 # which chromium does not build cleanly with (when treating warning as
872 default_warning_flags += [
874 "-Wno-ignored-qualifiers",
877 default_warning_flags_cc += [
878 # Disabling c++0x-compat should be handled in WebKit, but
879 # this currently doesn't work because gcc_version is not set
880 # correctly when building with the Android build system.
881 # TODO(torne): Fix this in WebKit.
882 "-Wno-error=c++0x-compat",
884 # Other things unrelated to -Wextra:
885 "-Wno-non-virtual-dtor",
890 if (gcc_version >= 48) {
891 # Don't warn about the "typedef 'foo' locally defined but not used"
893 # TODO: remove this flag once all builds work. See crbug.com/227506
894 default_warning_flags += [ "-Wno-unused-local-typedefs" ]
898 default_warning_flags += [
899 # This warns on using ints as initializers for floats in
900 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
901 # which happens in several places in chrome code. Not sure if
902 # this is worth fixing.
903 "-Wno-c++11-narrowing",
905 # Don't die on dtoa code that uses a char as an array index.
906 # This is required solely for base/third_party/dmg_fp/dtoa.cc.
907 # TODO(brettw) move this to that project then!
908 "-Wno-char-subscripts",
910 # Warns on switches on enums that cover all enum values but
911 # also contain a default: branch. Chrome is full of that.
912 "-Wno-covered-switch-default",
914 # Clang considers the `register` keyword as deprecated, but e.g.
915 # code generated by flex (used in angle) contains that keyword.
916 # http://crbug.com/255186
917 "-Wno-deprecated-register",
919 # TODO(thakis): This used to be implied by -Wno-unused-function,
920 # which we no longer use. Check if it makes sense to remove
921 # this as well. http://crbug.com/316352
922 "-Wno-unneeded-internal-declaration",
924 # TODO(thakis): Remove, http://crbug.com/263960
925 "-Wno-reserved-user-defined-literal",
928 # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost
929 # always have different versions. Certain flags may not be recognized by
930 # one version or the other.
932 # Flags NaCl does not recognize.
933 default_warning_flags += [
934 # TODO(hans): Get this cleaned up, http://crbug.com/428099
935 "-Wno-inconsistent-missing-override",
937 # TODO(thakis): Enable this, crbug.com/507717
938 "-Wno-shift-negative-value",
943 # chromium_code ---------------------------------------------------------------
945 # Toggles between higher and lower warnings for code that is (or isn't)
948 config("chromium_code") {
950 cflags = [ "/W4" ] # Warning level 4.
955 # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't,
956 # so we specify it explicitly.
957 # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it.
958 # http://code.google.com/p/chromium/issues/detail?id=90453
962 # In Chromium code, we define __STDC_foo_MACROS in order to get the
963 # C99 macros on Mac and Linux.
965 "__STDC_CONSTANT_MACROS",
966 "__STDC_FORMAT_MACROS",
969 if (!using_sanitizer && (!is_linux || !is_clang || is_official_build)) {
970 # _FORTIFY_SOURCE isn't really supported by Clang now, see
971 # http://llvm.org/bugs/show_bug.cgi?id=16821.
972 # It seems to work fine with Ubuntu 12 headers though, so use it in
975 # Non-chromium code is not guaranteed to compile cleanly with
976 # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are
977 # disabled, so only do that for Release build.
978 defines += [ "_FORTIFY_SOURCE=2" ]
981 cflags += default_warning_flags
982 cflags_cc = default_warning_flags_cc
984 config("no_chromium_code") {
991 "/W3", # Warning level 3.
992 "/wd4800", # Disable warning when forcing value to bool.
993 "/wd4267", # TODO(jschuh): size_t to int.
994 "/wd4996", # Deprecated function warning.
997 "_CRT_NONSTDC_NO_WARNINGS",
998 "_CRT_NONSTDC_NO_DEPRECATE",
1003 # Don't warn about ignoring the return value from e.g. close(). This is
1004 # off by default in some gccs but on by default in others. BSD systems do
1005 # not support this option, since they are usually using gcc 4.2.1, which
1006 # does not have this flag yet.
1007 cflags += [ "-Wno-unused-result" ]
1012 # TODO(mgiuca): Move this suppression into individual third-party
1013 # libraries as required. http://crbug.com/505301.
1014 "-Wno-overloaded-virtual",
1016 # Lots of third-party libraries have unused variables. Instead of
1017 # suppressing them individually, we just blanket suppress them here.
1018 "-Wno-unused-variable",
1022 if (is_linux || is_android) {
1024 # Don't warn about printf format problems. This is off by default in gcc
1025 # but on in Ubuntu's gcc(!).
1029 # Don't warn about hash_map in third-party code.
1033 cflags += default_warning_flags
1034 cflags_cc += default_warning_flags_cc
1037 # rtti ------------------------------------------------------------------------
1039 # Allows turning Run-Time Type Identification on or off.
1043 cflags_cc = [ "/GR" ]
1048 cflags_cc = [ "/GR-" ]
1050 cflags_cc = [ "-fno-rtti" ]
1051 cflags_objcc = cflags_cc
1055 # Warnings ---------------------------------------------------------------------
1057 # This will generate warnings when using Clang if code generates exit-time
1058 # destructors, which will slow down closing the program.
1059 # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600
1060 config("wexit_time_destructors") {
1061 # TODO: Enable on Windows too, http://crbug.com/404525
1062 if (is_clang && !is_win) {
1063 cflags = [ "-Wexit-time-destructors" ]
1067 # On Windows compiling on x64, VC will issue a warning when converting
1068 # size_t to int because it will truncate the value. Our code should not have
1069 # these warnings and one should use a static_cast or a checked_cast for the
1070 # conversion depending on the case. However, a lot of code still needs to be
1071 # fixed. Apply this config to such targets to disable the warning.
1073 # Note that this can be applied regardless of platform and architecture to
1074 # clean up the call sites. This will only apply the flag when necessary.
1076 # TODO(jschuh): crbug.com/167187 fix this and delete this config.
1077 config("no_size_t_to_int_warning") {
1078 if (is_win && current_cpu == "x64") {
1079 cflags = [ "/wd4267" ]
1083 # Some code presumes that pointers to structures/objects are compatible
1084 # regardless of whether what they point to is already known to be valid.
1085 # gcc 4.9 and earlier had no way of suppressing this warning without
1086 # supressing the rest of them. Here we centralize the identification of
1087 # the gcc 4.9 toolchains.
1088 config("no_incompatible_pointer_warnings") {
1091 cflags += [ "-Wno-incompatible-pointer-types" ]
1092 } else if (current_cpu == "mipsel") {
1094 } else if (is_chromeos && current_cpu == "arm") {
1099 # Optimization -----------------------------------------------------------------
1101 # Note that BUILDCONFIG.gn sets up a variable "default_optimization_config"
1102 # which it will assign to the config it implicitly applies to every target. If
1103 # you want to override the optimization level for your target, remove this
1104 # config (which will expand differently for debug or release builds), and then
1105 # add back the one you want to override it with:
1107 # configs -= default_optimization_config
1108 # configs += [ "//build/config/compiler/optimize_max" ]
1110 # Shared settings for both "optimize" and "optimize_max" configs.
1111 # IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags.
1113 common_optimize_on_cflags = [
1114 "/Ob2", # Both explicit and auto inlining.
1115 "/Oy-", # Disable omitting frame pointers, must be after /O2.
1118 common_optimize_on_cflags += [
1119 # Put data in separate COMDATs. This allows the linker
1120 # to put bit-identical constants at the same address even if
1121 # they're unrelated constants, which saves binary size.
1122 # This optimization can't be used when ASan is enabled because
1123 # it is not compatible with the ASan ODR checker.
1127 common_optimize_on_ldflags = [ "/OPT:REF" ]
1129 common_optimize_on_cflags = [
1130 # Don't emit the GCC version ident directives, they just end up in the
1131 # .comment section taking up binary size.
1134 # Put data and code in their own sections, so that unused symbols
1135 # can be removed at link time with --gc-sections.
1137 "-ffunction-sections",
1139 common_optimize_on_ldflags = []
1142 if (!using_sanitizer) {
1143 common_optimize_on_cflags += [ "-fomit-frame-pointer" ]
1146 # TODO(jdduke) Re-enable on mips after resolving linking
1147 # issues with libc++ (crbug.com/456380).
1148 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
1149 common_optimize_on_ldflags += [
1150 # Warn in case of text relocations.
1151 "-Wl,--warn-shared-textrel",
1157 if (symbol_level == 2) {
1158 # Mac dead code stripping requires symbols.
1159 common_optimize_on_ldflags += [ "-Wl,-dead_strip" ]
1162 # Non-Mac Posix linker flags.
1163 common_optimize_on_ldflags += [
1164 # Specifically tell the linker to perform optimizations.
1165 # See http://lwn.net/Articles/192624/ .
1167 "-Wl,--gc-sections",
1170 if (!using_sanitizer) {
1171 # Functions interposed by the sanitizers can make ld think
1172 # that some libraries aren't needed when they actually are,
1173 # http://crbug.com/234010. As workaround, disable --as-needed.
1174 common_optimize_on_ldflags += [ "-Wl,--as-needed" ]
1179 # Default "optimization on" config. On Windows, this favors size over speed.
1180 config("optimize") {
1182 # Favor size over speed, /O1 must be before the common flags. The GYP
1183 # build also specifies /Os and /GF but these are implied by /O1.
1184 cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
1185 } else if (is_android || is_ios) {
1186 cflags = [ "-Os" ] + common_optimize_on_cflags # Favor size over speed.
1188 cflags = [ "-O2" ] + common_optimize_on_cflags
1190 ldflags = common_optimize_on_ldflags
1193 # Turn off optimizations.
1194 config("no_optimize") {
1197 "/Od", # Disable optimization.
1198 "/Ob0", # Disable all inlining (on by default).
1199 "/RTC1", # Runtime checks for stack frame and uninitialized variables.
1201 } else if (is_android && !android_full_debug) {
1202 # On Android we kind of optimize some things that don't affect debugging
1203 # much even when optimization is disabled to get the binary size down.
1207 "-ffunction-sections",
1209 if (!using_sanitizer) {
1210 cflags += [ "-fomit-frame-pointer" ]
1212 ldflags = common_optimize_on_ldflags
1218 # Turns up the optimization level. On Windows, this implies whole program
1219 # optimization and link-time code generation which is very expensive and should
1220 # be used sparingly.
1221 config("optimize_max") {
1222 ldflags = common_optimize_on_ldflags
1224 # Favor speed over size, /O2 must be before the common flags. The GYP
1225 # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2.
1226 cflags = [ "/O2" ] + common_optimize_on_cflags
1227 if (is_official_build) {
1228 # TODO(GYP): TODO(dpranke): Should these only be on in an official
1229 # build, or on all the time? For now we'll require official build so
1230 # that the compile is clean.
1232 "/GL", # Whole program optimization.
1234 # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds.
1235 # Probably anything that this would catch that wouldn't be caught in a
1236 # normal build isn't going to actually be a bug, so the incremental
1237 # value of C4702 for PGO builds is likely very small.
1240 ldflags += [ "/LTCG" ]
1243 cflags = [ "-O2" ] + common_optimize_on_cflags
1247 # Symbols ----------------------------------------------------------------------
1251 import("//build/toolchain/goma.gni")
1253 cflags = [ "/Z7" ] # No PDB file
1255 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
1257 if (is_win_fastlink) {
1258 # Tell VS 2015+ to create a PDB that references debug
1259 # information in .obj and .lib files instead of copying
1260 # it all. This flag is incompatible with /PROFILE
1261 ldflags = [ "/DEBUG:FASTLINK" ]
1263 ldflags = [ "/DEBUG" ]
1267 if (use_debug_fission) {
1268 cflags += [ "-gsplit-dwarf" ]
1273 config("minimal_symbols") {
1275 # Linker symbols for backtraces only.
1276 if (is_win_fastlink) {
1277 # Tell VS 2015+ to create a PDB that references debug
1278 # information in .obj and .lib files instead of copying
1279 # it all. This flag is incompatible with /PROFILE
1280 ldflags = [ "/DEBUG:FASTLINK" ]
1282 ldflags = [ "/DEBUG" ]
1286 if (use_debug_fission) {
1287 cflags += [ "-gsplit-dwarf" ]
1292 config("no_symbols") {