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 # Don't check in changes that set this to false for more platforms; doing so 14 # is not supported. 15 use_custom_libcxx = is_fuchsia || is_android || is_apple || is_linux || 16 is_chromeos || (is_win && is_clang) 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 use_custom_libcxx_for_host = false 25 26 # Builds libcxx Natvis into the symbols for type visualization. 27 # Set to false to workaround http://crbug.com/966676 and 28 # http://crbug.com/966687. 29 libcxx_natvis_include = true 30 31 # When set, enables libc++ debug mode with iterator debugging. 32 # 33 # Iterator debugging is generally useful for catching bugs. But it can 34 # introduce extra locking to check the state of an iterator against the state 35 # of the current object. For iterator- and thread-heavy code, this can 36 # significantly slow execution - two orders of magnitude slowdown has been 37 # seen (crbug.com/903553) and iterator debugging also slows builds by making 38 # generation of snapshot_blob.bin take ~40-60 s longer. Therefore this 39 # defaults to off. 40 enable_iterator_debugging = false 41} 42 43use_custom_libcxx = 44 use_custom_libcxx || (use_custom_libcxx_for_host && !is_a_target_toolchain) 45use_custom_libcxx = use_custom_libcxx && !is_nacl 46 47declare_args() { 48 # WARNING: Setting this to a non-default value is highly discouraged. 49 # If true, libc++ will be built as a shared library; otherwise libc++ will be 50 # linked statically. Setting this to something other than the default is 51 # unsupported and can be broken by libc++ rolls. Note that if this is set to 52 # true, you must also set libcxx_abi_unstable=false, which is bad for 53 # performance and memory use. 54 libcxx_is_shared = use_custom_libcxx && is_component_build 55 56 # In case the C++ standard library implementation used is libstdc++, then 57 # enable its own hardening checks. As we cannot determine in GN if libstdc++ 58 # is used or not, by default enable it for Linux without the custom libc++. 59 use_safe_libstdcxx = is_linux && !use_custom_libcxx 60} 61 62# The saigo libc++ is distinct from the custom hermetic libc++. However, since 63# the Chrome team controls the saigo toolchain, it is safe to unconditionally 64# enable libc++ hardening there as well. 65use_safe_libcxx = (use_custom_libcxx && enable_safe_libcxx) || is_nacl_saigo 66 67# libc++abi needs to be exported from executables to be picked up by shared 68# libraries on certain instrumented builds. 69export_libcxxabi_from_executables = 70 use_custom_libcxx && !is_apple && !is_win && !is_component_build && 71 (is_asan || is_ubsan_vptr) 72 73# On Android, many shared libraries get loaded from the context of a JRE. In 74# this case, there's no "main executable" to export libc++abi from. We could 75# export libc++abi from each "toplevel" shared library instead, but that would 76# require adding an explicit dependency for each one, and might introduce 77# subtle, hard-to-fix problems down the line if the dependency is missing. 78# 79# export_libcxxabi_from_executables was added to avoid having an RPATH set in 80# static sanitizer builds just for executables to find libc++. But on Android, 81# the Bionic dynamic loader doesn't even look at RPATH; instead, LD_LIBRARY_PATH 82# is set for tests. Because of this, we make libc++ a shared library on android 83# since it should get loaded properly. 84if (is_android && export_libcxxabi_from_executables) { 85 export_libcxxabi_from_executables = false 86 libcxx_is_shared = true 87} 88 89libcxx_prefix = "//third_party/libc++/src" 90libcxxabi_prefix = "//third_party/libc++abi/src" 91 92assert(!(is_ios && libcxx_is_shared), 93 "Can't build libc++ as a shared library on iOS.") 94