Avi Drissman | 73a09d1 | 2022-09-08 20:33:38 | [diff] [blame] | 1 | # Copyright 2022 The Chromium Authors |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 2 | # 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 Sonzogni | c8ca4652 | 2023-10-16 19:08:55 | [diff] [blame] | 8 | # //base/allocator/partition_allocator/partition_alloc.gni will import |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 9 | # this file and will use the defined values as default build configuration. |
| 10 | # |
| 11 | # partition_alloc.gni declares the following variables: |
Bartek Nowierski | 07f51c6 | 2022-10-21 20:00:08 | [diff] [blame] | 12 | # - use_allocator_shim |
| 13 | # - use_partition_alloc_as_malloc |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 14 | # - enable_backup_ref_ptr_support |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 15 | # - enable_backup_ref_ptr_slow_checks |
| 16 | # - enable_dangling_raw_ptr_checks |
Michael LeMay | 23c78e78 | 2022-12-01 03:21:52 | [diff] [blame] | 17 | # - backup_ref_ptr_poison_oob_ptr |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 18 | # |
| 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 Sonzogni | 625aa33 | 2024-05-23 09:04:53 | [diff] [blame] | 26 | # 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 | |
| 30 | import("//build/config/android/config.gni") |
| 31 | import("//build/config/cast.gni") |
| 32 | import("//build/config/chromeos/ui_mode.gni") |
| 33 | import("//build/config/compiler/compiler.gni") |
| 34 | import("//build/config/cronet/config.gni") |
| 35 | import("//build/config/dcheck_always_on.gni") |
| 36 | import("//build/config/logging.gni") |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 37 | import("//build/config/sanitizers/sanitizers.gni") |
Arthur Sonzogni | 625aa33 | 2024-05-23 09:04:53 | [diff] [blame] | 38 | |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 39 | if (is_ios) { |
Justin | 69ec971 | 2023-01-25 14:37:25 | [diff] [blame] | 40 | import("//ios/features.gni") |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 41 | } |
| 42 | |
Arthur Sonzogni | dd97ff1 | 2024-05-28 09:04:54 | [diff] [blame] | 43 | partition_alloc_enable_arc_config = "//build/config/compiler:enable_arc" |
| 44 | |
Arthur Sonzogni | 625aa33 | 2024-05-23 09:04:53 | [diff] [blame] | 45 | declare_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 | |
| 56 | if (!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 Sakamoto | 2562c7e | 2024-06-11 04:18:40 | [diff] [blame] | 68 | # 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. |
| 71 | partition_alloc_remove_configs += |
| 72 | [ "//build/config/compiler/pgo:default_pgo_flags" ] |
| 73 | |
Takashi Sakamoto | 42cd794 | 2023-03-31 09:10:32 | [diff] [blame] | 74 | # - 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 Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 77 | # - Windows: debug CRT is not compatible, see below. |
Takashi Sakamoto | 42cd794 | 2023-03-31 09:10:32 | [diff] [blame] | 78 | _disable_partition_alloc_everywhere = |
Takashi Sakamoto | 42cd794 | 2023-03-31 09:10:32 | [diff] [blame] | 79 | (!is_linux && is_component_build) || (is_win && is_debug) |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 80 | |
| 81 | # - NaCl: No plans to support it. |
Justin | 69ec971 | 2023-01-25 14:37:25 | [diff] [blame] | 82 | # - iOS: Depends on ios_partition_alloc_enabled. |
Arthur Sonzogni | 647b65eb6 | 2024-09-12 09:52:30 | [diff] [blame] | 83 | _is_partition_alloc_everywhere_platform = |
| 84 | !is_nacl && (!is_ios || ios_partition_alloc_enabled) |
| 85 | |
| 86 | use_allocator_shim_default = true # Updated below: |
| 87 | |
| 88 | # Sanitizers replace the allocator, don't use our own. |
| 89 | if (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. |
| 94 | if (is_nacl) { |
| 95 | use_allocator_shim_default = false |
| 96 | } |
| 97 | |
| 98 | # Under Fuchsia, the allocator shim is only required for PA-E. |
| 99 | if (is_fuchsia && _disable_partition_alloc_everywhere) { |
| 100 | use_allocator_shim_default = false |
Justin | 69ec971 | 2023-01-25 14:37:25 | [diff] [blame] | 101 | } |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 102 | |
| 103 | # Under Windows debug build, the allocator shim is not compatible with CRT. |
Arthur Sonzogni | 647b65eb6 | 2024-09-12 09:52:30 | [diff] [blame] | 104 | # NaCl in particular does seem to link some binaries statically against the |
| 105 | # debug CRT with "is_nacl=false". |
| 106 | if (is_win && is_debug) { |
| 107 | use_allocator_shim_default = false |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 108 | } |
| 109 | |
Arthur Sonzogni | 647b65eb6 | 2024-09-12 09:52:30 | [diff] [blame] | 110 | if (is_win && is_component_build && (!use_custom_libcxx || libcxx_is_shared)) { |
| 111 | use_allocator_shim_default = false |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 112 | } |
| 113 | |
Arthur Sonzogni | 647b65eb6 | 2024-09-12 09:52:30 | [diff] [blame] | 114 | use_partition_alloc_as_malloc_default = |
| 115 | use_allocator_shim_default && _is_partition_alloc_everywhere_platform && |
| 116 | !_disable_partition_alloc_everywhere |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 117 | |
Arthur Sonzogni | 647b65eb6 | 2024-09-12 09:52:30 | [diff] [blame] | 118 | enable_backup_ref_ptr_support_default = use_partition_alloc_as_malloc_default |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 119 | |
Keishi Hattori | 1fca35b | 2023-01-24 04:14:33 | [diff] [blame] | 120 | enable_backup_ref_ptr_slow_checks_default = false |
Arthur Sonzogni | 647b65eb6 | 2024-09-12 09:52:30 | [diff] [blame] | 121 | |
Paul Semel | 67d96e7 | 2023-06-29 13:52:17 | [diff] [blame] | 122 | enable_dangling_raw_ptr_checks_default = |
Arthur Sonzogni | 647b65eb6 | 2024-09-12 09:52:30 | [diff] [blame] | 123 | # The DanglingPointerDetector relies on BackupRefPtr: |
Arthur Sonzogni | 43ec3647 | 2024-04-15 19:15:39 | [diff] [blame] | 124 | enable_backup_ref_ptr_support_default && |
Arthur Sonzogni | 647b65eb6 | 2024-09-12 09:52:30 | [diff] [blame] | 125 | # 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 Nowierski | 476039e1 | 2023-09-28 00:31:23 | [diff] [blame] | 145 | |
mikt | cd50ddaa | 2024-10-11 09:42:44 | [diff] [blame^] | 146 | enable_ios_corruption_hardening_default = |
| 147 | is_ios && ios_partition_alloc_corruption_hardening_enabled |
| 148 | |
Bartek Nowierski | 476039e1 | 2023-09-28 00:31:23 | [diff] [blame] | 149 | raw_ptr_zero_on_construct_default = true |
| 150 | raw_ptr_zero_on_move_default = true |
| 151 | raw_ptr_zero_on_destruct_default = false |
Ada Romanowski | 56a61ac | 2024-03-08 04:56:14 | [diff] [blame] | 152 | |
| 153 | # Allow embedders to opt-out of C++20 build which is set as default. |
| 154 | # Kindly notify PartitionAlloc owners of change to false. |
| 155 | assert_cpp20_default = true |