From bc5092d6e2a333c4bb7ca3add5ffcd8e7c6da1f1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 9 Mar 2024 20:04:27 +0900 Subject: [PATCH] Fix out-dated libc++ --- buildtools/third_party/libc++/BUILD.gn | 24 +++++++++++-------- .../third_party/libc++/__assertion_handler | 23 ++++++++++++++++++ buildtools/third_party/libc++/__config_site | 16 ++++++++++++- buildtools/third_party/libc++abi/BUILD.gn | 2 +- examples/libcxx/.gn | 7 ++++++ examples/libcxx/BUILD.gn | 10 ++++++++ examples/libcxx/main.cc | 6 +++++ scripts/create_dist.js | 1 + scripts/test.js | 4 ++++ third_party/libc++/src | 2 +- third_party/libc++abi/src | 2 +- third_party/libunwind/src | 2 +- 12 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 buildtools/third_party/libc++/__assertion_handler create mode 100644 examples/libcxx/.gn create mode 100644 examples/libcxx/BUILD.gn create mode 100644 examples/libcxx/main.cc diff --git a/buildtools/third_party/libc++/BUILD.gn b/buildtools/third_party/libc++/BUILD.gn index 448459e..21b1a75 100644 --- a/buildtools/third_party/libc++/BUILD.gn +++ b/buildtools/third_party/libc++/BUILD.gn @@ -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) { @@ -44,7 +45,11 @@ 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 @@ -52,6 +57,7 @@ target(_libcxx_target_type, "libc++") { # need to explicitly depend on libc++. visibility = [ "//build/config:common_deps", + "//electron:libcxx_objects_zip", "//third_party/catapult/devil:devil", ] if (is_linux) { @@ -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 = [ @@ -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", @@ -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 += [ @@ -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 diff --git a/buildtools/third_party/libc++/__assertion_handler b/buildtools/third_party/libc++/__assertion_handler new file mode 100644 index 0000000..111d305 --- /dev/null +++ b/buildtools/third_party/libc++/__assertion_handler @@ -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 diff --git a/buildtools/third_party/libc++/__config_site b/buildtools/third_party/libc++/__config_site index 54e6b7e..cc81747 100644 --- a/buildtools/third_party/libc++/__config_site +++ b/buildtools/third_party/libc++/__config_site @@ -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 */ @@ -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, @@ -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 diff --git a/buildtools/third_party/libc++abi/BUILD.gn b/buildtools/third_party/libc++abi/BUILD.gn index b5c15a0..f1f9842 100644 --- a/buildtools/third_party/libc++abi/BUILD.gn +++ b/buildtools/third_party/libc++abi/BUILD.gn @@ -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 { diff --git a/examples/libcxx/.gn b/examples/libcxx/.gn new file mode 100644 index 0000000..c58076b --- /dev/null +++ b/examples/libcxx/.gn @@ -0,0 +1,7 @@ +use_chromium_config = true + +default_args = { + is_clang = true + use_xcode_clang = false + use_custom_libcxx = true +} diff --git a/examples/libcxx/BUILD.gn b/examples/libcxx/BUILD.gn new file mode 100644 index 0000000..4d61123 --- /dev/null +++ b/examples/libcxx/BUILD.gn @@ -0,0 +1,10 @@ +executable("test") { + sources = [ + "main.cc", + ] + + deps = [ + "//build:branding_buildflags", + "//build:chromeos_buildflags", + ] +} diff --git a/examples/libcxx/main.cc b/examples/libcxx/main.cc new file mode 100644 index 0000000..510d4a7 --- /dev/null +++ b/examples/libcxx/main.cc @@ -0,0 +1,6 @@ +#include + +int main(int argc, const char *argv[]) { + printf("Passed\n"); + return 0; +} diff --git a/scripts/create_dist.js b/scripts/create_dist.js index de70f7a..bb924e9 100755 --- a/scripts/create_dist.js +++ b/scripts/create_dist.js @@ -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', '.') diff --git a/scripts/test.js b/scripts/test.js index 66de2b2..2093c80 100755 --- a/scripts/test.js +++ b/scripts/test.js @@ -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}) diff --git a/third_party/libc++/src b/third_party/libc++/src index 84fb809..b5fe27d 160000 --- a/third_party/libc++/src +++ b/third_party/libc++/src @@ -1 +1 @@ -Subproject commit 84fb809dd6dae36d556dc0bb702c6cc2ce9d4b80 +Subproject commit b5fe27de93814d35a026f7b6ff46a82045682e89 diff --git a/third_party/libc++abi/src b/third_party/libc++abi/src index 6a8358a..204deaa 160000 --- a/third_party/libc++abi/src +++ b/third_party/libc++abi/src @@ -1 +1 @@ -Subproject commit 6a8358a1423aa37f33d87b300b634c067b2741c1 +Subproject commit 204deaa9c53f76d6f23e0d119fc0110adc3ea6f2 diff --git a/third_party/libunwind/src b/third_party/libunwind/src index 76e621a..8bad7bd 160000 --- a/third_party/libunwind/src +++ b/third_party/libunwind/src @@ -1 +1 @@ -Subproject commit 76e621a89787516da745489245d8b65a48ad60d8 +Subproject commit 8bad7bd6ec30f94bce82f7cb5b58ecbd6ce02996