1# Copyright 2017 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 5import("//build/config/nacl/config.gni") 6import("//build/config/sanitizers/sanitizers.gni") 7import("//build_overrides/build.gni") 8 9declare_args() { 10 # Use in-tree libc++ (buildtools/third_party/libc++ and 11 # buildtools/third_party/libc++abi) instead of the system C++ library for C++ 12 # standard library support. 13 # 14 # WARNING: Bringing your own C++ standard library is deprecated and will not 15 # be supported in the future. This flag will be removed. 16 use_custom_libcxx = true 17 18 # Use libc++ instead of stdlibc++ when using the host_cpu toolchain, even if 19 # use_custom_libcxx is false. This is useful for cross-compiles where a custom 20 # toolchain for the target_cpu has been set as the default toolchain, but 21 # use_custom_libcxx should still be true when building for the host. The 22 # expected usage is to set use_custom_libcxx=false and 23 # use_custom_libcxx_for_host=true in the passed in buildargs. 24 # 25 # WARNING: Bringing your own C++ standard library is deprecated and will not 26 # be supported in the future. This flag will be removed. 27 use_custom_libcxx_for_host = true 28 29 # Builds libcxx Natvis into the symbols for type visualization. 30 # Set to false to workaround http://crbug.com/966676 and 31 # http://crbug.com/966687. 32 libcxx_natvis_include = true 33 34 # When set, enables libc++ debug mode with iterator debugging. 35 # 36 # Iterator debugging is generally useful for catching bugs. But it can 37 # introduce extra locking to check the state of an iterator against the state 38 # of the current object. For iterator- and thread-heavy code, this can 39 # significantly slow execution - two orders of magnitude slowdown has been 40 # seen (crbug.com/903553) and iterator debugging also slows builds by making 41 # generation of snapshot_blob.bin take ~40-60 s longer. Therefore this 42 # defaults to off. 43 enable_iterator_debugging = false 44 45 # Use Clang header modules for libc++. 46 # This is experimental only (see crbug.com/543704). 47 # For details on the current state of modules in Chromium see 48 # https://chromium.googlesource.com/chromium/src/+/main/docs/modules.md 49 use_libcxx_modules = false 50} 51 52assert(!use_libcxx_modules || !use_remoteexec, 53 "Implicit Clang header modules don't work with remote execution.") 54 55use_custom_libcxx = 56 use_custom_libcxx || (use_custom_libcxx_for_host && !is_a_target_toolchain) 57use_custom_libcxx = use_custom_libcxx && !is_nacl 58 59declare_args() { 60 # WARNING: Setting this to a non-default value is highly discouraged. 61 # If true, libc++ will be built as a shared library; otherwise libc++ will be 62 # linked statically. Setting this to something other than the default is 63 # unsupported and can be broken by libc++ rolls. Note that if this is set to 64 # true, you must also set libcxx_abi_unstable=false, which is bad for 65 # performance and memory use. 66 libcxx_is_shared = use_custom_libcxx && is_component_build 67 68 # In case the C++ standard library implementation used is libstdc++, then 69 # enable its own hardening checks. As we cannot determine in GN if libstdc++ 70 # is used or not, by default enable it for Linux without the custom libc++. 71 # 72 # WARNING: Bringing your own C++ standard library is deprecated and will not 73 # be supported in the future. This flag will be removed. 74 use_safe_libstdcxx = is_linux && !use_custom_libcxx 75} 76 77# The saigo libc++ is distinct from the custom hermetic libc++. However, since 78# the Chrome team controls the saigo toolchain, it is safe to unconditionally 79# enable libc++ hardening there as well. 80use_safe_libcxx = (use_custom_libcxx && enable_safe_libcxx) || is_nacl_saigo 81 82# libc++abi needs to be exported from executables to be picked up by shared 83# libraries on certain instrumented builds. 84export_libcxxabi_from_executables = 85 use_custom_libcxx && !is_apple && !is_win && !is_component_build && 86 (is_asan || is_ubsan_vptr) 87 88# On Android, many shared libraries get loaded from the context of a JRE. In 89# this case, there's no "main executable" to export libc++abi from. We could 90# export libc++abi from each "toplevel" shared library instead, but that would 91# require adding an explicit dependency for each one, and might introduce 92# subtle, hard-to-fix problems down the line if the dependency is missing. 93# 94# export_libcxxabi_from_executables was added to avoid having an RPATH set in 95# static sanitizer builds just for executables to find libc++. But on Android, 96# the Bionic dynamic loader doesn't even look at RPATH; instead, LD_LIBRARY_PATH 97# is set for tests. Because of this, we make libc++ a shared library on android 98# since it should get loaded properly. 99if (is_android && export_libcxxabi_from_executables) { 100 export_libcxxabi_from_executables = false 101 libcxx_is_shared = true 102} 103 104libcxx_prefix = "//third_party/libc++/src" 105libcxxabi_prefix = "//third_party/libc++abi/src" 106libcxx_module_prefix = "$root_gen_dir/libcxx" 107 108assert(!(is_ios && libcxx_is_shared), 109 "Can't build libc++ as a shared library on iOS.") 110 111# Chromium will require using its libc++ library implementation. Warn if the 112# current configuration is not using it. 113if ((!use_custom_libcxx || !use_custom_libcxx_for_host) && 114 # Standalone use of //build outside of Chromium can disable libc++. 115 build_with_chromium && 116 # Try to avoid spamming the console lots. It's not actually 117 # toolchain-specific. 118 current_toolchain == default_toolchain) { 119 print("*********************************************************************") 120 print("WARNING: Support for linking against a C++ standard library other ") 121 print(" than the one in-tree (buildtools/third_party/libc++) is deprecated") 122 print(" and support for this will end. We plan to remove this option in ") 123 print(" M138.") 124 print("*********************************************************************") 125} 126