# Copyright 2015 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import("//build/config/c++/c++.gni") import("//build/config/sanitizers/sanitizers.gni") import("//build/toolchain/toolchain.gni") # Used by libc++ and libc++abi. config("config") { cflags = [ "-fstrict-aliasing" ] if (is_win) { cflags += [ # libc++ wants to redefine the macros WIN32_LEAN_AND_MEAN and _CRT_RAND_S # in its implementation. "-Wno-macro-redefined", ] cflags_cc = [ # We want to use a uniform C++ version across all of chromium, but # upstream libc++ requires C++20 so we have to make an exception here. # No other target should override the default -std= flag. "-std:c++20", ] } else { cflags += [ "-fPIC" ] cflags_cc = [ "-std=c++20" ] } defines = [ "_LIBCPP_BUILDING_LIBRARY" ] } # Explicitly set version macros to Windows 7 to prevent libc++ from adding a # hard dependency on GetSystemTimePreciseAsFileTime, which was introduced in # Windows 8. config("winver") { defines = [ "NTDDI_VERSION=NTDDI_WIN7", "_WIN32_WINNT=_WIN32_WINNT_WIN7", "WINVER=_WIN32_WINNT_WIN7", ] } if (libcxx_is_shared) { _libcxx_target_type = "shared_library" } else { _libcxx_target_type = "source_set" } target(_libcxx_target_type, "libc++") { # Most things that need to depend on libc++ should do so via the implicit # 'common_deps' dependency below. Some targets that package libc++.so may # need to explicitly depend on libc++. visibility = [ "//build/config:common_deps", "//third_party/catapult/devil:devil", ] if (is_linux) { # This target packages libc++.so, so must have an explicit dependency on # libc++. visibility += [ "//remoting/host/linux:remoting_me2me_host_copy_user_session" ] } if (libcxx_is_shared) { no_default_deps = true } if (is_linux && !is_clang) { libs = [ "atomic" ] } inputs = [ "__config_site" ] sources = [ "trunk/src/algorithm.cpp", "trunk/src/any.cpp", "trunk/src/atomic.cpp", "trunk/src/barrier.cpp", "trunk/src/bind.cpp", "trunk/src/charconv.cpp", "trunk/src/chrono.cpp", "trunk/src/condition_variable.cpp", "trunk/src/condition_variable_destructor.cpp", "trunk/src/exception.cpp", "trunk/src/format.cpp", "trunk/src/functional.cpp", "trunk/src/future.cpp", "trunk/src/hash.cpp", "trunk/src/ios.cpp", "trunk/src/ios.instantiations.cpp", "trunk/src/iostream.cpp", "trunk/src/legacy_pointer_safety.cpp", "trunk/src/locale.cpp", "trunk/src/memory.cpp", "trunk/src/mutex.cpp", "trunk/src/mutex_destructor.cpp", "trunk/src/new.cpp", "trunk/src/optional.cpp", "trunk/src/random.cpp", "trunk/src/random_shuffle.cpp", "trunk/src/regex.cpp", "trunk/src/ryu/d2fixed.cpp", "trunk/src/ryu/d2s.cpp", "trunk/src/ryu/f2s.cpp", "trunk/src/shared_mutex.cpp", "trunk/src/stdexcept.cpp", "trunk/src/string.cpp", "trunk/src/strstream.cpp", "trunk/src/system_error.cpp", "trunk/src/thread.cpp", "trunk/src/typeinfo.cpp", "trunk/src/utility.cpp", "trunk/src/valarray.cpp", "trunk/src/variant.cpp", "trunk/src/vector.cpp", "trunk/src/verbose_abort.cpp", ] if (enable_iterator_debugging) { sources += [ "trunk/src/debug.cpp", "trunk/src/legacy_debug_handler.cpp", ] } include_dirs = [ "trunk/src" ] if (is_win) { sources += [ "trunk/src/support/win32/locale_win32.cpp", "trunk/src/support/win32/support.cpp", "trunk/src/support/win32/thread_win32.cpp", ] configs -= [ "//build/config/win:winver" ] configs += [ ":winver" ] if (libcxx_natvis_include) { inputs += [ # libc++.natvis listed as an input here instead of in # //build/config/c++:runtime_library to prevent unnecessary size # increase in generated build files. "//build/config/c++/libc++.natvis", ] } } configs -= [ "//build/config/compiler:chromium_code", "//build/config/compiler:no_exceptions", "//build/config/compiler:no_rtti", "//build/config/coverage:default_coverage", ] if ((is_android || is_apple) && libcxx_is_shared) { # Use libc++_chrome to avoid conflicting with system libc++ output_name = "libc++_chrome" if (is_android) { # See crbug.com/1076244#c11 for more detail. configs -= [ "//build/config/android:hide_all_but_jni_onload" ] } } configs += [ ":config", "//build/config/compiler:no_chromium_code", "//build/config/compiler:exceptions", "//build/config/compiler:rtti", ] if (libcxx_is_shared && !is_win) { configs -= [ "//build/config/gcc:symbol_visibility_hidden" ] configs += [ "//build/config/gcc:symbol_visibility_default" ] } defines = [] if (!libcxx_is_shared) { if (is_apple && is_clang) { # We want operator new/delete to be private on Mac, but these functions # are implicitly created by the compiler for each translation unit, as # specified in the C++ spec 3.7.4p2, which makes them always have default # visibility. This option is needed to force hidden visibility since # -fvisibility=hidden doesn't have the desired effect. cflags = [ "-fvisibility-global-new-delete-hidden" ] } else { defines += [ # This resets the visibility to default only for the various # flavors of operator new and operator delete. These symbols # are weak and get overriden by Chromium-provided ones, but if # these symbols had hidden visibility, this would make the # Chromium symbols hidden too because elf visibility rules # require that linkers use the least visible form when merging, # and if this is hidden, then when we merge it with tcmalloc's # operator new, hidden visibility would win. However, tcmalloc # needs a visible operator new to also override operator new # references from system libraries. # TODO(lld): Ask lld for a --force-public-visibility flag or # similar to that overrides the default elf merging rules, and # make tcmalloc's gn config pass that to all its dependencies, # then remove this override here. "_LIBCPP_OVERRIDABLE_FUNC_VIS=__attribute__((__visibility__(\"default\")))", ] } } if (!is_apple && (is_asan || is_tsan || is_msan)) { # In {a,t,m}san configurations, operator new and operator delete will be # provided by the sanitizer runtime library. Since libc++ defines these # symbols with weak linkage, and the *san runtime uses strong linkage, it # should technically be OK to omit this, but it's added to be explicit. defines += [ "_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS" ] } if (!is_win) { defines += [ "LIBCXX_BUILDING_LIBCXXABI" ] if (!export_libcxxabi_from_executables) { deps = [ "//buildtools/third_party/libc++abi" ] } } }