summaryrefslogtreecommitdiff
path: root/chromium/build/config/compiler/compiler.gni
blob: 6fddf3d05263fc3bda8158fe704ef7ba38456379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

if (is_android) {
  import("//build/config/android/abi.gni")
}
import("//build/config/arm.gni")
import("//build/config/chrome_build.gni")
import("//build/config/chromecast_build.gni")
import("//build/config/compiler/pgo/pgo.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/toolchain/goma.gni")
import("//build/toolchain/toolchain.gni")
import("//build_overrides/build.gni")

declare_args() {
  # How many symbols to include in the build. This affects the performance of
  # the build since the symbols are large and dealing with them is slow.
  #   2 means regular build with symbols.
  #   1 means minimal symbols, usually enough for backtraces only. Symbols with
  # internal linkage (static functions or those in anonymous namespaces) may not
  # appear when using this level.
  #   0 means no symbols.
  #   -1 means auto-set according to debug/release and platform.
  symbol_level = -1

  # Compile in such a way as to enable profiling of the generated code. For
  # example, don't omit the frame pointer and leave in symbols.
  enable_profiling = false

  # use_debug_fission: whether to use split DWARF debug info
  # files. This can reduce link time significantly, but is incompatible
  # with some utilities such as icecc and ccache. Requires gold and
  # gcc >= 4.8 or clang.
  # http://gcc.gnu.org/wiki/DebugFission
  #
  # This is a placeholder value indicating that the code below should set
  # the default.  This is necessary to delay the evaluation of the default
  # value expression until after its input values such as use_gold have
  # been set, e.g. by a toolchain_args() block.
  use_debug_fission = "default"

  # Enables support for ThinLTO, which links 3x-10x faster than full LTO. See
  # also http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html
  use_thin_lto = is_cfi

  # Tell VS to create a PDB that references information in .obj files rather
  # than copying it all. This should improve linker performance. mspdbcmf.exe
  # can be used to convert a fastlink pdb to a normal one.
  is_win_fastlink = false

  # Whether or not we should turn on incremental WPO. Only affects the VS
  # Windows build.
  use_incremental_wpo = false

  # Root directory that will store the MSVC link repro. This should only be
  # used for debugging purposes on the builders where a MSVC linker flakyness
  # has been observed. The targets for which a link repro should be generated
  # should add somethink like this to their configuration:
  #   if (linkrepro_root_dir != "") {
  #     ldflags = ["/LINKREPRO:" + linkrepro_root_dir + "/" + target_name]
  #   }
  #
  # Note that doing a link repro uses a lot of disk space and slows down the
  # build, so this shouldn't be enabled on too many targets.
  #
  # See crbug.com/669854.
  linkrepro_root_dir = ""

  # Whether or not we should use position independent code.
  use_pic = true
}

assert(!is_cfi || use_thin_lto, "CFI requires ThinLTO")

# Exclude unwind tables for official builds as unwinding can be done from stack
# dumps produced by Crashpad at a later time "offline" in the crash server.
# For unofficial (e.g. development) builds and non-Chrome branded (e.g. Cronet
# which doesn't use Crashpad, crbug.com/479283) builds it's useful to be able
# to unwind at runtime.
exclude_unwind_tables =
    (is_chrome_branded && is_official_build) ||
    (is_chromecast && !is_cast_desktop_build && !is_debug && !is_fuchsia)

# If true, optimize for size. Does not affect windows builds.
# Linux & Mac favor speed over size.
# TODO(brettw) it's weird that Mac and desktop Linux are different. We should
# explore favoring size over speed in this case as well.
optimize_for_size = is_android || is_ios

# Determine whether to enable or disable frame pointers, based on the platform
# and build arguments.
if (is_mac || is_ios || is_linux) {
  enable_frame_pointers = true
} else if (is_win) {
  # 64-bit Windows ABI doesn't support frame pointers.
  if (current_cpu == "x64") {
    enable_frame_pointers = false
  } else {
    enable_frame_pointers = true
  }
} else if (is_chromeos) {
  # ChromeOS generally prefers frame pointers, to support CWP.
  # However, Clang does not currently generate usable frame pointers in ARM
  # 32-bit builds (https://bugs.llvm.org/show_bug.cgi?id=18505) so disable them
  # there to avoid the unnecessary overhead.
  enable_frame_pointers = current_cpu != "arm"
} else if (is_android) {
  enable_frame_pointers =
      enable_profiling ||
      # Ensure that stacks from arm64 crash dumps are usable (crbug.com/391706).
      current_cpu == "arm64" ||
      # For x86 Android, unwind tables are huge without frame pointers
      # (crbug.com/762629). Enabling frame pointers grows the code size slightly
      # but overall shrinks binaries considerably by avoiding huge unwind
      # tables.
      (current_cpu == "x86" && !exclude_unwind_tables && optimize_for_size)
} else {
  # Explicitly ask for frame pointers, otherwise:
  # * Stacks may be missing for sanitizer and profiling builds.
  # * Debug tcmalloc can crash (crbug.com/636489).
  enable_frame_pointers = using_sanitizer || enable_profiling || is_debug
}

