blob: 4baec949673bf3ac9a2c2ca00562342b1dc551ee [file] [log] [blame]
Nico Weberb80b0852019-08-01 22:03:011# Copyright 2019 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Rob Hueber336a5ae2019-09-10 21:43:055import("//build/config/chromecast_build.gni")
Nico Weberb80b0852019-08-01 22:03:016import("//build/config/sanitizers/sanitizers.gni")
7
Benoit Lize88016fd2021-01-13 16:25:118# Sanitizers replace the allocator, don't use our own.
9_is_using_sanitizers = is_asan || is_hwasan || is_lsan || is_tsan || is_msan
10
Benoit Lize1ac7ce72021-07-01 10:59:5511# - Component build support is disabled on all platforms. It is known to cause
12# issues on some (e.g. Windows with shims, Android with non-universal symbol
13# wrapping), and has not been validated on others.
14# - Windows: debug CRT is not compatible, see below.
Benoit Lize53e1c742021-01-28 21:14:0215# - Chromecast on Android: causes issues with crash reporting, see b/178423326.
16_disable_partition_alloc =
Benoit Lize1ac7ce72021-07-01 10:59:5517 is_component_build || (is_win && is_debug) || (is_android && is_chromecast)
Thiabaud Engelbrecht64773c5572021-07-21 21:20:5618_is_partition_alloc_platform = is_android || is_win || is_linux || is_chromeos
Benoit Lizeb30fcd42021-01-15 13:44:1219
Nico Weberb80b0852019-08-01 22:03:0120# The debug CRT on Windows has some debug features that are incompatible with
21# the shim. NaCl in particular does seem to link some binaries statically
22# against the debug CRT with "is_nacl=false".
Sean McAllisterdeaa7402020-07-31 04:42:5423if ((is_linux || is_chromeos || is_android || is_apple ||
Benoit Lize88016fd2021-01-13 16:25:1124 (is_win && !is_component_build && !is_debug)) && !_is_using_sanitizers) {
Nico Weberb80b0852019-08-01 22:03:0125 _default_use_allocator_shim = true
26} else {
27 _default_use_allocator_shim = false
28}
29
Benoit Lize060ef062021-02-01 11:41:4630if (_default_use_allocator_shim && _is_partition_alloc_platform &&
Benoit Lizeb30fcd42021-01-15 13:44:1231 !_disable_partition_alloc) {
Yuki Shiinod476ae3032020-11-18 05:56:2332 _default_allocator = "partition"
Nina Satragno3f9a04c82021-07-30 15:26:0633} else if (is_android || is_apple || _is_using_sanitizers || is_win ||
34 is_fuchsia || ((is_linux || is_chromeos) && target_cpu == "arm64") ||
35 (is_cast_audio_only && target_cpu == "arm")) {
36 # Temporarily disable tcmalloc on arm64 linux to get rid of compilation
37 # errors.
Benoit Lizeb2b8274c2021-07-30 10:40:1638 _default_allocator = "none"
Nina Satragno3f9a04c82021-07-30 15:26:0639} else {
40 _default_allocator = "tcmalloc"
Yuki Shiinoa17905e32020-10-09 18:04:5941}
42
Nico Weberb80b0852019-08-01 22:03:0143declare_args() {
44 # Memory allocator to use. Set to "none" to use default allocator.
45 use_allocator = _default_allocator
46
47 # Causes all the allocations to be routed via allocator_shim.cc.
48 use_allocator_shim = _default_use_allocator_shim
Yuki Shiino24622fa2020-08-26 12:01:0249
Yuki Shiino90d5fe682020-09-02 11:03:5150 # Whether PartitionAlloc should be available for use or not.
51 # true makes PartitionAlloc linked to the executable or shared library and
52 # makes it available for use, but it doesn't mean that the default allocator
53 # is PartitionAlloc. PartitionAlloc may or may not be the default allocator.
54 #
55 # |use_allocator = "partition"| makes PartitionAlloc the default allocator
56 # but it's effective only when |use_partition_alloc = true|.
57 #
58 # TODO(lizeb, yukishiino): Determine if |use_partition_alloc| is necessary or
59 # not, and redesign or remove the flag accordingly. We may want to assert a
60 # possible conflict between |use_allocator = "partition"| and
61 # |use_partition_alloc = true| rather than prioritizing use_partition_alloc.
62 use_partition_alloc = !is_ios # Never use PartitionAlloc on iOS.
Bartek Nowierskiceb2fb32021-05-26 15:09:0563
Bartek Nowierskib4c39702021-08-06 00:42:1564 # Set use_backup_ref_ptr true to use BackupRefPtr (BRP) as the implementation
65 # of raw_ptr<T>, and enable PartitionAlloc support for it. The _fake option
66 # doesn't enable BRP, but pretends it's enabled for the syntethic field trial
67 #(for testing purposes only).
Bartek Nowierskiceb2fb32021-05-26 15:09:0568 use_backup_ref_ptr = false
69 use_backup_ref_ptr_fake = false
70
Bartek Nowierskib4c39702021-08-06 00:42:1571 # If BRP is enabled, additional options are available:
Bartek Nowierskiceb2fb32021-05-26 15:09:0572 # - enable_runtime_backup_ref_ptr_control: control BRP support at run-time
73 # (disable in some processes)
74 # - put_ref_count_in_previous_slot: place the ref-count at the end of the
75 # previous slot (or in metadata if a slot starts on the page boundary), as
76 # opposed to the beginning of the slot.
Bartek Nowierskiceb2fb32021-05-26 15:09:0577 # - never_remove_from_brp_pool_blocklist: never remove super-pages from the
Bartek Nowierski53904392021-07-14 06:55:1378 # BRP-pool block list
Bartek Nowierskiceb2fb32021-05-26 15:09:0579 # - enable_backup_ref_ptr_slow_checks: enable additional safety checks that
80 # are too expensive to have on by default.
81 enable_runtime_backup_ref_ptr_control = false
Keishi Hattoric46a5032021-06-21 05:02:2082 enable_backup_ref_ptr_in_renderer_process = false
Bartek Nowierskiceb2fb32021-05-26 15:09:0583 put_ref_count_in_previous_slot = false
Bartek Nowierskiceb2fb32021-05-26 15:09:0584 never_remove_from_brp_pool_blocklist = false
85 enable_backup_ref_ptr_slow_checks = false
Yuki Shiino90d5fe682020-09-02 11:03:5186}
87
88if (!use_partition_alloc && use_allocator == "partition") {
89 # If there is a conflict, prioritize |use_partition_alloc| over
90 # |use_allocator|.
91 use_allocator = "none"
Nico Weberb80b0852019-08-01 22:03:0192}
93
Benoit Lizea27feee2020-06-10 12:48:5294assert(use_allocator == "none" || use_allocator == "tcmalloc" ||
95 use_allocator == "partition")
96
Nina Satragno3f9a04c82021-07-30 15:26:0697assert(!is_win || use_allocator != "tcmalloc",
98 "Tcmalloc doesn't work on Windows.")
99assert(!is_mac || use_allocator != "tcmalloc",
100 "Tcmalloc doesn't work on macOS.")
101assert(!is_ios || use_allocator != "tcmalloc", "Tcmalloc doesn't work on iOS.")
Nico Weberb80b0852019-08-01 22:03:01102
Rohit Rao849b4262020-05-01 19:10:34103assert(
Yuki Shiino24622fa2020-08-26 12:01:02104 !use_allocator_shim || is_linux || is_chromeos || is_android || is_win ||
105 is_apple,
Rohit Rao849b4262020-05-01 19:10:34106 "use_allocator_shim works only on Android, iOS, Linux, macOS, and Windows.")
Nico Weberb80b0852019-08-01 22:03:01107
108if (is_win && use_allocator_shim) {
109 assert(!is_component_build,
110 "The allocator shim doesn't work for the component build on Windows.")
111}
Bartek Nowierskiceb2fb32021-05-26 15:09:05112
113# Prevent using BackupRefPtr when PartitionAlloc-Everywhere isn't used.
114# In theory, such a configuration is possible, but its scope would be limited to
115# only Blink partitions, which is currently not tested. Better to trigger an
116# error, than have BackupRefPtr silently disabled while believing it is enabled.
117if (!is_nacl) {
118 assert(!use_backup_ref_ptr || use_allocator == "partition",
119 "Can't use BackupRefPtr without PartitionAlloc-Everywhere")
120}
121
122# enable_runtime_backup_ref_ptr_control can only be used if use_backup_ref_ptr
123# is true.
124assert(use_backup_ref_ptr || !enable_runtime_backup_ref_ptr_control,
125 "Can't control BackupRefPtr at run-time if it isn't enabled at all")
126
Keishi Hattoric46a5032021-06-21 05:02:20127# enable_backup_ref_ptr_in_renderer_process can only be used if
128# enable_runtime_backup_ref_ptr_control is true.
129assert(
130 enable_runtime_backup_ref_ptr_control ||
131 !enable_backup_ref_ptr_in_renderer_process,
132 "Can't enable BackupRefPtr in renderer process if runtime control isn't enabled")
133
Bartek Nowierskiceb2fb32021-05-26 15:09:05134# put_ref_count_in_previous_slot can only be used if use_backup_ref_ptr
135# is true.
136assert(
137 use_backup_ref_ptr || !put_ref_count_in_previous_slot,
138 "Can't put ref count in the previous slot if BackupRefPtr isn't enabled at all")
139
Bartek Nowierski53904392021-07-14 06:55:13140# never_remove_from_brp_pool_blocklist can only be used if use_backup_ref_ptr
Bartek Nowierskiceb2fb32021-05-26 15:09:05141# is true.
142assert(
Bartek Nowierski53904392021-07-14 06:55:13143 use_backup_ref_ptr || !never_remove_from_brp_pool_blocklist,
144 "never_remove_from_brp_pool_blocklist requires BackupRefPtr to be enabled")
Bartek Nowierskiceb2fb32021-05-26 15:09:05145
146# enable_backup_ref_ptr_slow_checks can only be used if use_backup_ref_ptr
147# is true.
148assert(use_backup_ref_ptr || !enable_backup_ref_ptr_slow_checks,
149 "Can't enable additional BackupRefPtr checks if it isn't enabled at all")