blob: 4d135093e1bea1e9707d723a3540251732dc8e5b [file] [log] [blame]
Avi Drissman73a09d12022-09-08 20:33:381# Copyright 2022 The Chromium Authors
Takashi Sakamoto7fdb1692022-08-26 08:17:582# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# This defines PartitionAlloc's default build configuration for chromium.
6# If building PartitionAlloc as a part of chromium,
7# //build_overrides/partition_alloc.gni points out this file.
Arthur Sonzognic8ca46522023-10-16 19:08:558# //base/allocator/partition_allocator/partition_alloc.gni will import
Takashi Sakamoto7fdb1692022-08-26 08:17:589# this file and will use the defined values as default build configuration.
10#
11# partition_alloc.gni declares the following variables:
Bartek Nowierski07f51c62022-10-21 20:00:0812# - use_allocator_shim
13# - use_partition_alloc_as_malloc
Takashi Sakamoto7fdb1692022-08-26 08:17:5814# - enable_backup_ref_ptr_support
Takashi Sakamoto7fdb1692022-08-26 08:17:5815# - enable_backup_ref_ptr_slow_checks
16# - enable_dangling_raw_ptr_checks
Michael LeMay23c78e782022-12-01 03:21:5217# - backup_ref_ptr_poison_oob_ptr
Takashi Sakamoto7fdb1692022-08-26 08:17:5818#
19# Temporarily defines use_allocator_shim here. After deciding what
20# allocator_shim should be (e.g. a part of PartitionAlloc, a new component:
21# allocator_shim, and so on), move use_allocator_shim_default to the place.
22# - use_allocator_shim
23#
24# {variable}_default works as the default value of {variable}.
25
Arthur Sonzogni625aa332024-05-23 09:04:5326# TODO(crbug.com/41481467) Document what are the required and optional GN
27# variable embedders can provide to partition_alloc. For the least common,
28# consider wrapping them into some partition_alloc specific names.
29
30import("//build/config/android/config.gni")
31import("//build/config/cast.gni")
32import("//build/config/chromeos/ui_mode.gni")
33import("//build/config/compiler/compiler.gni")
34import("//build/config/cronet/config.gni")
35import("//build/config/dcheck_always_on.gni")
36import("//build/config/logging.gni")
Takashi Sakamoto7fdb1692022-08-26 08:17:5837import("//build/config/sanitizers/sanitizers.gni")
Arthur Sonzogni625aa332024-05-23 09:04:5338
Takashi Sakamoto7fdb1692022-08-26 08:17:5839if (is_ios) {
Justin69ec9712023-01-25 14:37:2540 import("//ios/features.gni")
Takashi Sakamoto7fdb1692022-08-26 08:17:5841}
42
Arthur Sonzognidd97ff12024-05-28 09:04:5443partition_alloc_enable_arc_config = "//build/config/compiler:enable_arc"
44
Arthur Sonzogni625aa332024-05-23 09:04:5345declare_args() {
46 # Turns on compiler optimizations in PartitionAlloc in Debug build. If
47 # enabling PartitionAlloc-Everywhere in Debug build for tests in Debug build,
48 # since all memory allocations and deallocations are executed by non-optimized
49 # PartitionAlloc, chrome (including tests) will be much slower. This will
50 # cause debug trybots' timeouts. If we want to debug PartitionAlloc itself,
51 # use partition_alloc_optimized_debug=false. Otherwise, use
52 # partition_alloc_optimized_debug=true to enable optimized PartitionAlloc.
53 partition_alloc_optimized_debug = true
54}
55
56if (!is_debug || partition_alloc_optimized_debug) {
57 # In chrome, partition_alloc is relatively hot (>1% of cycles for users of
58 # CrOS). Use speed-focused optimizations for it.
59 partition_alloc_remove_configs =
60 [ "//build/config/compiler:default_optimization" ]
61 partition_alloc_add_configs = [ "//build/config/compiler:optimize_speed" ]
62} else {
63 partition_alloc_remove_configs =
64 [ "//build/config/compiler:default_optimization" ]
65 partition_alloc_add_configs = [ "//build/config/compiler:no_optimize" ]
66}
67
Takashi Sakamoto2562c7e2024-06-11 04:18:4068# llvm_profile_set_target() generated by -fgenerate-profile invokes malloc()
69# internally. Since allocator_shim and PartitionAlloc are not reenterant,
70# the code will cause crashes. See crbug.com/338094768.
71partition_alloc_remove_configs +=
72 [ "//build/config/compiler/pgo:default_pgo_flags" ]
73
Takashi Sakamoto42cd7942023-03-31 09:10:3274# - Component build support is disabled on all platforms except Linux. It is
75# known to cause issues on some (e.g. Windows with shims, Android with
76# non-universal symbol wrapping), and has not been validated on others.
Takashi Sakamoto7fdb1692022-08-26 08:17:5877# - Windows: debug CRT is not compatible, see below.
Takashi Sakamoto42cd7942023-03-31 09:10:3278_disable_partition_alloc_everywhere =
Takashi Sakamoto42cd7942023-03-31 09:10:3279 (!is_linux && is_component_build) || (is_win && is_debug)
Takashi Sakamoto7fdb1692022-08-26 08:17:5880
81# - NaCl: No plans to support it.
Justin69ec9712023-01-25 14:37:2582# - iOS: Depends on ios_partition_alloc_enabled.
Arthur Sonzogni647b65eb62024-09-12 09:52:3083_is_partition_alloc_everywhere_platform =
84 !is_nacl && (!is_ios || ios_partition_alloc_enabled)
85
86use_allocator_shim_default = true # Updated below:
87
88# Sanitizers replace the allocator, don't use our own.
89if (is_asan || is_hwasan || is_lsan || is_tsan || is_msan) {
90 use_allocator_shim_default = false
91}
92
93# NaCl will never support the allocator shim.
94if (is_nacl) {
95 use_allocator_shim_default = false
96}
97
98# Under Fuchsia, the allocator shim is only required for PA-E.
99if (is_fuchsia && _disable_partition_alloc_everywhere) {
100 use_allocator_shim_default = false
Justin69ec9712023-01-25 14:37:25101}
Takashi Sakamoto7fdb1692022-08-26 08:17:58102
103# Under Windows debug build, the allocator shim is not compatible with CRT.
Arthur Sonzogni647b65eb62024-09-12 09:52:30104# NaCl in particular does seem to link some binaries statically against the
105# debug CRT with "is_nacl=false".
106if (is_win && is_debug) {
107 use_allocator_shim_default = false
Takashi Sakamoto7fdb1692022-08-26 08:17:58108}
109
Arthur Sonzogni647b65eb62024-09-12 09:52:30110if (is_win && is_component_build && (!use_custom_libcxx || libcxx_is_shared)) {
111 use_allocator_shim_default = false
Takashi Sakamoto7fdb1692022-08-26 08:17:58112}
113
Arthur Sonzogni647b65eb62024-09-12 09:52:30114use_partition_alloc_as_malloc_default =
115 use_allocator_shim_default && _is_partition_alloc_everywhere_platform &&
116 !_disable_partition_alloc_everywhere
Takashi Sakamoto7fdb1692022-08-26 08:17:58117
Arthur Sonzogni647b65eb62024-09-12 09:52:30118enable_backup_ref_ptr_support_default = use_partition_alloc_as_malloc_default
Takashi Sakamoto7fdb1692022-08-26 08:17:58119
Keishi Hattori1fca35b2023-01-24 04:14:33120enable_backup_ref_ptr_slow_checks_default = false
Arthur Sonzogni647b65eb62024-09-12 09:52:30121
Paul Semel67d96e72023-06-29 13:52:17122enable_dangling_raw_ptr_checks_default =
Arthur Sonzogni647b65eb62024-09-12 09:52:30123 # The DanglingPointerDetector relies on BackupRefPtr:
Arthur Sonzogni43ec36472024-04-15 19:15:39124 enable_backup_ref_ptr_support_default &&
Arthur Sonzogni647b65eb62024-09-12 09:52:30125 # DanglingPointerDetector is not yet enabled for official builds.
126 # Enabling it would require:
127 # - Metric-monitored dry-runs to assess real-world impact.
128 # - Performance re-evaluation, although past impact was neutral.
129 # - Additional considerations (etc.).
130 #
131 # It's also unclear if potential security issues warrant crash reports,
132 # as this could burden developers. Non-crashing metrics might help assess
133 # the value.
134 !is_official_build &&
135 # In unofficial builds, enable only for developers interested in
136 # DCHECKd/Debug builds. In the future, given its neutral performance impact,
137 # we could consider removing this restriction.
138 (is_debug || dcheck_always_on) &&
139 # Fuchsia and iOS have never been tested against DanglingPointerDetector at
140 # the moment.
141 !is_ios && !is_fuchsia &&
142 # Only the `android-rel` CQ bot has enforced DanglingPointerDetector checks
143 # at the moment. The other Android bots are not ready for it yet.
144 !is_android
Bartek Nowierski476039e12023-09-28 00:31:23145
miktcd50ddaa2024-10-11 09:42:44146enable_ios_corruption_hardening_default =
147 is_ios && ios_partition_alloc_corruption_hardening_enabled
148
Bartek Nowierski476039e12023-09-28 00:31:23149raw_ptr_zero_on_construct_default = true
150raw_ptr_zero_on_move_default = true
151raw_ptr_zero_on_destruct_default = false
Ada Romanowski56a61ac2024-03-08 04:56:14152
153# Allow embedders to opt-out of C++20 build which is set as default.
154# Kindly notify PartitionAlloc owners of change to false.
155assert_cpp20_default = true