OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import("//build/config/android/config.gni") | 5 import("//build/config/android/config.gni") |
6 import("//build/config/chrome_build.gni") | 6 import("//build/config/chrome_build.gni") |
7 if (current_cpu == "arm") { | 7 if (current_cpu == "arm") { |
8 import("//build/config/arm.gni") | 8 import("//build/config/arm.gni") |
9 } | 9 } |
10 if (current_cpu == "mipsel" || current_cpu == "mips64el") { | 10 if (current_cpu == "mipsel" || current_cpu == "mips64el") { |
11 import("//build/config/mips.gni") | 11 import("//build/config/mips.gni") |
12 } | 12 } |
13 if (is_posix) { | 13 if (is_posix) { |
14 import("//build/config/gcc/gcc_version.gni") | 14 import("//build/config/gcc/gcc_version.gni") |
15 } | 15 } |
16 | 16 |
17 import("//build/toolchain/ccache.gni") | 17 import("//build/toolchain/ccache.gni") |
| 18 import("//build/config/sanitizers/sanitizers.gni") |
18 | 19 |
19 declare_args() { | 20 declare_args() { |
20 # Normally, Android builds are lightly optimized, even for debug builds, to | 21 # Normally, Android builds are lightly optimized, even for debug builds, to |
21 # keep binary size down. Setting this flag to true disables such optimization | 22 # keep binary size down. Setting this flag to true disables such optimization |
22 android_full_debug = false | 23 android_full_debug = false |
23 | 24 |
24 # Whether to use the binary binutils checked into third_party/binutils. | 25 # Whether to use the binary binutils checked into third_party/binutils. |
25 # These are not multi-arch so cannot be used except on x86 and x86-64 (the | 26 # These are not multi-arch so cannot be used except on x86 and x86-64 (the |
26 # only two architectures that are currently checked in). Turn this off when | 27 # only two architectures that are currently checked in). Turn this off when |
27 # you are using a custom toolchain and need to control -B in cflags. | 28 # you are using a custom toolchain and need to control -B in cflags. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 # GCC flags, and then we handle the other non-Windows platforms specifically | 95 # GCC flags, and then we handle the other non-Windows platforms specifically |
95 # below. | 96 # below. |
96 if (is_win) { | 97 if (is_win) { |
97 # Windows compiler flags setup. | 98 # Windows compiler flags setup. |
98 # ----------------------------- | 99 # ----------------------------- |
99 cflags += [ | 100 cflags += [ |
100 "/Gy", # Enable function-level linking. | 101 "/Gy", # Enable function-level linking. |
101 "/GS", # Enable buffer security checking. | 102 "/GS", # Enable buffer security checking. |
102 "/FS", # Preserve previous PDB behavior. | 103 "/FS", # Preserve previous PDB behavior. |
103 ] | 104 ] |
| 105 |
| 106 # Building with Clang on Windows is a work in progress and very |
| 107 # experimental. See crbug.com/82385. |
| 108 # Keep this in sync with the similar block in build/common.gypi |
| 109 if (is_clang) { |
| 110 cflags += [ |
| 111 # Many files use intrinsics without including this header. |
| 112 # TODO(hans): Fix those files, or move this to sub-GYPs. |
| 113 "/FIIntrin.h", |
| 114 ] |
| 115 |
| 116 if (visual_studio_version == "2013") { |
| 117 cflags += [ "-fmsc-version=1800" ] |
| 118 } else if (visual_studio_version == "2015") { |
| 119 cflags += [ "-fmsc-version=1900" ] |
| 120 } |
| 121 |
| 122 if (current_cpu == "x86") { |
| 123 cflags += [ |
| 124 "/fallback", |
| 125 "-m32", |
| 126 ] |
| 127 } else { |
| 128 cflags += [ "-m64" ] |
| 129 } |
| 130 } |
104 } else { | 131 } else { |
105 # Common GCC compiler flags setup. | 132 # Common GCC compiler flags setup. |
106 # -------------------------------- | 133 # -------------------------------- |
107 cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204 | 134 cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204 |
108 cflags_cc += [ | 135 cflags_cc += [ |
109 "-fno-threadsafe-statics", | 136 "-fno-threadsafe-statics", |
110 | 137 |
111 # Not exporting C++ inline functions can generally be applied anywhere | 138 # Not exporting C++ inline functions can generally be applied anywhere |
112 # so we do so here. Normal function visibility is controlled by | 139 # so we do so here. Normal function visibility is controlled by |
113 # //build/config/gcc:symbol_visibility_hidden. | 140 # //build/config/gcc:symbol_visibility_hidden. |
114 "-fvisibility-inlines-hidden", | 141 "-fvisibility-inlines-hidden", |
115 ] | 142 ] |
116 | 143 |
117 # Stack protection. | 144 # Stack protection. |
118 if (is_mac) { | 145 if (is_mac) { |
119 cflags += [ "-fstack-protector-all" ] | 146 cflags += [ "-fstack-protector-all" ] |
120 } else if (is_linux) { | 147 } else if (is_linux) { |
121 cflags += [ | 148 cflags += [ |
122 "-fstack-protector", | 149 "-fstack-protector", |
123 "--param=ssp-buffer-size=4", | 150 "--param=ssp-buffer-size=4", |
124 ] | 151 ] |
125 } | 152 } |
126 | 153 |
127 # Linker warnings. | 154 # Linker warnings. |
128 if (!(is_chromeos && current_cpu == "arm") && !is_mac) { | 155 if (!(is_chromeos && current_cpu == "arm") && !is_mac && !is_ios) { |
129 # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580 | 156 # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580 |
130 ldflags += [ "-Wl,--fatal-warnings" ] | 157 ldflags += [ "-Wl,--fatal-warnings" ] |
131 } | 158 } |
132 | 159 |
133 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer and | 160 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer and |
134 # MemorySanitizer | 161 # MemorySanitizer |
135 if (using_sanitizer) { | 162 if (using_sanitizer) { |
136 cflags += [ | 163 cflags += [ |
137 "-fno-omit-frame-pointer", | 164 "-fno-omit-frame-pointer", |
138 "-gline-tables-only", | 165 "-gline-tables-only", |
139 ] | 166 ] |
140 } | 167 } |
141 if (is_asan) { | 168 if (is_asan) { |
142 cflags += [ "-fsanitize=address" ] | 169 asan_blacklist_path = |
| 170 rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir) |
| 171 cflags += [ |
| 172 "-fsanitize=address", |
| 173 "-fsanitize-blacklist=$asan_blacklist_path", |
| 174 ] |
143 if (is_mac) { | 175 if (is_mac) { |
144 cflags += [ "-mllvm -asan-globals=0" ] # http://crbug.com/352073 | 176 cflags += [ "-mllvm -asan-globals=0" ] # http://crbug.com/352073 |
145 # TODO(GYP): deal with mac_bundles. | 177 # TODO(GYP): deal with mac_bundles. |
146 } | 178 } |
147 } | 179 } |
| 180 if (is_lsan) { |
| 181 cflags += [ "-fsanitize=leak" ] |
| 182 } |
| 183 if (is_tsan) { |
| 184 tsan_blacklist_path = |
| 185 rebase_path("//tools/memory/tsan_v2/ignores.txt", root_build_dir) |
| 186 cflags += [ |
| 187 "-fsanitize=thread", |
| 188 "-fsanitize-blacklist=$tsan_blacklist_path", |
| 189 ] |
| 190 } |
| 191 if (is_msan) { |
| 192 msan_blacklist_path = |
| 193 rebase_path("//tools/msan/blacklist.txt", root_build_dir) |
| 194 cflags += [ |
| 195 "-fsanitize=memory", |
| 196 "-fsanitize-memory-track-origins=$msan_track_origins", |
| 197 "-fsanitize-blacklist=$msan_blacklist_path", |
| 198 ] |
| 199 } |
| 200 |
| 201 if (use_custom_libcxx) { |
| 202 cflags_cc += [ "-nostdinc++" ] |
| 203 include_dirs = [ |
| 204 "//buildtools/third_party/libc++/trunk/include", |
| 205 "//buildtools/third_party/libc++abi/trunk/include", |
| 206 ] |
| 207 } |
148 } | 208 } |
149 | 209 |
150 if (is_clang && is_debug) { | 210 if (is_clang && is_debug) { |
151 # Allow comparing the address of references and 'this' against 0 | 211 # Allow comparing the address of references and 'this' against 0 |
152 # in debug builds. Technically, these can never be null in | 212 # in debug builds. Technically, these can never be null in |
153 # well-defined C/C++ and Clang can optimize such checks away in | 213 # well-defined C/C++ and Clang can optimize such checks away in |
154 # release builds, but they may be used in asserts in debug builds. | 214 # release builds, but they may be used in asserts in debug builds. |
155 cflags_cc += [ | 215 cflags_cc += [ |
156 "-Wno-undefined-bool-conversion", | 216 "-Wno-undefined-bool-conversion", |
157 "-Wno-tautological-undefined-compare", | 217 "-Wno-tautological-undefined-compare", |
(...skipping 21 matching lines...) Expand all Loading... |
179 if (current_cpu == "x64") { | 239 if (current_cpu == "x64") { |
180 common_mac_flags += [ | 240 common_mac_flags += [ |
181 "-arch", | 241 "-arch", |
182 "x86_64", | 242 "x86_64", |
183 ] | 243 ] |
184 } else if (current_cpu == "x86") { | 244 } else if (current_cpu == "x86") { |
185 common_mac_flags += [ | 245 common_mac_flags += [ |
186 "-arch", | 246 "-arch", |
187 "i386", | 247 "i386", |
188 ] | 248 ] |
| 249 } else if (current_cpu == "arm") { |
| 250 common_mac_flags += [ |
| 251 "-arch", |
| 252 "armv7", |
| 253 ] |
189 } | 254 } |
190 | 255 |
191 cflags += common_mac_flags | 256 cflags += common_mac_flags |
192 | 257 |
193 # Without this, the constructors and destructors of a C++ object inside | 258 # Without this, the constructors and destructors of a C++ object inside |
194 # an Objective C struct won't be called, which is very bad. | 259 # an Objective C struct won't be called, which is very bad. |
195 cflags_objcc = [ "-fobjc-call-cxx-cdtors" ] | 260 cflags_objcc = [ "-fobjc-call-cxx-cdtors" ] |
196 | 261 |
197 cflags_c += [ "-std=c99" ] | 262 cflags_c += [ "-std=c99" ] |
198 | 263 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 # for these builds. | 398 # for these builds. |
334 if (is_chrome_branded && is_official_build) { | 399 if (is_chrome_branded && is_official_build) { |
335 cflags += [ | 400 cflags += [ |
336 "-fno-unwind-tables", | 401 "-fno-unwind-tables", |
337 "-fno-asynchronous-unwind-tables", | 402 "-fno-asynchronous-unwind-tables", |
338 ] | 403 ] |
339 defines += [ "NO_UNWIND_TABLES" ] | 404 defines += [ "NO_UNWIND_TABLES" ] |
340 } else { | 405 } else { |
341 cflags += [ "-funwind-tables" ] | 406 cflags += [ "-funwind-tables" ] |
342 } | 407 } |
| 408 |
| 409 if (is_clang && !is_nacl && !is_debug) { |
| 410 # Non-unique section names appears to make linker dead stripping |
| 411 # less effective. See http://crbug.com/483026#c20 |
| 412 # TODO(hans): Remove this if resolved upstream. |
| 413 cflags += [ "-funique-section-names" ] |
| 414 } |
343 } | 415 } |
344 | 416 |
345 # Linux/Android common flags setup. | 417 # Linux/Android common flags setup. |
346 # --------------------------------- | 418 # --------------------------------- |
347 if (is_linux || is_android) { | 419 if (is_linux || is_android) { |
348 cflags += [ | 420 cflags += [ |
349 "-fPIC", | 421 "-fPIC", |
350 "-pipe", # Use pipes for communicating between sub-processes. Faster. | 422 "-pipe", # Use pipes for communicating between sub-processes. Faster. |
351 ] | 423 ] |
352 | 424 |
(...skipping 18 matching lines...) Expand all Loading... |
371 gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", | 443 gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", |
372 root_build_dir) | 444 root_build_dir) |
373 ldflags += [ | 445 ldflags += [ |
374 "-B$gold_path", | 446 "-B$gold_path", |
375 | 447 |
376 # Newer gccs and clangs support -fuse-ld, use the flag to force gold | 448 # Newer gccs and clangs support -fuse-ld, use the flag to force gold |
377 # selection. | 449 # selection. |
378 # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html | 450 # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html |
379 "-fuse-ld=gold", | 451 "-fuse-ld=gold", |
380 | 452 |
381 # TODO(brettw) common.gypi has this only for target toolset. | |
382 "-Wl,--icf=safe", | |
383 | |
384 # Experimentation found that using four linking threads | 453 # Experimentation found that using four linking threads |
385 # saved ~20% of link time. | 454 # saved ~20% of link time. |
386 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_threa
d/thread/281527606915bb36 | 455 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_threa
d/thread/281527606915bb36 |
387 # Only apply this to the target linker, since the host | 456 # Only apply this to the target linker, since the host |
388 # linker might not be gold, but isn't used much anyway. | 457 # linker might not be gold, but isn't used much anyway. |
389 # TODO(raymes): Disable threading because gold is frequently | 458 # TODO(raymes): Disable threading because gold is frequently |
390 # crashing on the bots: crbug.com/161942. | 459 # crashing on the bots: crbug.com/161942. |
391 #"-Wl,--threads", | 460 #"-Wl,--threads", |
392 #"-Wl,--thread-count=4", | 461 #"-Wl,--thread-count=4", |
393 ] | 462 ] |
394 | 463 |
| 464 if (!is_asan && !is_msan && !is_lsan && !is_tsan) { |
| 465 # TODO(brettw) common.gypi has this only for target toolset. |
| 466 if (current_cpu == "x64") { |
| 467 # --icf=safe disables much more folding on x86_64 than elsewhere, see |
| 468 # http://crbug.com/492177. Turning it on saves over 12 MB of binary |
| 469 # size, but it seems to regress cold startup time by over a second |
| 470 # (see http://crbug.com/492809). |
| 471 # TODO(thakis): Check if disabling ICF would inmprove android cold start |
| 472 # times by several seconds too. |
| 473 ldflags += [ "-Wl,--icf=safe" ] |
| 474 } else { |
| 475 ldflags += [ "-Wl,--icf=all" ] |
| 476 } |
| 477 } |
| 478 |
395 # TODO(thestig): Make this flag work with GN. | 479 # TODO(thestig): Make this flag work with GN. |
396 #if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan |
| is_msan)) { | 480 #if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan |
| is_msan)) { |
397 # ldflags += [ | 481 # ldflags += [ |
398 # "-Wl,--detect-odr-violations", | 482 # "-Wl,--detect-odr-violations", |
399 # ] | 483 # ] |
400 #} | 484 #} |
401 } | 485 } |
402 | 486 |
403 if (linux_use_bundled_binutils) { | 487 if (linux_use_bundled_binutils) { |
404 binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", | 488 binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 ldflags += [ "-target arm-linux-androideabi" ] | 570 ldflags += [ "-target arm-linux-androideabi" ] |
487 } else if (current_cpu == "x86") { | 571 } else if (current_cpu == "x86") { |
488 cflags += [ "-target x86-linux-androideabi" ] | 572 cflags += [ "-target x86-linux-androideabi" ] |
489 ldflags += [ "-target x86-linux-androideabi" ] | 573 ldflags += [ "-target x86-linux-androideabi" ] |
490 } | 574 } |
491 } | 575 } |
492 } | 576 } |
493 } | 577 } |
494 | 578 |
495 config("compiler_arm_fpu") { | 579 config("compiler_arm_fpu") { |
496 if (current_cpu == "arm") { | 580 if (current_cpu == "arm" && !is_ios) { |
497 cflags = [ "-mfpu=$arm_fpu" ] | 581 cflags = [ "-mfpu=$arm_fpu" ] |
498 } | 582 } |
499 } | 583 } |
500 | 584 |
501 # runtime_library ------------------------------------------------------------- | 585 # runtime_library ------------------------------------------------------------- |
502 # | 586 # |
503 # Sets the runtime library and associated options. | 587 # Sets the runtime library and associated options. |
504 # | 588 # |
505 # How do you determine what should go in here vs. "compiler" above? Consider if | 589 # How do you determine what should go in here vs. "compiler" above? Consider if |
506 # a target might choose to use a different runtime library (ignore for a moment | 590 # a target might choose to use a different runtime library (ignore for a moment |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 ] | 671 ] |
588 | 672 |
589 lib_dirs += [ "$android_libcpp_root/libs/$android_app_abi" ] | 673 lib_dirs += [ "$android_libcpp_root/libs/$android_app_abi" ] |
590 | 674 |
591 if (component_mode == "shared_library") { | 675 if (component_mode == "shared_library") { |
592 android_libcpp_library = "c++_shared" | 676 android_libcpp_library = "c++_shared" |
593 } else { | 677 } else { |
594 android_libcpp_library = "c++_static" | 678 android_libcpp_library = "c++_static" |
595 } | 679 } |
596 | 680 |
| 681 libs += [ "$android_libcpp_library" ] |
| 682 |
| 683 if (current_cpu == "mipsel") { |
| 684 libs += [ |
| 685 # ld linker is used for mips Android, and ld does not accept library |
| 686 # absolute path prefixed by "-l"; Since libgcc does not exist in mips |
| 687 # sysroot the proper library will be linked. |
| 688 # TODO(gordanac): Remove once gold linker is used for mips Android. |
| 689 "gcc", |
| 690 ] |
| 691 } else { |
| 692 libs += [ |
| 693 # Manually link the libgcc.a that the cross compiler uses. This is |
| 694 # absolute because the linker will look inside the sysroot if it's not. |
| 695 rebase_path(android_libgcc_file), |
| 696 ] |
| 697 } |
| 698 |
597 libs += [ | 699 libs += [ |
598 "$android_libcpp_library", | |
599 | |
600 # Manually link the libgcc.a that the cross compiler uses. This is | |
601 # absolute because the linker will look inside the sysroot if it's not. | |
602 rebase_path(android_libgcc_file), | |
603 "c", | 700 "c", |
604 "dl", | 701 "dl", |
605 "m", | 702 "m", |
606 ] | 703 ] |
607 | 704 |
608 # Clang with libc++ does not require an explicit atomic library reference. | 705 # Clang with libc++ does not require an explicit atomic library reference. |
609 if (!is_clang) { | 706 if (!is_clang) { |
610 libs += [ "atomic" ] | 707 libs += [ "atomic" ] |
611 } | 708 } |
612 } | 709 } |
613 } | 710 } |
614 | 711 |
| 712 # default_warning_flags collects all warning flags that are used by default. |
| 713 # This is in a variable instead of a config so that it can be used in |
| 714 # both chromium_code and no_chromium_code. This way these flags are guaranteed |
| 715 # to appear on the compile command line after -Wall. |
| 716 |
| 717 default_warning_flags = [] |
| 718 default_warning_flags_cc = [] |
| 719 if (is_win) { |
| 720 if (!is_clang || current_cpu != "x86") { |
| 721 default_warning_flags += [ "/WX" ] # Treat warnings as errors. |
| 722 } |
| 723 |
| 724 default_warning_flags += [ |
| 725 # Warnings permanently disabled: |
| 726 |
| 727 # TODO(GYP) The GYP build doesn't have this globally enabled but disabled |
| 728 # for a bunch of individual targets. Re-enable this globally when those |
| 729 # targets are fixed. |
| 730 "/wd4018", # Comparing signed and unsigned values. |
| 731 |
| 732 # C4127: conditional expression is constant |
| 733 # This warning can in theory catch dead code and other problems, but |
| 734 # triggers in far too many desirable cases where the conditional |
| 735 # expression is either set by macros or corresponds some legitimate |
| 736 # compile-time constant expression (due to constant template args, |
| 737 # conditionals comparing the sizes of different types, etc.). Some of |
| 738 # these can be worked around, but it's not worth it. |
| 739 "/wd4127", |
| 740 |
| 741 # C4251: 'identifier' : class 'type' needs to have dll-interface to be |
| 742 # used by clients of class 'type2' |
| 743 # This is necessary for the shared library build. |
| 744 "/wd4251", |
| 745 |
| 746 # C4351: new behavior: elements of array 'array' will be default |
| 747 # initialized |
| 748 # This is a silly "warning" that basically just alerts you that the |
| 749 # compiler is going to actually follow the language spec like it's |
| 750 # supposed to, instead of not following it like old buggy versions did. |
| 751 # There's absolutely no reason to turn this on. |
| 752 "/wd4351", |
| 753 |
| 754 # C4355: 'this': used in base member initializer list |
| 755 # It's commonly useful to pass |this| to objects in a class' initializer |
| 756 # list. While this warning can catch real bugs, most of the time the |
| 757 # constructors in question don't attempt to call methods on the passed-in |
| 758 # pointer (until later), and annotating every legit usage of this is |
| 759 # simply more hassle than the warning is worth. |
| 760 "/wd4355", |
| 761 |
| 762 # C4503: 'identifier': decorated name length exceeded, name was |
| 763 # truncated |
| 764 # This only means that some long error messages might have truncated |
| 765 # identifiers in the presence of lots of templates. It has no effect on |
| 766 # program correctness and there's no real reason to waste time trying to |
| 767 # prevent it. |
| 768 "/wd4503", |
| 769 |
| 770 # C4611: interaction between 'function' and C++ object destruction is |
| 771 # non-portable |
| 772 # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN |
| 773 # suggests using exceptions instead of setjmp/longjmp for C++, but |
| 774 # Chromium code compiles without exception support. We therefore have to |
| 775 # use setjmp/longjmp for e.g. JPEG decode error handling, which means we |
| 776 # have to turn off this warning (and be careful about how object |
| 777 # destruction happens in such cases). |
| 778 "/wd4611", |
| 779 |
| 780 # Warnings to evaluate and possibly fix/reenable later: |
| 781 |
| 782 "/wd4100", # Unreferenced formal function parameter. |
| 783 "/wd4121", # Alignment of a member was sensitive to packing. |
| 784 "/wd4244", # Conversion: possible loss of data. |
| 785 "/wd4481", # Nonstandard extension: override specifier. |
| 786 "/wd4505", # Unreferenced local function has been removed. |
| 787 "/wd4510", # Default constructor could not be generated. |
| 788 "/wd4512", # Assignment operator could not be generated. |
| 789 "/wd4610", # Class can never be instantiated, constructor required. |
| 790 "/wd4996", # Deprecated function warning. |
| 791 ] |
| 792 |
| 793 # VS xtree header file needs to be patched or 4702 (unreachable code |
| 794 # warning) is reported if _HAS_EXCEPTIONS=0. Disable the warning if xtree is |
| 795 # not patched. |
| 796 if (!msvs_xtree_patched && |
| 797 exec_script("../../win_is_xtree_patched.py", [], "value") == 0) { |
| 798 default_warning_flags += [ "/wd4702" ] # Unreachable code. |
| 799 } |
| 800 |
| 801 # Building with Clang on Windows is a work in progress and very |
| 802 # experimental. See crbug.com/82385. |
| 803 # Keep this in sync with the similar block in build/common.gypi |
| 804 if (is_clang) { |
| 805 default_warning_flags += [ |
| 806 # TODO(hans): Make this list shorter eventually. |
| 807 "-Qunused-arguments", |
| 808 "-Wno-c++11-compat-deprecated-writable-strings", |
| 809 "-Wno-deprecated-declarations", |
| 810 "-Wno-empty-body", |
| 811 "-Wno-enum-conversion", |
| 812 "-Wno-extra-tokens", |
| 813 "-Wno-ignored-attributes", |
| 814 "-Wno-incompatible-pointer-types", |
| 815 "-Wno-int-to-void-pointer-cast", |
| 816 "-Wno-invalid-noreturn", |
| 817 "-Wno-logical-op-parentheses", |
| 818 "-Wno-microsoft", |
| 819 "-Wno-missing-braces", |
| 820 "-Wno-missing-declarations", |
| 821 "-Wno-msvc-include", |
| 822 "-Wno-null-dereference", |
| 823 "-Wno-overloaded-virtual", |
| 824 "-Wno-parentheses", |
| 825 "-Wno-pointer-sign", |
| 826 "-Wno-reorder", |
| 827 "-Wno-return-type-c-linkage", |
| 828 "-Wno-self-assign", |
| 829 "-Wno-sometimes-uninitialized", |
| 830 "-Wno-switch", |
| 831 "-Wno-tautological-compare", |
| 832 "-Wno-unknown-pragmas", |
| 833 "-Wno-unsequenced", |
| 834 "-Wno-unused-function", |
| 835 "-Wno-unused-private-field", |
| 836 "-Wno-unused-value", |
| 837 "-Wno-unused-variable", |
| 838 "-Wno-unused-local-typedef", # http://crbug.com/411648 |
| 839 "-Wno-inconsistent-missing-override", #http://crbug.com/428099 |
| 840 ] |
| 841 } |
| 842 } else { |
| 843 # Common GCC warning setup. |
| 844 default_warning_flags += [ |
| 845 # Enables. |
| 846 "-Wendif-labels", # Weird old-style text after an #endif. |
| 847 "-Werror", # Warnings as errors. |
| 848 |
| 849 # Disables. |
| 850 "-Wno-missing-field-initializers", # "struct foo f = {0};" |
| 851 "-Wno-unused-parameter", # Unused function parameters. |
| 852 ] |
| 853 |
| 854 if (is_mac) { |
| 855 default_warning_flags += [ "-Wnewline-eof" ] |
| 856 if (!is_nacl) { |
| 857 # When compiling Objective-C, warns if a method is used whose |
| 858 # availability is newer than the deployment target. This is not |
| 859 # required when compiling Chrome for iOS. |
| 860 default_warning_flags += [ "-Wpartial-availability" ] |
| 861 } |
| 862 } |
| 863 |
| 864 if (gcc_version >= 48) { |
| 865 default_warning_flags_cc += [ |
| 866 # See comment for -Wno-c++11-narrowing. |
| 867 "-Wno-narrowing", |
| 868 |
| 869 # TODO(thakis): Remove, http://crbug.com/263960 |
| 870 "-Wno-literal-suffix", |
| 871 ] |
| 872 } |
| 873 |
| 874 # Suppress warnings about ABI changes on ARM (Clang doesn't give this |
| 875 # warning). |
| 876 if (current_cpu == "arm" && !is_clang) { |
| 877 default_warning_flags += [ "-Wno-psabi" ] |
| 878 } |
| 879 |
| 880 if (is_android) { |
| 881 # Disable any additional warnings enabled by the Android build system but |
| 882 # which chromium does not build cleanly with (when treating warning as |
| 883 # errors). |
| 884 default_warning_flags += [ |
| 885 "-Wno-extra", |
| 886 "-Wno-ignored-qualifiers", |
| 887 "-Wno-type-limits", |
| 888 ] |
| 889 default_warning_flags_cc += [ |
| 890 # Disabling c++0x-compat should be handled in WebKit, but |
| 891 # this currently doesn't work because gcc_version is not set |
| 892 # correctly when building with the Android build system. |
| 893 # TODO(torne): Fix this in WebKit. |
| 894 "-Wno-error=c++0x-compat", |
| 895 |
| 896 # Other things unrelated to -Wextra: |
| 897 "-Wno-non-virtual-dtor", |
| 898 "-Wno-sign-promo", |
| 899 ] |
| 900 } |
| 901 |
| 902 if (gcc_version >= 48) { |
| 903 # Don't warn about the "typedef 'foo' locally defined but not used" |
| 904 # for gcc 4.8. |
| 905 # TODO: remove this flag once all builds work. See crbug.com/227506 |
| 906 default_warning_flags += [ "-Wno-unused-local-typedefs" ] |
| 907 } |
| 908 } |
| 909 if (is_clang) { |
| 910 default_warning_flags += [ |
| 911 # This warns on using ints as initializers for floats in |
| 912 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|), |
| 913 # which happens in several places in chrome code. Not sure if |
| 914 # this is worth fixing. |
| 915 "-Wno-c++11-narrowing", |
| 916 |
| 917 # Don't die on dtoa code that uses a char as an array index. |
| 918 # This is required solely for base/third_party/dmg_fp/dtoa.cc. |
| 919 # TODO(brettw) move this to that project then! |
| 920 "-Wno-char-subscripts", |
| 921 |
| 922 # Warns on switches on enums that cover all enum values but |
| 923 # also contain a default: branch. Chrome is full of that. |
| 924 "-Wno-covered-switch-default", |
| 925 |
| 926 # Clang considers the `register` keyword as deprecated, but e.g. |
| 927 # code generated by flex (used in angle) contains that keyword. |
| 928 # http://crbug.com/255186 |
| 929 "-Wno-deprecated-register", |
| 930 |
| 931 # TODO(thakis): This used to be implied by -Wno-unused-function, |
| 932 # which we no longer use. Check if it makes sense to remove |
| 933 # this as well. http://crbug.com/316352 |
| 934 "-Wno-unneeded-internal-declaration", |
| 935 |
| 936 # TODO(thakis): Remove, http://crbug.com/263960 |
| 937 "-Wno-reserved-user-defined-literal", |
| 938 ] |
| 939 |
| 940 # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost |
| 941 # always have different versions. Certain flags may not be recognized by |
| 942 # one version or the other. |
| 943 if (!is_nacl) { |
| 944 # Flags NaCl does not recognize. |
| 945 default_warning_flags += [ |
| 946 # TODO(hans): Get this cleaned up. |
| 947 "-Wno-inconsistent-missing-override", |
| 948 ] |
| 949 } |
| 950 } |
| 951 |
615 # chromium_code --------------------------------------------------------------- | 952 # chromium_code --------------------------------------------------------------- |
616 # | 953 # |
617 # Toggles between higher and lower warnings for code that is (or isn't) | 954 # Toggles between higher and lower warnings for code that is (or isn't) |
618 # part of Chromium. | 955 # part of Chromium. |
619 | 956 |
620 config("chromium_code") { | 957 config("chromium_code") { |
621 if (is_win) { | 958 if (is_win) { |
622 cflags = [ "/W4" ] # Warning level 4. | 959 cflags = [ "/W4" ] # Warning level 4. |
623 } else { | 960 } else { |
624 cflags = [ | 961 cflags = [ |
625 "-Wall", | 962 "-Wall", |
626 | 963 |
627 # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't, | 964 # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't, |
628 # so we specify it explicitly. | 965 # so we specify it explicitly. |
629 # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it. | 966 # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it. |
630 # http://code.google.com/p/chromium/issues/detail?id=90453 | 967 # http://code.google.com/p/chromium/issues/detail?id=90453 |
631 "-Wsign-compare", | 968 "-Wsign-compare", |
632 ] | 969 ] |
633 | 970 |
634 # In Chromium code, we define __STDC_foo_MACROS in order to get the | 971 # In Chromium code, we define __STDC_foo_MACROS in order to get the |
635 # C99 macros on Mac and Linux. | 972 # C99 macros on Mac and Linux. |
636 defines = [ | 973 defines = [ |
637 "__STDC_CONSTANT_MACROS", | 974 "__STDC_CONSTANT_MACROS", |
638 "__STDC_FORMAT_MACROS", | 975 "__STDC_FORMAT_MACROS", |
639 ] | 976 ] |
640 | 977 |
641 if (using_sanitizer) { | 978 if (!using_sanitizer && (!is_linux || !is_clang || is_official_build)) { |
642 # _FORTIFY_SOURCE isn't really supported by Clang now, see | 979 # _FORTIFY_SOURCE isn't really supported by Clang now, see |
643 # http://llvm.org/bugs/show_bug.cgi?id=16821. | 980 # http://llvm.org/bugs/show_bug.cgi?id=16821. |
644 # It seems to work fine with Ubuntu 12 headers though, so use it in | 981 # It seems to work fine with Ubuntu 12 headers though, so use it in |
645 # official builds. | 982 # official builds. |
646 # | 983 # |
647 # Non-chromium code is not guaranteed to compile cleanly with | 984 # Non-chromium code is not guaranteed to compile cleanly with |
648 # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are | 985 # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are |
649 # disabled, so only do that for Release build. | 986 # disabled, so only do that for Release build. |
650 defines += [ "_FORTIFY_SOURCE=2" ] | 987 defines += [ "_FORTIFY_SOURCE=2" ] |
651 } | 988 } |
652 } | 989 } |
| 990 cflags += default_warning_flags |
| 991 cflags_cc = default_warning_flags_cc |
653 } | 992 } |
654 config("no_chromium_code") { | 993 config("no_chromium_code") { |
655 cflags = [] | 994 cflags = [] |
656 cflags_cc = [] | 995 cflags_cc = [] |
657 defines = [] | 996 defines = [] |
658 | 997 |
659 if (is_win) { | 998 if (is_win) { |
660 cflags += [ | 999 cflags += [ |
661 "/W3", # Warning level 3. | 1000 "/W3", # Warning level 3. |
662 "/wd4800", # Disable warning when forcing value to bool. | 1001 "/wd4800", # Disable warning when forcing value to bool. |
(...skipping 18 matching lines...) Expand all Loading... |
681 cflags += [ | 1020 cflags += [ |
682 # Don't warn about printf format problems. This is off by default in gcc | 1021 # Don't warn about printf format problems. This is off by default in gcc |
683 # but on in Ubuntu's gcc(!). | 1022 # but on in Ubuntu's gcc(!). |
684 "-Wno-format", | 1023 "-Wno-format", |
685 ] | 1024 ] |
686 cflags_cc += [ | 1025 cflags_cc += [ |
687 # Don't warn about hash_map in third-party code. | 1026 # Don't warn about hash_map in third-party code. |
688 "-Wno-deprecated", | 1027 "-Wno-deprecated", |
689 ] | 1028 ] |
690 } | 1029 } |
| 1030 cflags += default_warning_flags |
| 1031 cflags_cc += default_warning_flags_cc |
691 } | 1032 } |
692 | 1033 |
693 # rtti ------------------------------------------------------------------------ | 1034 # rtti ------------------------------------------------------------------------ |
694 # | 1035 # |
695 # Allows turning Run-Time Type Identification on or off. | 1036 # Allows turning Run-Time Type Identification on or off. |
696 | 1037 |
697 config("rtti") { | 1038 config("rtti") { |
698 if (is_win) { | 1039 if (is_win) { |
699 cflags_cc = [ "/GR" ] | 1040 cflags_cc = [ "/GR" ] |
700 } | 1041 } |
701 } | 1042 } |
702 config("no_rtti") { | 1043 config("no_rtti") { |
703 if (is_win) { | 1044 if (is_win) { |
704 cflags_cc = [ "/GR-" ] | 1045 cflags_cc = [ "/GR-" ] |
705 } else { | 1046 } else { |
706 cflags_cc = [ "-fno-rtti" ] | 1047 cflags_cc = [ "-fno-rtti" ] |
707 } | 1048 } |
708 } | 1049 } |
709 | 1050 |
710 # Warnings --------------------------------------------------------------------- | 1051 # Warnings --------------------------------------------------------------------- |
711 # | |
712 # This is where we disable various warnings that we've decided aren't | |
713 # worthwhile, and enable special warnings. | |
714 | |
715 config("default_warnings") { | |
716 if (is_win) { | |
717 cflags = [ | |
718 "/WX", # Treat warnings as errors. | |
719 | |
720 # Warnings permanently disabled: | |
721 | |
722 # TODO(GYP) The GYP build doesn't have this globally enabled but disabled | |
723 # for a bunch of individual targets. Re-enable this globally when those | |
724 # targets are fixed. | |
725 "/wd4018", # Comparing signed and unsigned values. | |
726 | |
727 # C4127: conditional expression is constant | |
728 # This warning can in theory catch dead code and other problems, but | |
729 # triggers in far too many desirable cases where the conditional | |
730 # expression is either set by macros or corresponds some legitimate | |
731 # compile-time constant expression (due to constant template args, | |
732 # conditionals comparing the sizes of different types, etc.). Some of | |
733 # these can be worked around, but it's not worth it. | |
734 "/wd4127", | |
735 | |
736 # C4251: 'identifier' : class 'type' needs to have dll-interface to be | |
737 # used by clients of class 'type2' | |
738 # This is necessary for the shared library build. | |
739 "/wd4251", | |
740 | |
741 # C4351: new behavior: elements of array 'array' will be default | |
742 # initialized | |
743 # This is a silly "warning" that basically just alerts you that the | |
744 # compiler is going to actually follow the language spec like it's | |
745 # supposed to, instead of not following it like old buggy versions did. | |
746 # There's absolutely no reason to turn this on. | |
747 "/wd4351", | |
748 | |
749 # C4355: 'this': used in base member initializer list | |
750 # It's commonly useful to pass |this| to objects in a class' initializer | |
751 # list. While this warning can catch real bugs, most of the time the | |
752 # constructors in question don't attempt to call methods on the passed-in | |
753 # pointer (until later), and annotating every legit usage of this is | |
754 # simply more hassle than the warning is worth. | |
755 "/wd4355", | |
756 | |
757 # C4503: 'identifier': decorated name length exceeded, name was | |
758 # truncated | |
759 # This only means that some long error messages might have truncated | |
760 # identifiers in the presence of lots of templates. It has no effect on | |
761 # program correctness and there's no real reason to waste time trying to | |
762 # prevent it. | |
763 "/wd4503", | |
764 | |
765 # C4611: interaction between 'function' and C++ object destruction is | |
766 # non-portable | |
767 # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN | |
768 # suggests using exceptions instead of setjmp/longjmp for C++, but | |
769 # Chromium code compiles without exception support. We therefore have to | |
770 # use setjmp/longjmp for e.g. JPEG decode error handling, which means we | |
771 # have to turn off this warning (and be careful about how object | |
772 # destruction happens in such cases). | |
773 "/wd4611", | |
774 | |
775 # Warnings to evaluate and possibly fix/reenable later: | |
776 | |
777 "/wd4100", # Unreferenced formal function parameter. | |
778 "/wd4121", # Alignment of a member was sensitive to packing. | |
779 "/wd4244", # Conversion: possible loss of data. | |
780 "/wd4481", # Nonstandard extension: override specifier. | |
781 "/wd4505", # Unreferenced local function has been removed. | |
782 "/wd4510", # Default constructor could not be generated. | |
783 "/wd4512", # Assignment operator could not be generated. | |
784 "/wd4610", # Class can never be instantiated, constructor required. | |
785 "/wd4996", # Deprecated function warning. | |
786 ] | |
787 | |
788 # VS xtree header file needs to be patched or 4702 (unreachable code | |
789 # warning) is reported if _HAS_EXCEPTIONS=0. Disable the warning if xtree is | |
790 # not patched. | |
791 if (!msvs_xtree_patched && | |
792 exec_script("../../win_is_xtree_patched.py", [], "value") == 0) { | |
793 cflags += [ "/wd4702" ] # Unreachable code. | |
794 } | |
795 } else { | |
796 # Common GCC warning setup. | |
797 cflags = [ | |
798 # Enables. | |
799 "-Wendif-labels", # Weird old-style text after an #endif. | |
800 "-Werror", # Warnings as errors. | |
801 | |
802 # Disables. | |
803 "-Wno-missing-field-initializers", # "struct foo f = {0};" | |
804 "-Wno-unused-parameter", # Unused function parameters. | |
805 ] | |
806 cflags_cc = [] | |
807 | |
808 if (is_mac) { | |
809 cflags += [ "-Wnewline-eof" ] | |
810 } | |
811 | |
812 if (is_clang) { | |
813 cflags += [ | |
814 # This warns on using ints as initializers for floats in | |
815 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|), | |
816 # which happens in several places in chrome code. Not sure if | |
817 # this is worth fixing. | |
818 "-Wno-c++11-narrowing", | |
819 | |
820 # Don't die on dtoa code that uses a char as an array index. | |
821 # This is required solely for base/third_party/dmg_fp/dtoa.cc. | |
822 # TODO(brettw) move this to that project then! | |
823 "-Wno-char-subscripts", | |
824 | |
825 # Warns on switches on enums that cover all enum values but | |
826 # also contain a default: branch. Chrome is full of that. | |
827 "-Wno-covered-switch-default", | |
828 | |
829 # Clang considers the `register` keyword as deprecated, but e.g. | |
830 # code generated by flex (used in angle) contains that keyword. | |
831 # http://crbug.com/255186 | |
832 "-Wno-deprecated-register", | |
833 | |
834 # TODO(thakis): This used to be implied by -Wno-unused-function, | |
835 # which we no longer use. Check if it makes sense to remove | |
836 # this as well. http://crbug.com/316352 | |
837 "-Wno-unneeded-internal-declaration", | |
838 | |
839 # TODO(thakis): Remove, http://crbug.com/263960 | |
840 "-Wno-reserved-user-defined-literal", | |
841 ] | |
842 | |
843 # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost | |
844 # always have different versions. Certain flags may not be recognized by | |
845 # one version or the other. | |
846 if (!is_nacl) { | |
847 # Flags NaCl does not recognize. | |
848 cflags += [ | |
849 # TODO(hans): Get this cleaned up. | |
850 "-Wno-inconsistent-missing-override", | |
851 ] | |
852 } | |
853 } | |
854 if (gcc_version >= 48) { | |
855 cflags_cc += [ | |
856 # See comment for -Wno-c++11-narrowing. | |
857 "-Wno-narrowing", | |
858 | |
859 # TODO(thakis): Remove, http://crbug.com/263960 | |
860 "-Wno-literal-suffix", | |
861 ] | |
862 } | |
863 | |
864 # Suppress warnings about ABI changes on ARM (Clang doesn't give this | |
865 # warning). | |
866 if (current_cpu == "arm" && !is_clang) { | |
867 cflags += [ "-Wno-psabi" ] | |
868 } | |
869 | |
870 if (is_android) { | |
871 # Disable any additional warnings enabled by the Android build system but | |
872 # which chromium does not build cleanly with (when treating warning as | |
873 # errors). | |
874 cflags += [ | |
875 "-Wno-extra", | |
876 "-Wno-ignored-qualifiers", | |
877 "-Wno-type-limits", | |
878 ] | |
879 cflags_cc += [ | |
880 # Disabling c++0x-compat should be handled in WebKit, but | |
881 # this currently doesn't work because gcc_version is not set | |
882 # correctly when building with the Android build system. | |
883 # TODO(torne): Fix this in WebKit. | |
884 "-Wno-error=c++0x-compat", | |
885 | |
886 # Other things unrelated to -Wextra: | |
887 "-Wno-non-virtual-dtor", | |
888 "-Wno-sign-promo", | |
889 ] | |
890 } | |
891 | |
892 if (gcc_version >= 48) { | |
893 # Don't warn about the "typedef 'foo' locally defined but not used" | |
894 # for gcc 4.8. | |
895 # TODO: remove this flag once all builds work. See crbug.com/227506 | |
896 cflags += [ "-Wno-unused-local-typedefs" ] | |
897 } | |
898 } | |
899 } | |
900 | 1052 |
901 # This will generate warnings when using Clang if code generates exit-time | 1053 # This will generate warnings when using Clang if code generates exit-time |
902 # destructors, which will slow down closing the program. | 1054 # destructors, which will slow down closing the program. |
903 # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600 | 1055 # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600 |
904 config("wexit_time_destructors") { | 1056 config("wexit_time_destructors") { |
905 if (is_clang) { | 1057 # TODO: Enable on Windows too, http://crbug.com/404525 |
| 1058 if (is_clang && !is_win) { |
906 cflags = [ "-Wexit-time-destructors" ] | 1059 cflags = [ "-Wexit-time-destructors" ] |
907 } | 1060 } |
908 } | 1061 } |
909 | 1062 |
910 # On Windows compiling on x64, VC will issue a warning when converting | 1063 # On Windows compiling on x64, VC will issue a warning when converting |
911 # size_t to int because it will truncate the value. Our code should not have | 1064 # size_t to int because it will truncate the value. Our code should not have |
912 # these warnings and one should use a static_cast or a checked_cast for the | 1065 # these warnings and one should use a static_cast or a checked_cast for the |
913 # conversion depending on the case. However, a lot of code still needs to be | 1066 # conversion depending on the case. However, a lot of code still needs to be |
914 # fixed. Apply this config to such targets to disable the warning. | 1067 # fixed. Apply this config to such targets to disable the warning. |
915 # | 1068 # |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 cflags += [ "-gsplit-dwarf" ] | 1253 cflags += [ "-gsplit-dwarf" ] |
1101 } | 1254 } |
1102 } | 1255 } |
1103 } | 1256 } |
1104 | 1257 |
1105 config("no_symbols") { | 1258 config("no_symbols") { |
1106 if (!is_win) { | 1259 if (!is_win) { |
1107 cflags = [ "-g0" ] | 1260 cflags = [ "-g0" ] |
1108 } | 1261 } |
1109 } | 1262 } |
OLD | NEW |