| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 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. | 
|  | 4 | 
|  | 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") | 
|  | 9 } | 
|  | 10 if (current_cpu == "mipsel" || current_cpu == "mips64el") { | 
|  | 11   import("//build/config/mips.gni") | 
|  | 12 } | 
|  | 13 if (is_posix) { | 
|  | 14   import("//build/config/gcc/gcc_version.gni") | 
|  | 15 } | 
|  | 16 if (is_win) { | 
|  | 17   import("//build/config/win/visual_studio_version.gni") | 
|  | 18 } | 
|  | 19 | 
|  | 20 import("//build/toolchain/ccache.gni") | 
|  | 21 import("//build/config/sanitizers/sanitizers.gni") | 
|  | 22 | 
|  | 23 declare_args() { | 
|  | 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 | 
|  | 27 | 
|  | 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 | 
|  | 34   # Compile in such a way as to enable profiling of the generated code. For | 
|  | 35   # example, don't omit the frame pointer and leave in symbols. | 
|  | 36   enable_profiling = false | 
|  | 37 | 
|  | 38   # Compile in such a way as to make it possible for the profiler to unwind full | 
|  | 39   # stack frames. Setting this flag has a large effect on the performance of the | 
|  | 40   # generated code than just setting profiling, but gives the profiler more | 
|  | 41   # information to analyze. | 
|  | 42   # Requires profiling to be set to true. | 
|  | 43   enable_full_stack_frames_for_profiling = false | 
|  | 44 | 
|  | 45   # Use gold for linking on 64-bit Linux only (on 32-bit it runs out of | 
|  | 46   # address space, and it doesn't support cross-compiling). | 
|  | 47   use_gold = is_linux && current_cpu == "x64" | 
|  | 48 | 
|  | 49   # use_debug_fission: whether to use split DWARF debug info | 
|  | 50   # files. This can reduce link time significantly, but is incompatible | 
|  | 51   # with some utilities such as icecc and ccache. Requires gold and | 
|  | 52   # gcc >= 4.8 or clang. | 
|  | 53   # http://gcc.gnu.org/wiki/DebugFission | 
|  | 54   use_debug_fission = is_debug && !is_win && use_gold && | 
|  | 55                       linux_use_bundled_binutils && !use_ccache | 
|  | 56 | 
|  | 57   if (is_win) { | 
|  | 58     # Whether the VS xtree header has been patched to disable warning 4702. If | 
|  | 59     # it has, then we don't need to disable 4702 (unreachable code warning). | 
|  | 60     # The patch is preapplied to the internal toolchain and hence all bots. | 
|  | 61     msvs_xtree_patched = false | 
|  | 62   } | 
|  | 63 } | 
|  | 64 | 
|  | 65 # default_include_dirs --------------------------------------------------------- | 
|  | 66 # | 
|  | 67 # This is a separate config so that third_party code (which would not use the | 
|  | 68 # source root and might have conflicting versions of some headers) can remove | 
|  | 69 # this and specify their own include paths. | 
|  | 70 config("default_include_dirs") { | 
|  | 71   include_dirs = [ | 
|  | 72     "//", | 
|  | 73     root_gen_dir, | 
|  | 74   ] | 
|  | 75 } | 
|  | 76 | 
|  | 77 # TODO(GYP): is_ubsan, is_ubsan_vptr | 
|  | 78 if (!is_win) { | 
|  | 79   using_sanitizer = is_asan || is_lsan || is_tsan || is_msan | 
|  | 80 } | 
|  | 81 | 
|  | 82 # compiler --------------------------------------------------------------------- | 
|  | 83 # | 
|  | 84 # Base compiler configuration. | 
|  | 85 # | 
|  | 86 # See also "runtime_library" below for related stuff and a discussion about | 
|  | 87 # where stuff should go. Put warning related stuff in the "warnings" config. | 
|  | 88 | 
|  | 89 config("compiler") { | 
|  | 90   cflags = [] | 
|  | 91   cflags_c = [] | 
|  | 92   cflags_cc = [] | 
|  | 93   cflags_objcc = [] | 
|  | 94   ldflags = [] | 
|  | 95   defines = [] | 
|  | 96 | 
|  | 97   # In general, Windows is totally different, but all the other builds share | 
|  | 98   # some common GCC configuration. This section sets up Windows and the common | 
|  | 99   # GCC flags, and then we handle the other non-Windows platforms specifically | 
|  | 100   # below. | 
|  | 101   if (is_win) { | 
|  | 102     # Windows compiler flags setup. | 
|  | 103     # ----------------------------- | 
|  | 104     cflags += [ | 
|  | 105       "/Gy",  # Enable function-level linking. | 
|  | 106       "/GS",  # Enable buffer security checking. | 
|  | 107       "/FS",  # Preserve previous PDB behavior. | 
|  | 108     ] | 
|  | 109 | 
|  | 110     # Building with Clang on Windows is a work in progress and very | 
|  | 111     # experimental. See crbug.com/82385. | 
|  | 112     # Keep this in sync with the similar block in build/common.gypi | 
|  | 113     if (is_clang) { | 
|  | 114       cflags += [ | 
|  | 115         # Many files use intrinsics without including this header. | 
|  | 116         # TODO(hans): Fix those files, or move this to sub-GYPs. | 
|  | 117         "/FIIntrin.h", | 
|  | 118       ] | 
|  | 119 | 
|  | 120       if (visual_studio_version == "2013") { | 
|  | 121         cflags += [ "-fmsc-version=1800" ] | 
|  | 122       } else if (visual_studio_version == "2015") { | 
|  | 123         cflags += [ "-fmsc-version=1900" ] | 
|  | 124       } | 
|  | 125 | 
|  | 126       if (current_cpu == "x86") { | 
|  | 127         cflags += [ | 
|  | 128           "/fallback", | 
|  | 129           "-m32", | 
|  | 130         ] | 
|  | 131       } else { | 
|  | 132         cflags += [ "-m64" ] | 
|  | 133       } | 
|  | 134       if (exec_script("//build/win/use_ansi_codes.py", [], "trim string") == | 
|  | 135           "True") { | 
|  | 136         cflags += [ | 
|  | 137           # cmd.exe doesn't understand ANSI escape codes by default, | 
|  | 138           # so only enable them if something emulating them is around. | 
|  | 139           "-fansi-escape-codes", | 
|  | 140         ] | 
|  | 141       } | 
|  | 142     } | 
|  | 143   } else { | 
|  | 144     # Common GCC compiler flags setup. | 
|  | 145     # -------------------------------- | 
|  | 146     cflags += [ "-fno-strict-aliasing" ]  # See http://crbug.com/32204 | 
|  | 147     common_flags = [ | 
|  | 148       # Not exporting C++ inline functions can generally be applied anywhere | 
|  | 149       # so we do so here. Normal function visibility is controlled by | 
|  | 150       # //build/config/gcc:symbol_visibility_hidden. | 
|  | 151       "-fvisibility-inlines-hidden", | 
|  | 152     ] | 
|  | 153     cflags_cc += common_flags | 
|  | 154     cflags_objcc += common_flags | 
|  | 155 | 
|  | 156     # Stack protection. | 
|  | 157     if (is_mac) { | 
|  | 158       cflags += [ "-fstack-protector-all" ] | 
|  | 159     } else if (is_linux) { | 
|  | 160       cflags += [ | 
|  | 161         "-fstack-protector", | 
|  | 162         "--param=ssp-buffer-size=4", | 
|  | 163       ] | 
|  | 164     } | 
|  | 165 | 
|  | 166     # Linker warnings. | 
|  | 167     if (!(is_chromeos && current_cpu == "arm") && !is_mac && !is_ios) { | 
|  | 168       # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580 | 
|  | 169       ldflags += [ "-Wl,--fatal-warnings" ] | 
|  | 170     } | 
|  | 171 | 
|  | 172     # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer and | 
|  | 173     # MemorySanitizer | 
|  | 174     if (using_sanitizer) { | 
|  | 175       cflags += [ | 
|  | 176         "-fno-omit-frame-pointer", | 
|  | 177         "-gline-tables-only", | 
|  | 178       ] | 
|  | 179     } | 
|  | 180     if (is_asan) { | 
|  | 181       asan_blacklist_path = | 
|  | 182           rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir) | 
|  | 183       cflags += [ | 
|  | 184         "-fsanitize=address", | 
|  | 185         "-fsanitize-blacklist=$asan_blacklist_path", | 
|  | 186       ] | 
|  | 187       if (is_mac) { | 
|  | 188         cflags += [ "-mllvm -asan-globals=0" ]  # http://crbug.com/352073 | 
|  | 189         # TODO(GYP): deal with mac_bundles. | 
|  | 190       } | 
|  | 191     } | 
|  | 192     if (is_lsan) { | 
|  | 193       cflags += [ "-fsanitize=leak" ] | 
|  | 194     } | 
|  | 195     if (is_tsan) { | 
|  | 196       tsan_blacklist_path = | 
|  | 197           rebase_path("//tools/memory/tsan_v2/ignores.txt", root_build_dir) | 
|  | 198       cflags += [ | 
|  | 199         "-fsanitize=thread", | 
|  | 200         "-fsanitize-blacklist=$tsan_blacklist_path", | 
|  | 201       ] | 
|  | 202     } | 
|  | 203     if (is_msan) { | 
|  | 204       msan_blacklist_path = | 
|  | 205           rebase_path("//tools/msan/blacklist.txt", root_build_dir) | 
|  | 206       cflags += [ | 
|  | 207         "-fsanitize=memory", | 
|  | 208         "-fsanitize-memory-track-origins=$msan_track_origins", | 
|  | 209         "-fsanitize-blacklist=$msan_blacklist_path", | 
|  | 210       ] | 
|  | 211     } | 
|  | 212 | 
|  | 213     if (use_custom_libcxx) { | 
|  | 214       cflags_cc += [ "-nostdinc++" ] | 
|  | 215       include_dirs = [ | 
|  | 216         "//buildtools/third_party/libc++/trunk/include", | 
|  | 217         "//buildtools/third_party/libc++abi/trunk/include", | 
|  | 218       ] | 
|  | 219     } | 
|  | 220 | 
|  | 221     if (is_fnl) { | 
|  | 222       # TODO(kulakowski) remove when fnl no longer uses gcc | 
|  | 223       cflags += [ "-Wno-maybe-uninitialized" ] | 
|  | 224     } | 
|  | 225   } | 
|  | 226 | 
|  | 227   if (is_clang && is_debug) { | 
|  | 228     # Allow comparing the address of references and 'this' against 0 | 
|  | 229     # in debug builds. Technically, these can never be null in | 
|  | 230     # well-defined C/C++ and Clang can optimize such checks away in | 
|  | 231     # release builds, but they may be used in asserts in debug builds. | 
|  | 232     extra_flags = [ | 
|  | 233       "-Wno-undefined-bool-conversion", | 
|  | 234       "-Wno-tautological-undefined-compare", | 
|  | 235     ] | 
|  | 236     cflags_cc += extra_flags | 
|  | 237     cflags_objcc += extra_flags | 
|  | 238   } | 
|  | 239 | 
|  | 240   if (is_clang && !is_nacl) { | 
|  | 241     # This is here so that all files get recompiled after a clang roll and | 
|  | 242     # when turning clang on or off. (defines are passed via the command line, | 
|  | 243     # and build system rebuild things when their commandline changes). Nothing | 
|  | 244     # should ever read this define. | 
|  | 245     defines += | 
|  | 246         [ "CR_CLANG_REVISION=" + exec_script("//tools/clang/scripts/update.py", | 
|  | 247                                              [ "--print-revision" ], | 
|  | 248                                              "trim string") ] | 
|  | 249   } | 
|  | 250 | 
|  | 251   # Mac-specific compiler flags setup. | 
|  | 252   # ---------------------------------- | 
|  | 253   if (is_mac || is_ios) { | 
|  | 254     # These flags are shared between the C compiler and linker. | 
|  | 255     common_mac_flags = [] | 
|  | 256 | 
|  | 257     # CPU architecture. | 
|  | 258     if (current_cpu == "x64") { | 
|  | 259       common_mac_flags += [ | 
|  | 260         "-arch", | 
|  | 261         "x86_64", | 
|  | 262       ] | 
|  | 263     } else if (current_cpu == "x86") { | 
|  | 264       common_mac_flags += [ | 
|  | 265         "-arch", | 
|  | 266         "i386", | 
|  | 267       ] | 
|  | 268     } else if (current_cpu == "arm") { | 
|  | 269       common_mac_flags += [ | 
|  | 270         "-arch", | 
|  | 271         "armv7", | 
|  | 272       ] | 
|  | 273     } else if (current_cpu == "arm64") { | 
|  | 274       common_mac_flags += [ | 
|  | 275         "-arch", | 
|  | 276         "arm64", | 
|  | 277       ] | 
|  | 278     } | 
|  | 279 | 
|  | 280     cflags += common_mac_flags | 
|  | 281 | 
|  | 282     # Without this, the constructors and destructors of a C++ object inside | 
|  | 283     # an Objective C struct won't be called, which is very bad. | 
|  | 284     cflags_objcc += [ "-fobjc-call-cxx-cdtors" ] | 
|  | 285 | 
|  | 286     cflags_c += [ "-std=c99" ] | 
|  | 287 | 
|  | 288     ldflags += common_mac_flags | 
|  | 289   } else if (is_posix) { | 
|  | 290     # CPU architecture. We may or may not be doing a cross compile now, so for | 
|  | 291     # simplicity we always explicitly set the architecture. | 
|  | 292     if (current_cpu == "x64") { | 
|  | 293       cflags += [ | 
|  | 294         "-m64", | 
|  | 295         "-march=x86-64", | 
|  | 296       ] | 
|  | 297       ldflags += [ "-m64" ] | 
|  | 298     } else if (current_cpu == "x86") { | 
|  | 299       cflags += [ "-m32" ] | 
|  | 300       ldflags += [ "-m32" ] | 
|  | 301       if (is_clang) { | 
|  | 302         cflags += [ | 
|  | 303           # Else building libyuv gives clang's register allocator issues, | 
|  | 304           # see llvm.org/PR15798 / crbug.com/233709 | 
|  | 305           "-momit-leaf-frame-pointer", | 
|  | 306 | 
|  | 307           # Align the stack on 16-byte boundaries, http://crbug.com/418554. | 
|  | 308           "-mstack-alignment=16", | 
|  | 309           "-mstackrealign", | 
|  | 310         ] | 
|  | 311       } | 
|  | 312     } else if (current_cpu == "arm") { | 
|  | 313       cflags += [ | 
|  | 314         "-march=$arm_arch", | 
|  | 315         "-mfloat-abi=$arm_float_abi", | 
|  | 316       ] | 
|  | 317       if (arm_tune != "") { | 
|  | 318         cflags += [ "-mtune=$arm_tune" ] | 
|  | 319       } | 
|  | 320       if (arm_use_thumb) { | 
|  | 321         cflags += [ "-mthumb" ] | 
|  | 322         if (is_android && !is_clang) {  # Clang doesn't support this option. | 
|  | 323           cflags += [ "-mthumb-interwork" ] | 
|  | 324         } | 
|  | 325       } | 
|  | 326       if (!is_clang) { | 
|  | 327         # Clang doesn't support these flags. | 
|  | 328         cflags += [ | 
|  | 329           # The tree-sra optimization (scalar replacement for | 
|  | 330           # aggregates enabling subsequent optimizations) leads to | 
|  | 331           # invalid code generation when using the Android NDK's | 
|  | 332           # compiler (r5-r7). This can be verified using | 
|  | 333           # webkit_unit_tests' WTF.Checked_int8_t test. | 
|  | 334           "-fno-tree-sra", | 
|  | 335 | 
|  | 336           # The following option is disabled to improve binary | 
|  | 337           # size and performance in gcc 4.9. | 
|  | 338           "-fno-caller-saves", | 
|  | 339         ] | 
|  | 340       } | 
|  | 341     } else if (current_cpu == "mipsel") { | 
|  | 342       if (mips_arch_variant == "r6") { | 
|  | 343         cflags += [ | 
|  | 344           "-mips32r6", | 
|  | 345           "-Wa,-mips32r6", | 
|  | 346         ] | 
|  | 347         if (is_android) { | 
|  | 348           ldflags += [ | 
|  | 349             "-mips32r6", | 
|  | 350             "-Wl,-melf32ltsmip", | 
|  | 351           ] | 
|  | 352         } | 
|  | 353       } else if (mips_arch_variant == "r2") { | 
|  | 354         cflags += [ | 
|  | 355           "-mips32r2", | 
|  | 356           "-Wa,-mips32r2", | 
|  | 357         ] | 
|  | 358         if (mips_float_abi == "hard" && mips_fpu_mode != "") { | 
|  | 359           cflags += [ "-m$mips_fpu_mode" ] | 
|  | 360         } | 
|  | 361       } else if (mips_arch_variant == "r1") { | 
|  | 362         cflags += [ | 
|  | 363           "-mips32", | 
|  | 364           "-Wa,-mips32", | 
|  | 365         ] | 
|  | 366       } | 
|  | 367 | 
|  | 368       if (mips_dsp_rev == 1) { | 
|  | 369         cflags += [ "-mdsp" ] | 
|  | 370       } else if (mips_dsp_rev == 2) { | 
|  | 371         cflags += [ "-mdspr2" ] | 
|  | 372       } | 
|  | 373 | 
|  | 374       cflags += [ "-m${mips_float_abi}-float" ] | 
|  | 375     } else if (current_cpu == "mips64el") { | 
|  | 376       if (mips_arch_variant == "r6") { | 
|  | 377         cflags += [ | 
|  | 378           "-mips64r6", | 
|  | 379           "-Wa,-mips64r6", | 
|  | 380         ] | 
|  | 381         ldflags += [ "-mips64r6" ] | 
|  | 382       } else if (mips_arch_variant == "r2") { | 
|  | 383         cflags += [ | 
|  | 384           "-mips64r2", | 
|  | 385           "-Wa,-mips64r2", | 
|  | 386         ] | 
|  | 387         ldflags += [ "-mips64r2" ] | 
|  | 388       } | 
|  | 389     } | 
|  | 390 | 
|  | 391     defines += [ "_FILE_OFFSET_BITS=64" ] | 
|  | 392 | 
|  | 393     if (!is_android) { | 
|  | 394       defines += [ | 
|  | 395         "_LARGEFILE_SOURCE", | 
|  | 396         "_LARGEFILE64_SOURCE", | 
|  | 397       ] | 
|  | 398     } | 
|  | 399 | 
|  | 400     # Omit unwind support in official builds to save space. We can use breakpad | 
|  | 401     # for these builds. | 
|  | 402     if (is_chrome_branded && is_official_build) { | 
|  | 403       cflags += [ | 
|  | 404         "-fno-unwind-tables", | 
|  | 405         "-fno-asynchronous-unwind-tables", | 
|  | 406       ] | 
|  | 407       defines += [ "NO_UNWIND_TABLES" ] | 
|  | 408     } else { | 
|  | 409       cflags += [ "-funwind-tables" ] | 
|  | 410     } | 
|  | 411   } | 
|  | 412 | 
|  | 413   if (enable_profiling && !is_debug) { | 
|  | 414     # The GYP build spams this define into every compilation unit, as we do | 
|  | 415     # here, but it only appears to be used in base and a couple other places. | 
|  | 416     # TODO(abarth): Should we move this define closer to where it's used? | 
|  | 417     defines += [ "ENABLE_PROFILING" ] | 
|  | 418 | 
|  | 419     cflags += [ | 
|  | 420       "-fno-omit-frame-pointer", | 
|  | 421       "-g", | 
|  | 422     ] | 
|  | 423 | 
|  | 424     if (enable_full_stack_frames_for_profiling) { | 
|  | 425       cflags += [ | 
|  | 426         "-fno-inline", | 
|  | 427         "-fno-optimize-sibling-calls", | 
|  | 428       ] | 
|  | 429     } | 
|  | 430   } | 
|  | 431 | 
|  | 432   # Linux/Android common flags setup. | 
|  | 433   # --------------------------------- | 
|  | 434   if (is_linux || is_android) { | 
|  | 435     cflags += [ | 
|  | 436       "-fPIC", | 
|  | 437       "-pipe",  # Use pipes for communicating between sub-processes. Faster. | 
|  | 438     ] | 
|  | 439 | 
|  | 440     ldflags += [ | 
|  | 441       "-fPIC", | 
|  | 442       "-Wl,-z,noexecstack", | 
|  | 443       "-Wl,-z,now", | 
|  | 444       "-Wl,-z,relro", | 
|  | 445     ] | 
|  | 446     if (!using_sanitizer) { | 
|  | 447       ldflags += [ "-Wl,-z,defs" ] | 
|  | 448     } | 
|  | 449   } | 
|  | 450 | 
|  | 451   # Linux-specific compiler flags setup. | 
|  | 452   # ------------------------------------ | 
|  | 453   if (is_linux) { | 
|  | 454     cflags += [ "-pthread" ] | 
|  | 455     ldflags += [ "-pthread" ] | 
|  | 456   } | 
|  | 457   if (use_gold) { | 
|  | 458     gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", | 
|  | 459                             root_build_dir) | 
|  | 460     ldflags += [ | 
|  | 461       "-B$gold_path", | 
|  | 462 | 
|  | 463       # Newer gccs and clangs support -fuse-ld, use the flag to force gold | 
|  | 464       # selection. | 
|  | 465       # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html | 
|  | 466       "-fuse-ld=gold", | 
|  | 467 | 
|  | 468       # Experimentation found that using four linking threads | 
|  | 469       # saved ~20% of link time. | 
|  | 470       # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_threa
      d/thread/281527606915bb36 | 
|  | 471       # Only apply this to the target linker, since the host | 
|  | 472       # linker might not be gold, but isn't used much anyway. | 
|  | 473       # TODO(raymes): Disable threading because gold is frequently | 
|  | 474       # crashing on the bots: crbug.com/161942. | 
|  | 475       #"-Wl,--threads", | 
|  | 476       #"-Wl,--thread-count=4", | 
|  | 477     ] | 
|  | 478 | 
|  | 479     if (!is_asan && !is_msan && !is_lsan && !is_tsan) { | 
|  | 480       # TODO(brettw) common.gypi has this only for target toolset. | 
|  | 481       ldflags += [ "-Wl,--icf=all" ] | 
|  | 482     } | 
|  | 483 | 
|  | 484     # TODO(thestig): Make this flag work with GN. | 
|  | 485     #if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan |
      | is_msan)) { | 
|  | 486     #  ldflags += [ | 
|  | 487     #    "-Wl,--detect-odr-violations", | 
|  | 488     #  ] | 
|  | 489     #} | 
|  | 490   } | 
|  | 491 | 
|  | 492   if (linux_use_bundled_binutils) { | 
|  | 493     binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", | 
|  | 494                                 root_build_dir) | 
|  | 495     cflags += [ "-B$binutils_path" ] | 
|  | 496   } | 
|  | 497 | 
|  | 498   # Clang-specific compiler flags setup. | 
|  | 499   # ------------------------------------ | 
|  | 500   if (is_clang) { | 
|  | 501     cflags += [ "-fcolor-diagnostics" ] | 
|  | 502   } | 
|  | 503 | 
|  | 504   # C++11 compiler flags setup. | 
|  | 505   # --------------------------- | 
|  | 506   if (is_linux || is_android || is_nacl) { | 
|  | 507     # gnu++11 instead of c++11 is needed because some code uses typeof() (a | 
|  | 508     # GNU extension). | 
|  | 509     # TODO(thakis): Eventually switch this to c++11 instead, | 
|  | 510     # http://crbug.com/427584 | 
|  | 511     cflags_cc += [ "-std=gnu++11" ] | 
|  | 512   } else if (!is_win) { | 
|  | 513     cc_std = [ "-std=c++11" ] | 
|  | 514     cflags_cc += cc_std | 
|  | 515     cflags_objcc += cc_std | 
|  | 516   } | 
|  | 517 | 
|  | 518   # Android-specific flags setup. | 
|  | 519   # ----------------------------- | 
|  | 520   if (is_android) { | 
|  | 521     cflags += [ | 
|  | 522       "-ffunction-sections", | 
|  | 523       "-funwind-tables", | 
|  | 524       "-fno-short-enums", | 
|  | 525     ] | 
|  | 526     if (!is_clang) { | 
|  | 527       # Clang doesn't support these flags. | 
|  | 528       cflags += [ "-finline-limit=64" ] | 
|  | 529     } | 
|  | 530     if (is_asan) { | 
|  | 531       # Android build relies on -Wl,--gc-sections removing unreachable code. | 
|  | 532       # ASan instrumentation for globals inhibits this and results in a library | 
|  | 533       # with unresolvable relocations. | 
|  | 534       # TODO(eugenis): find a way to reenable this. | 
|  | 535       cflags += [ "-mllvm -asan-globals=0" ] | 
|  | 536     } | 
|  | 537 | 
|  | 538     defines += [ "ANDROID" ] | 
|  | 539 | 
|  | 540     # The NDK has these things, but doesn't define the constants | 
|  | 541     # to say that it does. Define them here instead. | 
|  | 542     defines += [ "HAVE_SYS_UIO_H" ] | 
|  | 543 | 
|  | 544     # Use gold for Android for most CPU architectures. | 
|  | 545     if (current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm") { | 
|  | 546       ldflags += [ "-fuse-ld=gold" ] | 
|  | 547       if (is_clang) { | 
|  | 548         # Let clang find the ld.gold in the NDK. | 
|  | 549         ldflags += [ "--gcc-toolchain=" + | 
|  | 550                      rebase_path(android_toolchain_root, root_build_dir) ] | 
|  | 551       } | 
|  | 552     } | 
|  | 553 | 
|  | 554     ldflags += [ | 
|  | 555       "-Wl,--no-undefined", | 
|  | 556 | 
|  | 557       # Don't allow visible symbols from libgcc or libc++ to be | 
|  | 558       # re-exported. | 
|  | 559       "-Wl,--exclude-libs=libgcc.a", | 
|  | 560       "-Wl,--exclude-libs=libc++_static.a", | 
|  | 561 | 
|  | 562       # Don't allow visible symbols from libraries that contain | 
|  | 563       # assembly code with symbols that aren't hidden properly. | 
|  | 564       # http://crbug.com/448386 | 
|  | 565       "-Wl,--exclude-libs=libvpx_assembly_arm.a", | 
|  | 566     ] | 
|  | 567     if (current_cpu == "arm") { | 
|  | 568       ldflags += [ | 
|  | 569         # Enable identical code folding to reduce size. | 
|  | 570         "-Wl,--icf=safe", | 
|  | 571       ] | 
|  | 572     } | 
|  | 573 | 
|  | 574     if (is_clang) { | 
|  | 575       if (current_cpu == "arm") { | 
|  | 576         cflags += [ "--target=arm-linux-androideabi" ] | 
|  | 577         ldflags += [ "--target=arm-linux-androideabi" ] | 
|  | 578       } else if (current_cpu == "x86") { | 
|  | 579         cflags += [ "--target=x86-linux-androideabi" ] | 
|  | 580         ldflags += [ "--target=x86-linux-androideabi" ] | 
|  | 581       } | 
|  | 582     } | 
|  | 583   } | 
|  | 584 } | 
|  | 585 | 
|  | 586 config("compiler_arm_fpu") { | 
|  | 587   if (current_cpu == "arm" && !is_ios) { | 
|  | 588     cflags = [ "-mfpu=$arm_fpu" ] | 
|  | 589   } | 
|  | 590 } | 
|  | 591 | 
|  | 592 # runtime_library ------------------------------------------------------------- | 
|  | 593 # | 
|  | 594 # Sets the runtime library and associated options. | 
|  | 595 # | 
|  | 596 # How do you determine what should go in here vs. "compiler" above? Consider if | 
|  | 597 # a target might choose to use a different runtime library (ignore for a moment | 
|  | 598 # if this is possible or reasonable on your system). If such a target would want | 
|  | 599 # to change or remove your option, put it in the runtime_library config. If a | 
|  | 600 # target wants the option regardless, put it in the compiler config. | 
|  | 601 | 
|  | 602 config("runtime_library") { | 
|  | 603   cflags = [] | 
|  | 604   defines = [] | 
|  | 605   ldflags = [] | 
|  | 606   lib_dirs = [] | 
|  | 607   libs = [] | 
|  | 608 | 
|  | 609   if (is_component_build) { | 
|  | 610     # Component mode: dynamic CRT. | 
|  | 611     defines += [ "COMPONENT_BUILD" ] | 
|  | 612     if (is_win) { | 
|  | 613       # Since the library is shared, it requires exceptions or will give errors | 
|  | 614       # about things not matching, so keep exceptions on. | 
|  | 615       if (is_debug) { | 
|  | 616         cflags += [ "/MDd" ] | 
|  | 617       } else { | 
|  | 618         cflags += [ "/MD" ] | 
|  | 619       } | 
|  | 620     } | 
|  | 621   } else { | 
|  | 622     # Static CRT. | 
|  | 623     if (is_win) { | 
|  | 624       if (is_debug) { | 
|  | 625         cflags += [ "/MTd" ] | 
|  | 626       } else { | 
|  | 627         cflags += [ "/MT" ] | 
|  | 628       } | 
|  | 629     } | 
|  | 630   } | 
|  | 631 | 
|  | 632   if (is_win) { | 
|  | 633     defines += [ | 
|  | 634       "__STD_C", | 
|  | 635       "_CRT_RAND_S", | 
|  | 636       "_CRT_SECURE_NO_DEPRECATE", | 
|  | 637       "_HAS_EXCEPTIONS=0", | 
|  | 638       "_SCL_SECURE_NO_DEPRECATE", | 
|  | 639     ] | 
|  | 640   } | 
|  | 641 | 
|  | 642   # Android standard library setup. | 
|  | 643   if (is_android) { | 
|  | 644     if (is_clang) { | 
|  | 645       # Work around incompatibilities between bionic and clang headers. | 
|  | 646       defines += [ | 
|  | 647         "__compiler_offsetof=__builtin_offsetof", | 
|  | 648         "nan=__builtin_nan", | 
|  | 649       ] | 
|  | 650     } | 
|  | 651 | 
|  | 652     defines += [ "__GNU_SOURCE=1" ]  # Necessary for clone(). | 
|  | 653 | 
|  | 654     # TODO(jdduke) Re-enable on mips after resolving linking | 
|  | 655     # issues with libc++ (crbug.com/456380). | 
|  | 656     if (current_cpu != "mipsel" && current_cpu != "mips64el") { | 
|  | 657       ldflags += [ "-Wl,--warn-shared-textrel" ] | 
|  | 658     } | 
|  | 659     ldflags += [ "-nostdlib" ] | 
|  | 660 | 
|  | 661     # NOTE: The libc++ header include paths below are specified in cflags | 
|  | 662     # rather than include_dirs because they need to come after include_dirs. | 
|  | 663     # Think of them like system headers, but don't use '-isystem' because the | 
|  | 664     # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit | 
|  | 665     # strange errors. The include ordering here is important; change with | 
|  | 666     # caution. | 
|  | 667     cflags += [ | 
|  | 668       "-isystem" + | 
|  | 669           rebase_path("$android_libcpp_root/libcxx/include", root_build_dir), | 
|  | 670       "-isystem" + rebase_path( | 
|  | 671               "$android_ndk_root/sources/cxx-stl/llvm-libc++abi/libcxxabi/includ
      e", | 
|  | 672               root_build_dir), | 
|  | 673       "-isystem" + | 
|  | 674           rebase_path("$android_ndk_root/sources/android/support/include", | 
|  | 675                       root_build_dir), | 
|  | 676     ] | 
|  | 677 | 
|  | 678     lib_dirs += [ "$android_libcpp_root/libs/$android_app_abi" ] | 
|  | 679     libs += [ "$android_libcpp_library" ] | 
|  | 680 | 
|  | 681     if (current_cpu == "mipsel") { | 
|  | 682       libs += [ | 
|  | 683         # ld linker is used for mips Android, and ld does not accept library | 
|  | 684         # absolute path prefixed by "-l"; Since libgcc does not exist in mips | 
|  | 685         # sysroot the proper library will be linked. | 
|  | 686         # TODO(gordanac): Remove once gold linker is used for mips Android. | 
|  | 687         "gcc", | 
|  | 688       ] | 
|  | 689     } else { | 
|  | 690       libs += [ | 
|  | 691         # Manually link the libgcc.a that the cross compiler uses. This is | 
|  | 692         # absolute because the linker will look inside the sysroot if it's not. | 
|  | 693         rebase_path(android_libgcc_file), | 
|  | 694       ] | 
|  | 695     } | 
|  | 696 | 
|  | 697     libs += [ | 
|  | 698       "c", | 
|  | 699       "dl", | 
|  | 700       "m", | 
|  | 701     ] | 
|  | 702 | 
|  | 703     # Clang with libc++ does not require an explicit atomic library reference. | 
|  | 704     if (!is_clang) { | 
|  | 705       libs += [ "atomic" ] | 
|  | 706     } | 
|  | 707   } | 
|  | 708 } | 
|  | 709 | 
|  | 710 # default_warning_flags collects all warning flags that are used by default. | 
|  | 711 # This is in a variable instead of a config so that it can be used in | 
|  | 712 # both chromium_code and no_chromium_code.  This way these flags are guaranteed | 
|  | 713 # to appear on the compile command line after -Wall. | 
|  | 714 | 
|  | 715 default_warning_flags = [] | 
|  | 716 default_warning_flags_cc = [] | 
|  | 717 if (is_win) { | 
|  | 718   if (!is_clang || current_cpu != "x86") { | 
|  | 719     default_warning_flags += [ "/WX" ]  # Treat warnings as errors. | 
|  | 720   } | 
|  | 721 | 
|  | 722   default_warning_flags += [ | 
|  | 723     # Warnings permanently disabled: | 
|  | 724 | 
|  | 725     # TODO(GYP) The GYP build doesn't have this globally enabled but disabled | 
|  | 726     # for a bunch of individual targets. Re-enable this globally when those | 
|  | 727     # targets are fixed. | 
|  | 728     "/wd4018",  # Comparing signed and unsigned values. | 
|  | 729 | 
|  | 730     # C4127: conditional expression is constant | 
|  | 731     # This warning can in theory catch dead code and other problems, but | 
|  | 732     # triggers in far too many desirable cases where the conditional | 
|  | 733     # expression is either set by macros or corresponds some legitimate | 
|  | 734     # compile-time constant expression (due to constant template args, | 
|  | 735     # conditionals comparing the sizes of different types, etc.).  Some of | 
|  | 736     # these can be worked around, but it's not worth it. | 
|  | 737     "/wd4127", | 
|  | 738 | 
|  | 739     # C4251: 'identifier' : class 'type' needs to have dll-interface to be | 
|  | 740     #        used by clients of class 'type2' | 
|  | 741     # This is necessary for the shared library build. | 
|  | 742     "/wd4251", | 
|  | 743 | 
|  | 744     # C4351: new behavior: elements of array 'array' will be default | 
|  | 745     #        initialized | 
|  | 746     # This is a silly "warning" that basically just alerts you that the | 
|  | 747     # compiler is going to actually follow the language spec like it's | 
|  | 748     # supposed to, instead of not following it like old buggy versions did. | 
|  | 749     # There's absolutely no reason to turn this on. | 
|  | 750     "/wd4351", | 
|  | 751 | 
|  | 752     # C4355: 'this': used in base member initializer list | 
|  | 753     # It's commonly useful to pass |this| to objects in a class' initializer | 
|  | 754     # list.  While this warning can catch real bugs, most of the time the | 
|  | 755     # constructors in question don't attempt to call methods on the passed-in | 
|  | 756     # pointer (until later), and annotating every legit usage of this is | 
|  | 757     # simply more hassle than the warning is worth. | 
|  | 758     "/wd4355", | 
|  | 759 | 
|  | 760     # C4503: 'identifier': decorated name length exceeded, name was | 
|  | 761     #        truncated | 
|  | 762     # This only means that some long error messages might have truncated | 
|  | 763     # identifiers in the presence of lots of templates.  It has no effect on | 
|  | 764     # program correctness and there's no real reason to waste time trying to | 
|  | 765     # prevent it. | 
|  | 766     "/wd4503", | 
|  | 767 | 
|  | 768     # Warning C4589 says: "Constructor of abstract class ignores | 
|  | 769     # initializer for virtual base class." Disable this warning because it | 
|  | 770     # is flaky in VS 2015 RTM. It triggers on compiler generated | 
|  | 771     # copy-constructors in some cases. | 
|  | 772     "/wd4589", | 
|  | 773 | 
|  | 774     # C4611: interaction between 'function' and C++ object destruction is | 
|  | 775     #        non-portable | 
|  | 776     # This warning is unavoidable when using e.g. setjmp/longjmp.  MSDN | 
|  | 777     # suggests using exceptions instead of setjmp/longjmp for C++, but | 
|  | 778     # Chromium code compiles without exception support.  We therefore have to | 
|  | 779     # use setjmp/longjmp for e.g. JPEG decode error handling, which means we | 
|  | 780     # have to turn off this warning (and be careful about how object | 
|  | 781     # destruction happens in such cases). | 
|  | 782     "/wd4611", | 
|  | 783 | 
|  | 784     # Warnings to evaluate and possibly fix/reenable later: | 
|  | 785 | 
|  | 786     "/wd4100",  # Unreferenced formal function parameter. | 
|  | 787     "/wd4121",  # Alignment of a member was sensitive to packing. | 
|  | 788     "/wd4244",  # Conversion: possible loss of data. | 
|  | 789     "/wd4481",  # Nonstandard extension: override specifier. | 
|  | 790     "/wd4505",  # Unreferenced local function has been removed. | 
|  | 791     "/wd4510",  # Default constructor could not be generated. | 
|  | 792     "/wd4512",  # Assignment operator could not be generated. | 
|  | 793     "/wd4610",  # Class can never be instantiated, constructor required. | 
|  | 794     "/wd4996",  # Deprecated function warning. | 
|  | 795   ] | 
|  | 796 | 
|  | 797   # VS xtree header file needs to be patched or 4702 (unreachable code | 
|  | 798   # warning) is reported if _HAS_EXCEPTIONS=0. Disable the warning if xtree is | 
|  | 799   # not patched. | 
|  | 800   if (!msvs_xtree_patched && | 
|  | 801       exec_script("../../win_is_xtree_patched.py", [], "value") == 0) { | 
|  | 802     default_warning_flags += [ "/wd4702" ]  # Unreachable code. | 
|  | 803   } | 
|  | 804 | 
|  | 805   # Building with Clang on Windows is a work in progress and very | 
|  | 806   # experimental. See crbug.com/82385. | 
|  | 807   # Keep this in sync with the similar block in build/common.gypi | 
|  | 808   if (is_clang) { | 
|  | 809     default_warning_flags += [ | 
|  | 810       # TODO(hans): Make this list shorter eventually, http://crbug.com/504657 | 
|  | 811       "-Qunused-arguments",  # http://crbug.com/504658 | 
|  | 812       "-Wno-microsoft",  # http://crbug.com/505296 | 
|  | 813       "-Wno-switch",  # http://crbug.com/505308 | 
|  | 814       "-Wno-unknown-pragmas",  # http://crbug.com/505314 | 
|  | 815       "-Wno-unused-function",  # http://crbug.com/505316 | 
|  | 816       "-Wno-unused-value",  # http://crbug.com/505318 | 
|  | 817       "-Wno-unused-local-typedef",  # http://crbug.com/411648 | 
|  | 818     ] | 
|  | 819   } | 
|  | 820 } else { | 
|  | 821   # Common GCC warning setup. | 
|  | 822   default_warning_flags += [ | 
|  | 823     # Enables. | 
|  | 824     "-Wendif-labels",  # Weird old-style text after an #endif. | 
|  | 825     "-Werror",  # Warnings as errors. | 
|  | 826 | 
|  | 827     # Disables. | 
|  | 828     "-Wno-missing-field-initializers",  # "struct foo f = {0};" | 
|  | 829     "-Wno-unused-parameter",  # Unused function parameters. | 
|  | 830   ] | 
|  | 831 | 
|  | 832   if (is_mac) { | 
|  | 833     # TODO(abarth): Re-enable once https://github.com/domokit/mojo/issues/728 | 
|  | 834     #               is fixed. | 
|  | 835     # default_warning_flags += [ "-Wnewline-eof" ] | 
|  | 836     if (!is_nacl) { | 
|  | 837       # When compiling Objective-C, warns if a method is used whose | 
|  | 838       # availability is newer than the deployment target. This is not | 
|  | 839       # required when compiling Chrome for iOS. | 
|  | 840       default_warning_flags += [ "-Wpartial-availability" ] | 
|  | 841     } | 
|  | 842   } | 
|  | 843 | 
|  | 844   if (gcc_version >= 48) { | 
|  | 845     default_warning_flags_cc += [ | 
|  | 846       # See comment for -Wno-c++11-narrowing. | 
|  | 847       "-Wno-narrowing", | 
|  | 848     ] | 
|  | 849   } | 
|  | 850 | 
|  | 851   # Suppress warnings about ABI changes on ARM (Clang doesn't give this | 
|  | 852   # warning). | 
|  | 853   if (current_cpu == "arm" && !is_clang) { | 
|  | 854     default_warning_flags += [ "-Wno-psabi" ] | 
|  | 855   } | 
|  | 856 | 
|  | 857   if (is_android) { | 
|  | 858     # Disable any additional warnings enabled by the Android build system but | 
|  | 859     # which chromium does not build cleanly with (when treating warning as | 
|  | 860     # errors). | 
|  | 861     default_warning_flags += [ | 
|  | 862       "-Wno-extra", | 
|  | 863       "-Wno-ignored-qualifiers", | 
|  | 864       "-Wno-type-limits", | 
|  | 865     ] | 
|  | 866     default_warning_flags_cc += [ | 
|  | 867       # Disabling c++0x-compat should be handled in WebKit, but | 
|  | 868       # this currently doesn't work because gcc_version is not set | 
|  | 869       # correctly when building with the Android build system. | 
|  | 870       # TODO(torne): Fix this in WebKit. | 
|  | 871       "-Wno-error=c++0x-compat", | 
|  | 872 | 
|  | 873       # Other things unrelated to -Wextra: | 
|  | 874       "-Wno-non-virtual-dtor", | 
|  | 875       "-Wno-sign-promo", | 
|  | 876     ] | 
|  | 877   } | 
|  | 878 | 
|  | 879   if (gcc_version >= 48) { | 
|  | 880     # Don't warn about the "typedef 'foo' locally defined but not used" | 
|  | 881     # for gcc 4.8. | 
|  | 882     # TODO: remove this flag once all builds work. See crbug.com/227506 | 
|  | 883     default_warning_flags += [ "-Wno-unused-local-typedefs" ] | 
|  | 884   } | 
|  | 885 } | 
|  | 886 if (is_clang) { | 
|  | 887   default_warning_flags += [ | 
|  | 888     # This warns on using ints as initializers for floats in | 
|  | 889     # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|), | 
|  | 890     # which happens in several places in chrome code. Not sure if | 
|  | 891     # this is worth fixing. | 
|  | 892     "-Wno-c++11-narrowing", | 
|  | 893 | 
|  | 894     # Don't die on dtoa code that uses a char as an array index. | 
|  | 895     # This is required solely for base/third_party/dmg_fp/dtoa.cc. | 
|  | 896     # TODO(brettw) move this to that project then! | 
|  | 897     "-Wno-char-subscripts", | 
|  | 898 | 
|  | 899     # Warns on switches on enums that cover all enum values but | 
|  | 900     # also contain a default: branch. Chrome is full of that. | 
|  | 901     "-Wno-covered-switch-default", | 
|  | 902 | 
|  | 903     # Clang considers the `register` keyword as deprecated, but e.g. | 
|  | 904     # code generated by flex (used in angle) contains that keyword. | 
|  | 905     # http://crbug.com/255186 | 
|  | 906     "-Wno-deprecated-register", | 
|  | 907   ] | 
|  | 908 | 
|  | 909   # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost | 
|  | 910   # always have different versions. Certain flags may not be recognized by | 
|  | 911   # one version or the other. | 
|  | 912   if (!is_nacl) { | 
|  | 913     # Flags NaCl does not recognize. | 
|  | 914     default_warning_flags += [ | 
|  | 915       # TODO(hans): Get this cleaned up, http://crbug.com/428099 | 
|  | 916       "-Wno-inconsistent-missing-override", | 
|  | 917 | 
|  | 918       # TODO(thakis): Enable this, crbug.com/507717 | 
|  | 919       "-Wno-shift-negative-value", | 
|  | 920     ] | 
|  | 921   } | 
|  | 922 } | 
|  | 923 | 
|  | 924 # chromium_code --------------------------------------------------------------- | 
|  | 925 # | 
|  | 926 # Toggles between higher and lower warnings for code that is (or isn't) | 
|  | 927 # part of Chromium. | 
|  | 928 | 
|  | 929 config("chromium_code") { | 
|  | 930   if (is_win) { | 
|  | 931     cflags = [ "/W4" ]  # Warning level 4. | 
|  | 932   } else { | 
|  | 933     cflags = [ | 
|  | 934       "-Wall", | 
|  | 935       "-Wextra", | 
|  | 936     ] | 
|  | 937 | 
|  | 938     # In Chromium code, we define __STDC_foo_MACROS in order to get the | 
|  | 939     # C99 macros on Mac and Linux. | 
|  | 940     defines = [ | 
|  | 941       "__STDC_CONSTANT_MACROS", | 
|  | 942       "__STDC_FORMAT_MACROS", | 
|  | 943     ] | 
|  | 944 | 
|  | 945     if (!using_sanitizer && (!is_linux || !is_clang || is_official_build)) { | 
|  | 946       # _FORTIFY_SOURCE isn't really supported by Clang now, see | 
|  | 947       # http://llvm.org/bugs/show_bug.cgi?id=16821. | 
|  | 948       # It seems to work fine with Ubuntu 12 headers though, so use it in | 
|  | 949       # official builds. | 
|  | 950       # | 
|  | 951       # Non-chromium code is not guaranteed to compile cleanly with | 
|  | 952       # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are | 
|  | 953       # disabled, so only do that for Release build. | 
|  | 954       defines += [ "_FORTIFY_SOURCE=2" ] | 
|  | 955     } | 
|  | 956   } | 
|  | 957   cflags += default_warning_flags | 
|  | 958   cflags_cc = default_warning_flags_cc | 
|  | 959 } | 
|  | 960 config("no_chromium_code") { | 
|  | 961   cflags = [] | 
|  | 962   cflags_cc = [] | 
|  | 963   defines = [] | 
|  | 964 | 
|  | 965   if (is_win) { | 
|  | 966     cflags += [ | 
|  | 967       "/W3",  # Warning level 3. | 
|  | 968       "/wd4800",  # Disable warning when forcing value to bool. | 
|  | 969       "/wd4267",  # TODO(jschuh): size_t to int. | 
|  | 970       "/wd4996",  # Deprecated function warning. | 
|  | 971     ] | 
|  | 972     defines += [ | 
|  | 973       "_CRT_NONSTDC_NO_WARNINGS", | 
|  | 974       "_CRT_NONSTDC_NO_DEPRECATE", | 
|  | 975     ] | 
|  | 976   } | 
|  | 977 | 
|  | 978   if (is_linux) { | 
|  | 979     # Don't warn about ignoring the return value from e.g. close(). This is | 
|  | 980     # off by default in some gccs but on by default in others. BSD systems do | 
|  | 981     # not support this option, since they are usually using gcc 4.2.1, which | 
|  | 982     # does not have this flag yet. | 
|  | 983     cflags += [ "-Wno-unused-result" ] | 
|  | 984   } | 
|  | 985 | 
|  | 986   if (is_clang) { | 
|  | 987     cflags += [ | 
|  | 988       # TODO(mgiuca): Move this suppression into individual third-party | 
|  | 989       # libraries as required. http://crbug.com/505301. | 
|  | 990       "-Wno-overloaded-virtual", | 
|  | 991 | 
|  | 992       # Lots of third-party libraries have unused variables. Instead of | 
|  | 993       # suppressing them individually, we just blanket suppress them here. | 
|  | 994       "-Wno-unused-variable", | 
|  | 995     ] | 
|  | 996   } | 
|  | 997 | 
|  | 998   if (is_linux || is_android) { | 
|  | 999     cflags += [ | 
|  | 1000       # Don't warn about printf format problems. This is off by default in gcc | 
|  | 1001       # but on in Ubuntu's gcc(!). | 
|  | 1002       "-Wno-format", | 
|  | 1003     ] | 
|  | 1004     cflags_cc += [ | 
|  | 1005       # Don't warn about hash_map in third-party code. | 
|  | 1006       "-Wno-deprecated", | 
|  | 1007     ] | 
|  | 1008   } | 
|  | 1009   cflags += default_warning_flags | 
|  | 1010   cflags_cc += default_warning_flags_cc | 
|  | 1011 } | 
|  | 1012 | 
|  | 1013 # rtti ------------------------------------------------------------------------ | 
|  | 1014 # | 
|  | 1015 # Allows turning Run-Time Type Identification on or off. | 
|  | 1016 | 
|  | 1017 config("rtti") { | 
|  | 1018   if (is_win) { | 
|  | 1019     cflags_cc = [ "/GR" ] | 
|  | 1020   } | 
|  | 1021 } | 
|  | 1022 config("no_rtti") { | 
|  | 1023   if (is_win) { | 
|  | 1024     cflags_cc = [ "/GR-" ] | 
|  | 1025   } else { | 
|  | 1026     rtti_flags = [ "-fno-rtti" ] | 
|  | 1027     cflags_cc = rtti_flags | 
|  | 1028     cflags_objcc = rtti_flags | 
|  | 1029   } | 
|  | 1030 } | 
|  | 1031 | 
|  | 1032 # Warnings --------------------------------------------------------------------- | 
|  | 1033 | 
|  | 1034 # This will generate warnings when using Clang if code generates exit-time | 
|  | 1035 # destructors, which will slow down closing the program. | 
|  | 1036 # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600 | 
|  | 1037 config("wexit_time_destructors") { | 
|  | 1038   # TODO: Enable on Windows too, http://crbug.com/404525 | 
|  | 1039   if (is_clang && !is_win) { | 
|  | 1040     cflags = [ "-Wexit-time-destructors" ] | 
|  | 1041   } | 
|  | 1042 } | 
|  | 1043 | 
|  | 1044 # On Windows compiling on x64, VC will issue a warning when converting | 
|  | 1045 # size_t to int because it will truncate the value. Our code should not have | 
|  | 1046 # these warnings and one should use a static_cast or a checked_cast for the | 
|  | 1047 # conversion depending on the case. However, a lot of code still needs to be | 
|  | 1048 # fixed. Apply this config to such targets to disable the warning. | 
|  | 1049 # | 
|  | 1050 # Note that this can be applied regardless of platform and architecture to | 
|  | 1051 # clean up the call sites. This will only apply the flag when necessary. | 
|  | 1052 # | 
|  | 1053 # TODO(jschuh): crbug.com/167187 fix this and delete this config. | 
|  | 1054 config("no_size_t_to_int_warning") { | 
|  | 1055   if (is_win && current_cpu == "x64") { | 
|  | 1056     cflags = [ "/wd4267" ] | 
|  | 1057   } | 
|  | 1058 } | 
|  | 1059 | 
|  | 1060 # Optimization ----------------------------------------------------------------- | 
|  | 1061 # | 
|  | 1062 # Note that BUILDCONFIG.gn sets up a variable "default_optimization_config" | 
|  | 1063 # which it will assign to the config it implicitly applies to every target. If | 
|  | 1064 # you want to override the optimization level for your target, remove this | 
|  | 1065 # config (which will expand differently for debug or release builds), and then | 
|  | 1066 # add back the one you want to override it with: | 
|  | 1067 # | 
|  | 1068 #   configs -= default_optimization_config | 
|  | 1069 #   configs += [ "//build/config/compiler/optimize_max" ] | 
|  | 1070 | 
|  | 1071 # Shared settings for both "optimize" and "optimize_max" configs. | 
|  | 1072 # IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags. | 
|  | 1073 if (is_win) { | 
|  | 1074   common_optimize_on_cflags = [ | 
|  | 1075     "/Ob2",  # Both explicit and auto inlining. | 
|  | 1076     "/Oy-",  # Disable omitting frame pointers, must be after /O2. | 
|  | 1077   ] | 
|  | 1078   if (!is_asan) { | 
|  | 1079     common_optimize_on_cflags += [ | 
|  | 1080       # Put data in separate COMDATs. This allows the linker | 
|  | 1081       # to put bit-identical constants at the same address even if | 
|  | 1082       # they're unrelated constants, which saves binary size. | 
|  | 1083       # This optimization can't be used when ASan is enabled because | 
|  | 1084       # it is not compatible with the ASan ODR checker. | 
|  | 1085       "/Gw", | 
|  | 1086     ] | 
|  | 1087   } | 
|  | 1088   common_optimize_on_ldflags = [ "/OPT:REF" ] | 
|  | 1089 } else { | 
|  | 1090   common_optimize_on_cflags = [ | 
|  | 1091     # Don't emit the GCC version ident directives, they just end up in the | 
|  | 1092     # .comment section taking up binary size. | 
|  | 1093     "-fno-ident", | 
|  | 1094 | 
|  | 1095     # Put data and code in their own sections, so that unused symbols | 
|  | 1096     # can be removed at link time with --gc-sections. | 
|  | 1097     "-fdata-sections", | 
|  | 1098     "-ffunction-sections", | 
|  | 1099   ] | 
|  | 1100   common_optimize_on_ldflags = [] | 
|  | 1101 | 
|  | 1102   if (is_android) { | 
|  | 1103     if (!using_sanitizer) { | 
|  | 1104       common_optimize_on_cflags += [ "-fomit-frame-pointer" ] | 
|  | 1105     } | 
|  | 1106 | 
|  | 1107     # TODO(jdduke) Re-enable on mips after resolving linking | 
|  | 1108     # issues with libc++ (crbug.com/456380). | 
|  | 1109     if (current_cpu != "mipsel" && current_cpu != "mips64el") { | 
|  | 1110       common_optimize_on_ldflags += [ | 
|  | 1111         # Warn in case of text relocations. | 
|  | 1112         "-Wl,--warn-shared-textrel", | 
|  | 1113       ] | 
|  | 1114     } | 
|  | 1115   } | 
|  | 1116 | 
|  | 1117   if (is_mac || is_ios) { | 
|  | 1118     if (symbol_level == 2) { | 
|  | 1119       # Mac dead code stripping requires symbols. | 
|  | 1120       common_optimize_on_ldflags += [ "-Wl,-dead_strip" ] | 
|  | 1121     } | 
|  | 1122   } else { | 
|  | 1123     # Non-Mac Posix linker flags. | 
|  | 1124     common_optimize_on_ldflags += [ | 
|  | 1125       # Specifically tell the linker to perform optimizations. | 
|  | 1126       # See http://lwn.net/Articles/192624/ . | 
|  | 1127       "-Wl,-O1", | 
|  | 1128       "-Wl,--gc-sections", | 
|  | 1129     ] | 
|  | 1130 | 
|  | 1131     if (!using_sanitizer) { | 
|  | 1132       # Functions interposed by the sanitizers can make ld think | 
|  | 1133       # that some libraries aren't needed when they actually are, | 
|  | 1134       # http://crbug.com/234010. As workaround, disable --as-needed. | 
|  | 1135       common_optimize_on_ldflags += [ "-Wl,--as-needed" ] | 
|  | 1136     } | 
|  | 1137   } | 
|  | 1138 } | 
|  | 1139 | 
|  | 1140 # Default "optimization on" config. On Windows, this favors size over speed. | 
|  | 1141 config("optimize") { | 
|  | 1142   if (is_win) { | 
|  | 1143     # Favor size over speed, /O1 must be before the common flags. The GYP | 
|  | 1144     # build also specifies /Os and /GF but these are implied by /O1. | 
|  | 1145     cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ] | 
|  | 1146   } else if (is_android || is_ios) { | 
|  | 1147     cflags = [ "-Os" ] + common_optimize_on_cflags  # Favor size over speed. | 
|  | 1148   } else { | 
|  | 1149     cflags = [ "-O2" ] + common_optimize_on_cflags | 
|  | 1150   } | 
|  | 1151   ldflags = common_optimize_on_ldflags | 
|  | 1152 } | 
|  | 1153 | 
|  | 1154 # Turn off optimizations. | 
|  | 1155 config("no_optimize") { | 
|  | 1156   if (is_win) { | 
|  | 1157     cflags = [ | 
|  | 1158       "/Od",  # Disable optimization. | 
|  | 1159       "/Ob0",  # Disable all inlining (on by default). | 
|  | 1160       "/RTC1",  # Runtime checks for stack frame and uninitialized variables. | 
|  | 1161     ] | 
|  | 1162   } else if (is_android && !android_full_debug) { | 
|  | 1163     # On Android we kind of optimize some things that don't affect debugging | 
|  | 1164     # much even when optimization is disabled to get the binary size down. | 
|  | 1165     cflags = [ | 
|  | 1166       "-Os", | 
|  | 1167       "-fdata-sections", | 
|  | 1168       "-ffunction-sections", | 
|  | 1169     ] | 
|  | 1170     if (!using_sanitizer) { | 
|  | 1171       cflags += [ "-fomit-frame-pointer" ] | 
|  | 1172     } | 
|  | 1173     ldflags = common_optimize_on_ldflags | 
|  | 1174   } else { | 
|  | 1175     cflags = [ "-O0" ] | 
|  | 1176   } | 
|  | 1177 } | 
|  | 1178 | 
|  | 1179 # Turns up the optimization level. On Windows, this implies whole program | 
|  | 1180 # optimization and link-time code generation which is very expensive and should | 
|  | 1181 # be used sparingly. | 
|  | 1182 config("optimize_max") { | 
|  | 1183   ldflags = common_optimize_on_ldflags | 
|  | 1184   if (is_win) { | 
|  | 1185     # Favor speed over size, /O2 must be before the common flags. The GYP | 
|  | 1186     # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2. | 
|  | 1187     cflags = [ "/O2" ] + common_optimize_on_cflags | 
|  | 1188     if (is_official_build) { | 
|  | 1189       # TODO(GYP): TODO(dpranke): Should these only be on in an official | 
|  | 1190       # build, or on all the time? For now we'll require official build so | 
|  | 1191       # that the compile is clean. | 
|  | 1192       cflags += [ | 
|  | 1193         "/GL",  # Whole program optimization. | 
|  | 1194 | 
|  | 1195         # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds. | 
|  | 1196         # Probably anything that this would catch that wouldn't be caught in a | 
|  | 1197         # normal build isn't going to actually be a bug, so the incremental | 
|  | 1198         # value of C4702 for PGO builds is likely very small. | 
|  | 1199         "/wd4702", | 
|  | 1200       ] | 
|  | 1201       ldflags += [ "/LTCG" ] | 
|  | 1202     } | 
|  | 1203   } else { | 
|  | 1204     cflags = [ "-O2" ] + common_optimize_on_cflags | 
|  | 1205   } | 
|  | 1206 } | 
|  | 1207 | 
|  | 1208 # Symbols ---------------------------------------------------------------------- | 
|  | 1209 | 
|  | 1210 config("symbols") { | 
|  | 1211   if (is_win) { | 
|  | 1212     import("//build/toolchain/goma.gni") | 
|  | 1213     if (use_goma) { | 
|  | 1214       cflags = [ "/Z7" ]  # No PDB file | 
|  | 1215     } else { | 
|  | 1216       cflags = [ "/Zi" ]  # Produce PDB file, no edit and continue. | 
|  | 1217     } | 
|  | 1218     ldflags = [ "/DEBUG" ] | 
|  | 1219   } else { | 
|  | 1220     cflags = [ "-g2" ] | 
|  | 1221     if (use_debug_fission) { | 
|  | 1222       cflags += [ "-gsplit-dwarf" ] | 
|  | 1223     } | 
|  | 1224   } | 
|  | 1225 } | 
|  | 1226 | 
|  | 1227 config("minimal_symbols") { | 
|  | 1228   if (is_win) { | 
|  | 1229     # Linker symbols for backtraces only. | 
|  | 1230     ldflags = [ "/DEBUG" ] | 
|  | 1231   } else { | 
|  | 1232     cflags = [ "-g1" ] | 
|  | 1233     if (use_debug_fission) { | 
|  | 1234       cflags += [ "-gsplit-dwarf" ] | 
|  | 1235     } | 
|  | 1236   } | 
|  | 1237 } | 
|  | 1238 | 
|  | 1239 config("no_symbols") { | 
|  | 1240   if (!is_win) { | 
|  | 1241     cflags = [ "-g0" ] | 
|  | 1242   } | 
|  | 1243 } | 
| OLD | NEW | 
|---|