Skip to content

Commit f4e01b0

Browse files
authored
Enable crashpad for arm, and cxx17, toolchains (#7479)
This PR includes a few sets of changes to enable crash reporting on our evergreen-raspi reference platform: * Customizations to build //base wtih cxx17, which partner toolchains can opt into with a toolchain arg * Customizations to build zlib with arm toolchains that are on a version less than ARMv8 * Compiler flags added to the raspi port to disable warnings that are not issued by more modern compilers. With these changes it should now be fairly straightforward for most partners to enable crashpad on their platforms. Issue: 446904317 Issue: 406511608
1 parent 94a3de2 commit f4e01b0

25 files changed

Lines changed: 237 additions & 46 deletions

File tree

base/allocator/partition_allocator/partition_alloc.gni

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ declare_args() {
4747
# and doesn't wish to incur the library size increase (crbug.com/674570).
4848
# 2. On NaCl (through this declaration), where PartitionAlloc doesn't
4949
# build at all.
50-
use_partition_alloc = !is_nacl
50+
#
51+
# Cobalt comment: it would be a significant change to use PartitionAlloc as
52+
# the default allocator in components built by partners. We're considering
53+
# that change in b/447346129 but for now set this false in partner toolchains
54+
# so that PartitionAlloc is not even linked into partner built binaries.
55+
use_partition_alloc =
56+
!is_nacl && !(is_cobalt && ((current_toolchain == starboard_toolchain &&
57+
starboard_toolchain != default_toolchain) ||
58+
current_toolchain == native_target))
5159
}
5260

5361
declare_args() {

base/allocator/partition_allocator/partition_alloc_base/cxx20_is_constant_evaluated.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_CXX20_IS_CONSTANT_EVALUATED_H_
66
#define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_CXX20_IS_CONSTANT_EVALUATED_H_
77

8+
#include "build/build_config.h"
9+
810
namespace partition_alloc::internal::base {
911

1012
// std::is_constant_evaluated was introduced in C++20. PartitionAlloc's minimum
@@ -23,7 +25,15 @@ using std::is_constant_evaluated;
2325
// - https://en.cppreference.com/w/cpp/types/is_constant_evaluated
2426
// - https://wg21.link/meta.const.eval
2527
constexpr bool is_constant_evaluated() noexcept {
28+
#if BUILDFLAG(BUILD_BASE_WITH_CPP17)
29+
// Compilers are not guaranteed to provide this builtin. Always returning
30+
// false should be safe: if a calling function that uses this result to select
31+
// a runtime or compile-time path were actually used in a constant-evaluated
32+
// context then we should get a compile-time error.
33+
return false;
34+
#else
2635
return __builtin_is_constant_evaluated();
36+
#endif
2737
}
2838

2939
#endif

base/allocator/partition_allocator/partition_alloc_base/numerics/safe_conversions_impl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <limits>
1111
#include <type_traits>
1212

13+
#include "build/build_config.h"
14+
1315
#if defined(__GNUC__) || defined(__clang__)
1416
#define PA_BASE_NUMERICS_LIKELY(x) __builtin_expect(!!(x), 1)
1517
#define PA_BASE_NUMERICS_UNLIKELY(x) __builtin_expect(!!(x), 0)
@@ -85,9 +87,20 @@ constexpr typename std::make_unsigned<T>::type SafeUnsignedAbs(T value) {
8587
: static_cast<UnsignedT>(value);
8688
}
8789

90+
#if BUILDFLAG(BUILD_BASE_WITH_CPP17)
91+
constexpr bool pa_is_constant_evaluated_stub() noexcept {
92+
// Compilers are not guaranteed to provide this builtin. Always returning
93+
// false should be safe: if a calling function that uses this result to select
94+
// a runtime or compile-time path were actually used in a constant-evaluated
95+
// context then we should get a compile-time error.
96+
return false;
97+
}
98+
#define PA_IsConstantEvaluated() (pa_is_constant_evaluated_stub())
99+
#else
88100
// TODO(jschuh): Switch to std::is_constant_evaluated() once C++20 is supported.
89101
// Alternately, the usage could be restructured for "consteval if" in C++23.
90102
#define PA_IsConstantEvaluated() (__builtin_is_constant_evaluated())
103+
#endif
91104

92105
// TODO(jschuh): Debug builds don't reliably propagate constants, so we restrict
93106
// some accelerated runtime paths to release builds until this can be forced

base/containers/flat_tree.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "base/functional/not_fn.h"
1818
#include "base/memory/raw_ptr_exclusion.h"
1919
#include "base/ranges/algorithm.h"
20+
#include "build/build_config.h"
2021

2122
namespace base {
2223

@@ -158,7 +159,12 @@ class flat_tree {
158159
struct value_compare {
159160
constexpr bool operator()(const value_type& left,
160161
const value_type& right) const {
162+
#if BUILDFLAG(BUILD_BASE_WITH_CPP17)
163+
// C++17 does not allow default initialization here.
164+
GetKeyFromValue extractor{};
165+
#else
161166
GetKeyFromValue extractor;
167+
#endif
162168
return comp(extractor(left), extractor(right));
163169
}
164170

base/cxx20_is_constant_evaluated.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef BASE_CXX20_IS_CONSTANT_EVALUATED_H_
66
#define BASE_CXX20_IS_CONSTANT_EVALUATED_H_
77

8+
#include "build/build_config.h"
9+
810
namespace base {
911

1012
// Implementation of C++20's std::is_constant_evaluated.
@@ -13,7 +15,15 @@ namespace base {
1315
// - https://en.cppreference.com/w/cpp/types/is_constant_evaluated
1416
// - https://wg21.link/meta.const.eval
1517
constexpr bool is_constant_evaluated() noexcept {
18+
#if BUILDFLAG(BUILD_BASE_WITH_CPP17)
19+
// Compilers are not guaranteed to provide this builtin. Always returning
20+
// false should be safe: if a calling function that uses this result to select
21+
// a runtime or compile-time path were actually used in a constant-evaluated
22+
// context then we should get a compile-time error.
23+
return false;
24+
#else
1625
return __builtin_is_constant_evaluated();
26+
#endif
1727
}
1828

1929
} // namespace base

base/numerics/safe_conversions_impl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <limits>
1111
#include <type_traits>
1212

13+
#include "build/build_config.h"
14+
1315
#if defined(__GNUC__) || defined(__clang__)
1416
#define BASE_NUMERICS_LIKELY(x) __builtin_expect(!!(x), 1)
1517
#define BASE_NUMERICS_UNLIKELY(x) __builtin_expect(!!(x), 0)
@@ -86,9 +88,20 @@ constexpr typename std::make_unsigned<T>::type SafeUnsignedAbs(T value) {
8688
: static_cast<UnsignedT>(value);
8789
}
8890

91+
#if BUILDFLAG(BUILD_BASE_WITH_CPP17)
92+
constexpr bool is_constant_evaluated_stub() noexcept {
93+
// Compilers are not guaranteed to provide this builtin. Always returning
94+
// false should be safe: if a calling function that uses this result to select
95+
// a runtime or compile-time path were actually used in a constant-evaluated
96+
// context then we should get a compile-time error.
97+
return false;
98+
}
99+
#define IsConstantEvaluated() (is_constant_evaluated_stub())
100+
#else
89101
// TODO(jschuh): Switch to std::is_constant_evaluated() once C++20 is supported.
90102
// Alternately, the usage could be restructured for "consteval if" in C++23.
91103
#define IsConstantEvaluated() (__builtin_is_constant_evaluated())
104+
#endif
92105

93106
// TODO(jschuh): Debug builds don't reliably propagate constants, so we restrict
94107
// some accelerated runtime paths to release builds until this can be forced

base/task/sequence_manager/sequence_manager.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include <utility>
88

9+
#include "build/build_config.h"
10+
911
namespace base {
1012
namespace sequence_manager {
1113

@@ -104,7 +106,11 @@ SequenceManager::PrioritySettings& SequenceManager::PrioritySettings::operator=(
104106

105107
SequenceManager::Settings::Settings() = default;
106108

109+
#if BUILDFLAG(BUILD_BASE_WITH_CPP17)
110+
SequenceManager::Settings::Settings(Settings&& move_from) = default;
111+
#else
107112
SequenceManager::Settings::Settings(Settings&& move_from) noexcept = default;
113+
#endif
108114

109115
SequenceManager::Settings::~Settings() = default;
110116

base/task/sequence_manager/sequence_manager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "base/task/sequenced_task_runner.h"
2222
#include "base/task/single_thread_task_runner.h"
2323
#include "base/time/default_tick_clock.h"
24+
#include "build/build_config.h"
2425

2526
namespace base {
2627

@@ -163,7 +164,13 @@ class BASE_EXPORT SequenceManager {
163164
Settings& operator=(const Settings&) = delete;
164165
// In the future MessagePump (which is move-only) will also be a setting,
165166
// so we are making Settings move-only in preparation.
167+
#if BUILDFLAG(BUILD_BASE_WITH_CPP17)
168+
// The compiler does not agree that the default move constructor should be
169+
// declared as non-throwing.
170+
Settings(Settings&& move_from);
171+
#else
166172
Settings(Settings&& move_from) noexcept;
173+
#endif
167174

168175
~Settings();
169176

base/trace_event/heap_profiler_allocation_context.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <cstring>
99

1010
#include "base/hash/hash.h"
11+
#include "build/build_config.h"
1112

1213
namespace base {
1314
namespace trace_event {
@@ -26,6 +27,10 @@ bool operator != (const StackFrame& lhs, const StackFrame& rhs) {
2627

2728
Backtrace::Backtrace() = default;
2829

30+
#if BUILDFLAG(BUILD_BASE_WITH_CPP17)
31+
Backtrace::Backtrace(const Backtrace& other) = default;
32+
#endif
33+
2934
bool operator==(const Backtrace& lhs, const Backtrace& rhs) {
3035
if (lhs.frame_count != rhs.frame_count) return false;
3136
return std::equal(lhs.frames, lhs.frames + lhs.frame_count, rhs.frames);

base/trace_event/heap_profiler_allocation_context.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "base/base_export.h"
1414
#include "base/memory/raw_ptr.h"
15+
#include "build/build_config.h"
1516

1617
namespace base {
1718
namespace trace_event {
@@ -53,6 +54,11 @@ bool BASE_EXPORT operator != (const StackFrame& lhs, const StackFrame& rhs);
5354
struct BASE_EXPORT Backtrace {
5455
Backtrace();
5556

57+
#if BUILDFLAG(BUILD_BASE_WITH_CPP17)
58+
// The copy constructor is for some reason deleted by the compiler.
59+
Backtrace(const Backtrace& other);
60+
#endif
61+
5662
// If the stack is higher than what can be stored here, the top frames
5763
// (the ones further from main()) are stored. Depth of 12 is enough for most
5864
// pseudo traces (see above), but not for native traces, where we need more.

0 commit comments

Comments
 (0)