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 import("//build/config/compiler/compiler.gni") |
| 8 import("//build/config/nacl/config.gni") |
| 9 import("//build/toolchain/cc_wrapper.gni") |
| 10 import("//build/toolchain/toolchain.gni") |
| 11 |
| 12 if (current_cpu == "arm" || current_cpu == "arm64") { |
| 13 import("//build/config/arm.gni") |
| 14 } |
| 15 if (current_cpu == "mipsel" || current_cpu == "mips64el") { |
| 16 import("//build/config/mips.gni") |
| 17 } |
| 18 if (is_win) { |
| 19 import("//build/config/win/visual_studio_version.gni") |
| 20 } |
| 21 |
| 22 declare_args() { |
| 23 # Default to warnings as errors for default workflow, where we catch |
| 24 # warnings with known toolchains. Allow overriding this e.g. for Chromium |
| 25 # builds on Linux that could use a different version of the compiler. |
| 26 # With GCC, warnings in no-Chromium code are always not treated as errors. |
| 27 treat_warnings_as_errors = true |
| 28 |
| 29 # Normally, Android builds are lightly optimized, even for debug builds, to |
| 30 # keep binary size down. Setting this flag to true disables such optimization |
| 31 android_full_debug = false |
| 32 |
| 33 # Whether to use the binary binutils checked into third_party/binutils. |
| 34 # These are not multi-arch so cannot be used except on x86 and x86-64 (the |
| 35 # only two architectures that are currently checked in). Turn this off when |
| 36 # you are using a custom toolchain and need to control -B in cflags. |
| 37 linux_use_bundled_binutils = |
| 38 is_linux && (current_cpu == "x64" || current_cpu == "x86") |
| 39 binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", |
| 40 root_build_dir) |
| 41 |
| 42 # Compile in such a way as to make it possible for the profiler to unwind full |
| 43 # stack frames. Setting this flag has a large effect on the performance of the |
| 44 # generated code than just setting profiling, but gives the profiler more |
| 45 # information to analyze. |
| 46 # Requires profiling to be set to true. |
| 47 enable_full_stack_frames_for_profiling = false |
| 48 |
| 49 # When we are going to use gold we need to find it. |
| 50 # This is initialized below, after use_gold might have been overridden. |
| 51 gold_path = false |
| 52 |
| 53 # use_debug_fission: whether to use split DWARF debug info |
| 54 # files. This can reduce link time significantly, but is incompatible |
| 55 # with some utilities such as icecc and ccache. Requires gold and |
| 56 # gcc >= 4.8 or clang. |
| 57 # http://gcc.gnu.org/wiki/DebugFission |
| 58 # |
| 59 # This is a placeholder value indicating that the code below should set |
| 60 # the default. This is necessary to delay the evaluation of the default |
| 61 # value expression until after its input values such as use_gold have |
| 62 # been set, e.g. by a toolchain_args() block. |
| 63 use_debug_fission = "default" |
| 64 |
| 65 if (is_win) { |
| 66 # Whether the VS xtree header has been patched to disable warning 4702. If |
| 67 # it has, then we don't need to disable 4702 (unreachable code warning). |
| 68 # The patch is preapplied to the internal toolchain and hence all bots. |
| 69 msvs_xtree_patched = false |
| 70 } |
| 71 |
| 72 # Omit unwind support in official builds to save space. |
| 73 # We can use breakpad for these builds. |
| 74 exclude_unwind_tables = is_chrome_branded && is_official_build |
| 75 |
| 76 # If true, gold linker will save symbol table inside object files. |
| 77 # This speeds up gdb startup by 60% |
| 78 gdb_index = false |
| 79 |
| 80 # If true, optimize for size. Does not affect windows builds. |
| 81 # Linux & Mac favor speed over size. |
| 82 # TODO(brettw) it's weird that Mac and desktop Linux are different. We should |
| 83 # explore favoring size over speed in this case as well. |
| 84 optimize_for_size = is_android || is_ios |
| 85 |
| 86 # If this is set to true, or if LLVM_FORCE_HEAD_REVISION is set to 1 |
| 87 # in the environment, we use the revision in the llvm repo to determine |
| 88 # the CLANG_REVISION to use, instead of the version hard-coded into |
| 89 # //tools/clang/scripts/update.py. This should only be used in |
| 90 # conjunction with setting LLVM_FORCE_HEAD_REVISION in the |
| 91 # environment when `gclient runhooks` is run as well. |
| 92 llvm_force_head_revision = false |
| 93 } |
| 94 |
| 95 if (is_clang && !is_nacl) { |
| 96 update_args = [ "--print-revision" ] |
| 97 if (llvm_force_head_revision) { |
| 98 update_args += [ "--llvm-force-head-revision" ] |
| 99 } |
| 100 clang_revision = |
| 101 exec_script("//tools/clang/scripts/update.py", update_args, "trim string") |
| 102 } |
| 103 |
| 104 # Apply the default logic for these values if they were not set explicitly. |
| 105 if (gold_path == false) { |
| 106 if (use_gold) { |
| 107 gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", |
| 108 root_build_dir) |
| 109 } else { |
| 110 gold_path = "" |
| 111 } |
| 112 } |
| 113 |
| 114 if (use_debug_fission == "default") { |
| 115 use_debug_fission = is_debug && !is_win && use_gold && |
| 116 linux_use_bundled_binutils && cc_wrapper == "" |
| 117 } |
| 118 |
| 119 # default_include_dirs --------------------------------------------------------- |
| 120 # |
| 121 # This is a separate config so that third_party code (which would not use the |
| 122 # source root and might have conflicting versions of some headers) can remove |
| 123 # this and specify their own include paths. |
| 124 config("default_include_dirs") { |
| 125 include_dirs = [ |
| 126 "//", |
| 127 root_gen_dir, |
| 128 ] |
| 129 } |
| 130 |
| 131 # compiler --------------------------------------------------------------------- |
| 132 # |
| 133 # Base compiler configuration. |
| 134 # |
| 135 # See also "runtime_library" below for related stuff and a discussion about |
| 136 # where stuff should go. Put warning related stuff in the "warnings" config. |
| 137 |
| 138 config("compiler") { |
| 139 asmflags = [] |
| 140 cflags = [] |
| 141 cflags_c = [] |
| 142 cflags_cc = [] |
| 143 cflags_objc = [] |
| 144 cflags_objcc = [] |
| 145 ldflags = [] |
| 146 defines = [] |
| 147 configs = [] |
| 148 |
| 149 # System-specific flags. If your compiler flags apply to one of the |
| 150 # categories here, add it to the associated file to keep this shared config |
| 151 # smaller. |
| 152 if (is_win) { |
| 153 configs += [ "//build/config/win:compiler" ] |
| 154 } else if (is_android) { |
| 155 configs += [ "//build/config/android:compiler" ] |
| 156 } else if (is_linux) { |
| 157 configs += [ "//build/config/linux:compiler" ] |
| 158 } else if (is_nacl) { |
| 159 configs += [ "//build/config/nacl:compiler" ] |
| 160 } else if (is_ios || is_mac) { |
| 161 configs += [ "//build/config/mac:compiler" ] |
| 162 } |
| 163 |
| 164 # Applies to all Posix systems. |
| 165 if (is_posix) { |
| 166 configs += [ "//build/config/posix:compiler" ] |
| 167 } |
| 168 |
| 169 # See the definitions below. |
| 170 configs += [ |
| 171 ":compiler_cpu_abi", |
| 172 ":compiler_codegen", |
| 173 ] |
| 174 |
| 175 # In general, Windows is totally different, but all the other builds share |
| 176 # some common GCC configuration. |
| 177 if (!is_win) { |
| 178 # Common GCC compiler flags setup. |
| 179 # -------------------------------- |
| 180 cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204 |
| 181 cflags_cc += [ |
| 182 # If this is removed then remove the corresponding /Zc:threadSafeInit- for |
| 183 # Windows. |
| 184 "-fno-threadsafe-statics", |
| 185 |
| 186 # Not exporting C++ inline functions can generally be applied anywhere |
| 187 # so we do so here. Normal function visibility is controlled by |
| 188 # //build/config/gcc:symbol_visibility_hidden. |
| 189 "-fvisibility-inlines-hidden", |
| 190 ] |
| 191 |
| 192 # Stack protection. |
| 193 if (is_mac) { |
| 194 cflags += [ "-fstack-protector-all" ] |
| 195 } else if (is_posix && !is_chromeos && !is_nacl) { |
| 196 # TODO(phajdan.jr): Use -fstack-protector-strong when our gcc supports it. |
| 197 cflags += [ "--param=ssp-buffer-size=4" ] |
| 198 |
| 199 # The x86 toolchain currently has problems with stack-protector. |
| 200 if (is_android && current_cpu == "x86") { |
| 201 cflags += [ "-fno-stack-protector" ] |
| 202 } else { |
| 203 cflags += [ "-fstack-protector" ] |
| 204 } |
| 205 } |
| 206 |
| 207 # Linker warnings. |
| 208 if (!(is_chromeos && current_cpu == "arm") && |
| 209 !(is_android && use_order_profiling) && !is_mac && !is_ios) { |
| 210 # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580 |
| 211 # TODO(lizeb,pasko): Fix link errors when linking with order_profiling=1 |
| 212 # crbug.com/485542 |
| 213 ldflags += [ "-Wl,--fatal-warnings" ] |
| 214 } |
| 215 } |
| 216 |
| 217 if (is_clang && is_debug) { |
| 218 # Allow comparing the address of references and 'this' against 0 |
| 219 # in debug builds. Technically, these can never be null in |
| 220 # well-defined C/C++ and Clang can optimize such checks away in |
| 221 # release builds, but they may be used in asserts in debug builds. |
| 222 cflags_cc += [ |
| 223 "-Wno-undefined-bool-conversion", |
| 224 "-Wno-tautological-undefined-compare", |
| 225 ] |
| 226 } |
| 227 |
| 228 if (is_clang && !is_nacl) { |
| 229 # This is here so that all files get recompiled after a clang roll and |
| 230 # when turning clang on or off. (defines are passed via the command line, |
| 231 # and build system rebuild things when their commandline changes). Nothing |
| 232 # should ever read this define. |
| 233 defines += [ "CR_CLANG_REVISION=$clang_revision" ] |
| 234 } |
| 235 |
| 236 # Non-Mac Posix compiler flags setup. |
| 237 # ----------------------------------- |
| 238 if (is_posix && !(is_mac || is_ios)) { |
| 239 if (enable_profiling) { |
| 240 # Explicitly ask for frame pointers. Otherwise they are omitted when |
| 241 # any optimization level is used (and Android debug builds use -Os). |
| 242 cflags += [ "-fno-omit-frame-pointer" ] |
| 243 if (!is_debug) { |
| 244 cflags += [ "-g" ] |
| 245 |
| 246 if (enable_full_stack_frames_for_profiling) { |
| 247 cflags += [ |
| 248 "-fno-inline", |
| 249 "-fno-optimize-sibling-calls", |
| 250 ] |
| 251 } |
| 252 } |
| 253 } |
| 254 |
| 255 defines += [ "_FILE_OFFSET_BITS=64" ] |
| 256 |
| 257 if (!is_android) { |
| 258 defines += [ |
| 259 "_LARGEFILE_SOURCE", |
| 260 "_LARGEFILE64_SOURCE", |
| 261 ] |
| 262 } |
| 263 |
| 264 if (!is_nacl) { |
| 265 if (exclude_unwind_tables) { |
| 266 cflags += [ |
| 267 "-fno-unwind-tables", |
| 268 "-fno-asynchronous-unwind-tables", |
| 269 ] |
| 270 defines += [ "NO_UNWIND_TABLES" ] |
| 271 } else { |
| 272 cflags += [ "-funwind-tables" ] |
| 273 } |
| 274 } |
| 275 } |
| 276 |
| 277 # Linux/Android common flags setup. |
| 278 # --------------------------------- |
| 279 if (is_linux || is_android) { |
| 280 cflags += [ |
| 281 "-fPIC", |
| 282 "-pipe", # Use pipes for communicating between sub-processes. Faster. |
| 283 ] |
| 284 |
| 285 ldflags += [ |
| 286 "-fPIC", |
| 287 "-Wl,-z,noexecstack", |
| 288 "-Wl,-z,now", |
| 289 "-Wl,-z,relro", |
| 290 ] |
| 291 if (!using_sanitizer && !use_cfi_diag) { |
| 292 ldflags += [ "-Wl,-z,defs" ] |
| 293 } |
| 294 } |
| 295 |
| 296 # Linux-specific compiler flags setup. |
| 297 # ------------------------------------ |
| 298 if (is_posix && use_lld && !is_nacl) { |
| 299 ldflags += [ "-fuse-ld=lld" ] |
| 300 } else if (use_gold) { |
| 301 ldflags += [ "-fuse-ld=gold" ] |
| 302 if (is_android) { |
| 303 if (is_clang) { |
| 304 _rebased_android_toolchain_root = |
| 305 rebase_path(android_toolchain_root, root_build_dir) |
| 306 |
| 307 # Let clang find the ld.gold in the NDK. |
| 308 ldflags += [ "--gcc-toolchain=$_rebased_android_toolchain_root" ] |
| 309 } |
| 310 |
| 311 # Use -mstackrealign due to a bug on ia32 Jelly Bean. |
| 312 # See crbug.com/521527 |
| 313 if (current_cpu == "x86") { |
| 314 cflags += [ "-mstackrealign" ] |
| 315 } |
| 316 } else { |
| 317 ldflags += [ |
| 318 "-B$gold_path", |
| 319 # Experimentation found that using four linking threads |
| 320 # saved ~20% of link time. |
| 321 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thr
ead/thread/281527606915bb36 |
| 322 # Only apply this to the target linker, since the host |
| 323 # linker might not be gold, but isn't used much anyway. |
| 324 # TODO(raymes): Disable threading because gold is frequently |
| 325 # crashing on the bots: crbug.com/161942. |
| 326 #"-Wl,--threads", |
| 327 #"-Wl,--thread-count=4", |
| 328 ] |
| 329 } |
| 330 |
| 331 if (gdb_index) { |
| 332 ldflags += [ "-Wl,--gdb-index" ] |
| 333 } |
| 334 |
| 335 # TODO(thestig): Make this flag work with GN. |
| 336 #if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan |
| is_msan)) { |
| 337 # ldflags += [ |
| 338 # "-Wl,--detect-odr-violations", |
| 339 # ] |
| 340 #} |
| 341 } else if (linux_use_bundled_binutils) { |
| 342 # Gold is the default linker for the bundled binutils so we explicitly |
| 343 # enable the bfd linker when use_gold is not set. |
| 344 ldflags += [ "-fuse-ld=bfd" ] |
| 345 } else if (is_android && current_cpu == "mipsel" && is_clang) { |
| 346 # Let clang find the ld.bfd in the NDK. |
| 347 _rebased_android_toolchain_root = |
| 348 rebase_path(android_toolchain_root, root_build_dir) |
| 349 ldflags += [ "--gcc-toolchain=$rebased_android_toolchain_root" ] |
| 350 } |
| 351 |
| 352 if (is_posix && (use_gold || (use_lld && !is_nacl)) && !using_sanitizer && |
| 353 !(is_android && use_order_profiling)) { |
| 354 # TODO(crbug.com/576197) - gcc on x86 platforms + gold + icf=all |
| 355 # doesn't currently work. Once it does, use icf=all everywhere. |
| 356 # Additionally, on Android x86 --icf=safe seems to cause issues as well. |
| 357 if (is_clang || (target_cpu != "x86" && target_cpu != "x64")) { |
| 358 ldflags += [ "-Wl,--icf=all" ] |
| 359 } else if (!is_android) { |
| 360 ldflags += [ "-Wl,--icf=safe" ] |
| 361 } |
| 362 } |
| 363 |
| 364 if (linux_use_bundled_binutils) { |
| 365 cflags += [ "-B$binutils_path" ] |
| 366 } |
| 367 |
| 368 # Clang-specific compiler flags setup. |
| 369 # ------------------------------------ |
| 370 if (is_clang) { |
| 371 cflags += [ "-fcolor-diagnostics" ] |
| 372 } |
| 373 |
| 374 # Makes builds independent of absolute file path. |
| 375 # clang-cl (used if is_win) doesn't expose this flag. |
| 376 # Currently disabled for nacl since its toolchain lacks this flag (too old). |
| 377 # TODO(zforman): Once nacl's toolchain is updated, remove check. |
| 378 if (is_clang && is_linux) { |
| 379 absolute_path = rebase_path("//.") |
| 380 cflags += [ "-fdebug-prefix-map=$absolute_path=." ] |
| 381 } |
| 382 |
| 383 # C++11 compiler flags setup. |
| 384 # --------------------------- |
| 385 if (is_linux || is_android || (is_nacl && is_clang)) { |
| 386 # gnu++11 instead of c++11 is needed because some code uses typeof() (a |
| 387 # GNU extension). |
| 388 # TODO(thakis): Eventually switch this to c++11 instead, |
| 389 # http://crbug.com/427584 |
| 390 cflags_cc += [ "-std=gnu++11" ] |
| 391 } else if (!is_win && !is_nacl) { |
| 392 # TODO(mcgrathr) - the NaCl GCC toolchain doesn't support either gnu++11 |
| 393 # or c++11; we technically don't need this toolchain any more, but there |
| 394 # are still a few buildbots using it, so until those are turned off |
| 395 # we need the !is_nacl clause and the (is_nacl && is_clang) clause, above. |
| 396 cflags_cc += [ "-std=c++11" ] |
| 397 } |
| 398 |
| 399 if (is_mac) { |
| 400 # Tell the compiler to use libc++'s headers and the linker to link |
| 401 # against libc++. The latter part normally requires OS X 10.7, |
| 402 # but we still support running on 10.6. How does this work? Two |
| 403 # parts: |
| 404 # 1. Chromium's clang doesn't error on -mmacosx-version-min=10.6 |
| 405 # combined with -stdlib=libc++ (it normally silently produced a |
| 406 # binary that doesn't run on 10.6) |
| 407 # 2. Further down, library_dirs is set to |
| 408 # third_party/libc++-static, which contains a static |
| 409 # libc++.a library. The linker then links against that instead |
| 410 # of against /usr/lib/libc++.dylib when it sees the -lc++ flag |
| 411 # added by the driver. |
| 412 # |
| 413 # In component builds, just link to the system libc++. This has |
| 414 # the effect of making everything depend on libc++, which means |
| 415 # component-build binaries won't run on 10.6 (no libc++ there), |
| 416 # but for a developer-only configuration that's ok. (We don't |
| 417 # want to raise the deployment target yet so that official and |
| 418 # dev builds have the same deployment target. This affects |
| 419 # things like which functions are considered deprecated.) |
| 420 cflags_cc += [ "-stdlib=libc++" ] |
| 421 ldflags += [ "-stdlib=libc++" ] |
| 422 if (!is_component_build && !is_asan) { |
| 423 ldflags += [ |
| 424 "-L", |
| 425 rebase_path("//third_party/libc++-static", root_build_dir), |
| 426 ] |
| 427 } |
| 428 } |
| 429 |
| 430 # Add flags for link-time optimization. These flags enable |
| 431 # optimizations/transformations that require whole-program visibility at link |
| 432 # time, so they need to be applied to all translation units, and we may end up |
| 433 # with miscompiles if only part of the program is compiled with LTO flags. For |
| 434 # that reason, we cannot allow targets to enable or disable these flags, for |
| 435 # example by disabling the optimize configuration. |
| 436 # TODO(pcc): Make this conditional on is_official_build rather than on gn |
| 437 # flags for specific features. |
| 438 if (!is_debug && (allow_posix_link_time_opt || is_cfi) && !is_nacl) { |
| 439 cflags += [ "-flto" ] |
| 440 ldflags += [ "-flto" ] |
| 441 |
| 442 # Apply a lower LTO optimization level as the default is too slow. |
| 443 if (is_linux) { |
| 444 if (use_lld) { |
| 445 ldflags += [ "-Wl,--lto-O1" ] |
| 446 } else { |
| 447 ldflags += [ "-Wl,-plugin-opt,O1" ] |
| 448 } |
| 449 } else if (is_mac) { |
| 450 ldflags += [ "-Wl,-mllvm,-O1" ] |
| 451 } |
| 452 |
| 453 # Work-around for http://openradar.appspot.com/20356002 |
| 454 if (is_mac) { |
| 455 ldflags += [ "-Wl,-all_load" ] |
| 456 } |
| 457 |
| 458 # Allows the linker to apply ICF to the LTO object file. Also, when |
| 459 # targeting ARM, without this flag, LTO produces a .text section that is |
| 460 # larger than the maximum call displacement, preventing the linker from |
| 461 # relocating calls (http://llvm.org/PR22999). |
| 462 if (is_linux) { |
| 463 ldflags += [ "-Wl,-plugin-opt,-function-sections" ] |
| 464 } |
| 465 |
| 466 # TODO(pcc): Make these flags work correctly with CFI. |
| 467 if (!is_cfi) { |
| 468 cflags += [ "-fwhole-program-vtables" ] |
| 469 ldflags += [ "-fwhole-program-vtables" ] |
| 470 } |
| 471 } |
| 472 |
| 473 # Pass the same C/C++ flags to the objective C/C++ compiler. |
| 474 cflags_objc += cflags_c |
| 475 cflags_objcc += cflags_cc |
| 476 |
| 477 # Assign any flags set for the C compiler to asmflags so that they are sent |
| 478 # to the assembler. The Windows assembler takes different types of flags |
| 479 # so only do so for posix platforms. |
| 480 if (is_posix) { |
| 481 asmflags += cflags |
| 482 asmflags += cflags_c |
| 483 } |
| 484 } |
| 485 |
| 486 # This provides the basic options to select the target CPU and ABI. |
| 487 # It is factored out of "compiler" so that special cases can use this |
| 488 # without using everything that "compiler" brings in. Options that |
| 489 # tweak code generation for a particular CPU do not belong here! |
| 490 # See "compiler_codegen", below. |
| 491 config("compiler_cpu_abi") { |
| 492 cflags = [] |
| 493 ldflags = [] |
| 494 |
| 495 if (is_posix && !(is_mac || is_ios)) { |
| 496 # CPU architecture. We may or may not be doing a cross compile now, so for |
| 497 # simplicity we always explicitly set the architecture. |
| 498 if (current_cpu == "x64") { |
| 499 cflags += [ |
| 500 "-m64", |
| 501 "-march=x86-64", |
| 502 ] |
| 503 ldflags += [ "-m64" ] |
| 504 } else if (current_cpu == "x86") { |
| 505 cflags += [ "-m32" ] |
| 506 ldflags += [ "-m32" ] |
| 507 if (!is_nacl) { |
| 508 cflags += [ |
| 509 "-msse2", |
| 510 "-mfpmath=sse", |
| 511 "-mmmx", |
| 512 ] |
| 513 } |
| 514 } else if (current_cpu == "arm") { |
| 515 if (is_clang && !is_android && !is_nacl) { |
| 516 cflags += [ "--target=arm-linux-gnueabihf" ] |
| 517 ldflags += [ "--target=arm-linux-gnueabihf" ] |
| 518 } |
| 519 if (!is_nacl) { |
| 520 cflags += [ |
| 521 "-march=$arm_arch", |
| 522 "-mfloat-abi=$arm_float_abi", |
| 523 ] |
| 524 if (arm_use_thumb) { |
| 525 cflags += [ "-mthumb" ] |
| 526 if (is_android && !is_clang) { |
| 527 # Clang doesn't support this option. |
| 528 cflags += [ "-mthumb-interwork" ] |
| 529 } |
| 530 } |
| 531 } |
| 532 if (arm_tune != "") { |
| 533 cflags += [ "-mtune=$arm_tune" ] |
| 534 } |
| 535 } else if (current_cpu == "mipsel") { |
| 536 if (mips_arch_variant == "r6") { |
| 537 if (is_clang) { |
| 538 cflags += [ |
| 539 "--target=mipsel-linux-gnu", |
| 540 "-march=mips32r6", |
| 541 ] |
| 542 ldflags += [ "--target=mipsel-linux-gnu" ] |
| 543 } else { |
| 544 cflags += [ |
| 545 "-mips32r6", |
| 546 "-Wa,-mips32r6", |
| 547 ] |
| 548 if (is_android) { |
| 549 ldflags += [ |
| 550 "-mips32r6", |
| 551 "-Wl,-melf32ltsmip", |
| 552 ] |
| 553 } |
| 554 } |
| 555 } else if (mips_arch_variant == "r2") { |
| 556 if (is_clang) { |
| 557 if (is_android) { |
| 558 cflags += [ |
| 559 "--target=mipsel-linux-android", |
| 560 "-march=mipsel", |
| 561 "-mcpu=mips32r2", |
| 562 ] |
| 563 ldflags += [ "--target=mipsel-linux-android" ] |
| 564 } else { |
| 565 cflags += [ |
| 566 "--target=mipsel-linux-gnu", |
| 567 "-march=mipsel", |
| 568 "-mcpu=mips32r2", |
| 569 ] |
| 570 ldflags += [ "--target=mipsel-linux-gnu" ] |
| 571 } |
| 572 } else { |
| 573 cflags += [ |
| 574 "-mips32r2", |
| 575 "-Wa,-mips32r2", |
| 576 ] |
| 577 if (mips_float_abi == "hard" && mips_fpu_mode != "") { |
| 578 cflags += [ "-m$mips_fpu_mode" ] |
| 579 } |
| 580 } |
| 581 } else if (mips_arch_variant == "r1") { |
| 582 if (is_clang) { |
| 583 if (is_android) { |
| 584 cflags += [ |
| 585 "--target=mipsel-linux-android", |
| 586 "-march=mipsel", |
| 587 "-mcpu=mips32", |
| 588 ] |
| 589 ldflags += [ "--target=mipsel-linux-android" ] |
| 590 } else { |
| 591 cflags += [ |
| 592 "--target=mipsel-linux-gnu", |
| 593 "-march=mipsel", |
| 594 "-mcpu=mips32", |
| 595 ] |
| 596 ldflags += [ "--target=mipsel-linux-gnu" ] |
| 597 } |
| 598 } else { |
| 599 cflags += [ |
| 600 "-mips32", |
| 601 "-Wa,-mips32", |
| 602 ] |
| 603 } |
| 604 } |
| 605 |
| 606 if (mips_dsp_rev == 1) { |
| 607 cflags += [ "-mdsp" ] |
| 608 } else if (mips_dsp_rev == 2) { |
| 609 cflags += [ "-mdspr2" ] |
| 610 } |
| 611 |
| 612 cflags += [ "-m${mips_float_abi}-float" ] |
| 613 } else if (current_cpu == "mips64el") { |
| 614 if (mips_arch_variant == "r6") { |
| 615 cflags += [ |
| 616 "-mips64r6", |
| 617 "-Wa,-mips64r6", |
| 618 ] |
| 619 ldflags += [ "-mips64r6" ] |
| 620 } else if (mips_arch_variant == "r2") { |
| 621 cflags += [ |
| 622 "-mips64r2", |
| 623 "-Wa,-mips64r2", |
| 624 ] |
| 625 ldflags += [ "-mips64r2" ] |
| 626 } |
| 627 } else if (current_cpu == "pnacl" && is_nacl_nonsfi) { |
| 628 if (target_cpu == "x86" || target_cpu == "x64") { |
| 629 cflags += [ |
| 630 "-arch", |
| 631 "x86-32-nonsfi", |
| 632 "--pnacl-bias=x86-32-nonsfi", |
| 633 "--target=i686-unknown-nacl", |
| 634 ] |
| 635 ldflags += [ |
| 636 "-arch", |
| 637 "x86-32-nonsfi", |
| 638 "--target=i686-unknown-nacl", |
| 639 ] |
| 640 } else if (target_cpu == "arm") { |
| 641 cflags += [ |
| 642 "-arch", |
| 643 "arm-nonsfi", |
| 644 "--pnacl-bias=arm-nonsfi", |
| 645 "--target=armv7-unknown-nacl-gnueabihf", |
| 646 ] |
| 647 ldflags += [ |
| 648 "-arch", |
| 649 "arm-nonsfi", |
| 650 "--target=armv7-unknown-nacl-gnueabihf", |
| 651 ] |
| 652 } |
| 653 } |
| 654 } |
| 655 |
| 656 asmflags = cflags |
| 657 } |
| 658 |
| 659 # This provides options to tweak code generation that are necessary |
| 660 # for particular Chromium code or for working around particular |
| 661 # compiler bugs (or the combination of the two). |
| 662 config("compiler_codegen") { |
| 663 configs = [] |
| 664 cflags = [] |
| 665 |
| 666 if (is_nacl) { |
| 667 configs += [ "//build/config/nacl:compiler_codegen" ] |
| 668 } else if (is_posix && !is_mac && !is_ios) { |
| 669 if (current_cpu == "x86") { |
| 670 if (is_clang) { |
| 671 cflags += [ |
| 672 # Else building libyuv gives clang's register allocator issues, |
| 673 # see llvm.org/PR15798 / crbug.com/233709 |
| 674 "-momit-leaf-frame-pointer", |
| 675 ] |
| 676 } |
| 677 } else if (current_cpu == "arm") { |
| 678 if (is_android && !is_clang) { |
| 679 # Clang doesn't support these flags. |
| 680 cflags += [ |
| 681 # The tree-sra optimization (scalar replacement for |
| 682 # aggregates enabling subsequent optimizations) leads to |
| 683 # invalid code generation when using the Android NDK's |
| 684 # compiler (r5-r7). This can be verified using |
| 685 # webkit_unit_tests' WTF.Checked_int8_t test. |
| 686 "-fno-tree-sra", |
| 687 |
| 688 # The following option is disabled to improve binary |
| 689 # size and performance in gcc 4.9. |
| 690 "-fno-caller-saves", |
| 691 ] |
| 692 } |
| 693 } |
| 694 } |
| 695 |
| 696 asmflags = cflags |
| 697 } |
| 698 |
| 699 # This is separate from :compiler_codegen (and not even a sub-config there) |
| 700 # so that some targets can remove it from the list with: |
| 701 # configs -= [ "//build/config/compiler:clang_stackrealign" ] |
| 702 # See https://crbug.com/556393 for details of where it must be avoided. |
| 703 config("clang_stackrealign") { |
| 704 if (is_clang && current_cpu == "x86" && is_linux) { |
| 705 cflags = [ |
| 706 # Align the stack on 16-byte boundaries, http://crbug.com/418554. |
| 707 "-mstack-alignment=16", |
| 708 "-mstackrealign", |
| 709 ] |
| 710 } |
| 711 } |
| 712 |
| 713 config("compiler_arm_fpu") { |
| 714 if (current_cpu == "arm" && !is_ios && !is_nacl) { |
| 715 cflags = [ "-mfpu=$arm_fpu" ] |
| 716 asmflags = cflags |
| 717 } |
| 718 } |
| 719 |
| 720 # runtime_library ------------------------------------------------------------- |
| 721 # |
| 722 # Sets the runtime library and associated options. |
| 723 # |
| 724 # How do you determine what should go in here vs. "compiler" above? Consider if |
| 725 # a target might choose to use a different runtime library (ignore for a moment |
| 726 # if this is possible or reasonable on your system). If such a target would want |
| 727 # to change or remove your option, put it in the runtime_library config. If a |
| 728 # target wants the option regardless, put it in the compiler config. |
| 729 |
| 730 config("runtime_library") { |
| 731 defines = [] |
| 732 configs = [] |
| 733 |
| 734 # System-specific flags. If your compiler flags apply to one of the |
| 735 # categories here, add it to the associated file to keep this shared config |
| 736 # smaller. |
| 737 if (is_win) { |
| 738 configs += [ "//build/config/win:runtime_library" ] |
| 739 } else if (is_linux) { |
| 740 configs += [ "//build/config/linux:runtime_library" ] |
| 741 } else if (is_ios) { |
| 742 configs += [ "//build/config/ios:runtime_library" ] |
| 743 } else if (is_mac) { |
| 744 configs += [ "//build/config/mac:runtime_library" ] |
| 745 } else if (is_android) { |
| 746 configs += [ "//build/config/android:runtime_library" ] |
| 747 } |
| 748 |
| 749 if (is_posix) { |
| 750 configs += [ "//build/config/posix:runtime_library" ] |
| 751 } |
| 752 |
| 753 if (is_component_build) { |
| 754 defines += [ "COMPONENT_BUILD" ] |
| 755 } |
| 756 } |
| 757 |
| 758 # default_warnings ------------------------------------------------------------ |
| 759 # |
| 760 # Collects all warning flags that are used by default. This is used as a |
| 761 # subconfig of both chromium_code and no_chromium_code. This way these |
| 762 # flags are guaranteed to appear on the compile command line after -Wall. |
| 763 config("default_warnings") { |
| 764 cflags = [] |
| 765 cflags_cc = [] |
| 766 |
| 767 if (is_win) { |
| 768 if (treat_warnings_as_errors) { |
| 769 cflags += [ "/WX" ] |
| 770 } |
| 771 |
| 772 cflags += [ |
| 773 # Warnings permanently disabled: |
| 774 |
| 775 # C4091: 'typedef ': ignored on left of 'X' when no variable is |
| 776 # declared. |
| 777 # This happens in a number of Windows headers. Dumb. |
| 778 "/wd4091", |
| 779 |
| 780 # C4127: conditional expression is constant |
| 781 # This warning can in theory catch dead code and other problems, but |
| 782 # triggers in far too many desirable cases where the conditional |
| 783 # expression is either set by macros or corresponds some legitimate |
| 784 # compile-time constant expression (due to constant template args, |
| 785 # conditionals comparing the sizes of different types, etc.). Some of |
| 786 # these can be worked around, but it's not worth it. |
| 787 "/wd4127", |
| 788 |
| 789 # C4251: 'identifier' : class 'type' needs to have dll-interface to be |
| 790 # used by clients of class 'type2' |
| 791 # This is necessary for the shared library build. |
| 792 "/wd4251", |
| 793 |
| 794 # C4351: new behavior: elements of array 'array' will be default |
| 795 # initialized |
| 796 # This is a silly "warning" that basically just alerts you that the |
| 797 # compiler is going to actually follow the language spec like it's |
| 798 # supposed to, instead of not following it like old buggy versions did. |
| 799 # There's absolutely no reason to turn this on. |
| 800 "/wd4351", |
| 801 |
| 802 # C4355: 'this': used in base member initializer list |
| 803 # It's commonly useful to pass |this| to objects in a class' initializer |
| 804 # list. While this warning can catch real bugs, most of the time the |
| 805 # constructors in question don't attempt to call methods on the passed-in |
| 806 # pointer (until later), and annotating every legit usage of this is |
| 807 # simply more hassle than the warning is worth. |
| 808 "/wd4355", |
| 809 |
| 810 # C4503: 'identifier': decorated name length exceeded, name was |
| 811 # truncated |
| 812 # This only means that some long error messages might have truncated |
| 813 # identifiers in the presence of lots of templates. It has no effect on |
| 814 # program correctness and there's no real reason to waste time trying to |
| 815 # prevent it. |
| 816 "/wd4503", |
| 817 |
| 818 # Warning C4589 says: "Constructor of abstract class ignores |
| 819 # initializer for virtual base class." Disable this warning because it |
| 820 # is flaky in VS 2015 RTM. It triggers on compiler generated |
| 821 # copy-constructors in some cases. |
| 822 "/wd4589", |
| 823 |
| 824 # C4611: interaction between 'function' and C++ object destruction is |
| 825 # non-portable |
| 826 # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN |
| 827 # suggests using exceptions instead of setjmp/longjmp for C++, but |
| 828 # Chromium code compiles without exception support. We therefore have to |
| 829 # use setjmp/longjmp for e.g. JPEG decode error handling, which means we |
| 830 # have to turn off this warning (and be careful about how object |
| 831 # destruction happens in such cases). |
| 832 "/wd4611", |
| 833 |
| 834 # Warnings to evaluate and possibly fix/reenable later: |
| 835 |
| 836 "/wd4100", # Unreferenced formal function parameter. |
| 837 "/wd4121", # Alignment of a member was sensitive to packing. |
| 838 "/wd4244", # Conversion: possible loss of data. |
| 839 "/wd4505", # Unreferenced local function has been removed. |
| 840 "/wd4510", # Default constructor could not be generated. |
| 841 "/wd4512", # Assignment operator could not be generated. |
| 842 "/wd4610", # Class can never be instantiated, constructor required. |
| 843 "/wd4838", # Narrowing conversion. Doesn't seem to be very useful. |
| 844 "/wd4995", # 'X': name was marked as #pragma deprecated |
| 845 "/wd4996", # Deprecated function warning. |
| 846 |
| 847 # These are variable shadowing warnings that are new in VS2015. We |
| 848 # should work through these at some point -- they may be removed from |
| 849 # the RTM release in the /W4 set. |
| 850 "/wd4456", |
| 851 "/wd4457", |
| 852 "/wd4458", |
| 853 "/wd4459", |
| 854 ] |
| 855 |
| 856 if (visual_studio_version == "2015") { |
| 857 cflags += [ |
| 858 # C4312 is a VS 2015 64-bit warning for integer to larger pointer. |
| 859 # TODO(brucedawson): fix warnings, crbug.com/554200 |
| 860 "/wd4312", |
| 861 |
| 862 # TODO(brucedawson): http://crbug.com/593448 - C4595 is an 'illegal |
| 863 # inline operator new' warning that is new in VS 2015 Update 2. |
| 864 # This is equivalent to clang's no-inline-new-delete warning. |
| 865 # See http://bugs.icu-project.org/trac/ticket/11122 |
| 866 "/wd4595", |
| 867 ] |
| 868 |
| 869 if (current_cpu == "x86") { |
| 870 cflags += [ |
| 871 # VC++ 2015 changes 32-bit size_t truncation warnings from 4244 to |
| 872 # 4267. Example: short TruncTest(size_t x) { return x; } |
| 873 # Since we disable 4244 we need to disable 4267 during migration. |
| 874 # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. |
| 875 "/wd4267", |
| 876 ] |
| 877 } |
| 878 } |
| 879 |
| 880 # VS xtree header file needs to be patched or 4702 (unreachable code |
| 881 # warning) is reported if _HAS_EXCEPTIONS=0. Disable the warning if xtree is |
| 882 # not patched. |
| 883 if (!msvs_xtree_patched && |
| 884 exec_script("../../win_is_xtree_patched.py", [], "value") == 0) { |
| 885 cflags += [ "/wd4702" ] # Unreachable code. |
| 886 } |
| 887 |
| 888 # Building with Clang on Windows is a work in progress and very |
| 889 # experimental. See crbug.com/82385. |
| 890 # Keep this in sync with the similar block in build/common.gypi |
| 891 if (is_clang) { |
| 892 cflags += [ |
| 893 # TODO(hans): Make this list shorter eventually, http://crbug.com/504657 |
| 894 "-Wno-microsoft-enum-value", # http://crbug.com/505296 |
| 895 "-Wno-unknown-pragmas", # http://crbug.com/505314 |
| 896 "-Wno-microsoft-cast", # http://crbug.com/550065 |
| 897 ] |
| 898 } |
| 899 } else { |
| 900 if (is_mac && !is_nacl) { |
| 901 # When compiling Objective-C, warns if a method is used whose |
| 902 # availability is newer than the deployment target. This is not |
| 903 # required when compiling Chrome for iOS. |
| 904 cflags += [ "-Wpartial-availability" ] |
| 905 } |
| 906 |
| 907 # Suppress warnings about ABI changes on ARM (Clang doesn't give this |
| 908 # warning). |
| 909 if (current_cpu == "arm" && !is_clang) { |
| 910 cflags += [ "-Wno-psabi" ] |
| 911 } |
| 912 |
| 913 if (!is_clang) { |
| 914 cflags_cc += [ |
| 915 # See comment for -Wno-c++11-narrowing. |
| 916 "-Wno-narrowing", |
| 917 ] |
| 918 |
| 919 # Don't warn about the "typedef 'foo' locally defined but not used" |
| 920 # for gcc 4.8. |
| 921 # TODO: remove this flag once all builds work. See crbug.com/227506 |
| 922 cflags += [ "-Wno-unused-local-typedefs" ] |
| 923 |
| 924 # Don't warn about "maybe" uninitialized. Clang doesn't include this |
| 925 # in -Wall but gcc does, and it gives false positives. |
| 926 cflags += [ "-Wno-maybe-uninitialized" ] |
| 927 } |
| 928 } |
| 929 |
| 930 # Common Clang and GCC warning setup. |
| 931 if (!is_win || is_clang) { |
| 932 cflags += [ |
| 933 # Disables. |
| 934 "-Wno-missing-field-initializers", # "struct foo f = {0};" |
| 935 "-Wno-unused-parameter", # Unused function parameters. |
| 936 ] |
| 937 } |
| 938 |
| 939 if (is_chromeos) { |
| 940 # TODO(thakis): Remove, http://crbug.com/263960 |
| 941 if (is_clang) { |
| 942 cflags_cc += [ "-Wno-reserved-user-defined-literal" ] |
| 943 } else { |
| 944 cflags_cc += [ "-Wno-literal-suffix" ] |
| 945 } |
| 946 } |
| 947 |
| 948 if (is_clang) { |
| 949 cflags += [ |
| 950 # TODO(thakis): Consider -Wloop-analysis (turns on |
| 951 # -Wrange-loop-analysis too). |
| 952 |
| 953 # This warns on using ints as initializers for floats in |
| 954 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|), |
| 955 # which happens in several places in chrome code. Not sure if |
| 956 # this is worth fixing. |
| 957 "-Wno-c++11-narrowing", |
| 958 |
| 959 # Warns on switches on enums that cover all enum values but |
| 960 # also contain a default: branch. Chrome is full of that. |
| 961 "-Wno-covered-switch-default", |
| 962 |
| 963 # Clang considers the `register` keyword as deprecated, but e.g. |
| 964 # code generated by flex (used in angle) contains that keyword. |
| 965 # http://crbug.com/255186 |
| 966 "-Wno-deprecated-register", |
| 967 |
| 968 # TODO(thakis): This used to be implied by -Wno-unused-function, |
| 969 # which we no longer use. Check if it makes sense to remove |
| 970 # this as well. http://crbug.com/316352 |
| 971 "-Wno-unneeded-internal-declaration", |
| 972 |
| 973 # TODO(hans): Get this cleaned up, http://crbug.com/428099 |
| 974 "-Wno-inconsistent-missing-override", |
| 975 ] |
| 976 |
| 977 # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost |
| 978 # always have different versions. Certain flags may not be recognized by |
| 979 # one version or the other. |
| 980 if (!is_nacl) { |
| 981 # Flags NaCl (Clang 3.7) does not recognize. |
| 982 cflags += [ |
| 983 # TODO(thakis): Enable this, crbug.com/507717 |
| 984 "-Wno-shift-negative-value", |
| 985 |
| 986 # TODO(thakis): https://crbug.com/604888 |
| 987 "-Wno-undefined-var-template", |
| 988 ] |
| 989 } |
| 990 } |
| 991 } |
| 992 |
| 993 # chromium_code --------------------------------------------------------------- |
| 994 # |
| 995 # Toggles between higher and lower warnings for code that is (or isn't) |
| 996 # part of Chromium. |
| 997 |
| 998 config("chromium_code") { |
| 999 if (is_win) { |
| 1000 cflags = [ "/W4" ] # Warning level 4. |
| 1001 } else { |
| 1002 cflags = [ "-Wall" ] |
| 1003 if (treat_warnings_as_errors) { |
| 1004 cflags += [ "-Werror" ] |
| 1005 } |
| 1006 if (is_clang) { |
| 1007 # Enable -Wextra for chromium_code when we control the compiler. |
| 1008 cflags += [ "-Wextra" ] |
| 1009 } |
| 1010 |
| 1011 # In Chromium code, we define __STDC_foo_MACROS in order to get the |
| 1012 # C99 macros on Mac and Linux. |
| 1013 defines = [ |
| 1014 "__STDC_CONSTANT_MACROS", |
| 1015 "__STDC_FORMAT_MACROS", |
| 1016 ] |
| 1017 |
| 1018 if (!is_debug && !using_sanitizer && |
| 1019 (!is_linux || !is_clang || is_official_build)) { |
| 1020 # _FORTIFY_SOURCE isn't really supported by Clang now, see |
| 1021 # http://llvm.org/bugs/show_bug.cgi?id=16821. |
| 1022 # It seems to work fine with Ubuntu 12 headers though, so use it in |
| 1023 # official builds. |
| 1024 # |
| 1025 # Non-chromium code is not guaranteed to compile cleanly with |
| 1026 # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are |
| 1027 # disabled, so only do that for Release build. |
| 1028 defines += [ "_FORTIFY_SOURCE=2" ] |
| 1029 } |
| 1030 } |
| 1031 |
| 1032 configs = [ ":default_warnings" ] |
| 1033 } |
| 1034 |
| 1035 config("no_chromium_code") { |
| 1036 cflags = [] |
| 1037 cflags_cc = [] |
| 1038 defines = [] |
| 1039 |
| 1040 if (is_win) { |
| 1041 cflags += [ |
| 1042 "/W3", # Warning level 3. |
| 1043 "/wd4800", # Disable warning when forcing value to bool. |
| 1044 "/wd4267", # TODO(jschuh): size_t to int. |
| 1045 "/wd4996", # Deprecated function warning. |
| 1046 ] |
| 1047 defines += [ |
| 1048 "_CRT_NONSTDC_NO_WARNINGS", |
| 1049 "_CRT_NONSTDC_NO_DEPRECATE", |
| 1050 ] |
| 1051 } else { |
| 1052 # GCC may emit unsuppressible warnings so don't add -Werror for no chromium |
| 1053 # code. crbug.com/589724 |
| 1054 if (treat_warnings_as_errors && is_clang) { |
| 1055 cflags += [ "-Werror" ] |
| 1056 } |
| 1057 if (is_clang && !is_nacl) { |
| 1058 # TODO(thakis): Remove !is_nacl once |
| 1059 # https://codereview.webrtc.org/1552863002/ made its way into chromium. |
| 1060 cflags += [ "-Wall" ] |
| 1061 } |
| 1062 } |
| 1063 |
| 1064 if (is_clang) { |
| 1065 cflags += [ |
| 1066 # Lots of third-party libraries have unused variables. Instead of |
| 1067 # suppressing them individually, we just blanket suppress them here. |
| 1068 "-Wno-unused-variable", |
| 1069 ] |
| 1070 } |
| 1071 |
| 1072 if (is_linux || is_android) { |
| 1073 cflags_cc += [ |
| 1074 # Don't warn about hash_map in third-party code. |
| 1075 "-Wno-deprecated", |
| 1076 ] |
| 1077 } |
| 1078 |
| 1079 configs = [ ":default_warnings" ] |
| 1080 } |
| 1081 |
| 1082 # rtti ------------------------------------------------------------------------ |
| 1083 # |
| 1084 # Allows turning Run-Time Type Identification on or off. |
| 1085 |
| 1086 config("rtti") { |
| 1087 if (is_win) { |
| 1088 cflags_cc = [ "/GR" ] |
| 1089 } else { |
| 1090 cflags_cc = [ "-frtti" ] |
| 1091 } |
| 1092 } |
| 1093 config("no_rtti") { |
| 1094 # CFI diagnostics and UBsan vptr require RTTI. |
| 1095 if (!use_cfi_diag && !is_ubsan_vptr) { |
| 1096 if (is_win) { |
| 1097 cflags_cc = [ "/GR-" ] |
| 1098 } else { |
| 1099 cflags_cc = [ "-fno-rtti" ] |
| 1100 cflags_objcc = cflags_cc |
| 1101 } |
| 1102 } |
| 1103 } |
| 1104 |
| 1105 # Warnings --------------------------------------------------------------------- |
| 1106 |
| 1107 # This will generate warnings when using Clang if code generates exit-time |
| 1108 # destructors, which will slow down closing the program. |
| 1109 # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600 |
| 1110 config("wexit_time_destructors") { |
| 1111 # TODO: Enable on Windows too, http://crbug.com/404525 |
| 1112 if (is_clang && !is_win) { |
| 1113 cflags = [ "-Wexit-time-destructors" ] |
| 1114 } |
| 1115 } |
| 1116 |
| 1117 # On Windows compiling on x64, VC will issue a warning when converting |
| 1118 # size_t to int because it will truncate the value. Our code should not have |
| 1119 # these warnings and one should use a static_cast or a checked_cast for the |
| 1120 # conversion depending on the case. However, a lot of code still needs to be |
| 1121 # fixed. Apply this config to such targets to disable the warning. |
| 1122 # |
| 1123 # Note that this can be applied regardless of platform and architecture to |
| 1124 # clean up the call sites. This will only apply the flag when necessary. |
| 1125 # |
| 1126 # TODO(jschuh): crbug.com/167187 fix this and delete this config. |
| 1127 config("no_size_t_to_int_warning") { |
| 1128 if (is_win && current_cpu == "x64") { |
| 1129 cflags = [ "/wd4267" ] |
| 1130 } |
| 1131 } |
| 1132 |
| 1133 # Some code presumes that pointers to structures/objects are compatible |
| 1134 # regardless of whether what they point to is already known to be valid. |
| 1135 # gcc 4.9 and earlier had no way of suppressing this warning without |
| 1136 # supressing the rest of them. Here we centralize the identification of |
| 1137 # the gcc 4.9 toolchains. |
| 1138 config("no_incompatible_pointer_warnings") { |
| 1139 cflags = [] |
| 1140 if (is_clang) { |
| 1141 cflags += [ "-Wno-incompatible-pointer-types" ] |
| 1142 } else if (current_cpu == "mipsel") { |
| 1143 cflags += [ "-w" ] |
| 1144 } else if (is_chromeos && current_cpu == "arm") { |
| 1145 cflags += [ "-w" ] |
| 1146 } |
| 1147 } |
| 1148 |
| 1149 # Optimization ----------------------------------------------------------------- |
| 1150 # |
| 1151 # The BUILDCONFIG file sets the "default_optimization" config on targets by |
| 1152 # default. It will be equivalent to either "optimize" (release) or |
| 1153 # "no_optimize" (debug) optimization configs. |
| 1154 # |
| 1155 # You can override the optimization level on a per-target basis by removing the |
| 1156 # default config and then adding the named one you want: |
| 1157 # |
| 1158 # configs -= [ "//build/config/compiler:default_optimization" ] |
| 1159 # configs += [ "//build/config/compiler:optimize_max" ] |
| 1160 |
| 1161 # Shared settings for both "optimize" and "optimize_max" configs. |
| 1162 # IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags. |
| 1163 if (is_win) { |
| 1164 common_optimize_on_cflags = [ |
| 1165 "/Ob2", # Both explicit and auto inlining. |
| 1166 "/Oy-", # Disable omitting frame pointers, must be after /O2. |
| 1167 "/d2Zi+", # Improve debugging of optimized code. |
| 1168 "/Zc:inline", # Remove unreferenced COMDAT (faster links). |
| 1169 ] |
| 1170 if (!is_asan) { |
| 1171 common_optimize_on_cflags += [ |
| 1172 # Put data in separate COMDATs. This allows the linker |
| 1173 # to put bit-identical constants at the same address even if |
| 1174 # they're unrelated constants, which saves binary size. |
| 1175 # This optimization can't be used when ASan is enabled because |
| 1176 # it is not compatible with the ASan ODR checker. |
| 1177 "/Gw", |
| 1178 ] |
| 1179 } |
| 1180 common_optimize_on_ldflags = [ "/OPT:ICF" ] # Redundant COMDAT folding. |
| 1181 if (is_official_build) { |
| 1182 common_optimize_on_ldflags += [ |
| 1183 "/OPT:REF", # Remove unreferenced data. |
| 1184 "/LTCG", # Link-time code generation. |
| 1185 |
| 1186 # Set the number of LTCG code-gen threads to eight. The default is four. |
| 1187 # This gives a 5-10% link speedup. |
| 1188 "/cgthreads:8", |
| 1189 ] |
| 1190 } |
| 1191 } else { |
| 1192 common_optimize_on_cflags = [ |
| 1193 # Don't emit the GCC version ident directives, they just end up in the |
| 1194 # .comment section taking up binary size. |
| 1195 "-fno-ident", |
| 1196 |
| 1197 # Put data and code in their own sections, so that unused symbols |
| 1198 # can be removed at link time with --gc-sections. |
| 1199 "-fdata-sections", |
| 1200 "-ffunction-sections", |
| 1201 ] |
| 1202 common_optimize_on_ldflags = [] |
| 1203 |
| 1204 if (is_android) { |
| 1205 # We don't omit frame pointers on arm64 since they are required |
| 1206 # to correctly unwind stackframes which contain system library |
| 1207 # function frames (crbug.com/391706). |
| 1208 if (!using_sanitizer && !enable_profiling && target_cpu != "arm64") { |
| 1209 common_optimize_on_cflags += [ "-fomit-frame-pointer" ] |
| 1210 } |
| 1211 |
| 1212 # TODO(jdduke) Re-enable on mips after resolving linking |
| 1213 # issues with libc++ (crbug.com/456380). |
| 1214 if (current_cpu != "mipsel" && current_cpu != "mips64el") { |
| 1215 common_optimize_on_ldflags += [ |
| 1216 # Warn in case of text relocations. |
| 1217 "-Wl,--warn-shared-textrel", |
| 1218 ] |
| 1219 } |
| 1220 } |
| 1221 |
| 1222 if (is_mac || is_ios) { |
| 1223 if (symbol_level == 2) { |
| 1224 # Mac dead code stripping requires symbols. |
| 1225 common_optimize_on_ldflags += [ "-Wl,-dead_strip" ] |
| 1226 } |
| 1227 } else { |
| 1228 # Non-Mac Posix linker flags. |
| 1229 common_optimize_on_ldflags += [ |
| 1230 # Specifically tell the linker to perform optimizations. |
| 1231 # See http://lwn.net/Articles/192624/ . |
| 1232 "-Wl,-O1", |
| 1233 "-Wl,--gc-sections", |
| 1234 ] |
| 1235 |
| 1236 if (!using_sanitizer) { |
| 1237 # Functions interposed by the sanitizers can make ld think |
| 1238 # that some libraries aren't needed when they actually are, |
| 1239 # http://crbug.com/234010. As workaround, disable --as-needed. |
| 1240 common_optimize_on_ldflags += [ "-Wl,--as-needed" ] |
| 1241 } |
| 1242 } |
| 1243 } |
| 1244 |
| 1245 # Default "optimization on" config. |
| 1246 config("optimize") { |
| 1247 if (is_win) { |
| 1248 if (is_official_build && full_wpo_on_official) { |
| 1249 common_optimize_on_cflags += [ "/GL" ] |
| 1250 } |
| 1251 |
| 1252 # Favor size over speed, /O1 must be before the common flags. The GYP |
| 1253 # build also specifies /Os and /GF but these are implied by /O1. |
| 1254 cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ] |
| 1255 } else if (optimize_for_size) { |
| 1256 # Favor size over speed. |
| 1257 cflags = [ "-Os" ] + common_optimize_on_cflags |
| 1258 } else { |
| 1259 cflags = [ "-O2" ] + common_optimize_on_cflags |
| 1260 } |
| 1261 ldflags = common_optimize_on_ldflags |
| 1262 } |
| 1263 |
| 1264 # Same config as 'optimize' but without the WPO flag. |
| 1265 config("optimize_no_wpo") { |
| 1266 if (is_win) { |
| 1267 # Favor size over speed, /O1 must be before the common flags. The GYP |
| 1268 # build also specifies /Os and /GF but these are implied by /O1. |
| 1269 cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ] |
| 1270 } else if (optimize_for_size) { |
| 1271 # Favor size over speed. |
| 1272 cflags = [ "-Os" ] + common_optimize_on_cflags |
| 1273 } else { |
| 1274 cflags = [ "-O2" ] + common_optimize_on_cflags |
| 1275 } |
| 1276 ldflags = common_optimize_on_ldflags |
| 1277 } |
| 1278 |
| 1279 # Turn off optimizations. |
| 1280 config("no_optimize") { |
| 1281 if (is_win) { |
| 1282 cflags = [ |
| 1283 "/Od", # Disable optimization. |
| 1284 "/Ob0", # Disable all inlining (on by default). |
| 1285 ] |
| 1286 } else if (is_android && !android_full_debug) { |
| 1287 # On Android we kind of optimize some things that don't affect debugging |
| 1288 # much even when optimization is disabled to get the binary size down. |
| 1289 cflags = [ |
| 1290 "-Os", |
| 1291 "-fdata-sections", |
| 1292 "-ffunction-sections", |
| 1293 ] |
| 1294 |
| 1295 # We don't omit frame pointers on arm64 since they are required |
| 1296 # to correctly unwind stackframes which contain system library |
| 1297 # function frames (crbug.com/391706). |
| 1298 if (!using_sanitizer && !enable_profiling && target_cpu != "arm64") { |
| 1299 cflags += [ "-fomit-frame-pointer" ] |
| 1300 } |
| 1301 |
| 1302 # Don't use gc-sections since it can cause links to succeed when they |
| 1303 # actually shouldn't. http://crbug.com/159847 |
| 1304 ldflags = common_optimize_on_ldflags - [ "-Wl,--gc-sections" ] |
| 1305 } else { |
| 1306 cflags = [ "-O0" ] |
| 1307 ldflags = [] |
| 1308 } |
| 1309 } |
| 1310 |
| 1311 # Turns up the optimization level. On Windows, this implies whole program |
| 1312 # optimization and link-time code generation which is very expensive and should |
| 1313 # be used sparingly. |
| 1314 config("optimize_max") { |
| 1315 if (is_nacl_irt) { |
| 1316 # The NaCl IRT is a special case and always wants its own config. |
| 1317 # Various components do: |
| 1318 # if (!is_debug) { |
| 1319 # configs -= [ "//build/config/compiler:default_optimization" ] |
| 1320 # configs += [ "//build/config/compiler:optimize_max" ] |
| 1321 # } |
| 1322 # So this config has to have the selection logic just like |
| 1323 # "default_optimization", below. |
| 1324 configs = [ "//build/config/nacl:irt_optimize" ] |
| 1325 } else { |
| 1326 ldflags = common_optimize_on_ldflags |
| 1327 if (is_win) { |
| 1328 # Favor speed over size, /O2 must be before the common flags. The GYP |
| 1329 # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2. |
| 1330 cflags = [ "/O2" ] + common_optimize_on_cflags |
| 1331 |
| 1332 # TODO(thakis): Remove is_clang here, https://crbug.com/598772 |
| 1333 if (is_official_build && !is_clang) { |
| 1334 cflags += [ |
| 1335 "/GL", # Whole program optimization. |
| 1336 |
| 1337 # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds. |
| 1338 # Probably anything that this would catch that wouldn't be caught in a |
| 1339 # normal build isn't going to actually be a bug, so the incremental |
| 1340 # value of C4702 for PGO builds is likely very small. |
| 1341 "/wd4702", |
| 1342 ] |
| 1343 } |
| 1344 } else { |
| 1345 cflags = [ "-O2" ] + common_optimize_on_cflags |
| 1346 } |
| 1347 } |
| 1348 } |
| 1349 |
| 1350 # The default optimization applied to all targets. This will be equivalent to |
| 1351 # either "optimize" or "no_optimize", depending on the build flags. |
| 1352 config("default_optimization") { |
| 1353 if (is_nacl_irt) { |
| 1354 # The NaCl IRT is a special case and always wants its own config. |
| 1355 # It gets optimized the same way regardless of the type of build. |
| 1356 configs = [ "//build/config/nacl:irt_optimize" ] |
| 1357 } else if (is_debug) { |
| 1358 configs = [ ":no_optimize" ] |
| 1359 } else { |
| 1360 configs = [ ":optimize" ] |
| 1361 } |
| 1362 } |
| 1363 |
| 1364 # Symbols ---------------------------------------------------------------------- |
| 1365 |
| 1366 # The BUILDCONFIG file sets the "default_symbols" config on targets by |
| 1367 # default. It will be equivalent to one the three specific symbol levels. |
| 1368 # |
| 1369 # You can override the symbol level on a per-target basis by removing the |
| 1370 # default config and then adding the named one you want: |
| 1371 # |
| 1372 # configs -= [ "//build/config/compiler:default_symbols" ] |
| 1373 # configs += [ "//build/config/compiler:symbols" ] |
| 1374 |
| 1375 # Full symbols. |
| 1376 config("symbols") { |
| 1377 if (is_win) { |
| 1378 import("//build/toolchain/goma.gni") |
| 1379 if (use_goma) { |
| 1380 cflags = [ "/Z7" ] # No PDB file |
| 1381 } else { |
| 1382 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue. |
| 1383 } |
| 1384 if (is_win_fastlink && visual_studio_version != "2013") { |
| 1385 # Tell VS 2015+ to create a PDB that references debug |
| 1386 # information in .obj and .lib files instead of copying |
| 1387 # it all. This flag is incompatible with /PROFILE |
| 1388 ldflags = [ "/DEBUG:FASTLINK" ] |
| 1389 } else { |
| 1390 ldflags = [ "/DEBUG" ] |
| 1391 } |
| 1392 } else { |
| 1393 if (is_ios) { |
| 1394 cflags = [ "-gdwarf-2" ] |
| 1395 } else { |
| 1396 cflags = [ "-g2" ] |
| 1397 } |
| 1398 if (use_debug_fission) { |
| 1399 cflags += [ "-gsplit-dwarf" ] |
| 1400 } |
| 1401 asmflags = cflags |
| 1402 ldflags = [] |
| 1403 } |
| 1404 } |
| 1405 |
| 1406 # Minimal symbols. |
| 1407 config("minimal_symbols") { |
| 1408 if (is_win) { |
| 1409 # Linker symbols for backtraces only. |
| 1410 cflags = [] |
| 1411 if (is_win_fastlink && visual_studio_version != "2013") { |
| 1412 # Tell VS 2015+ to create a PDB that references debug |
| 1413 # information in .obj and .lib files instead of copying |
| 1414 # it all. This flag is incompatible with /PROFILE |
| 1415 ldflags = [ "/DEBUG:FASTLINK" ] |
| 1416 } else { |
| 1417 ldflags = [ "/DEBUG" ] |
| 1418 } |
| 1419 } else { |
| 1420 cflags = [ "-g1" ] |
| 1421 if (use_debug_fission) { |
| 1422 cflags += [ "-gsplit-dwarf" ] |
| 1423 } |
| 1424 asmflags = cflags |
| 1425 ldflags = [] |
| 1426 } |
| 1427 } |
| 1428 |
| 1429 # No symbols. |
| 1430 config("no_symbols") { |
| 1431 if (!is_win) { |
| 1432 cflags = [ "-g0" ] |
| 1433 asmflags = cflags |
| 1434 } |
| 1435 } |
| 1436 |
| 1437 # Default symbols. |
| 1438 config("default_symbols") { |
| 1439 if (symbol_level == 0) { |
| 1440 configs = [ ":no_symbols" ] |
| 1441 } else if (symbol_level == 1) { |
| 1442 configs = [ ":minimal_symbols" ] |
| 1443 } else if (symbol_level == 2) { |
| 1444 configs = [ ":symbols" ] |
| 1445 } else { |
| 1446 assert(false) |
| 1447 } |
| 1448 } |
| 1449 |
| 1450 if (is_ios || is_mac) { |
| 1451 # On Mac and iOS, this enables support for ARC (automatic ref-counting). |
| 1452 # See http://clang.llvm.org/docs/AutomaticReferenceCounting.html. |
| 1453 config("enable_arc") { |
| 1454 common_flags = [ "-fobjc-arc" ] |
| 1455 cflags_objc = common_flags |
| 1456 cflags_objcc = common_flags |
| 1457 } |
| 1458 } |
OLD | NEW |