1# Copyright 2015 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/c++/c++.gni") 6import("//build/config/sanitizers/sanitizers.gni") 7import("//build/toolchain/toolchain.gni") 8 9# Used by libc++ and libc++abi. 10# See //build/config/c++:runtime_library for the config used by users of libc++. 11config("config") { 12 cflags = [ "-fstrict-aliasing" ] 13 if (is_win) { 14 cflags += [ 15 # libc++ wants to redefine the macros WIN32_LEAN_AND_MEAN and _CRT_RAND_S 16 # in its implementation. 17 "-Wno-macro-redefined", 18 ] 19 20 cflags_cc = [ 21 # We want to use a uniform C++ version across all of chromium, but 22 # upstream libc++ requires C++20 so we have to make an exception here. 23 # No other target should override the default -std= flag. 24 "-std:c++20", 25 ] 26 } else { 27 cflags += [ "-fPIC" ] 28 cflags_cc = [ "-std=c++20" ] 29 } 30 31 defines = [ "_LIBCPP_BUILDING_LIBRARY" ] 32} 33 34# Explicitly set version macros to Windows 7 to prevent libc++ from adding a 35# hard dependency on GetSystemTimePreciseAsFileTime, which was introduced in 36# Windows 8. 37config("winver") { 38 defines = [ 39 "NTDDI_VERSION=NTDDI_WIN7", 40 "_WIN32_WINNT=_WIN32_WINNT_WIN7", 41 "WINVER=_WIN32_WINNT_WIN7", 42 ] 43} 44 45if (libcxx_is_shared) { 46 _libcxx_target_type = "shared_library" 47} else { 48 _libcxx_target_type = "source_set" 49} 50target(_libcxx_target_type, "libc++") { 51 # Most things that need to depend on libc++ should do so via the implicit 52 # 'common_deps' dependency below. Some targets that package libc++.so may 53 # need to explicitly depend on libc++. 54 visibility = [ 55 "//build/config:common_deps", 56 "//third_party/catapult/devil:devil", 57 ] 58 if (is_linux) { 59 # This target packages libc++.so, so must have an explicit dependency on 60 # libc++. 61 visibility += 62 [ "//remoting/host/linux:remoting_me2me_host_copy_user_session" ] 63 } 64 if (libcxx_is_shared) { 65 no_default_deps = true 66 } 67 68 if (is_linux && !is_clang) { 69 libs = [ "atomic" ] 70 } 71 72 inputs = [ 73 "__assertion_handler", 74 "__config_site", 75 ] 76 77 # TODO(crbug.com/1458042): Move this build file to third_party/libc++/BUILD.gn 78 # once submodule migration is done. 79 sources = [ 80 "//third_party/libc++/src/src/algorithm.cpp", 81 "//third_party/libc++/src/src/any.cpp", 82 "//third_party/libc++/src/src/atomic.cpp", 83 "//third_party/libc++/src/src/barrier.cpp", 84 "//third_party/libc++/src/src/bind.cpp", 85 "//third_party/libc++/src/src/call_once.cpp", 86 "//third_party/libc++/src/src/charconv.cpp", 87 "//third_party/libc++/src/src/chrono.cpp", 88 "//third_party/libc++/src/src/condition_variable.cpp", 89 "//third_party/libc++/src/src/condition_variable_destructor.cpp", 90 "//third_party/libc++/src/src/error_category.cpp", 91 "//third_party/libc++/src/src/exception.cpp", 92 "//third_party/libc++/src/src/filesystem/directory_iterator.cpp", 93 "//third_party/libc++/src/src/filesystem/filesystem_error.cpp", 94 "//third_party/libc++/src/src/filesystem/operations.cpp", 95 "//third_party/libc++/src/src/filesystem/path.cpp", 96 "//third_party/libc++/src/src/functional.cpp", 97 "//third_party/libc++/src/src/future.cpp", 98 "//third_party/libc++/src/src/hash.cpp", 99 "//third_party/libc++/src/src/ios.cpp", 100 "//third_party/libc++/src/src/ios.instantiations.cpp", 101 "//third_party/libc++/src/src/iostream.cpp", 102 "//third_party/libc++/src/src/legacy_pointer_safety.cpp", 103 "//third_party/libc++/src/src/locale.cpp", 104 "//third_party/libc++/src/src/memory.cpp", 105 "//third_party/libc++/src/src/mutex.cpp", 106 "//third_party/libc++/src/src/mutex_destructor.cpp", 107 "//third_party/libc++/src/src/new_handler.cpp", 108 "//third_party/libc++/src/src/new_helpers.cpp", 109 "//third_party/libc++/src/src/optional.cpp", 110 "//third_party/libc++/src/src/random.cpp", 111 "//third_party/libc++/src/src/random_shuffle.cpp", 112 "//third_party/libc++/src/src/regex.cpp", 113 "//third_party/libc++/src/src/ryu/d2fixed.cpp", 114 "//third_party/libc++/src/src/ryu/d2s.cpp", 115 "//third_party/libc++/src/src/ryu/f2s.cpp", 116 "//third_party/libc++/src/src/shared_mutex.cpp", 117 "//third_party/libc++/src/src/stdexcept.cpp", 118 "//third_party/libc++/src/src/string.cpp", 119 "//third_party/libc++/src/src/strstream.cpp", 120 "//third_party/libc++/src/src/system_error.cpp", 121 "//third_party/libc++/src/src/thread.cpp", 122 "//third_party/libc++/src/src/typeinfo.cpp", 123 "//third_party/libc++/src/src/valarray.cpp", 124 "//third_party/libc++/src/src/variant.cpp", 125 "//third_party/libc++/src/src/vector.cpp", 126 "//third_party/libc++/src/src/verbose_abort.cpp", 127 ] 128 129 if (is_apple || (!is_asan && !is_tsan && !is_msan)) { 130 # In {a,t,m}san configurations, operator new and operator delete will be 131 # provided by the sanitizer runtime library. Since libc++ defines these 132 # symbols with weak linkage, and the *san runtime uses strong linkage, it 133 # should technically be OK to include this file, but it's removed to be 134 # explicit. 135 sources += [ "//third_party/libc++/src/src/new.cpp" ] 136 } 137 138 if (is_linux) { 139 # These sources are necessary for the Centipede fuzzer, 140 # which currently only needs to run on Linux. 141 sources += [ 142 "//third_party/libc++/src/src/filesystem/directory_entry.cpp", 143 "//third_party/libc++/src/src/filesystem/filesystem_clock.cpp", 144 ] 145 } 146 147 include_dirs = [ "//third_party/libc++/src/src" ] 148 if (is_win) { 149 sources += [ 150 "//third_party/libc++/src/src/support/win32/locale_win32.cpp", 151 "//third_party/libc++/src/src/support/win32/support.cpp", 152 "//third_party/libc++/src/src/support/win32/thread_win32.cpp", 153 ] 154 configs -= [ "//build/config/win:winver" ] 155 configs += [ ":winver" ] 156 if (libcxx_natvis_include) { 157 inputs += [ 158 # libc++.natvis listed as an input here instead of in 159 # //build/config/c++:runtime_library to prevent unnecessary size 160 # increase in generated build files. 161 "//build/config/c++/libc++.natvis", 162 ] 163 } 164 } 165 configs -= [ 166 "//build/config/compiler:chromium_code", 167 "//build/config/compiler:no_exceptions", 168 "//build/config/compiler:no_rtti", 169 "//build/config/coverage:default_coverage", 170 ] 171 if ((is_android || is_apple) && libcxx_is_shared) { 172 # Use libc++_chrome to avoid conflicting with system libc++ 173 output_name = "libc++_chrome" 174 if (is_android) { 175 # See crbug.com/1076244#c11 for more detail. 176 configs -= [ "//build/config/android:hide_all_but_jni_onload" ] 177 } 178 } 179 configs += [ 180 ":config", 181 "//build/config/compiler:no_chromium_code", 182 "//build/config/compiler:exceptions", 183 "//build/config/compiler:rtti", 184 ] 185 186 if (libcxx_is_shared && !is_win) { 187 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ] 188 configs += [ "//build/config/gcc:symbol_visibility_default" ] 189 } 190 191 defines = [] 192 193 if (!libcxx_is_shared) { 194 if (is_apple && is_clang) { 195 # We want operator new/delete to be private on Mac, but these functions 196 # are implicitly created by the compiler for each translation unit, as 197 # specified in the C++ spec 3.7.4p2, which makes them always have default 198 # visibility. This option is needed to force hidden visibility since 199 # -fvisibility=hidden doesn't have the desired effect. 200 cflags = [ "-fvisibility-global-new-delete=force-hidden" ] 201 } else { 202 defines += [ 203 # This resets the visibility to default only for the various 204 # flavors of operator new and operator delete. These symbols 205 # are weak and get overriden by Chromium-provided ones, but if 206 # these symbols had hidden visibility, this would make the 207 # Chromium symbols hidden too because elf visibility rules 208 # require that linkers use the least visible form when merging, 209 # and if this is hidden, then when we merge it with tcmalloc's 210 # operator new, hidden visibility would win. However, tcmalloc 211 # needs a visible operator new to also override operator new 212 # references from system libraries. 213 # TODO(lld): Ask lld for a --force-public-visibility flag or 214 # similar to that overrides the default elf merging rules, and 215 # make tcmalloc's gn config pass that to all its dependencies, 216 # then remove this override here. 217 "_LIBCPP_OVERRIDABLE_FUNC_VIS=__attribute__((__visibility__(\"default\")))", 218 ] 219 } 220 } 221 222 if (!is_win) { 223 defines += [ "LIBCXX_BUILDING_LIBCXXABI" ] 224 if (!export_libcxxabi_from_executables) { 225 deps = [ "//buildtools/third_party/libc++abi" ] 226 } 227 } 228} 229