Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 1 | # 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 Hueber | 336a5ae | 2019-09-10 21:43:05 | [diff] [blame] | 5 | import("//build/config/chromecast_build.gni") |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 6 | import("//build/config/sanitizers/sanitizers.gni") |
| 7 | |
Ali Juma | 50a1938 | 2021-09-20 21:25:23 | [diff] [blame] | 8 | if (is_ios) { |
| 9 | import("//build/config/ios/ios_sdk.gni") |
| 10 | } |
| 11 | |
Benoit Lize | 88016fd | 2021-01-13 16:25:11 | [diff] [blame] | 12 | # 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 Lize | 1ac7ce7 | 2021-07-01 10:59:55 | [diff] [blame] | 15 | # - 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 Lize | c74f98f | 2021-10-25 13:15:29 | [diff] [blame] | 19 | _disable_partition_alloc = is_component_build || (is_win && is_debug) |
Benoit Lize | 36552d8 | 2022-01-28 10:53:32 | [diff] [blame] | 20 | |
| 21 | # - NaCl: No plans to support it. |
| 22 | # - iOS: not done yet. |
| 23 | _is_partition_alloc_platform = !is_nacl && !is_ios |
Benoit Lize | b30fcd4 | 2021-01-15 13:44:12 | [diff] [blame] | 24 | |
Kevin Marshall | 7a835b4 | 2022-01-08 23:17:11 | [diff] [blame] | 25 | # Under Windows Debug the allocator shim is not compatible with CRT. |
| 26 | # NaCl in particular does seem to link some binaries statically |
| 27 | # against the debug CRT with "is_nacl=false". |
| 28 | # Under Fuchsia the allocator shim is only required for PA-E. |
| 29 | # For all other platforms & configurations, the shim is required, to replace |
Thiabaud Engelbrecht | 6d44361 | 2022-02-11 00:22:18 | [diff] [blame] | 30 | # the default system allocators, e.g. with Partition Alloc. |
Kunihiko Sakamoto | 466878a4 | 2021-11-24 07:49:01 | [diff] [blame] | 31 | if ((is_linux || is_chromeos || is_android || is_apple || |
Benoit Lize | 36552d8 | 2022-01-28 10:53:32 | [diff] [blame] | 32 | (is_fuchsia && !_disable_partition_alloc) || |
Benoit Lize | 88016fd | 2021-01-13 16:25:11 | [diff] [blame] | 33 | (is_win && !is_component_build && !is_debug)) && !_is_using_sanitizers) { |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 34 | _default_use_allocator_shim = true |
| 35 | } else { |
| 36 | _default_use_allocator_shim = false |
| 37 | } |
| 38 | |
Benoit Lize | 060ef06 | 2021-02-01 11:41:46 | [diff] [blame] | 39 | if (_default_use_allocator_shim && _is_partition_alloc_platform && |
Benoit Lize | b30fcd4 | 2021-01-15 13:44:12 | [diff] [blame] | 40 | !_disable_partition_alloc) { |
Yuki Shiino | d476ae303 | 2020-11-18 05:56:23 | [diff] [blame] | 41 | _default_allocator = "partition" |
Lan Wei | db909c37 | 2021-09-10 17:34:09 | [diff] [blame] | 42 | } else { |
Benoit L | d4000aec | 2021-09-15 13:23:26 | [diff] [blame] | 43 | _default_allocator = "none" |
Yuki Shiino | a17905e3 | 2020-10-09 18:04:59 | [diff] [blame] | 44 | } |
| 45 | |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 46 | declare_args() { |
| 47 | # Memory allocator to use. Set to "none" to use default allocator. |
| 48 | use_allocator = _default_allocator |
| 49 | |
| 50 | # Causes all the allocations to be routed via allocator_shim.cc. |
| 51 | use_allocator_shim = _default_use_allocator_shim |
Yuki Shiino | 24622fa | 2020-08-26 12:01:02 | [diff] [blame] | 52 | |
Yuki Shiino | 90d5fe68 | 2020-09-02 11:03:51 | [diff] [blame] | 53 | # Whether PartitionAlloc should be available for use or not. |
| 54 | # true makes PartitionAlloc linked to the executable or shared library and |
Bartek Nowierski | 974b49b | 2022-02-03 04:29:09 | [diff] [blame] | 55 | # makes it available for use. It doesn't mean that the default allocator |
| 56 | # is PartitionAlloc, which is governed by |use_allocator|. |
Yuki Shiino | 90d5fe68 | 2020-09-02 11:03:51 | [diff] [blame] | 57 | # |
Bartek Nowierski | 974b49b | 2022-02-03 04:29:09 | [diff] [blame] | 58 | # This flag is currently set to false only on Cronet bots, because Cronet |
| 59 | # doesn't use PartitionAlloc at all, and doesn't wish to incur the library |
| 60 | # size increase (crbug.com/674570). |
| 61 | use_partition_alloc = true |
Yuki Shiino | 90d5fe68 | 2020-09-02 11:03:51 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | if (!use_partition_alloc && use_allocator == "partition") { |
| 65 | # If there is a conflict, prioritize |use_partition_alloc| over |
| 66 | # |use_allocator|. |
| 67 | use_allocator = "none" |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 68 | } |
| 69 | |
Benoit Lize | f4e1472 | 2022-01-12 10:56:52 | [diff] [blame] | 70 | assert(use_allocator == "none" || use_allocator == "partition") |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 71 | |
Rohit Rao | 849b426 | 2020-05-01 19:10:34 | [diff] [blame] | 72 | assert( |
Yuki Shiino | 24622fa | 2020-08-26 12:01:02 | [diff] [blame] | 73 | !use_allocator_shim || is_linux || is_chromeos || is_android || is_win || |
Kevin Marshall | 64a82a9 | 2021-09-08 20:49:45 | [diff] [blame] | 74 | is_fuchsia || is_apple, |
| 75 | "use_allocator_shim works only on Android, iOS, Linux, macOS, Fuchsia, " + |
| 76 | "and Windows.") |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 77 | |
Moe Ahmadi | a36d801a | 2021-08-30 22:30:53 | [diff] [blame] | 78 | if (is_win && use_allocator_shim) { |
Kevin Marshall | 64a82a9 | 2021-09-08 20:49:45 | [diff] [blame] | 79 | # TODO(crbug.com/1245317): Add a comment indicating why the shim doesn't work. |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 80 | assert(!is_component_build, |
Moe Ahmadi | a36d801a | 2021-08-30 22:30:53 | [diff] [blame] | 81 | "The allocator shim doesn't work for the component build on Windows.") |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 82 | } |
Bartek Nowierski | ceb2fb3 | 2021-05-26 15:09:05 | [diff] [blame] | 83 | |
Keishi Hattori | f8cb0ae | 2022-07-20 07:39:38 | [diff] [blame] | 84 | _is_brp_supported = (is_win || is_android || is_linux || is_mac || |
| 85 | is_chromeos) && use_allocator == "partition" |
Keishi Hattori | 01d5ac8fe | 2021-11-26 23:59:14 | [diff] [blame] | 86 | |
Kalvin Lee | ecf3a88 | 2022-07-22 15:10:47 | [diff] [blame^] | 87 | _is_mcp_supported = is_win && use_allocator == "partition" |
| 88 | |
| 89 | declare_args() { |
| 90 | # We jam MTECheckedPtr off by default, but can set it to |
| 91 | # `_is_mcp_supported` to activate it. |
| 92 | use_mte_checked_ptr = false |
| 93 | } |
| 94 | |
Keishi Hattori | 01d5ac8fe | 2021-11-26 23:59:14 | [diff] [blame] | 95 | declare_args() { |
| 96 | # Set use_backup_ref_ptr true to use BackupRefPtr (BRP) as the implementation |
| 97 | # of raw_ptr<T>, and enable PartitionAlloc support for it. |
Kalvin Lee | ecf3a88 | 2022-07-22 15:10:47 | [diff] [blame^] | 98 | # We also disable BRP in the presence of MTECheckedPtr, which is almost |
| 99 | # never enabled. |
| 100 | use_backup_ref_ptr = _is_brp_supported && !use_mte_checked_ptr |
Kalvin Lee | 6f79e39 | 2022-02-18 18:55:50 | [diff] [blame] | 101 | } |
Keishi Hattori | 01d5ac8fe | 2021-11-26 23:59:14 | [diff] [blame] | 102 | |
Kalvin Lee | 240f4d1 | 2022-03-21 22:35:19 | [diff] [blame] | 103 | assert(!(use_backup_ref_ptr && use_mte_checked_ptr), |
| 104 | "MTECheckedPtr conflicts with BRP.") |
| 105 | |
Kalvin Lee | 6f79e39 | 2022-02-18 18:55:50 | [diff] [blame] | 106 | declare_args() { |
Keishi Hattori | 01d5ac8fe | 2021-11-26 23:59:14 | [diff] [blame] | 107 | # If BRP is enabled, additional options are available: |
| 108 | # - put_ref_count_in_previous_slot: place the ref-count at the end of the |
| 109 | # previous slot (or in metadata if a slot starts on the page boundary), as |
| 110 | # opposed to the beginning of the slot. |
Keishi Hattori | 01d5ac8fe | 2021-11-26 23:59:14 | [diff] [blame] | 111 | # - enable_backup_ref_ptr_slow_checks: enable additional safety checks that |
| 112 | # are too expensive to have on by default. |
Arthur Sonzogni | 0db17dd | 2022-02-14 13:50:27 | [diff] [blame] | 113 | # - enable_dangling_raw_ptr_checks: enable checking raw_ptr do not become |
| 114 | # dangling during their lifetime. |
Keishi Hattori | c4aeea4 | 2022-03-23 11:02:37 | [diff] [blame] | 115 | put_ref_count_in_previous_slot = use_backup_ref_ptr |
Keishi Hattori | 14dcefd | 2021-11-28 10:46:22 | [diff] [blame] | 116 | enable_backup_ref_ptr_slow_checks = false |
Arthur Sonzogni | 0db17dd | 2022-02-14 13:50:27 | [diff] [blame] | 117 | enable_dangling_raw_ptr_checks = false |
Keishi Hattori | 01d5ac8fe | 2021-11-26 23:59:14 | [diff] [blame] | 118 | |
| 119 | # Registers the binary for a fake binary A/B experiment. The binaries built |
| 120 | # with this flag have no behavior difference, except for setting a synthetic |
| 121 | # Finch. |
| 122 | use_fake_binary_experiment = false |
Sergei Glazunov | 017ec4e8 | 2022-01-26 11:50:49 | [diff] [blame] | 123 | |
Sergei Glazunov | 38f07f6 | 2022-06-15 09:45:58 | [diff] [blame] | 124 | # The supported platforms are supposed to match `_is_brp_supported`, but we |
| 125 | # enable the feature on Linux early because it's most widely used for security |
| 126 | # research |
| 127 | use_asan_backup_ref_ptr = is_asan && (is_win || is_android || is_linux) |
Keishi Hattori | 01d5ac8fe | 2021-11-26 23:59:14 | [diff] [blame] | 128 | } |
| 129 | |
Bartek Nowierski | ceb2fb3 | 2021-05-26 15:09:05 | [diff] [blame] | 130 | # Prevent using BackupRefPtr when PartitionAlloc-Everywhere isn't used. |
| 131 | # In theory, such a configuration is possible, but its scope would be limited to |
| 132 | # only Blink partitions, which is currently not tested. Better to trigger an |
| 133 | # error, than have BackupRefPtr silently disabled while believing it is enabled. |
| 134 | if (!is_nacl) { |
| 135 | assert(!use_backup_ref_ptr || use_allocator == "partition", |
| 136 | "Can't use BackupRefPtr without PartitionAlloc-Everywhere") |
| 137 | } |
| 138 | |
Bartek Nowierski | ceb2fb3 | 2021-05-26 15:09:05 | [diff] [blame] | 139 | # put_ref_count_in_previous_slot can only be used if use_backup_ref_ptr |
| 140 | # is true. |
| 141 | assert( |
| 142 | use_backup_ref_ptr || !put_ref_count_in_previous_slot, |
| 143 | "Can't put ref count in the previous slot if BackupRefPtr isn't enabled at all") |
| 144 | |
Bartek Nowierski | ceb2fb3 | 2021-05-26 15:09:05 | [diff] [blame] | 145 | # enable_backup_ref_ptr_slow_checks can only be used if use_backup_ref_ptr |
| 146 | # is true. |
| 147 | assert(use_backup_ref_ptr || !enable_backup_ref_ptr_slow_checks, |
| 148 | "Can't enable additional BackupRefPtr checks if it isn't enabled at all") |
Sergei Glazunov | 017ec4e8 | 2022-01-26 11:50:49 | [diff] [blame] | 149 | |
Arthur Sonzogni | 0db17dd | 2022-02-14 13:50:27 | [diff] [blame] | 150 | # enable_dangling_raw_ptr_checks can only be used if use_backup_ref_ptr |
| 151 | # is true. |
| 152 | assert( |
| 153 | use_backup_ref_ptr || !enable_dangling_raw_ptr_checks, |
| 154 | "Can't enable dangling raw_ptr checks if BackupRefPtr isn't enabled at all") |
| 155 | |
Sergei Glazunov | 017ec4e8 | 2022-01-26 11:50:49 | [diff] [blame] | 156 | # BackupRefPtr and AsanBackupRefPtr are mutually exclusive variants of raw_ptr. |
| 157 | assert( |
| 158 | !use_backup_ref_ptr || !use_asan_backup_ref_ptr, |
| 159 | "Both BackupRefPtr and AsanBackupRefPtr can't be enabled at the same time") |
| 160 | |
| 161 | assert(!use_asan_backup_ref_ptr || is_asan, |
| 162 | "AsanBackupRefPtr requires AddressSanitizer") |