1# Copyright 2015 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 5import("//build/config/chrome_build.gni") 6import("//build/config/chromecast_build.gni") 7import("//build/config/chromeos/args.gni") 8import("//build/config/compiler/pgo/pgo.gni") 9import("//build/config/sanitizers/sanitizers.gni") 10import("//build/toolchain/goma.gni") 11import("//build/toolchain/toolchain.gni") 12import("//build_overrides/build.gni") 13 14if (is_android) { 15 import("//build/config/android/abi.gni") 16} 17if (current_cpu == "arm" || current_cpu == "arm64") { 18 import("//build/config/arm.gni") 19} 20 21if (is_mac) { 22 import("//build/config/mac/symbols.gni") 23} 24 25declare_args() { 26 # How many symbols to include in the build. This affects the performance of 27 # the build since the symbols are large and dealing with them is slow. 28 # 2 means regular build with symbols. 29 # 1 means minimal symbols, usually enough for backtraces only. Symbols with 30 # internal linkage (static functions or those in anonymous namespaces) may not 31 # appear when using this level. 32 # 0 means no symbols. 33 # -1 means auto-set according to debug/release and platform. 34 symbol_level = -1 35 36 # Android-only: Strip the debug info of libraries within lib.unstripped to 37 # reduce size. As long as symbol_level > 0, this will still allow stacks to be 38 # symbolized. 39 strip_debug_info = false 40 41 # Compile in such a way as to enable profiling of the generated code. For 42 # example, don't omit the frame pointer and leave in symbols. 43 enable_profiling = false 44 45 # Whether to use the binary binutils checked into third_party/binutils. 46 # These are not multi-arch so cannot be used except on x86 and x86-64 (the 47 # only two architectures that are currently checked in). Turn this off when 48 # you are using a custom toolchain and need to control -B in cflags. 49 linux_use_bundled_binutils = 50 linux_use_bundled_binutils_override && (is_linux && !is_bsd) && 51 (current_cpu == "x64" || current_cpu == "x86") 52 binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", 53 root_build_dir) 54 55 # use_debug_fission: whether to use split DWARF debug info 56 # files. This can reduce link time significantly, but is incompatible 57 # with some utilities such as icecc and ccache. Requires gold and 58 # gcc >= 4.8 or clang. 59 # http://gcc.gnu.org/wiki/DebugFission 60 # 61 # This is a placeholder value indicating that the code below should set 62 # the default. This is necessary to delay the evaluation of the default 63 # value expression until after its input values such as use_gold have 64 # been set, e.g. by a toolchain_args() block. 65 use_debug_fission = "default" 66 67 # Enables support for ThinLTO, which links 3x-10x faster than full LTO. See 68 # also http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html 69 # Use it by default on official-optimized android and Chrome OS builds, but 70 # not ARC or linux-chromeos since it's been seen to not play nicely with 71 # Chrome's clang. crbug.com/1033839 72 use_thin_lto = 73 is_cfi || (is_official_build && (target_os == "android" || 74 (target_os == "chromeos" && 75 is_chromeos_device && !is_android))) 76 77 # Performs ThinLTO code generation on Goma. 78 use_goma_thin_lto = false 79 80 # Limit the number of jobs (threads/processes) the linker is allowed 81 # to use (for linkers that support this). 82 max_jobs_per_link = 8 83 84 # Whether we're using a sample profile collected on an architecture different 85 # than the one we're compiling for. 86 # 87 # It's currently not possible to collect AFDO profiles on anything but 88 # x86{,_64}. 89 using_mismatched_sample_profile = current_cpu != "x64" && current_cpu != "x86" 90 91 # Whether an error should be raised on attempts to make debug builds with 92 # is_component_build=false. Very large debug symbols can have unwanted side 93 # effects so this is enforced by default for chromium. 94 forbid_non_component_debug_builds = build_with_chromium 95 96 # Exclude unwind tables by default for official builds as unwinding can be 97 # done from stack dumps produced by Crashpad at a later time "offline" in the 98 # crash server. Since this increases binary size, we don't recommend including 99 # them in shipping builds. 100 # For unofficial (e.g. development) builds and non-Chrome branded (e.g. Cronet 101 # which doesn't use Crashpad, crbug.com/479283) builds it's useful to be able 102 # to unwind at runtime. 103 exclude_unwind_tables = is_official_build 104} 105 106assert(!is_cfi || use_thin_lto, "CFI requires ThinLTO") 107assert( 108 !use_goma_thin_lto || (use_goma && use_thin_lto), 109 "use_goma_thin_lto requires both use_goma and use_thin_lto to be enabled") 110 111declare_args() { 112 113 # If true, optimize for size. Does not affect windows builds. 114 # Linux & Mac favor speed over size. 115 # TODO(brettw) it's weird that Mac and desktop Linux are different. We should 116 # explore favoring size over speed in this case as well. 117 optimize_for_size = is_android || is_chromecast || is_fuchsia || is_ios 118} 119 120declare_args() { 121 # Whether we should consider the profile we're using to be accurate. Accurate 122 # profiles have the benefit of (potentially substantial) binary size 123 # reductions, by instructing the compiler to optimize cold and uncovered 124 # functions heavily for size. This often comes at the cost of performance. 125 sample_profile_is_accurate = optimize_for_size 126} 127 128# Determine whether to enable or disable frame pointers, based on the platform 129# and build arguments. 130if (is_mac || is_ios || is_linux) { 131 enable_frame_pointers = true 132} else if (is_win) { 133 # 64-bit Windows ABI doesn't support frame pointers. 134 if (current_cpu == "x64") { 135 enable_frame_pointers = false 136 } else { 137 enable_frame_pointers = true 138 } 139} else if (is_chromeos) { 140 # ChromeOS generally prefers frame pointers, to support CWP. 141 # However, Clang does not currently generate usable frame pointers in ARM 142 # 32-bit builds (https://bugs.llvm.org/show_bug.cgi?id=18505) so disable them 143 # there to avoid the unnecessary overhead. 144 enable_frame_pointers = current_cpu != "arm" 145} else if (is_android) { 146 enable_frame_pointers = 147 enable_profiling || 148 # Ensure that stacks from arm64 crash dumps are usable (crbug.com/391706). 149 current_cpu == "arm64" || 150 # For x86 Android, unwind tables are huge without frame pointers 151 # (crbug.com/762629). Enabling frame pointers grows the code size slightly 152 # but overall shrinks binaries considerably by avoiding huge unwind 153 # tables. 154 (current_cpu == "x86" && !exclude_unwind_tables && optimize_for_size) || 155 using_sanitizer || 156 # For caller-callee instrumentation version which needs frame pointers to 157 # get the caller address. 158 use_call_graph 159} else { 160 # Explicitly ask for frame pointers, otherwise: 161 # * Stacks may be missing for sanitizer and profiling builds. 162 # * Debug tcmalloc can crash (crbug.com/636489). 163 enable_frame_pointers = using_sanitizer || enable_profiling || is_debug 164} 165 166# In general assume that if we have frame pointers then we can use them to 167# unwind the stack. However, this requires that they are enabled by default for 168# most translation units, that they are emitted correctly, and that the 169# compiler or platform provides a way to access them. 170can_unwind_with_frame_pointers = enable_frame_pointers 171if (current_cpu == "arm" && arm_use_thumb) { 172 # We cannot currently unwind ARM Thumb frame pointers correctly. 173 # See https://bugs.llvm.org/show_bug.cgi?id=18505 174 can_unwind_with_frame_pointers = false 175} else if (is_win) { 176 # Windows 32-bit does provide frame pointers, but the compiler does not 177 # provide intrinsics to access them, so we don't use them. 178 can_unwind_with_frame_pointers = false 179} 180 181assert(!can_unwind_with_frame_pointers || enable_frame_pointers) 182 183# Unwinding with CFI table is only possible on static library builds and 184# requried only when frame pointers are not enabled. 185can_unwind_with_cfi_table = is_android && !is_component_build && 186 !enable_frame_pointers && current_cpu == "arm" 187 188declare_args() { 189 # Set to true to use lld, the LLVM linker. 190 use_lld = is_clang && (!is_ios && !is_mac) 191} 192 193declare_args() { 194 # Whether to use the gold linker from binutils instead of lld or bfd. 195 use_gold = 196 !is_bsd && !use_lld && !(is_chromecast && is_linux && 197 (current_cpu == "arm" || current_cpu == "mipsel")) && 198 ((is_linux && (current_cpu == "x64" || current_cpu == "x86" || 199 current_cpu == "arm" || current_cpu == "arm64" || 200 current_cpu == "mipsel" || current_cpu == "mips64el")) || 201 (is_android && (current_cpu == "x86" || current_cpu == "x64" || 202 current_cpu == "arm" || current_cpu == "arm64"))) 203} 204 205# Use relative paths for debug info. This is important to make the build 206# results independent of the checkout and build directory names, which 207# in turn is important for goma compile hit rate. 208# Setting this to true may make it harder to debug binaries on Linux, see 209# https://chromium.googlesource.com/chromium/src/+/master/docs/linux/debugging.md#Source-level-debug-with-fdebug_compilation_dir 210# It's not clear if the crash server will correctly handle dSYMs with relative 211# paths, so we disable this feature for official benefit. The main benefit is 212# deterministic builds to reduce compile times, so this is less relevant for 213# official builders. 214strip_absolute_paths_from_debug_symbols_default = 215 is_android || is_fuchsia || is_nacl || (is_win && use_lld) || is_linux || 216 (is_mac && !enable_dsyms) || ios_use_goma_rbe 217 218declare_args() { 219 strip_absolute_paths_from_debug_symbols = strip_absolute_paths_from_debug_symbols_default 220} 221 222# If it wasn't manually set, set to an appropriate default. 223assert(symbol_level >= -1 && symbol_level <= 2, "Invalid symbol_level") 224if (symbol_level == -1) { 225 if (is_android && !is_component_build) { 226 # Reduce symbol level when it will cause invalid elf files to be created 227 # (due to file size). https://crbug.com/648948. 228 symbol_level = 1 229 } else if (is_chromeos_device) { 230 # Use lower symbol level in Simple Chrome build for faster link time. 231 # For Simple Chrome, this should take precedence over is_official_build, 232 # turned on by --internal. 233 if ((target_cpu == "x64" || target_cpu == "x86") && !is_debug) { 234 # For release x86/x64 build, specify symbol_level=0 for faster link time. 235 # x86/x64 shows backtraces with symbol_level=0 (arm requires 236 # symbol_level=1). 237 symbol_level = 0 238 } else { 239 symbol_level = 1 240 } 241 } else if (using_sanitizer) { 242 # Sanitizers need line table info for stack traces. They don't need type 243 # info or variable info, so we can leave that out to speed up the build. 244 # Sanitizers also require symbols for filename suppressions to work. 245 symbol_level = 1 246 } else if ((!is_nacl && !is_linux && !is_fuchsia && current_os != "aix") || 247 is_debug || is_official_build || is_chromecast) { 248 # Linux builds slower by having symbols as part of the target binary, 249 # whereas Mac and Windows have them separate, so in Release Linux, default 250 # them off, but keep them on for Official builds and Chromecast builds. 251 symbol_level = 2 252 } else { 253 symbol_level = 0 254 } 255} 256 257# Non-component debug builds with symbol_level = 2 are an undesirable (very slow 258# build times) and unsupported (some test binaries will fail with > 4 GB PDBs) 259# combination. This is only checked when current_toolchain == default_toolchain 260# because the is_component_build flag is set to false in various components of 261# the build (like nacl) and we don't want to assert on those. 262# iOS does not support component builds so add an exception for this platform. 263if (forbid_non_component_debug_builds) { 264 assert(symbol_level != 2 || current_toolchain != default_toolchain || 265 is_component_build || !is_debug || is_ios, 266 "Can't do non-component debug builds at symbol_level=2") 267} 268 269# Assert that the configuration isn't going to hit https://crbug.com/648948. 270# An exception is made when target_os == "chromeos" as we only use the Android 271# toolchain there to build relatively small binaries. 272assert(ignore_elf32_limitations || !is_android || target_os == "chromeos" || 273 is_component_build || symbol_level < 2, 274 "Android 32-bit non-component builds cannot have symbol_level=2 " + 275 "due to 4GiB file size limit, see https://crbug.com/648948. " + 276 "If you really want to try this out, " + 277 "set ignore_elf32_limitations=true.") 278