1# Copyright 2015 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("//build/config/c++/c++.gni") 6import("//build/config/chrome_build.gni") 7import("//build/config/chromecast_build.gni") 8import("//build/config/chromeos/args.gni") 9import("//build/config/chromeos/ui_mode.gni") 10import("//build/config/compiler/pgo/pgo.gni") 11import("//build/config/cronet/config.gni") 12import("//build/config/sanitizers/sanitizers.gni") 13import("//build/toolchain/cc_wrapper.gni") 14import("//build/toolchain/goma.gni") 15import("//build/toolchain/toolchain.gni") 16import("//build_overrides/build.gni") 17 18if (is_android) { 19 import("//build/config/android/abi.gni") 20} 21if (current_cpu == "arm" || current_cpu == "arm64") { 22 import("//build/config/arm.gni") 23} 24 25if (is_apple) { 26 import("//build/config/apple/symbols.gni") 27} 28 29if (is_ios) { 30 import("//build/config/ios/config.gni") 31} 32 33declare_args() { 34 # Set to true to use lld, the LLVM linker. 35 # In late bring-up on macOS (see docs/mac_lld.md). 36 # Tentatively used on iOS. 37 # The default linker everywhere else. 38 use_lld = is_clang && current_os != "zos" 39 40 # If true, optimize for size. 41 # Default to favoring speed over size for platforms not listed below. 42 optimize_for_size = 43 !is_high_end_android && (is_android || is_ios || is_castos) 44} 45 46declare_args() { 47 # Default to warnings as errors for default workflow, where we catch 48 # warnings with known toolchains. Allow overriding this e.g. for Chromium 49 # builds on Linux that could use a different version of the compiler. 50 # With GCC, warnings in no-Chromium code are always not treated as errors. 51 treat_warnings_as_errors = true 52 53 # How many symbols to include in the build. This affects the performance of 54 # the build since the symbols are large and dealing with them is slow. 55 # 2 means regular build with symbols. 56 # 1 means minimal symbols, usually enough for backtraces only. Symbols with 57 # internal linkage (static functions or those in anonymous namespaces) may not 58 # appear when using this level. 59 # 0 means no symbols. 60 # -1 means auto-set according to debug/release and platform. 61 symbol_level = -1 62 63 # Android-only: Strip the debug info of libraries within lib.unstripped to 64 # reduce size. As long as symbol_level > 0, this will still allow stacks to be 65 # symbolized. 66 strip_debug_info = false 67 68 # Compile in such a way as to enable profiling of the generated code. For 69 # example, don't omit the frame pointer and leave in symbols. 70 enable_profiling = false 71 72 # use_debug_fission: whether to use split DWARF debug info 73 # files. This can reduce link time significantly, but is incompatible 74 # with some utilities such as icecc and ccache. Requires gold and 75 # gcc >= 4.8 or clang. 76 # http://gcc.gnu.org/wiki/DebugFission 77 # 78 # This is a placeholder value indicating that the code below should set 79 # the default. This is necessary to delay the evaluation of the default 80 # value expression until after its input values such as use_gold have 81 # been set, e.g. by a toolchain_args() block. 82 use_debug_fission = "default" 83 84 # Enables support for ThinLTO, which links 3x-10x faster than full LTO. See 85 # also http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html 86 # Use it by default on official-optimized android and Chrome OS builds, but 87 # not ARC or linux-chromeos since it's been seen to not play nicely with 88 # Chrome's clang. crbug.com/1033839 89 # Disabled in iOS cronet builds since build step cronet_static_complete 90 # wants to build a .a file consumable by external clients, and they won't 91 # have the same LLVM revisions as us, making bitcode useless to them. 92 use_thin_lto = 93 is_cfi || (is_clang && is_official_build && chrome_pgo_phase != 1 && 94 (is_linux || is_win || is_mac || 95 (is_ios && use_lld && !is_cronet_build) || 96 (is_android && target_os != "chromeos") || 97 (is_chromeos && is_chromeos_device))) 98 99 # If true, use Goma for ThinLTO code generation where applicable. 100 use_goma_thin_lto = false 101 102 # Whether we're using a sample profile collected on an architecture different 103 # than the one we're compiling for. 104 # 105 # It's currently not possible to collect AFDO profiles on anything but 106 # x86{,_64}. 107 using_mismatched_sample_profile = current_cpu != "x64" && current_cpu != "x86" 108 109 # Whether an error should be raised on attempts to make debug builds with 110 # is_component_build=false. Very large debug symbols can have unwanted side 111 # effects so this is enforced by default for chromium. 112 forbid_non_component_debug_builds = build_with_chromium 113 114 # Exclude unwind tables by default for official builds as unwinding can be 115 # done from stack dumps produced by Crashpad at a later time "offline" in the 116 # crash server. Since this increases binary size, we don't recommend including 117 # them in shipping builds. 118 # For unofficial (e.g. development) builds and non-Chrome branded (e.g. Cronet 119 # which doesn't use Crashpad, crbug.com/479283) builds it's useful to be able 120 # to unwind at runtime. 121 # Include the unwind tables on Android even for official builds, as otherwise 122 # the crash dumps generated by Android's debuggerd are largely useless, and 123 # having this additional mechanism to understand issues is particularly helpful 124 # to WebView. 125 exclude_unwind_tables = is_official_build && !is_android 126 127 # Where to redirect clang crash diagnoses 128 clang_diagnostic_dir = 129 rebase_path("//tools/clang/crashreports", root_build_dir) 130 131 # Mark binaries as compatible with Shadow Stack of Control-flow Enforcement 132 # Technology (CET). If Windows version and hardware supports the feature and 133 # it's enabled by OS then additional validation of return address will be 134 # performed as mitigation against Return-oriented programming (ROP). 135 # https://chromium.googlesource.com/chromium/src/+/main/docs/design/sandbox.md#cet-shadow-stack 136 enable_cet_shadow_stack = target_cpu == "x64" 137 138 # Set to true to enable using the ML inliner in LLVM. This currently only 139 # enables the ML inliner when targeting Android. 140 # Currently the ML inliner is only supported on linux hosts 141 use_ml_inliner = host_os == "linux" && is_android 142 143 # Set to true to use the android unwinder V2 implementation. 144 use_android_unwinder_v2 = true 145 146 # Whether we should consider the profile we're using to be accurate. Accurate 147 # profiles have the benefit of (potentially substantial) binary size 148 # reductions, by instructing the compiler to optimize cold and uncovered 149 # functions heavily for size. This often comes at the cost of performance. 150 sample_profile_is_accurate = optimize_for_size 151 152 # Use offsets rather than pointers in vtables in order to reduce the number of 153 # relocations. This is safe to enable only when all C++ code is built with the 154 # flag set to the same value. 155 use_relative_vtables_abi = is_android && current_cpu == "arm64" && 156 use_custom_libcxx && !is_component_build 157} 158 159# To try out this combination, delete this assert. 160assert( 161 !use_relative_vtables_abi || !is_cfi, 162 "is_cfi=true is known to conflict with use_relative_vtables_abi=true.\n" + 163 "See https://bugs.chromium.org/p/chromium/issues/detail?id=1375035#c53") 164 165assert(!is_cfi || use_thin_lto, "CFI requires ThinLTO") 166assert(!enable_profiling || !is_component_build, 167 "Cannot profile component builds (crbug.com/1199271).") 168 169if (use_thin_lto && is_debug) { 170 print("WARNING: ThinLTO (use_thin_lto=true) doesn't work with debug" + 171 " (is_debug=true) build.") 172} 173 174# Determine whether to enable or disable frame pointers, based on the platform 175# and build arguments. 176if (is_chromeos) { 177 # ChromeOS generally prefers frame pointers, to support CWP. 178 # However, Clang does not currently generate usable frame pointers in ARM 179 # 32-bit builds (https://bugs.llvm.org/show_bug.cgi?id=18505) so disable them 180 # there to avoid the unnecessary overhead. 181 enable_frame_pointers = current_cpu != "arm" 182} else if (is_apple || is_linux) { 183 enable_frame_pointers = true 184} else if (is_win) { 185 # 64-bit Windows ABI doesn't support frame pointers. 186 # NOTE: This setting is actually not used in the BUILD.gn for Windows, 187 # but it still reflects correctly that we don't emit frame pointers on x64. 188 if (current_cpu == "x64") { 189 enable_frame_pointers = false 190 } else { 191 enable_frame_pointers = true 192 } 193} else if (is_android) { 194 enable_frame_pointers = 195 enable_profiling || 196 # Ensure that stacks from arm64 crash dumps are usable (crbug.com/391706). 197 current_cpu == "arm64" || 198 # For x86 Android, unwind tables are huge without frame pointers 199 # (crbug.com/762629). Enabling frame pointers grows the code size slightly 200 # but overall shrinks binaries considerably by avoiding huge unwind 201 # tables. 202 (current_cpu == "x86" && !exclude_unwind_tables && optimize_for_size) || 203 using_sanitizer || 204 # For caller-callee instrumentation version which needs frame pointers to 205 # get the caller address. 206 use_call_graph 207} else if (is_fuchsia) { 208 # Fuchsia on arm64 could use shadow call stack for unwinding. 209 enable_frame_pointers = current_cpu != "arm64" 210} else { 211 # Explicitly ask for frame pointers, otherwise stacks may be missing for 212 # sanitizer and profiling builds. 213 enable_frame_pointers = using_sanitizer || enable_profiling || is_debug 214} 215 216# In general assume that if we have frame pointers then we can use them to 217# unwind the stack. However, this requires that they are enabled by default for 218# most translation units, that they are emitted correctly, and that the 219# compiler or platform provides a way to access them. 220can_unwind_with_frame_pointers = enable_frame_pointers 221if (current_cpu == "arm" && arm_use_thumb) { 222 # We cannot currently unwind ARM Thumb frame pointers correctly. 223 # See https://bugs.llvm.org/show_bug.cgi?id=18505 224 can_unwind_with_frame_pointers = false 225} else if (is_win) { 226 # Windows 32-bit does provide frame pointers, but the compiler does not 227 # provide intrinsics to access them, so we don't use them. 228 can_unwind_with_frame_pointers = false 229} 230 231assert(!can_unwind_with_frame_pointers || enable_frame_pointers) 232 233# Unwinding with CFI table is only possible on static library builds and 234# requried only when frame pointers are not enabled. 235can_unwind_with_cfi_table = is_android && !is_component_build && 236 !enable_frame_pointers && current_cpu == "arm" 237 238# Whether or not cfi table should be enabled on arm. 239# TODO(crbug.com/1090409): Replace can_unwind_with_cfi_table with this once 240# sampling profiler is enabled on android. 241enable_arm_cfi_table = is_android && !is_component_build && current_cpu == "arm" 242 243declare_args() { 244 # Whether to use the gold linker from binutils instead of lld or bfd. 245 use_gold = !use_lld && !(is_castos && 246 (current_cpu == "arm" || current_cpu == "mipsel")) && 247 (((is_linux || is_chromeos_lacros) && 248 (current_cpu == "x64" || current_cpu == "x86" || 249 current_cpu == "arm" || current_cpu == "arm64" || 250 current_cpu == "mipsel" || current_cpu == "mips64el")) || 251 (is_android && (current_cpu == "x86" || current_cpu == "x64" || 252 current_cpu == "arm" || current_cpu == "arm64"))) 253} 254 255# Use relative paths for debug info. This is important to make the build 256# results independent of the checkout and build directory names, which 257# in turn is important for goma compile hit rate. 258# Setting this to true may make it harder to debug binaries on Linux, see 259# https://chromium.googlesource.com/chromium/src/+/main/docs/linux/debugging.md#Source-level-debug-with-fdebug_compilation_dir 260# It's not clear if the crash server will correctly handle dSYMs with relative 261# paths, so we disable this feature for official benefit. The main benefit is 262# deterministic builds to reduce compile times, so this is less relevant for 263# official builders. 264strip_absolute_paths_from_debug_symbols_default = 265 is_android || is_fuchsia || is_nacl || (is_win && use_lld) || is_linux || 266 is_chromeos || (is_apple && !enable_dsyms) 267 268# If the platform uses stripped absolute paths by default, then we don't expose 269# it as a configuration option. If this is causing problems, please file a bug. 270if (strip_absolute_paths_from_debug_symbols_default) { 271 strip_absolute_paths_from_debug_symbols = true 272} else { 273 declare_args() { 274 strip_absolute_paths_from_debug_symbols = false 275 } 276} 277 278# If it wasn't manually set, then default use_debug_fission to false. 279assert( 280 use_debug_fission == "default" || use_debug_fission || !use_debug_fission, 281 "Invalid use_debug_fission.") 282if (use_debug_fission == "default") { 283 use_debug_fission = is_debug && !is_android && !is_fuchsia && !is_apple && 284 !is_win && (use_gold || use_lld) && cc_wrapper == "" 285} 286 287# If it wasn't manually set, set to an appropriate default. 288assert(symbol_level >= -1 && symbol_level <= 2, "Invalid symbol_level") 289if (symbol_level == -1) { 290 if (is_android && !is_component_build && !use_debug_fission) { 291 # Prefer faster & smaller release builds. 292 symbol_level = 1 293 } else if (is_chromeos_device) { 294 # Use lower symbol level in Simple Chrome build for faster link time. 295 # For Simple Chrome, this should take precedence over is_official_build, 296 # turned on by --internal. 297 if ((target_cpu == "x64" || target_cpu == "x86") && !is_debug) { 298 # For release x86/x64 build, specify symbol_level=0 for faster link time. 299 # x86/x64 shows backtraces with symbol_level=0 (arm requires 300 # symbol_level=1). 301 symbol_level = 0 302 } else { 303 symbol_level = 1 304 } 305 } else if (using_sanitizer) { 306 # Sanitizers need line table info for stack traces. They don't need type 307 # info or variable info, so we can leave that out to speed up the build. 308 # Sanitizers also require symbols for filename suppressions to work. 309 symbol_level = 1 310 } else if ((!is_nacl && !is_linux && !is_chromeos && !is_fuchsia && 311 current_os != "aix") || is_debug || is_official_build || 312 is_castos || is_cast_android) { 313 # Linux builds slower by having symbols as part of the target binary, 314 # whereas Mac and Windows have them separate, so in Release Linux, default 315 # them off, but keep them on for Official builds and Chromecast builds. 316 symbol_level = 2 317 } else { 318 symbol_level = 0 319 } 320} 321 322# Split dwarf works only for symbol_level == 2. 323use_debug_fission = use_debug_fission && symbol_level == 2 324 325# Non-component debug builds with symbol_level = 2 are an undesirable (very slow 326# build times) and unsupported (some test binaries will fail with > 4 GB PDBs) 327# combination. This is only checked when current_toolchain == default_toolchain 328# because the is_component_build flag is set to false in various components of 329# the build (like nacl) and we don't want to assert on those. 330# iOS does not support component builds so add an exception for this platform. 331if (forbid_non_component_debug_builds) { 332 assert( 333 symbol_level != 2 || current_toolchain != default_toolchain || 334 is_component_build || !is_debug || is_ios || use_debug_fission, 335 "Can't do non-component debug builds at symbol_level=2 without use_debug_fission=true") 336} 337 338# TODO(crbug.com/1341436) For Windows, to assemble lzma_sdk's assembly files, 339# ml64.exe needs to be utilized as llvm-ml cannot yet assemble it. Once llvm-ml 340# is able to assemble lzma_sdk assembly files, remove this. 341# LzmaDecOpt.asm only works on x64 and not x86. 342# https://sourceforge.net/p/sevenzip/discussion/45797/thread/768932e9dd/?limit=25#0d6c 343disable_llvm_ml = host_os == "win" && target_cpu == "x64" && !is_msan 344