Skip to content

Commit

Permalink
Merge Windows and Posix libc++ configs
Browse files Browse the repository at this point in the history
BUG=801780
R=thakis

Change-Id: I9ce7870d4205aedb02ca49a2483b7275b1c4b757
Reviewed-on: https://chromium-review.googlesource.com/c/1461335
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#631075}
  • Loading branch information
tanderson-google authored and Commit Bot committed Feb 12, 2019
1 parent 2e74dd6 commit 4c15f05
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 122 deletions.
115 changes: 115 additions & 0 deletions build/config/c++/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import("//build/config/c++/c++.gni")
import("//build/config/chrome_build.gni")
import("//buildtools/deps_revisions.gni")

assert(use_custom_libcxx, "should only be used if use_custom_libcxx is set")

declare_args() {
# lldb pretty printing only works when libc++ is built in the __1 (or __ndk1)
# namespaces. For pretty printing to work out-of-the-box on Mac (where lldb
# is primarily used), this flag is set to false to build with the __1
# namespace (to maintain ABI compatibility, this implies building without
# _LIBCPP_ABI_UNSTABLE). This is not necessary on non-component builds
# because we leave the ABI version set to __1 in that case because libc++
# symbols are not exported.
# TODO(thomasanderson): Set this to true by default once rL352899 is available
# in MacOS's lldb.
libcxx_abi_unstable = !(is_mac && is_debug && is_component_build)
}

# TODO(xiaohuic): https://crbug/917533 Crashes on internal ChromeOS build.
# Do unconditionally once the underlying problem is fixed.
if (is_chromeos && is_chrome_branded) {
libcxx_abi_unstable = false
}

# This is included by reference in the //build/config/compiler:runtime_library
# config that is applied to all targets. It is here to separate out the logic
# that is specific to libc++. Please see that target for advice on what should
# go in :runtime_library vs. :compiler.
config("runtime_library") {
cflags = []
cflags_cc = []
defines = []
ldflags = []
libs = []

if (libcxx_abi_unstable) {
defines += [ "_LIBCPP_ABI_UNSTABLE" ]
}

if (is_component_build) {
# In component builds, symbols from libc++.so are exported for all DSOs to
# use. If the system libc++ gets loaded (indirectly through a system
# library), then it will conflict with our libc++.so. Add a custom ABI
# version if we're building with _LIBCPP_ABI_UNSTABLE to avoid conflicts.
#
# Windows doesn't need to set _LIBCPP_ABI_VERSION since there's no system
# C++ library we could conflict with.
if (libcxx_abi_unstable && !is_win) {
defines += [ "_LIBCPP_ABI_VERSION=Cr" ]
}
} else {
# Don't leak any symbols on a static build.
defines += [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ]
if (!export_libcxxabi_from_executables) {
assert(!is_win, "don't use libcxxabi on win, see below")
defines += [ "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" ]
}
}

defines += [
"CR_LIBCXX_REVISION=$libcxx_svn_revision",
"CR_LIBCXXABI_REVISION=$libcxxabi_svn_revision",
"_LIBCPP_ENABLE_NODISCARD",
]

if (is_win) {
# Intentionally not using libc++abi on Windows because libc++abi only
# implements the Itanium C++ ABI, and not the Microsoft ABI which we use on
# Windows (and we need to use in order to interoperate correctly with COM
# among other things).
cflags_cc +=
[ "-I" + rebase_path("$libcxx_prefix/include", root_build_dir) ]

# Prevent libc++ from embedding linker flags to try to automatically link
# against its runtime library. This is unnecessary with our build system,
# and can also result in build failures if libc++'s name for a library
# does not match ours.
defines += [ "_LIBCPP_NO_AUTO_LINK" ]
} else {
cflags_cc += [
"-nostdinc++",
"-isystem" + rebase_path("$libcxx_prefix/include", root_build_dir),
"-isystem" + rebase_path("$libcxxabi_prefix/include", root_build_dir),
]

# Make sure we don't link against the system libstdc++ or libc++.
if (is_clang) {
# //build/config/android:runtime_library adds -nostdlib, which suppresses
# linking against all system libraries. -nostdlib++ would be redundant,
# and would generate an unused warning in this case.
if (!is_android) {
ldflags += [ "-nostdlib++" ]
}
} else {
# Gcc has a built-in abs() definition with default visibility.
# If it was not disabled, it would conflict with libc++'s abs()
# with hidden visibility.
cflags += [ "-fno-builtin-abs" ]

ldflags += [ "-nodefaultlibs" ]

# Unfortunately, there's no way to disable linking against just libc++
# (gcc doesn't have -notstdlib++:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83931); -nodefaultlibs
# removes all of the default libraries, so add back the ones that we need.
libs += [
"c",
"gcc_s",
"m",
"rt",
]
}
}
}
3 changes: 2 additions & 1 deletion build/config/c++/c++.gni
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ use_custom_libcxx = use_custom_libcxx && !is_nacl
# libc++abi needs to be exported from executables to be picked up by shared
# libraries on certian instrumented builds.
export_libcxxabi_from_executables =
use_custom_libcxx && !is_component_build && (is_asan || is_ubsan_vptr)
use_custom_libcxx && !is_win && !is_component_build &&
(is_asan || is_ubsan_vptr)
libcxx_is_shared = use_custom_libcxx && is_component_build