# In general assume that if we have frame pointers then we can use them to
# unwind the stack. However, this requires that they are enabled by default for
# most translation units, that they are emitted correctly, and that the
# compiler or platform provides a way to access them.
can_unwind_with_frame_pointers = enable_frame_pointers
if (current_cpu == "arm" && arm_use_thumb) {
  # We cannot currently unwind ARM Thumb frame pointers correctly.
  # See https://bugs.llvm.org/show_bug.cgi?id=18505
  can_unwind_with_frame_pointers = false
} else if (is_win) {
  # Windows 32-bit does provide frame pointers, but the compiler does not
  # provide intrinsics to access them, so we don't use them.
  can_unwind_with_frame_pointers = false
}

assert(!can_unwind_with_frame_pointers || enable_frame_pointers)

declare_args() {
  # Whether or not the official builds should be built with full WPO. Enabled by
  # default for the PGO and the x64 builds.
  if (chrome_pgo_phase > 0) {
    full_wpo_on_official = true
  } else {
    full_wpo_on_official = false
  }
}

declare_args() {
  # Set to true to use lld, the LLVM linker. This flag may be used on Windows,
  # Linux or Fuchsia.
  # TODO(pcc): Enable lld on more architectures on Linux. E.g. we probably need
  # to fix some of crbug.com/742655 to enable it on ARM.
  # TODO(pcc): Remove !is_msan once crbug.com/772559 is fixed.
  use_lld = is_clang && !is_msan &&
            ((is_win && host_os != "win") || is_fuchsia ||
             (use_thin_lto && target_os != "chromeos") ||
             (is_linux && current_cpu == "x64" && target_os != "chromeos"))
}

declare_args() {
  # Whether to use the gold linker from binutils instead of lld or bfd.
  use_gold =
      (!use_lld && !(is_chromecast && is_linux &&
                     (current_cpu == "arm" || current_cpu == "mipsel")) &&
       (is_linux && (current_cpu == "x64" || current_cpu == "x86" ||
                     current_cpu == "arm" || current_cpu == "mipsel"))) ||
      (is_android && (current_cpu == "x86" || current_cpu == "x64" ||
                      current_cpu == "arm" || current_cpu == "arm64"))
}

# If it wasn't manually set, set to an appropriate default.
assert(symbol_level >= -1 && symbol_level <= 2, "Invalid symbol_level")
if (symbol_level == -1) {
  if (is_android && use_order_profiling) {
    # With instrumentation enabled, debug info puts libchrome.so over 4gb, which
    # causes the linker to produce an invalid ELF. http://crbug.com/574476
    symbol_level = 0
  } else if (is_android && !is_component_build &&
             !(android_64bit_target_cpu && !build_apk_secondary_abi)) {
    # Reduce symbol level when it will cause invalid elf files to be created
    # (due to file size). https://crbug.com/648948.
    symbol_level = 1
  } else if (is_win && use_goma && !is_clang) {
    # goma doesn't support PDB files, so we disable symbols during goma
    # compilation because otherwise the redundant debug information generated
    # by visual studio (repeated in every .obj file) makes linker
    # memory consumption and link times unsustainable (crbug.com/630074).
    # Clang on windows does not have this issue.
    # If you use is_win_fastlink = true or lld or clang then you can set
    # symbol_level = 2 when using goma.
    symbol_level = 1
  } else if ((!is_nacl && !is_linux && !is_fuchsia) || is_debug ||
             is_official_build || is_chromecast) {
    # Linux builds slower by having symbols as part of the target binary,
    # whereas Mac and Windows have them separate, so in Release Linux, default
    # them off, but keep them on for Official builds and Chromecast builds.
    symbol_level = 2
  } else if (using_sanitizer) {
    # Sanitizers require symbols for filename suppressions to work.
    symbol_level = 1
  } else {
    symbol_level = 0
  }
} else if (symbol_level == 2) {
  if (is_win) {
    # See crbug.com/630074
    assert(is_win_fastlink || use_lld || !use_goma || is_clang,
           "VC++ goma builds that use symbol_level 2 must use " +
               "is_win_fastlink or use_lld.")
  }
}

# Assert that the configuration isn't going to hit https://crbug.com/648948.
assert(ignore_elf32_limitations || !is_android ||
           (android_64bit_target_cpu && !build_apk_secondary_abi) ||
           is_component_build || symbol_level < 2,
       "Android 32-bit non-component builds cannot have symbol_level=2 " +
           "due to 4GiB file size limit, see https://crbug.com/648948. " +
           "If you really want to try this out, " +
           "set ignore_elf32_limitations=true.")