From abbc0f332115264f0165722711bbd29ee15e7701 Mon Sep 17 00:00:00 2001 From: Primiano Tucci Date: Wed, 15 May 2024 19:15:00 +0100 Subject: [PATCH] Uprev libcxx Catch up with chromium's latest libcxx. Bug: https://github.com/llvm/llvm-project/pull/87111 Change-Id: I1d8d1c051feeca592ec064c715106d0b70acfb9e --- buildtools/BUILD.gn | 30 +++++++++-- buildtools/libcxx_config/__assertion_handler | 16 ++++++ buildtools/libcxx_config/__config_site | 52 ++++++++++++++++++- gn/perfetto.gni | 4 +- include/perfetto/ext/base/small_set.h | 4 +- include/perfetto/profiling/parse_smaps.h | 1 + python/generators/diff_tests/testing.py | 4 +- .../packages_list/packages_list_parser.cc | 2 + .../diff_tests/parser/profiling/tests.py | 2 +- .../stdlib/prelude/pprof_functions_tests.py | 2 +- tools/install-build-deps | 10 ++-- 11 files changed, 110 insertions(+), 17 deletions(-) create mode 100644 buildtools/libcxx_config/__assertion_handler diff --git a/buildtools/BUILD.gn b/buildtools/BUILD.gn index 07c6e217ea..ae25789a62 100644 --- a/buildtools/BUILD.gn +++ b/buildtools/BUILD.gn @@ -876,7 +876,10 @@ if (use_custom_libcxx) { libs = [ "atomic" ] } - inputs = [ "libcxx_config/__config_site" ] + inputs = [ + "libcxx_config/__assertion_handler", + "libcxx_config/__config_site", + ] sources = [ "libcxx/src/algorithm.cpp", @@ -884,12 +887,17 @@ if (use_custom_libcxx) { "libcxx/src/atomic.cpp", "libcxx/src/barrier.cpp", "libcxx/src/bind.cpp", + "libcxx/src/call_once.cpp", "libcxx/src/charconv.cpp", "libcxx/src/chrono.cpp", "libcxx/src/condition_variable.cpp", "libcxx/src/condition_variable_destructor.cpp", + "libcxx/src/error_category.cpp", "libcxx/src/exception.cpp", - "libcxx/src/format.cpp", + "libcxx/src/filesystem/directory_iterator.cpp", + "libcxx/src/filesystem/filesystem_error.cpp", + "libcxx/src/filesystem/operations.cpp", + "libcxx/src/filesystem/path.cpp", "libcxx/src/functional.cpp", "libcxx/src/future.cpp", "libcxx/src/hash.cpp", @@ -901,7 +909,8 @@ if (use_custom_libcxx) { "libcxx/src/memory.cpp", "libcxx/src/mutex.cpp", "libcxx/src/mutex_destructor.cpp", - "libcxx/src/new.cpp", + "libcxx/src/new_handler.cpp", + "libcxx/src/new_helpers.cpp", "libcxx/src/optional.cpp", "libcxx/src/random.cpp", "libcxx/src/random_shuffle.cpp", @@ -916,12 +925,23 @@ if (use_custom_libcxx) { "libcxx/src/system_error.cpp", "libcxx/src/thread.cpp", "libcxx/src/typeinfo.cpp", - "libcxx/src/utility.cpp", "libcxx/src/valarray.cpp", "libcxx/src/variant.cpp", "libcxx/src/vector.cpp", "libcxx/src/verbose_abort.cpp", ] + if (!using_sanitizer) { + # 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 include this file, but it's removed to be + # explicit. + # We need using_sanitizer rather than is_asan || is_msan ... because in + # perfetto, when cross-compiling, we build only targets with sanitizers, + # but not host artifacts, and using_sanitizer is only true for the + # target toolchain, while is_asan is globally true on all toolchains. + sources += [ "libcxx/src/new.cpp" ] + } include_dirs = [ "libcxx/src" ] if (is_win) { @@ -1543,7 +1563,7 @@ source_set("llvm_demangle") { "llvm-project/llvm/include/llvm/Demangle/ItaniumDemangle.h", "llvm-project/llvm/include/llvm/Demangle/MicrosoftDemangle.h", "llvm-project/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h", - "llvm-project/llvm/include/llvm/Demangle/StringView.h", + "llvm-project/llvm/include/llvm/Demangle/StringViewExtras.h", "llvm-project/llvm/include/llvm/Demangle/Utility.h", "llvm-project/llvm/lib/Demangle/DLangDemangle.cpp", "llvm-project/llvm/lib/Demangle/Demangle.cpp", diff --git a/buildtools/libcxx_config/__assertion_handler b/buildtools/libcxx_config/__assertion_handler new file mode 100644 index 0000000000..5d997d0b64 --- /dev/null +++ b/buildtools/libcxx_config/__assertion_handler @@ -0,0 +1,16 @@ +// From chromium's buildtools/third_party/libc++/__assertion_handler + +#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/libcxx_config/__config_site b/buildtools/libcxx_config/__config_site index 2df8632ec4..dd396f0a7a 100644 --- a/buildtools/libcxx_config/__config_site +++ b/buildtools/libcxx_config/__config_site @@ -1,3 +1,5 @@ +// From chromium's buildtools/third_party/libc++/__config_site + #ifndef _LIBCPP_CONFIG_SITE #define _LIBCPP_CONFIG_SITE @@ -11,7 +13,8 @@ // on Windows, the increase is great enough that we go above the 4GB size // 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_NAMESPACE __Cr + #define _LIBCPP_ABI_VERSION 2 /* #undef _LIBCPP_ABI_FORCE_ITANIUM */ @@ -27,12 +30,37 @@ #define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS /* #undef _LIBCPP_NO_VCRUNTIME */ /* #undef _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION */ -/* #undef _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY */ +/* #undef _LIBCPP_HAS_NO_FILESYSTEM */ /* #undef _LIBCPP_HAS_PARALLEL_ALGORITHMS */ /* #undef _LIBCPP_HAS_NO_RANDOM_DEVICE */ /* #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_BACKEND_SERIAL */ +#if defined(__APPLE__) +#define _LIBCPP_PSTL_BACKEND_LIBDISPATCH +#else +#define _LIBCPP_PSTL_BACKEND_STD_THREAD +#endif + +// PSTL backends, old spelling +// TODO(thakis): Remove these after the next libc++ roll is in. +/* #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, // unconditionally. @@ -45,4 +73,24 @@ #define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES +// Don't add ABI tags to libc++ symbols. ABI tags increase mangled name sizes. +// This only exists to allow multiple // libc++ versions to be linked into a +// binary, which Chrome doesn't do. +#define _LIBCPP_NO_ABI_TAG + +// Explicitly define _LIBCPP_VERBOSE_ABORT(...) to call the termination +// function because by default, this macro will does not call the verbose +// termination function on Apple platforms. +#define _LIBCPP_VERBOSE_ABORT(...) ::std::__libcpp_verbose_abort(__VA_ARGS__) + +// TODO(crbug.com/40272953) Link against compiler-rt's builtins library to +// enable 128-arithmetic. +#if defined(_WIN32) +#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 + +#define _LIBCPP_HARDENING_MODE_DEFAULT _LIBCPP_HARDENING_MODE_NONE #endif // _LIBCPP_CONFIG_SITE diff --git a/gn/perfetto.gni b/gn/perfetto.gni index 8cd9b086cb..c0aed1cd09 100644 --- a/gn/perfetto.gni +++ b/gn/perfetto.gni @@ -312,8 +312,10 @@ declare_args() { # Enables function name demangling using sources from llvm. Otherwise # trace_processor falls back onto using the c++ runtime demangler, which # typically handles only itanium mangling. + # llvm-demangle is incompatible with GCC and can be used only when building + # with clang. enable_perfetto_llvm_demangle = - enable_perfetto_trace_processor && perfetto_build_standalone + is_clang && enable_perfetto_trace_processor && perfetto_build_standalone # Enables gRPC in the Perfetto codebase. gRPC significantly increases build # times and the general footprint of Perfetto. As it only required for diff --git a/include/perfetto/ext/base/small_set.h b/include/perfetto/ext/base/small_set.h index db057a0e8c..5d8d8bcf18 100644 --- a/include/perfetto/ext/base/small_set.h +++ b/include/perfetto/ext/base/small_set.h @@ -49,7 +49,9 @@ class SmallSet { } const_iterator begin() const { return arr_.cbegin(); } - const_iterator end() const { return arr_.cbegin() + filled_; } + const_iterator end() const { + return arr_.cbegin() + static_cast(filled_); + } size_t size() const { return filled_; } private: diff --git a/include/perfetto/profiling/parse_smaps.h b/include/perfetto/profiling/parse_smaps.h index 9623c38105..80e7e6cf07 100644 --- a/include/perfetto/profiling/parse_smaps.h +++ b/include/perfetto/profiling/parse_smaps.h @@ -23,6 +23,7 @@ #include #include +#include #include #include diff --git a/python/generators/diff_tests/testing.py b/python/generators/diff_tests/testing.py index 515f95641a..b90e4cd4a1 100644 --- a/python/generators/diff_tests/testing.py +++ b/python/generators/diff_tests/testing.py @@ -270,12 +270,14 @@ def PrintProfileProto(profile): locations = {l.id: l for l in profile.location} functions = {f.id: f for f in profile.function} samples = [] + # Strips trailing annotations like (.__uniq.1657) from the function name. + filter_fname = lambda x: re.sub(' [(\[].*?uniq.*?[)\]]$', '', x) for s in profile.sample: stack = [] for location in [locations[id] for id in s.location_id]: for function in [functions[l.function_id] for l in location.line]: stack.append("{name} ({address})".format( - name=profile.string_table[function.name], + name=filter_fname(profile.string_table[function.name]), address=hex(location.address))) if len(location.line) == 0: stack.append("({address})".format(address=hex(location.address))) diff --git a/src/traced/probes/packages_list/packages_list_parser.cc b/src/traced/probes/packages_list/packages_list_parser.cc index 9b58e20fbd..3bba17b8ce 100644 --- a/src/traced/probes/packages_list/packages_list_parser.cc +++ b/src/traced/probes/packages_list/packages_list_parser.cc @@ -16,6 +16,8 @@ #include "src/traced/probes/packages_list/packages_list_parser.h" +#include + #include "perfetto/ext/base/scoped_file.h" #include "perfetto/ext/base/string_splitter.h" diff --git a/test/trace_processor/diff_tests/parser/profiling/tests.py b/test/trace_processor/diff_tests/parser/profiling/tests.py index 9420112eed..aa71d729c4 100644 --- a/test/trace_processor/diff_tests/parser/profiling/tests.py +++ b/test/trace_processor/diff_tests/parser/profiling/tests.py @@ -310,6 +310,7 @@ def test_annotations(self): from stack_profile_callsite spc join stack_profile_frame spf on (spc.frame_id = spf.id) where spf.name = "_ZN3art28ResolveFieldWithAccessChecksEPNS_6ThreadEPNS_11ClassLinkerEtPNS_9ArtMethodEbbm") + and depth != 10 -- Skipped because cause symbolization issues on clang vs gcc due to llvm-demangle order by depth asc; """, out=Csv(""" @@ -324,7 +325,6 @@ def test_annotations(self): 7,"aot","/system/framework/arm64/boot-framework.oat","com.android.internal.os.ZygoteInit.main" 8,"aot","/system/framework/arm64/boot-framework.oat","com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run" 9,"common-frame","/system/framework/arm64/boot.oat","art_jni_trampoline" - 10,"[NULL]","/apex/com.android.art/lib64/libart.so","art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*) (.__uniq.165753521025965369065708152063621506277)" 11,"common-frame","/apex/com.android.art/lib64/libart.so","_jobject* art::InvokeMethod<(art::PointerSize)8>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned long)" 12,"common-frame","/apex/com.android.art/lib64/libart.so","art_quick_invoke_static_stub" 13,"aot","/system/framework/arm64/boot-framework.oat","android.app.ActivityThread.main" diff --git a/test/trace_processor/diff_tests/stdlib/prelude/pprof_functions_tests.py b/test/trace_processor/diff_tests/stdlib/prelude/pprof_functions_tests.py index d810c089f1..c706c07db0 100644 --- a/test/trace_processor/diff_tests/stdlib/prelude/pprof_functions_tests.py +++ b/test/trace_processor/diff_tests/stdlib/prelude/pprof_functions_tests.py @@ -225,7 +225,7 @@ def test_annotated_callstack(self): android.app.ActivityThread.main [aot] (0x717454cc) art_quick_invoke_static_stub [common-frame] (0x724db2de00) _jobject* art::InvokeMethod<(art::PointerSize)8>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned long) [common-frame] (0x724db545ec) - art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*) (.__uniq.165753521025965369065708152063621506277) (0x724db53ad0) + art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*) (0x724db53ad0) art_jni_trampoline [common-frame] (0x6ff5c578) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run [aot] (0x71c4ab6c) com.android.internal.os.ZygoteInit.main [aot] (0x71c54c7c) diff --git a/tools/install-build-deps b/tools/install-build-deps index a3befb086b..8e1d88f1a2 100755 --- a/tools/install-build-deps +++ b/tools/install-build-deps @@ -195,15 +195,15 @@ BUILD_DEPS_HOST = [ Dependency( 'buildtools/libcxx', 'https://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxx.git', - 'f8571eaba606bde2eb8cd34b30104ca33e7c207e', 'all', 'all'), + '852bc6746f45add53fec19f3a29280e69e358d44', 'all', 'all'), Dependency( 'buildtools/libcxxabi', 'https://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxxabi.git', - '8dd405113a4f3694e910b79785dd7fb7535a888a', 'all', 'all'), + 'a37a3aa431f132b02a58656f13984d51098330a2', 'all', 'all'), Dependency( 'buildtools/libunwind', 'https://chromium.googlesource.com/external/github.com/llvm/llvm-project/libunwind.git', - 'aabcd8753678f1536e15eb6385a948470debdae4', 'all', 'all'), + '419b03c0b8f20d6da9ddcb0d661a94a97cdd7dad', 'all', 'all'), # Keep in sync with chromium DEPS. Dependency( @@ -259,8 +259,8 @@ BUILD_DEPS_HOST = [ # If updating the version, also update bazel/deps.bzl. Dependency( 'buildtools/llvm-project.tgz', - 'https://storage.googleapis.com/perfetto/llvm-project-3b4c59c156919902c785ce3cbae0eee2ee53064d.tgz', - 'f4a52e7f36edd7cacc844d5ae0e5f60b6f57c5afc40683e99f295886c9ce8ff4', + 'https://storage.googleapis.com/perfetto/llvm-project-617a15a9eac96088ae5e9134248d8236e34b91b1.tgz', + '7e2541446a27f2a09a84520da7bc93cd71749ba0f17318f2d5291fbf45b97956', 'all', 'all'), # These dependencies are for libunwindstack, which is used by src/profiling.