# On Android, many shared libraries get loaded from the context of a JRE. In
Expand Down
12 changes: 7 additions & 5 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1203,16 +1203,18 @@ config("assembler_debug_dir") {
# target wants the option regardless, put it in the compiler config.

config("runtime_library") {
defines = []
configs = []

# TODO(crbug.com/830987): Come up with a better name for is POSIX + Fuchsia
# configuration.
#
# The order of this config is important: it must appear before
# android:runtime_library. This is to ensure libc++ appears before
# libandroid_support in the -isystem include order. Otherwise, there will be
# build errors related to symbols declared in math.h.
if (use_custom_libcxx) {
configs += [ "//build/config/c++:runtime_library" ]
}

# TODO(crbug.com/830987): Come up with a better name for is POSIX + Fuchsia
# configuration.
if (is_posix || is_fuchsia) {
configs += [ "//build/config/posix:runtime_library" ]
}
Expand All @@ -1233,7 +1235,7 @@ config("runtime_library") {
}

if (is_component_build) {
defines += [ "COMPONENT_BUILD" ]
defines = [ "COMPONENT_BUILD" ]
}
}

Expand Down
88 changes: 0 additions & 88 deletions build/config/posix/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,11 @@
# 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/chrome_build.gni")
import("//build/config/clang/clang.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/sysroot.gni")
import("//build/toolchain/toolchain.gni")
import("//buildtools/deps_revisions.gni")

# This build configuration is used by both Fuchsia and POSIX systems.
assert(is_posix || is_fuchsia)

declare_args() {
# lldb pretty printing only works when libc++ is built in the __1 (or __ndk1)
# namespaces. For pretty printing to work out-of-the-box on Mac (where lldb
# is primarily used), this flag is set to false to build with the __1
# namespace (to maintain ABI compatibility, this implies building without
# _LIBCPP_ABI_UNSTABLE). This is not necessary on non-component builds
# because we leave the ABI version set to __1 in that case because libc++
# symbols are not exported.
# TODO(thomasanderson): Set this to true by default once rL352899 is available
# in MacOS's lldb.
libcxx_abi_unstable = !(is_mac && is_debug && is_component_build)
}

# TODO(xiaohuic): https://crbug/917533 Crashes on internal ChromeOS build.
# Do unconditionally once the underlying problem is fixed.
if (is_chromeos && is_chrome_branded) {
libcxx_abi_unstable = false
}

group("posix") {
visibility = [ "//:optimize_gn_gen" ]
}
Expand All @@ -50,68 +24,6 @@ config("runtime_library") {
cflags_objcc = []
defines = []
ldflags = []
lib_dirs = []
libs = []

if (use_custom_libcxx) {
if (libcxx_abi_unstable) {
defines += [ "_LIBCPP_ABI_UNSTABLE" ]
}

if (is_component_build) {
# In component builds, symbols from libc++.so are exported for all DSOs to
# use. If the system libc++ gets loaded (indirectly through a system
# library), then it will conflict with our libc++.so. Add a custom ABI
# version if we're building with _LIBCPP_ABI_UNSTABLE to avoid conflicts.
if (libcxx_abi_unstable) {
defines += [ "_LIBCPP_ABI_VERSION=Cr" ]
}
} else {
# Don't leak any symbols on a static build.
defines += [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ]
if (!export_libcxxabi_from_executables) {
defines += [ "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" ]
}
}
cflags_cc += [
"-nostdinc++",
"-isystem" + rebase_path("$libcxx_prefix/include", root_build_dir),
"-isystem" + rebase_path("$libcxxabi_prefix/include", root_build_dir),
]
defines += [
"CR_LIBCXX_REVISION=$libcxx_svn_revision",
"CR_LIBCXXABI_REVISION=$libcxxabi_svn_revision",
"_LIBCPP_ENABLE_NODISCARD",
]

# Make sure we don't link against libc++ or libstdc++.
if (is_clang) {
# //build/config/android:runtime_library adds -nostdlib, which suppresses
# linking against all system libraries. -nostdlib++ would be redundant,
# and would generate an unused warning in this case.
if (!is_android) {
ldflags += [ "-nostdlib++" ]
}
} else {
# Gcc has a built-in abs() definition with default visibility.
# If it was not disabled, it would conflict with libc++'s abs()
# with hidden visibility.
cflags += [ "-fno-builtin-abs" ]

ldflags += [ "-nodefaultlibs" ]

# Unfortunately, there's no way to disable linking against just libc++
# (gcc doesn't have -notstdlib++:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83931); -nodefaultlibs
# removes all of the default libraries, so add back the ones that we need.
libs += [
"c",
"gcc_s",
"m",
"rt",
]
}
}

if (!is_mac && !is_ios && sysroot != "") {
# Pass the sysroot to all C compiler variants, the assembler, and linker.
Expand Down
28 changes: 0 additions & 28 deletions build/config/win/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# 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/chrome_build.gni")
import("//build/config/clang/clang.gni")
import("//build/config/compiler/compiler.gni")
Expand All @@ -11,7 +10,6 @@ import("//build/config/win/visual_studio_version.gni")
import("//build/timestamp.gni")
import("//build/toolchain/goma.gni")
import("//build/toolchain/toolchain.gni")
import("//buildtools/deps_revisions.gni")

assert(is_win)

Expand Down Expand Up @@ -258,32 +256,6 @@ config("runtime_library") {
defines += [ "_USING_V110_SDK71_" ]
}

# TODO(thomasanderson): Move this into a target in //build/config/c++ and
# deduplicate with //build/config/posix/BUILD.gn.
if (use_custom_libcxx) {
cflags_cc +=
[ "-I" + rebase_path("$libcxx_prefix/include", root_build_dir) ]
if (!is_component_build) {
# Don't leak any symbols on a static build.
defines += [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ]
}

# Windows doesn't need to set _LIBCPP_ABI_VERSION since there's no system
# C++ library we could conflict with.
defines += [
"CR_LIBCXX_REVISION=$libcxx_svn_revision",
"CR_LIBCXXABI_REVISION=$libcxxabi_svn_revision",
"_LIBCPP_ABI_UNSTABLE",
"_LIBCPP_ENABLE_NODISCARD",

# Prevent libc++ from embedding linker flags to try to automatically link
# against its runtime library. This is unnecessary with our build system,
# and can also result in build failures if libc++'s name for a library
# does not match ours.
"_LIBCPP_NO_AUTO_LINK",
]
}

if (current_os == "winuwp") {
# When targeting Windows Runtime, certain compiler/linker flags are
# necessary.
Expand Down

0 comments on commit 4c15f05

Please sign in to comment.