blob: beff3fa789c737bf4e2b92961a35eaa6041e9d27 [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
Ali Juma50a19382021-09-20 21:25:238if (is_ios) {
9 import("//build/config/ios/ios_sdk.gni")
10}
11
Benoit Lize88016fd2021-01-13 16:25:1112# Sanitizers replace the allocator, don't use our own.
13_is_using_sanitizers = is_asan || is_hwasan || is_lsan || is_tsan || is_msan
14
Benoit Lize1ac7ce72021-07-01 10:59:5515# - Component build support is disabled on all platforms. It is known to cause
16# issues on some (e.g. Windows with shims, Android with non-universal symbol
17# wrapping), and has not been validated on others.
18# - Windows: debug CRT is not compatible, see below.
Benoit Lizec74f98f2021-10-25 13:15:2919_disable_partition_alloc = is_component_build || (is_win && is_debug)
Benoit Le8abca72021-08-10 19:42:1820_is_partition_alloc_platform = is_android || is_win || is_linux || is_chromeos
Benoit Lizeb30fcd42021-01-15 13:44:1221
Nico Weberb80b0852019-08-01 22:03:0122# The debug CRT on Windows has some debug features that are incompatible with
23# the shim. NaCl in particular does seem to link some binaries statically
24# against the debug CRT with "is_nacl=false".
Sean McAllisterdeaa7402020-07-31 04:42:5425if ((is_linux || is_chromeos || is_android || is_apple ||
Benoit Lize88016fd2021-01-13 16:25:1126 (is_win && !is_component_build && !is_debug)) && !_is_using_sanitizers) {
Nico Weberb80b0852019-08-01 22:03:0127 _default_use_allocator_shim = true
28} else {
29 _default_use_allocator_shim = false
30}
31
Benoit Lize060ef062021-02-01 11:41:4632if (_default_use_allocator_shim && _is_partition_alloc_platform &&
Benoit Lizeb30fcd42021-01-15 13:44:1233 !_disable_partition_alloc) {
Yuki Shiinod476ae3032020-11-18 05:56:2334 _default_allocator = "partition"
Lan Weidb909c372021-09-10 17:34:0935} else {
Benoit Ld4000aec2021-09-15 13:23:2636 _default_allocator = "none"
Yuki Shiinoa17905e32020-10-09 18:04:5937}
38
Nico Weberb80b0852019-08-01 22:03:0139declare_args() {
40 # Memory allocator to use. Set to "none" to use default allocator.
41 use_allocator = _default_allocator
42
43 # Causes all the allocations to be routed via allocator_shim.cc.
44 use_allocator_shim = _default_use_allocator_shim
Yuki Shiino24622fa2020-08-26 12:01:0245
Yuki Shiino90d5fe682020-09-02 11:03:5146 # Whether PartitionAlloc should be available for use or not.
47 # true makes PartitionAlloc linked to the executable or shared library and
48 # makes it available for use, but it doesn't mean that the default allocator
49 # is PartitionAlloc. PartitionAlloc may or may not be the default allocator.
50 #
51 # |use_allocator = "partition"| makes PartitionAlloc the default allocator
52 # but it's effective only when |use_partition_alloc = true|.
53 #
54 # TODO(lizeb, yukishiino): Determine if |use_partition_alloc| is necessary or
55 # not, and redesign or remove the flag accordingly. We may want to assert a
56 # possible conflict between |use_allocator = "partition"| and
57 # |use_partition_alloc = true| rather than prioritizing use_partition_alloc.
Ali Juma50a19382021-09-20 21:25:2358 # TODO(crbug.com/1250788): Enable use_partition_alloc on iOS device builds.
59 use_partition_alloc = !is_ios || target_environment == "simulator"
Bartek Nowierskiceb2fb32021-05-26 15:09:0560
Bartek Nowierskib4c39702021-08-06 00:42:1561 # Set use_backup_ref_ptr true to use BackupRefPtr (BRP) as the implementation
62 # of raw_ptr<T>, and enable PartitionAlloc support for it. The _fake option
63 # doesn't enable BRP, but pretends it's enabled for the syntethic field trial
64 #(for testing purposes only).
Bartek Nowierskiceb2fb32021-05-26 15:09:0565 use_backup_ref_ptr = false
66 use_backup_ref_ptr_fake = false
67
Bartek Nowierskib4c39702021-08-06 00:42:1568 # If BRP is enabled, additional options are available:
Bartek Nowierskiceb2fb32021-05-26 15:09:0569 # - put_ref_count_in_previous_slot: place the ref-count at the end of the
70 # previous slot (or in metadata if a slot starts on the page boundary), as
71 # opposed to the beginning of the slot.
Bartek Nowierskiceb2fb32021-05-26 15:09:0572 # - never_remove_from_brp_pool_blocklist: never remove super-pages from the
Bartek Nowierski53904392021-07-14 06:55:1373 # BRP-pool block list
Bartek Nowierskiceb2fb32021-05-26 15:09:0574 # - enable_backup_ref_ptr_slow_checks: enable additional safety checks that
75 # are too expensive to have on by default.
Bartek Nowierskiceb2fb32021-05-26 15:09:0576 put_ref_count_in_previous_slot = false
Bartek Nowierskiceb2fb32021-05-26 15:09:0577 never_remove_from_brp_pool_blocklist = false
78 enable_backup_ref_ptr_slow_checks = false
Yuki Shiino90d5fe682020-09-02 11:03:5179}
80
81if (!use_partition_alloc && use_allocator == "partition") {
82 # If there is a conflict, prioritize |use_partition_alloc| over
83 # |use_allocator|.
84 use_allocator = "none"
Nico Weberb80b0852019-08-01 22:03:0185}
86
Benoit Ld4000aec2021-09-15 13:23:2687# No longer the default on any platform, but still supported through GN args on Linux.
88assert(use_allocator != "tcmalloc" || is_linux,
89 "tcmalloc is only supported on Linux")
90assert(use_allocator == "none" || use_allocator == "partition" ||
91 use_allocator == "tcmalloc")
Nico Weberb80b0852019-08-01 22:03:0192
Rohit Rao849b4262020-05-01 19:10:3493assert(
Yuki Shiino24622fa2020-08-26 12:01:0294 !use_allocator_shim || is_linux || is_chromeos || is_android || is_win ||
Kevin Marshall64a82a92021-09-08 20:49:4595 is_fuchsia || is_apple,
96 "use_allocator_shim works only on Android, iOS, Linux, macOS, Fuchsia, " +
97 "and Windows.")
Nico Weberb80b0852019-08-01 22:03:0198
Moe Ahmadia36d801a2021-08-30 22:30:5399if (is_win && use_allocator_shim) {
Kevin Marshall64a82a92021-09-08 20:49:45100 # TODO(crbug.com/1245317): Add a comment indicating why the shim doesn't work.
Nico Weberb80b0852019-08-01 22:03:01101 assert(!is_component_build,
Moe Ahmadia36d801a2021-08-30 22:30:53102 "The allocator shim doesn't work for the component build on Windows.")
Nico Weberb80b0852019-08-01 22:03:01103}
Bartek Nowierskiceb2fb32021-05-26 15:09:05104
105# Prevent using BackupRefPtr when PartitionAlloc-Everywhere isn't used.
106# In theory, such a configuration is possible, but its scope would be limited to
107# only Blink partitions, which is currently not tested. Better to trigger an
108# error, than have BackupRefPtr silently disabled while believing it is enabled.
109if (!is_nacl) {
110 assert(!use_backup_ref_ptr || use_allocator == "partition",
111 "Can't use BackupRefPtr without PartitionAlloc-Everywhere")
112}
113
Bartek Nowierskiceb2fb32021-05-26 15:09:05114# put_ref_count_in_previous_slot can only be used if use_backup_ref_ptr
115# is true.
116assert(
117 use_backup_ref_ptr || !put_ref_count_in_previous_slot,
118 "Can't put ref count in the previous slot if BackupRefPtr isn't enabled at all")
119
Bartek Nowierski53904392021-07-14 06:55:13120# never_remove_from_brp_pool_blocklist can only be used if use_backup_ref_ptr
Bartek Nowierskiceb2fb32021-05-26 15:09:05121# is true.
122assert(
Bartek Nowierski53904392021-07-14 06:55:13123 use_backup_ref_ptr || !never_remove_from_brp_pool_blocklist,
124 "never_remove_from_brp_pool_blocklist requires BackupRefPtr to be enabled")
Bartek Nowierskiceb2fb32021-05-26 15:09:05125
126# enable_backup_ref_ptr_slow_checks can only be used if use_backup_ref_ptr
127# is true.
128assert(use_backup_ref_ptr || !enable_backup_ref_ptr_slow_checks,
129 "Can't enable additional BackupRefPtr checks if it isn't enabled at all")