tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

compiler.gni (15289B)


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