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