• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 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# This file should only be imported from files that define toolchains.
6# There's no way to enforce this exactly, but all toolchains are processed
7# in the context of the default_toolchain, so we can at least check for that.
8assert(current_toolchain == default_toolchain)
9
10import("//build/config/android/config.gni")
11import("//build/config/apple/symbols.gni")
12import("//build/config/chromeos/ui_mode.gni")
13import("//build/config/compiler/compiler.gni")
14import("//build/config/coverage/coverage.gni")
15import("//build/config/sanitizers/sanitizers.gni")
16import("//build/toolchain/toolchain.gni")
17
18declare_args() {
19  # Limit the number of concurrent links; we often want to run fewer
20  # links at once than we do compiles, because linking is memory-intensive.
21  # The default to use varies by platform and by the amount of memory
22  # available, so we call out to a script to get the right value.
23  concurrent_links = -1
24}
25
26if (concurrent_links == -1) {
27  if (use_thin_lto) {
28    _args = [
29      "--reserve_mem_gb=10",
30      "--thin-lto=local",
31    ]
32    if (is_win) {
33      # Based on measurements of linking chrome.dll and chrome_child.dll, plus
34      # a little padding to account for future growth.
35      _args += [ "--mem_per_link_gb=45" ]
36    } else if (is_android) {
37      # Large solink of Android official builds take 30-60GB.
38      _args += [ "--mem_per_link_gb=30" ]
39    } else {
40      _args += [ "--mem_per_link_gb=20" ]
41    }
42  } else if ((use_clang_coverage &&
43              # When coverage_instrumentation_input_file is not empty it means
44              # we're only instrumenting changed files and not using a lot of
45              # memory. Likewise, when it's empty we're building everything with
46              # coverage, which requires more memory.
47              coverage_instrumentation_input_file == "") ||
48             use_sanitizer_coverage || use_fuzzing_engine) {
49    # Full sanitizer coverage instrumentation increases linker memory consumption
50    # significantly.
51    _args = [ "--mem_per_link_gb=16" ]
52  } else if (is_win && symbol_level == 1 && !is_debug && is_component_build) {
53    _args = [ "--mem_per_link_gb=3" ]
54  } else if (is_win && target_cpu == "arm64" && !is_component_build) {
55    # crbug.com/340979111: OOM quite frequently for win-arm64-rel.
56    _args = [ "--mem_per_link_gb=10" ]
57  } else if (is_win) {
58    _args = [ "--mem_per_link_gb=6" ]
59  } else if (is_mac) {
60    if (enable_dsyms) {
61      _args = [ "--mem_per_link_gb=12" ]
62    } else {
63      _args = [ "--mem_per_link_gb=4" ]
64    }
65  } else if (is_android && !is_component_build && symbol_level == 2) {
66    # Full debug symbols require large memory for link.
67    _args = [ "--mem_per_link_gb=25" ]
68  } else if (is_android && !is_debug && !using_sanitizer && symbol_level < 2) {
69    if (symbol_level == 1) {
70      _args = [ "--mem_per_link_gb=6" ]
71    } else {
72      _args = [ "--mem_per_link_gb=4" ]
73    }
74  } else if ((is_linux || is_chromeos_lacros) && symbol_level == 0) {
75    # Memory consumption on link without debug symbols is low on linux.
76    _args = [ "--mem_per_link_gb=3" ]
77  } else if (current_os == "zos") {
78    _args = [ "--mem_per_link_gb=1" ]
79  } else if (is_fuchsia) {
80    # TODO(crbug.com/40854531): This was defaulting to 8GB. The number of
81    #    linker instances to run in parallel is calculated by diviging
82    #    the available memory by this value. On a 32GB machine with
83    #    roughly 29GB of available memory, this would cause three instances
84    #    to run. This started running out of memory and thrashing. This change
85    #    addresses that issue to get the SDk rollers running again but
86    #    could be optimized (maybe to 12GB or for different configs like
87    #    component build).
88    _args = [ "--mem_per_link_gb=16" ]
89  } else if (is_chromeos && is_msan) {
90    # crbug.com/1505350 - CrOS MSan builder consumes more memory and crushes.
91    # Max 25.2GB, Avg: 9.4GB, Median: 7.9GB
92    _args = [ "--mem_per_link_gb=12" ]
93  } else if (is_chromeos && is_debug) {
94    # b/315102033, b/312072730: Large links use 9GB-13.5GB.
95    _args = [ "--mem_per_link_gb=10" ]
96  } else {
97    _args = []
98  }
99
100  # For Android builds, we also need to be wary of:
101  # * ProGuard / R8
102  # * Android Lint
103  # These both have a peak usage of < 2GB, but that is still large enough for
104  # them to need to use a pool since they both typically happen at the
105  # same time as linking.
106  if (is_android) {
107    _args += [ "--secondary_mem_per_link=2" ]
108  }
109
110  # TODO(crbug.com/41257258) Pass more build configuration info to the script
111  # so that we can compute better values.
112  _command_dict = exec_script("get_concurrent_links.py", _args, "scope")
113
114  concurrent_links = _command_dict.primary_pool_size
115  concurrent_links_logs = _command_dict.explanation
116
117  if (_command_dict.secondary_pool_size >= concurrent_links) {
118    # Have R8 / Lint share the link pool unless we would safely get more
119    # concurrency out of using a separate one.
120    # On low-RAM machines, this allows an apk's native library to link at the
121    # same time as its java is optimized with R8.
122    java_cmd_pool_size = _command_dict.secondary_pool_size
123  }
124} else {
125  assert(!use_thin_lto, "can't explicitly set concurrent_links with thinlto")
126  concurrent_links_logs =
127      [ "concurrent_links set by GN arg (value=$concurrent_links)" ]
128}
129