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/sanitizers/sanitizers.gni") 6import("//build/toolchain/toolchain.gni") 7 8import("//build/misc/overrides/build.gni") 9 10if (is_ohos) { 11 import("//build/config/ohos/abi.gni") 12} 13if (is_android) { 14 import("//build_plugins/config/aosp/abi.gni") 15} 16if (current_cpu == "arm" || current_cpu == "arm64") { 17 import("//build/config/arm.gni") 18} 19 20is_ohos_or_android = is_ohos || is_android 21 22declare_args() { 23 # How many symbols to include in the build. This affects the performance of 24 # the build since the symbols are large and dealing with them is slow. 25 # 2 means regular build with symbols. 26 # 1 means minimal symbols, usually enough for backtraces only. Symbols with 27 # internal linkage (static functions or those in anonymous namespaces) may not 28 # appear when using this level. 29 # 0 means no symbols. 30 # -1 means auto-set according to debug/release and platform. 31 symbol_level = -1 32 33 # ohos-only: Strip the debug info of libraries within lib.unstripped to 34 # reduce size. As long as symbol_level > 0, this will still allow stacks to be 35 # symbolized. 36 strip_debug_info = false 37 38 # Compile in such a way as to enable profiling of the generated code. For 39 # example, don't omit the frame pointer and leave in symbols. 40 enable_profiling = false 41 42 # use_debug_fission: whether to use split DWARF debug info 43 # files. This can reduce link time significantly, but is incompatible 44 # with some utilities such as icecc and ccache. Requires gold and 45 # gcc >= 4.8 or clang. 46 # http://gcc.gnu.org/wiki/DebugFission 47 # 48 # This is a placeholder value indicating that the code below should set 49 # the default. This is necessary to delay the evaluation of the default 50 # value expression until after its input values such as use_gold have 51 # been set, e.g. by a toolchain_args() block. 52 use_debug_fission = "default" 53 54 # Enables support for ThinLTO, which links 3x-10x faster than full LTO. See 55 # also http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html 56 use_thin_lto = is_cfi || (is_ohos_or_android && is_official_build) 57 58 # Tell VS to create a PDB that references information in .obj files rather 59 # than copying it all. This should improve linker performance. mspdbcmf.exe 60 # can be used to convert a fastlink pdb to a normal one. 61 is_win_fastlink = false 62 63 # Whether or not we should turn on incremental WPO. Only affects the VS 64 # Windows build. 65 use_incremental_wpo = false 66 67 # Whether or not we should use position independent code. 68 use_pic = true 69 70 # Whether we're using a sample profile collected on an architecture different 71 # than the one we're compiling for. 72 # 73 # It's currently not possible to collect AFDO profiles on anything but 74 # x86{,_64}. 75 using_mismatched_sample_profile = current_cpu != "x64" && current_cpu != "x86" 76} 77 78assert(!is_cfi || use_thin_lto, "CFI requires ThinLTO") 79 80# If true, optimize for size. Does not affect windows builds. 81# Linux & Mac favor speed over size. 82optimize_for_size = is_ohos_or_android 83 84declare_args() { 85 # Whether we should consider the profile we're using to be accurate. Accurate 86 # profiles have the benefit of (potentially substantial) binary size 87 # reductions, by instructing the compiler to optimize cold and uncovered 88 # functions heavily for size. This often comes at the cost of performance. 89 sample_profile_is_accurate = optimize_for_size 90} 91 92# Determine whether to enable or disable frame pointers, based on the platform 93# and build arguments. 94if (is_mac || is_linux) { 95 enable_frame_pointers = true 96} else if (is_win) { 97 # 64-bit Windows ABI doesn't support frame pointers. 98 if (current_cpu == "x64") { 99 enable_frame_pointers = false 100 } else { 101 enable_frame_pointers = true 102 } 103} else if (is_chromeos) { 104 # ChromeOS generally prefers frame pointers, to support CWP. 105 # However, Clang does not currently generate usable frame pointers in ARM 106 # 32-bit builds (https://bugs.llvm.org/show_bug.cgi?id=18505) so disable them 107 # there to avoid the unnecessary overhead. 108 enable_frame_pointers = current_cpu != "arm" 109} else if (is_ohos_or_android) { 110 enable_frame_pointers = 111 enable_profiling || 112 # Ensure that stacks from arm64 crash dumps are usable (crbug.com/391706). 113 current_cpu == "arm64" || 114 # For x86 ohos, unwind tables are huge without frame pointers 115 # (crbug.com/762629). Enabling frame pointers grows the code size slightly 116 # but overall shrinks binaries considerably by avoiding huge unwind 117 # tables. 118 (current_cpu == "x86" && !exclude_unwind_tables && optimize_for_size) || 119 using_sanitizer 120} else { 121 # Explicitly ask for frame pointers, otherwise: 122 # * Stacks may be missing for sanitizer and profiling builds. 123 # * Debug tcmalloc can crash (crbug.com/636489). 124 enable_frame_pointers = using_sanitizer || enable_profiling || is_debug 125} 126 127# In general assume that if we have frame pointers then we can use them to 128# unwind the stack. However, this requires that they are enabled by default for 129# most translation units, that they are emitted correctly, and that the 130# compiler or platform provides a way to access them. 131can_unwind_with_frame_pointers = enable_frame_pointers 132if (current_cpu == "arm" && arm_use_thumb) { 133 # We cannot currently unwind ARM Thumb frame pointers correctly. 134 # See https://bugs.llvm.org/show_bug.cgi?id=18505 135 can_unwind_with_frame_pointers = false 136} else if (is_win) { 137 # Windows 32-bit does provide frame pointers, but the compiler does not 138 # provide intrinsics to access them, so we don't use them. 139 can_unwind_with_frame_pointers = false 140} 141 142assert(!can_unwind_with_frame_pointers || enable_frame_pointers) 143 144# Unwinding with CFI table is only possible on static library builds and 145# required only when frame pointers are not enabled. 146can_unwind_with_cfi_table = is_ohos_or_android && !is_component_build && 147 !enable_frame_pointers && current_cpu == "arm" 148 149declare_args() { 150 # Set to true to use lld, the LLVM linker. This flag may be used on Windows, 151 # Linux. 152 use_lld = 153 is_clang && 154 (is_win || (use_thin_lto && target_os != "chromeos") || 155 (is_linux && current_cpu == "x64" && target_os != "chromeos") || 156 (is_ohos_or_android && (current_cpu != "arm" || arm_version >= 7) && 157 current_cpu != "mipsel" && current_cpu != "mips64el")) 158} 159 160declare_args() { 161 # Whether to use the gold linker from binutils instead of lld or bfd. 162 use_gold = 163 !use_lld && 164 !(is_linux && (current_cpu == "arm" || current_cpu == "mipsel")) && 165 ((is_linux && 166 (current_cpu == "x64" || current_cpu == "x86" || current_cpu == "arm" || 167 current_cpu == "mipsel" || current_cpu == "mips64el")) || 168 (is_ohos_or_android && (current_cpu == "x86" || current_cpu == "x64" || 169 current_cpu == "arm" || current_cpu == "arm64"))) 170} 171 172# If it wasn't manually set, set to an appropriate default. 173assert(symbol_level >= -1 && symbol_level <= 2, "Invalid symbol_level") 174if (symbol_level == -1) { 175 if (is_ohos_or_android && use_order_profiling) { 176 # With instrumentation enabled, debug info puts libchrome.so over 4gb, which 177 # causes the linker to produce an invalid ELF. http://crbug.com/574476 178 symbol_level = 0 179 } else if ((is_ohos && !is_component_build && 180 !(ohos_64bit_target_cpu && !build_app_secondary_abi)) || 181 (is_android && !is_component_build && 182 !(aosp_64bit_target_cpu && !build_app_secondary_abi))) { 183 # Reduce symbol level when it will cause invalid elf files to be created 184 # (due to file size). https://crbug.com/648948. 185 symbol_level = 1 186 } else if ((!is_nacl && !is_linux) || is_debug || is_official_build) { 187 # Linux builds slower by having symbols as part of the target binary, 188 # whereas Mac and Windows have them separate, so in Release Linux, default 189 # them off, but keep them on for Official builds and Chromecast builds. 190 symbol_level = 2 191 } else if (using_sanitizer) { 192 # Sanitizers need line table info for stack traces. They don't need type 193 # info or variable info, so we can leave that out to speed up the build. 194 # Sanitizers also require symbols for filename suppressions to work. 195 symbol_level = 1 196 } else { 197 symbol_level = 0 198 } 199} 200 201# Assert that the configuration isn't going to hit https://crbug.com/648948. 202# An exception is made when target_os == "chromeos" as we only use the ohos 203# toolchain there to build relatively small binaries. 204assert(ignore_elf32_limitations || !is_ohos_or_android || 205 target_os == "chromeos" || 206 (ohos_64bit_target_cpu && !build_app_secondary_abi) || 207 is_component_build || symbol_level < 2, 208 "ohos 32-bit non-component builds cannot have symbol_level=2 " + 209 "due to 4GiB file size limit, see https://crbug.com/648948. " + 210 "If you really want to try this out, " + 211 "set ignore_elf32_limitations=true.") 212