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