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 = [ "__config_site" ] 73 74 # TODO(crbug.com/1458042): Move this build file to third_party/libc++/BUILD.gn once submodule migration is done 75 sources = [ 76 "//third_party/libc++/src/src/algorithm.cpp", 77 "//third_party/libc++/src/src/any.cpp", 78 "//third_party/libc++/src/src/atomic.cpp", 79 "//third_party/libc++/src/src/barrier.cpp", 80 "//third_party/libc++/src/src/bind.cpp", 81 "//third_party/libc++/src/src/call_once.cpp", 82 "//third_party/libc++/src/src/charconv.cpp", 83 "//third_party/libc++/src/src/chrono.cpp", 84 "//third_party/libc++/src/src/condition_variable.cpp", 85 "//third_party/libc++/src/src/condition_variable_destructor.cpp", 86 "//third_party/libc++/src/src/error_category.cpp", 87 "//third_party/libc++/src/src/exception.cpp", 88 "//third_party/libc++/src/src/filesystem/directory_iterator.cpp", 89 "//third_party/libc++/src/src/filesystem/filesystem_error.cpp", 90 "//third_party/libc++/src/src/filesystem/operations.cpp", 91 "//third_party/libc++/src/src/filesystem/path.cpp", 92 "//third_party/libc++/src/src/functional.cpp", 93 "//third_party/libc++/src/src/future.cpp", 94 "//third_party/libc++/src/src/hash.cpp", 95 "//third_party/libc++/src/src/ios.cpp", 96 "//third_party/libc++/src/src/ios.instantiations.cpp", 97 "//third_party/libc++/src/src/iostream.cpp", 98 "//third_party/libc++/src/src/legacy_pointer_safety.cpp", 99 "//third_party/libc++/src/src/locale.cpp", 100 "//third_party/libc++/src/src/memory.cpp", 101 "//third_party/libc++/src/src/mutex.cpp", 102 "//third_party/libc++/src/src/mutex_destructor.cpp", 103 "//third_party/libc++/src/src/new_handler.cpp", 104 "//third_party/libc++/src/src/new_helpers.cpp", 105 "//third_party/libc++/src/src/optional.cpp", 106 "//third_party/libc++/src/src/random.cpp", 107 "//third_party/libc++/src/src/random_shuffle.cpp", 108 "//third_party/libc++/src/src/regex.cpp", 109 "//third_party/libc++/src/src/ryu/d2fixed.cpp", 110 "//third_party/libc++/src/src/ryu/d2s.cpp", 111 "//third_party/libc++/src/src/ryu/f2s.cpp", 112 "//third_party/libc++/src/src/shared_mutex.cpp", 113 "//third_party/libc++/src/src/stdexcept.cpp", 114 "//third_party/libc++/src/src/string.cpp", 115 "//third_party/libc++/src/src/strstream.cpp", 116 "//third_party/libc++/src/src/system_error.cpp", 117 "//third_party/libc++/src/src/thread.cpp", 118 "//third_party/libc++/src/src/typeinfo.cpp", 119 "//third_party/libc++/src/src/valarray.cpp", 120 "//third_party/libc++/src/src/variant.cpp", 121 "//third_party/libc++/src/src/vector.cpp", 122 "//third_party/libc++/src/src/verbose_abort.cpp", 123 ] 124 125 if (is_apple || (!is_asan && !is_tsan && !is_msan)) { 126 # In {a,t,m}san configurations, operator new and operator delete will be 127 # provided by the sanitizer runtime library. Since libc++ defines these 128 # symbols with weak linkage, and the *san runtime uses strong linkage, it 129 # should technically be OK to include this file, but it's removed to be 130 # explicit. 131 sources += [ "//third_party/libc++/src/src/new.cpp" ] 132 } 133 134 if (is_linux) { 135 # These sources are necessary for the Centipede fuzzer, 136 # which currently only needs to run on Linux. 137 sources += [ 138 "//third_party/libc++/src/src/filesystem/directory_entry.cpp", 139 "//third_party/libc++/src/src/filesystem/filesystem_clock.cpp", 140 ] 141 } 142 143 include_dirs = [ "//third_party/libc++/src/src" ] 144 if (is_win) { 145 sources += [ 146 "//third_party/libc++/src/src/support/win32/locale_win32.cpp", 147 "//third_party/libc++/src/src/support/win32/support.cpp", 148 "//third_party/libc++/src/src/support/win32/thread_win32.cpp", 149 ] 150 configs -= [ "//build/config/win:winver" ] 151 configs += [ ":winver" ] 152 if (libcxx_natvis_include) { 153 inputs += [ 154 # libc++.natvis listed as an input here instead of in 155 # //build/config/c++:runtime_library to prevent unnecessary size 156 # increase in generated build files. 157 "//build/config/c++/libc++.natvis", 158 ] 159 } 160 } 161 configs -= [ 162 "//build/config/compiler:chromium_code", 163 "//build/config/compiler:no_exceptions", 164 "//build/config/compiler:no_rtti", 165 "//build/config/coverage:default_coverage", 166 ] 167 if ((is_android || is_apple) && libcxx_is_shared) { 168 # Use libc++_chrome to avoid conflicting with system libc++ 169 output_name = "libc++_chrome" 170 if (is_android) { 171 # See crbug.com/1076244#c11 for more detail. 172 configs -= [ "//build/config/android:hide_all_but_jni_onload" ] 173 } 174 } 175 configs += [ 176 ":config", 177 "//build/config/compiler:no_chromium_code", 178 "//build/config/compiler:exceptions", 179 "//build/config/compiler:rtti", 180 ] 181 182 if (libcxx_is_shared && !is_win) { 183 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ] 184 configs += [ "//build/config/gcc:symbol_visibility_default" ] 185 } 186 187 defines = [] 188 189 if (!libcxx_is_shared) { 190 if (is_apple && is_clang) { 191 # We want operator new/delete to be private on Mac, but these functions 192 # are implicitly created by the compiler for each translation unit, as 193 # specified in the C++ spec 3.7.4p2, which makes them always have default 194 # visibility. This option is needed to force hidden visibility since 195 # -fvisibility=hidden doesn't have the desired effect. 196 cflags = [ "-fvisibility-global-new-delete-hidden" ] 197 } else { 198 defines += [ 199 # This resets the visibility to default only for the various 200 # flavors of operator new and operator delete. These symbols 201 # are weak and get overriden by Chromium-provided ones, but if 202 # these symbols had hidden visibility, this would make the 203 # Chromium symbols hidden too because elf visibility rules 204 # require that linkers use the least visible form when merging, 205 # and if this is hidden, then when we merge it with tcmalloc's 206 # operator new, hidden visibility would win. However, tcmalloc 207 # needs a visible operator new to also override operator new 208 # references from system libraries. 209 # TODO(lld): Ask lld for a --force-public-visibility flag or 210 # similar to that overrides the default elf merging rules, and 211 # make tcmalloc's gn config pass that to all its dependencies, 212 # then remove this override here. 213 "_LIBCPP_OVERRIDABLE_FUNC_VIS=__attribute__((__visibility__(\"default\")))", 214 ] 215 } 216 } 217 218 if (!is_win) { 219 defines += [ "LIBCXX_BUILDING_LIBCXXABI" ] 220 if (!export_libcxxabi_from_executables) { 221 deps = [ "//buildtools/third_party/libc++abi" ] 222 } 223 } 224} 225