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 | |
| 8 | # Temporarily disable tcmalloc on arm64 linux to get rid of compilation errors. |
Sylvain Defresne | fafffe8 | 2020-07-27 14:16:50 | [diff] [blame] | 9 | if (is_android || is_apple || is_asan || is_lsan || is_tsan || is_msan || |
Yuki Shiino | 24622fa | 2020-08-26 12:01:02 | [diff] [blame] | 10 | is_win || is_fuchsia || |
| 11 | ((is_linux || is_chromeos) && target_cpu == "arm64") || |
Rob Hueber | 336a5ae | 2019-09-10 21:43:05 | [diff] [blame] | 12 | (is_cast_audio_only && target_cpu == "arm")) { |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 13 | _default_allocator = "none" |
| 14 | } else { |
| 15 | _default_allocator = "tcmalloc" |
| 16 | } |
| 17 | |
| 18 | # The debug CRT on Windows has some debug features that are incompatible with |
| 19 | # the shim. NaCl in particular does seem to link some binaries statically |
| 20 | # against the debug CRT with "is_nacl=false". |
Sean McAllister | deaa740 | 2020-07-31 04:42:54 | [diff] [blame] | 21 | if ((is_linux || is_chromeos || is_android || is_apple || |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 22 | (is_win && !is_component_build && !is_debug)) && !is_asan && !is_hwasan && |
| 23 | !is_lsan && !is_tsan && !is_msan) { |
| 24 | _default_use_allocator_shim = true |
| 25 | } else { |
| 26 | _default_use_allocator_shim = false |
| 27 | } |
| 28 | |
| 29 | declare_args() { |
| 30 | # Memory allocator to use. Set to "none" to use default allocator. |
| 31 | use_allocator = _default_allocator |
| 32 | |
| 33 | # Causes all the allocations to be routed via allocator_shim.cc. |
| 34 | use_allocator_shim = _default_use_allocator_shim |
Yuki Shiino | 24622fa | 2020-08-26 12:01:02 | [diff] [blame] | 35 | |
Yuki Shiino | 90d5fe68 | 2020-09-02 11:03:51 | [diff] [blame^] | 36 | # Whether PartitionAlloc should be available for use or not. |
| 37 | # true makes PartitionAlloc linked to the executable or shared library and |
| 38 | # makes it available for use, but it doesn't mean that the default allocator |
| 39 | # is PartitionAlloc. PartitionAlloc may or may not be the default allocator. |
| 40 | # |
| 41 | # |use_allocator = "partition"| makes PartitionAlloc the default allocator |
| 42 | # but it's effective only when |use_partition_alloc = true|. |
| 43 | # |
| 44 | # TODO(lizeb, yukishiino): Determine if |use_partition_alloc| is necessary or |
| 45 | # not, and redesign or remove the flag accordingly. We may want to assert a |
| 46 | # possible conflict between |use_allocator = "partition"| and |
| 47 | # |use_partition_alloc = true| rather than prioritizing use_partition_alloc. |
| 48 | use_partition_alloc = !is_ios # Never use PartitionAlloc on iOS. |
| 49 | } |
| 50 | |
| 51 | if (!use_partition_alloc && use_allocator == "partition") { |
| 52 | # If there is a conflict, prioritize |use_partition_alloc| over |
| 53 | # |use_allocator|. |
| 54 | use_allocator = "none" |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 55 | } |
| 56 | |
Benoit Lize | a27feee | 2020-06-10 12:48:52 | [diff] [blame] | 57 | assert(use_allocator == "none" || use_allocator == "tcmalloc" || |
| 58 | use_allocator == "partition") |
| 59 | |
| 60 | # Don't ship this configuration, not ready yet. |
| 61 | assert(!(use_allocator == "partition" && is_official_build)) |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 62 | |
Benoit Lize | 611121083 | 2020-08-26 13:38:08 | [diff] [blame] | 63 | assert(!is_win || use_allocator != "tcmalloc", |
| 64 | "Tcmalloc doesn't work on Windows.") |
| 65 | assert(!is_mac || use_allocator != "tcmalloc", |
| 66 | "Tcmalloc doesn't work on macOS.") |
| 67 | assert(!is_ios || use_allocator != "tcmalloc", "Tcmalloc doesn't work on iOS.") |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 68 | |
Rohit Rao | 849b426 | 2020-05-01 19:10:34 | [diff] [blame] | 69 | assert( |
Yuki Shiino | 24622fa | 2020-08-26 12:01:02 | [diff] [blame] | 70 | !use_allocator_shim || is_linux || is_chromeos || is_android || is_win || |
| 71 | is_apple, |
Rohit Rao | 849b426 | 2020-05-01 19:10:34 | [diff] [blame] | 72 | "use_allocator_shim works only on Android, iOS, Linux, macOS, and Windows.") |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 73 | |
| 74 | if (is_win && use_allocator_shim) { |
| 75 | assert(!is_component_build, |
| 76 | "The allocator shim doesn't work for the component build on Windows.") |
| 77 | } |