Skip to content

Commit

Permalink
Fix out-dated libc++
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Mar 9, 2024
1 parent c98d654 commit bc5092d
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 15 deletions.
24 changes: 14 additions & 10 deletions buildtools/third_party/libc++/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import("//build/config/sanitizers/sanitizers.gni")
import("//build/toolchain/toolchain.gni")

# Used by libc++ and libc++abi.
# See //build/config/c++:runtime_library for the config used by users of libc++.
config("config") {
cflags = [ "-fstrict-aliasing" ]
if (is_win) {
Expand Down Expand Up @@ -44,14 +45,19 @@ config("winver") {
if (libcxx_is_shared) {
_libcxx_target_type = "shared_library"
} else {
_libcxx_target_type = "source_set"
if (is_win) {
_libcxx_target_type = "source_set"
} else {
_libcxx_target_type = "static_library"
}
}
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",
"//electron:libcxx_objects_zip",
"//third_party/catapult/devil:devil",
]
if (is_linux) {
Expand All @@ -68,7 +74,10 @@ target(_libcxx_target_type, "libc++") {
libs = [ "atomic" ]
}

inputs = [ "__config_site" ]
inputs = [
"__assertion_handler",
"__config_site",
]

# TODO(crbug.com/1458042): Move this build file to third_party/libc++/BUILD.gn once submodule migration is done
sources = [
Expand All @@ -77,10 +86,12 @@ target(_libcxx_target_type, "libc++") {
"//third_party/libc++/src/src/atomic.cpp",
"//third_party/libc++/src/src/barrier.cpp",
"//third_party/libc++/src/src/bind.cpp",
"//third_party/libc++/src/src/call_once.cpp",
"//third_party/libc++/src/src/charconv.cpp",
"//third_party/libc++/src/src/chrono.cpp",
"//third_party/libc++/src/src/condition_variable.cpp",
"//third_party/libc++/src/src/condition_variable_destructor.cpp",
"//third_party/libc++/src/src/error_category.cpp",
"//third_party/libc++/src/src/exception.cpp",
"//third_party/libc++/src/src/filesystem/directory_iterator.cpp",
"//third_party/libc++/src/src/filesystem/filesystem_error.cpp",
Expand Down Expand Up @@ -137,13 +148,6 @@ target(_libcxx_target_type, "libc++") {
]
}

if (enable_iterator_debugging) {
sources += [
"//third_party/libc++/src/src/debug.cpp",
"//third_party/libc++/src/src/legacy_debug_handler.cpp",
]
}

include_dirs = [ "//third_party/libc++/src/src" ]
if (is_win) {
sources += [
Expand Down Expand Up @@ -197,7 +201,7 @@ target(_libcxx_target_type, "libc++") {
# 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" ]
cflags = [ "-fvisibility-global-new-delete=force-hidden" ]
} else {
defines += [
# This resets the visibility to default only for the various
Expand Down
23 changes: 23 additions & 0 deletions buildtools/third_party/libc++/__assertion_handler
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___ASSERTION_HANDLER
#define _LIBCPP___ASSERTION_HANDLER

#include <__config>
#include <__verbose_abort>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

// TODO(hardening): in production, trap rather than abort.
#define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_VERBOSE_ABORT("%s", message)

#endif // _LIBCPP___ASSERTION_HANDLER
16 changes: 15 additions & 1 deletion buildtools/third_party/libc++/__config_site
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// limit for PDBs (https://crbug.com/1327710#c5). To fix this, we set
// _LIBCPP_ABI_NAMESPACE to a shorter value.
#define _LIBCPP_ABI_NAMESPACE __Cr
#define _LIBCPP_ABI_VERSION 2

/* #undef _LIBCPP_ABI_FORCE_ITANIUM */
/* #undef _LIBCPP_ABI_FORCE_MICROSOFT */
Expand All @@ -33,9 +32,21 @@
/* #undef _LIBCPP_HAS_NO_LOCALIZATION */
/* #undef _LIBCPP_HAS_NO_WIDE_CHARACTERS */

// TODO(thakis): Is this right?
/* #undef _LIBCPP_HAS_NO_STD_MODULES */

// TODO(thakis): Is this right?
/* #undef _LIBCPP_HAS_NO_TIME_ZONE_DATABASE */

#define _LIBCPP_INSTRUMENTED_WITH_ASAN

// PSTL backends
/* #undef _LIBCPP_PSTL_CPU_BACKEND_SERIAL */
#if defined(__APPLE__)
#define _LIBCPP_PSTL_CPU_BACKEND_LIBDISPATCH
#else
#define _LIBCPP_PSTL_CPU_BACKEND_THREAD
#endif

// Settings below aren't part of __config_site upstream.
// We set them here since we want them to take effect everywhere,
Expand Down Expand Up @@ -65,4 +76,7 @@
#define _LIBCPP_HAS_NO_INT128
#endif

// TODO(thakis): Remove this after LLVM 19's libc++ is rolled in.
#define _LIBCPP_CHAR_TRAITS_REMOVE_BASE_SPECIALIZATION

#endif // _LIBCPP_CONFIG_SITE
2 changes: 1 addition & 1 deletion buildtools/third_party/libc++abi/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import("//build/config/android/config.gni")
import("//build/config/c++/c++.gni")
import("//build/config/unwind.gni")

source_set("libc++abi") {
static_library("libc++abi") {
if (export_libcxxabi_from_executables) {
visibility = [ "//build/config:executable_deps" ]
} else {
Expand Down
7 changes: 7 additions & 0 deletions examples/libcxx/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use_chromium_config = true

default_args = {
is_clang = true
use_xcode_clang = false
use_custom_libcxx = true
}
10 changes: 10 additions & 0 deletions examples/libcxx/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
executable("test") {
sources = [
"main.cc",
]

deps = [
"//build:branding_buildflags",
"//build:chromeos_buildflags",
]
}
6 changes: 6 additions & 0 deletions examples/libcxx/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>

int main(int argc, const char *argv[]) {
printf("Passed\n");
return 0;
}
1 change: 1 addition & 0 deletions scripts/create_dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const files =
searchFiles('third_party/libunwind/src/include'))
addFileToZip(gnzip, 'buildtools/deps_revisions.gni', '.')
addFileToZip(gnzip, 'buildtools/third_party/eu-strip/bin/eu-strip', '.')
addFileToZip(gnzip, 'buildtools/third_party/libc++/__assertion_handler', '.')
addFileToZip(gnzip, 'buildtools/third_party/libc++/__config_site', '.')
addFileToZip(gnzip, 'buildtools/third_party/libc++/BUILD.gn', '.')
addFileToZip(gnzip, 'buildtools/third_party/libc++abi/cxa_demangle_stub.cc', '.')
Expand Down
4 changes: 4 additions & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ function runEachTest(project, projectPath) {
const outdir = path.resolve('out', 'Test')
fs.emptyDirSync(outdir)

if (projectPath.endsWith('libcxx')) {
execSync(`python3 ${path.join(tmppath, 'gn/tools/clang/scripts/update.py')}`)
}

const gn = path.join(tmppath, 'gn', 'gn')
execSync(`${gn} gen ${outdir}`, {cwd: projectPath})

Expand Down
2 changes: 1 addition & 1 deletion third_party/libc++/src
Submodule src updated from 84fb80 to b5fe27
2 changes: 1 addition & 1 deletion third_party/libc++abi/src
Submodule src updated from 6a8358 to 204dea
2 changes: 1 addition & 1 deletion third_party/libunwind/src
Submodule src updated from 76e621 to 8bad7b

0 comments on commit bc5092d

Please sign in to comment.