15f9996aaSopenharmony_ci# Copyright 2015 The Chromium Authors. All rights reserved. 25f9996aaSopenharmony_ci# Use of this source code is governed by a BSD-style license that can be 35f9996aaSopenharmony_ci# found in the LICENSE file. 45f9996aaSopenharmony_ci 55f9996aaSopenharmony_ciimport("//build/config/sanitizers/sanitizers.gni") 65f9996aaSopenharmony_ciimport("//build/toolchain/toolchain.gni") 75f9996aaSopenharmony_ci 85f9996aaSopenharmony_ciimport("//build/misc/overrides/build.gni") 95f9996aaSopenharmony_ci 105f9996aaSopenharmony_ciif (is_ohos) { 115f9996aaSopenharmony_ci import("//build/config/ohos/abi.gni") 125f9996aaSopenharmony_ci} 135f9996aaSopenharmony_ciif (is_android) { 145f9996aaSopenharmony_ci import("//build_plugins/config/aosp/abi.gni") 155f9996aaSopenharmony_ci} 165f9996aaSopenharmony_ciif (current_cpu == "arm" || current_cpu == "arm64") { 175f9996aaSopenharmony_ci import("//build/config/arm.gni") 185f9996aaSopenharmony_ci} 195f9996aaSopenharmony_ci 205f9996aaSopenharmony_ciis_ohos_or_android = is_ohos || is_android 215f9996aaSopenharmony_ci 225f9996aaSopenharmony_cideclare_args() { 235f9996aaSopenharmony_ci # How many symbols to include in the build. This affects the performance of 245f9996aaSopenharmony_ci # the build since the symbols are large and dealing with them is slow. 255f9996aaSopenharmony_ci # 2 means regular build with symbols. 265f9996aaSopenharmony_ci # 1 means minimal symbols, usually enough for backtraces only. Symbols with 275f9996aaSopenharmony_ci # internal linkage (static functions or those in anonymous namespaces) may not 285f9996aaSopenharmony_ci # appear when using this level. 295f9996aaSopenharmony_ci # 0 means no symbols. 305f9996aaSopenharmony_ci # -1 means auto-set according to debug/release and platform. 315f9996aaSopenharmony_ci symbol_level = -1 325f9996aaSopenharmony_ci 335f9996aaSopenharmony_ci # ohos-only: Strip the debug info of libraries within lib.unstripped to 345f9996aaSopenharmony_ci # reduce size. As long as symbol_level > 0, this will still allow stacks to be 355f9996aaSopenharmony_ci # symbolized. 365f9996aaSopenharmony_ci strip_debug_info = false 375f9996aaSopenharmony_ci 385f9996aaSopenharmony_ci # Compile in such a way as to enable profiling of the generated code. For 395f9996aaSopenharmony_ci # example, don't omit the frame pointer and leave in symbols. 405f9996aaSopenharmony_ci enable_profiling = false 415f9996aaSopenharmony_ci 425f9996aaSopenharmony_ci # use_debug_fission: whether to use split DWARF debug info 435f9996aaSopenharmony_ci # files. This can reduce link time significantly, but is incompatible 445f9996aaSopenharmony_ci # with some utilities such as icecc and ccache. Requires gold and 455f9996aaSopenharmony_ci # gcc >= 4.8 or clang. 465f9996aaSopenharmony_ci # http://gcc.gnu.org/wiki/DebugFission 475f9996aaSopenharmony_ci # 485f9996aaSopenharmony_ci # This is a placeholder value indicating that the code below should set 495f9996aaSopenharmony_ci # the default. This is necessary to delay the evaluation of the default 505f9996aaSopenharmony_ci # value expression until after its input values such as use_gold have 515f9996aaSopenharmony_ci # been set, e.g. by a toolchain_args() block. 525f9996aaSopenharmony_ci use_debug_fission = "default" 535f9996aaSopenharmony_ci 545f9996aaSopenharmony_ci # Enables support for ThinLTO, which links 3x-10x faster than full LTO. See 555f9996aaSopenharmony_ci # also http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html 565f9996aaSopenharmony_ci if (use_libfuzzer) { 575f9996aaSopenharmony_ci use_thin_lto = is_cfi || (is_ohos_or_android && is_official_build) 585f9996aaSopenharmony_ci } else { 595f9996aaSopenharmony_ci use_thin_lto = is_cfi || is_ohos_or_android 605f9996aaSopenharmony_ci } 615f9996aaSopenharmony_ci 625f9996aaSopenharmony_ci # Tell VS to create a PDB that references information in .obj files rather 635f9996aaSopenharmony_ci # than copying it all. This should improve linker performance. mspdbcmf.exe 645f9996aaSopenharmony_ci # can be used to convert a fastlink pdb to a normal one. 655f9996aaSopenharmony_ci is_win_fastlink = false 665f9996aaSopenharmony_ci 675f9996aaSopenharmony_ci # Whether or not we should turn on incremental WPO. Only affects the VS 685f9996aaSopenharmony_ci # Windows build. 695f9996aaSopenharmony_ci use_incremental_wpo = false 705f9996aaSopenharmony_ci 715f9996aaSopenharmony_ci # Whether or not we should use position independent code. 725f9996aaSopenharmony_ci use_pic = true 735f9996aaSopenharmony_ci 745f9996aaSopenharmony_ci # Whether we're using a sample profile collected on an architecture different 755f9996aaSopenharmony_ci # than the one we're compiling for. 765f9996aaSopenharmony_ci # 775f9996aaSopenharmony_ci # It's currently not possible to collect AFDO profiles on anything but 785f9996aaSopenharmony_ci # x86{,_64}. 795f9996aaSopenharmony_ci using_mismatched_sample_profile = current_cpu != "x64" && current_cpu != "x86" 805f9996aaSopenharmony_ci} 815f9996aaSopenharmony_ci 825f9996aaSopenharmony_ciassert(!is_cfi || use_thin_lto, "CFI requires ThinLTO") 835f9996aaSopenharmony_ci 845f9996aaSopenharmony_ci# If true, optimize for size. Does not affect windows builds. 855f9996aaSopenharmony_ci# Linux & Mac favor speed over size. 865f9996aaSopenharmony_cioptimize_for_size = is_ohos_or_android 875f9996aaSopenharmony_ci 885f9996aaSopenharmony_cideclare_args() { 895f9996aaSopenharmony_ci # Whether we should consider the profile we're using to be accurate. Accurate 905f9996aaSopenharmony_ci # profiles have the benefit of (potentially substantial) binary size 915f9996aaSopenharmony_ci # reductions, by instructing the compiler to optimize cold and uncovered 925f9996aaSopenharmony_ci # functions heavily for size. This often comes at the cost of performance. 935f9996aaSopenharmony_ci sample_profile_is_accurate = optimize_for_size 945f9996aaSopenharmony_ci} 955f9996aaSopenharmony_ci 965f9996aaSopenharmony_ci# Determine whether to enable or disable frame pointers, based on the platform 975f9996aaSopenharmony_ci# and build arguments. 985f9996aaSopenharmony_ciif (is_mac || is_linux) { 995f9996aaSopenharmony_ci enable_frame_pointers = true 1005f9996aaSopenharmony_ci} else if (is_win) { 1015f9996aaSopenharmony_ci # 64-bit Windows ABI doesn't support frame pointers. 1025f9996aaSopenharmony_ci if (current_cpu == "x64") { 1035f9996aaSopenharmony_ci enable_frame_pointers = false 1045f9996aaSopenharmony_ci } else { 1055f9996aaSopenharmony_ci enable_frame_pointers = true 1065f9996aaSopenharmony_ci } 1075f9996aaSopenharmony_ci} else if (is_chromeos) { 1085f9996aaSopenharmony_ci # ChromeOS generally prefers frame pointers, to support CWP. 1095f9996aaSopenharmony_ci # However, Clang does not currently generate usable frame pointers in ARM 1105f9996aaSopenharmony_ci # 32-bit builds (https://bugs.llvm.org/show_bug.cgi?id=18505) so disable them 1115f9996aaSopenharmony_ci # there to avoid the unnecessary overhead. 1125f9996aaSopenharmony_ci enable_frame_pointers = current_cpu != "arm" 1135f9996aaSopenharmony_ci} else if (is_ohos_or_android) { 1145f9996aaSopenharmony_ci enable_frame_pointers = 1155f9996aaSopenharmony_ci enable_profiling || 1165f9996aaSopenharmony_ci # Ensure that stacks from arm64 crash dumps are usable (crbug.com/391706). 1175f9996aaSopenharmony_ci current_cpu == "arm64" || 1185f9996aaSopenharmony_ci # For x86 ohos, unwind tables are huge without frame pointers 1195f9996aaSopenharmony_ci # (crbug.com/762629). Enabling frame pointers grows the code size slightly 1205f9996aaSopenharmony_ci # but overall shrinks binaries considerably by avoiding huge unwind 1215f9996aaSopenharmony_ci # tables. 1225f9996aaSopenharmony_ci (current_cpu == "x86" && !exclude_unwind_tables && optimize_for_size) || 1235f9996aaSopenharmony_ci using_sanitizer || current_cpu == "riscv64" 1245f9996aaSopenharmony_ci} else { 1255f9996aaSopenharmony_ci # Explicitly ask for frame pointers, otherwise: 1265f9996aaSopenharmony_ci # * Stacks may be missing for sanitizer and profiling builds. 1275f9996aaSopenharmony_ci # * Debug tcmalloc can crash (crbug.com/636489). 1285f9996aaSopenharmony_ci enable_frame_pointers = using_sanitizer || enable_profiling || is_debug 1295f9996aaSopenharmony_ci} 1305f9996aaSopenharmony_ci 1315f9996aaSopenharmony_ci# In general assume that if we have frame pointers then we can use them to 1325f9996aaSopenharmony_ci# unwind the stack. However, this requires that they are enabled by default for 1335f9996aaSopenharmony_ci# most translation units, that they are emitted correctly, and that the 1345f9996aaSopenharmony_ci# compiler or platform provides a way to access them. 1355f9996aaSopenharmony_cican_unwind_with_frame_pointers = enable_frame_pointers 1365f9996aaSopenharmony_ciif (current_cpu == "arm" && arm_use_thumb) { 1375f9996aaSopenharmony_ci # We cannot currently unwind ARM Thumb frame pointers correctly. 1385f9996aaSopenharmony_ci # See https://bugs.llvm.org/show_bug.cgi?id=18505 1395f9996aaSopenharmony_ci can_unwind_with_frame_pointers = false 1405f9996aaSopenharmony_ci} else if (is_win) { 1415f9996aaSopenharmony_ci # Windows 32-bit does provide frame pointers, but the compiler does not 1425f9996aaSopenharmony_ci # provide intrinsics to access them, so we don't use them. 1435f9996aaSopenharmony_ci can_unwind_with_frame_pointers = false 1445f9996aaSopenharmony_ci} 1455f9996aaSopenharmony_ci 1465f9996aaSopenharmony_ciassert(!can_unwind_with_frame_pointers || enable_frame_pointers) 1475f9996aaSopenharmony_ci 1485f9996aaSopenharmony_ci# Unwinding with CFI table is only possible on static library builds and 1495f9996aaSopenharmony_ci# required only when frame pointers are not enabled. 1505f9996aaSopenharmony_cican_unwind_with_cfi_table = is_ohos_or_android && !is_component_build && 1515f9996aaSopenharmony_ci !enable_frame_pointers && current_cpu == "arm" 1525f9996aaSopenharmony_ci 1535f9996aaSopenharmony_cideclare_args() { 1545f9996aaSopenharmony_ci # Set to true to use lld, the LLVM linker. This flag may be used on Windows, 1555f9996aaSopenharmony_ci # Linux. 1565f9996aaSopenharmony_ci use_lld = 1575f9996aaSopenharmony_ci is_clang && 1585f9996aaSopenharmony_ci (is_win || (use_thin_lto && target_os != "chromeos") || 1595f9996aaSopenharmony_ci (is_linux && current_cpu == "x64" && target_os != "chromeos") || 1605f9996aaSopenharmony_ci (is_ohos_or_android && (current_cpu != "arm" || arm_version >= 7) && 1615f9996aaSopenharmony_ci current_cpu != "mipsel" && current_cpu != "mips64el")) 1625f9996aaSopenharmony_ci} 1635f9996aaSopenharmony_ci 1645f9996aaSopenharmony_cideclare_args() { 1655f9996aaSopenharmony_ci # Whether to use the gold linker from binutils instead of lld or bfd. 1665f9996aaSopenharmony_ci use_gold = 1675f9996aaSopenharmony_ci !use_lld && 1685f9996aaSopenharmony_ci !(is_linux && (current_cpu == "arm" || current_cpu == "mipsel")) && 1695f9996aaSopenharmony_ci ((is_linux && 1705f9996aaSopenharmony_ci (current_cpu == "x64" || current_cpu == "x86" || current_cpu == "arm" || 1715f9996aaSopenharmony_ci current_cpu == "mipsel" || current_cpu == "mips64el")) || 1725f9996aaSopenharmony_ci (is_ohos_or_android && 1735f9996aaSopenharmony_ci (current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm" || 1745f9996aaSopenharmony_ci current_cpu == "arm64" || current_cpu == "riscv64"))) 1755f9996aaSopenharmony_ci} 1765f9996aaSopenharmony_ci 1775f9996aaSopenharmony_ci# If it wasn't manually set, set to an appropriate default. 1785f9996aaSopenharmony_ciassert(symbol_level >= -1 && symbol_level <= 2, "Invalid symbol_level") 1795f9996aaSopenharmony_ciif (symbol_level == -1) { 1805f9996aaSopenharmony_ci if (is_ohos_or_android && use_order_profiling) { 1815f9996aaSopenharmony_ci # With instrumentation enabled, debug info puts libchrome.so over 4gb, which 1825f9996aaSopenharmony_ci # causes the linker to produce an invalid ELF. http://crbug.com/574476 1835f9996aaSopenharmony_ci symbol_level = 0 1845f9996aaSopenharmony_ci } else if ((is_ohos && !is_component_build && 1855f9996aaSopenharmony_ci !(ohos_64bit_target_cpu && !build_app_secondary_abi)) || 1865f9996aaSopenharmony_ci (is_android && !is_component_build && 1875f9996aaSopenharmony_ci !(aosp_64bit_target_cpu && !build_app_secondary_abi))) { 1885f9996aaSopenharmony_ci # Reduce symbol level when it will cause invalid elf files to be created 1895f9996aaSopenharmony_ci # (due to file size). https://crbug.com/648948. 1905f9996aaSopenharmony_ci symbol_level = 1 1915f9996aaSopenharmony_ci } else if ((!is_nacl && !is_linux) || is_debug || is_official_build) { 1925f9996aaSopenharmony_ci # Linux builds slower by having symbols as part of the target binary, 1935f9996aaSopenharmony_ci # whereas Mac and Windows have them separate, so in Release Linux, default 1945f9996aaSopenharmony_ci # them off, but keep them on for Official builds and Chromecast builds. 1955f9996aaSopenharmony_ci symbol_level = 2 1965f9996aaSopenharmony_ci } else if (using_sanitizer) { 1975f9996aaSopenharmony_ci # Sanitizers need line table info for stack traces. They don't need type 1985f9996aaSopenharmony_ci # info or variable info, so we can leave that out to speed up the build. 1995f9996aaSopenharmony_ci # Sanitizers also require symbols for filename suppressions to work. 2005f9996aaSopenharmony_ci symbol_level = 1 2015f9996aaSopenharmony_ci } else { 2025f9996aaSopenharmony_ci symbol_level = 0 2035f9996aaSopenharmony_ci } 2045f9996aaSopenharmony_ci} 2055f9996aaSopenharmony_ci 2065f9996aaSopenharmony_ci# Assert that the configuration isn't going to hit https://crbug.com/648948. 2075f9996aaSopenharmony_ci# An exception is made when target_os == "chromeos" as we only use the ohos 2085f9996aaSopenharmony_ci# toolchain there to build relatively small binaries. 2095f9996aaSopenharmony_ciassert(ignore_elf32_limitations || !is_ohos_or_android || 2105f9996aaSopenharmony_ci target_os == "chromeos" || 2115f9996aaSopenharmony_ci (ohos_64bit_target_cpu && !build_app_secondary_abi) || 2125f9996aaSopenharmony_ci is_component_build || symbol_level < 2, 2135f9996aaSopenharmony_ci "ohos 32-bit non-component builds cannot have symbol_level=2 " + 2145f9996aaSopenharmony_ci "due to 4GiB file size limit, see https://crbug.com/648948. " + 2155f9996aaSopenharmony_ci "If you really want to try this out, " + 2165f9996aaSopenharmony_ci "set ignore_elf32_limitations=true.") 217