• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/buildflag_header.gni")
6import("//build/config/android/config.gni")
7import("//build/config/cast.gni")
8import("//build/config/chromeos/ui_mode.gni")
9import("//build/config/compiler/compiler.gni")
10import("//build/config/dcheck_always_on.gni")
11import("//build/config/logging.gni")
12import("../../partition_alloc.gni")
13
14# Add partition_alloc.gni and import it for partition_alloc configs.
15
16# TODO(https://crbug.com/1467773): Split PartitionAlloc into a public and
17# private parts. The public config would include add the "./include" dir and
18# the private config would add the "./src" dir.
19# TODO(https://crbug.com/1467773): Move this config and several target into
20# "../..".
21config("public_includes") {
22  include_dirs = [
23    "..",
24    "$root_gen_dir/" + rebase_path("..", "//"),
25  ]
26}
27
28# Enable more warnings that were found when using PartitionAlloc in other
29# projects.
30#
31# This list was initially copied from Dawn, who gathered this list from its own
32# dependants.
33config("dependants_extra_warnings") {
34  # Add them only when building PartitionAlloc as part of Chrome, because we
35  # control which clang version we use. Otherwise we risk breaking dependants
36  # when they use a different clang version.
37  #
38  # Fuchsia has been excluded from the extra warnings: Dependency over
39  # fuchsia.kernel involves too many warning. This is not a real issue, because
40  # the header is only used by PartitionAlloc internally. The dependants do not
41  # include it transitively.
42  if (build_with_chromium && is_clang && !is_fuchsia) {
43    cflags = [
44      "-Wc++11-narrowing",
45      "-Wconditional-uninitialized",
46      "-Wcstring-format-directive",
47      "-Wctad-maybe-unsupported",
48      "-Wdeprecated-copy",
49      "-Wdeprecated-copy-dtor",
50      "-Wduplicate-enum",
51      "-Wextra-semi",
52      "-Wextra-semi-stmt",
53      "-Wimplicit-fallthrough",
54      "-Winconsistent-missing-destructor-override",
55      "-Winvalid-offsetof",
56      "-Wmissing-field-initializers",
57      "-Wnon-c-typedef-for-linkage",
58      "-Wpessimizing-move",
59      "-Wrange-loop-analysis",
60      "-Wredundant-move",
61      "-Wshadow-field",
62      "-Wstrict-prototypes",
63      "-Wsuggest-destructor-override",
64      "-Wsuggest-override",
65      "-Wtautological-unsigned-zero-compare",
66      "-Wunreachable-code-aggressive",
67      "-Wunused-but-set-variable",
68      "-Wunused-macros",
69    ]
70
71    # clang-cl doesn't know -pedantic, pass it explicitly to the clang driver
72    if (is_win) {
73      cflags += [ "/clang:-pedantic" ]
74    } else {
75      cflags += [ "-pedantic" ]
76    }
77
78    # TODO(https://crbug.com/1464560) Get rid of those warning exceptions.
79    # This is blocking using PartitionAlloc in Dawn. Most fixes have been
80    # prototyped in:
81    # https://chromium-review.googlesource.com/c/chromium/src/+/5057762
82    cflags += [
83      # Those are compiler extension banned by -pedantic.
84      "-Wno-import-preprocessor-directive-pedantic",
85      "-Wno-embedded-directive",
86      "-Wno-gnu-statement-expression-from-macro-expansion",
87      "-Wno-language-extension-token",
88      "-Wno-zero-length-array",
89    ]
90  }
91}
92
93_remove_configs = []
94_add_configs = []
95if (!is_debug || partition_alloc_optimized_debug) {
96  _remove_configs += [ "//build/config/compiler:default_optimization" ]
97
98  # Partition alloc is relatively hot (>1% of cycles for users of CrOS).
99  # Use speed-focused optimizations for it.
100  _add_configs += [ "//build/config/compiler:optimize_speed" ]
101} else {
102  _remove_configs += [ "//build/config/compiler:default_optimization" ]
103  _add_configs += [ "//build/config/compiler:no_optimize" ]
104}
105
106component("raw_ptr") {
107  # `gn check` is unhappy with most `#includes` when PA isn't
108  # actually built.
109  check_includes = use_partition_alloc
110  public = [
111    "pointers/raw_ptr.h",
112    "pointers/raw_ptr_cast.h",
113    "pointers/raw_ptr_exclusion.h",
114    "pointers/raw_ptr_noop_impl.h",
115    "pointers/raw_ref.h",
116  ]
117  sources = []
118  public_configs = [ ":public_includes" ]
119  configs += [ "//build/config/compiler:wexit_time_destructors" ]
120
121  if (enable_backup_ref_ptr_support) {
122    sources += [
123      "pointers/raw_ptr_backup_ref_impl.cc",
124      "pointers/raw_ptr_backup_ref_impl.h",
125    ]
126  } else if (use_hookable_raw_ptr) {
127    sources += [
128      "pointers/raw_ptr_hookable_impl.cc",
129      "pointers/raw_ptr_hookable_impl.h",
130    ]
131  } else if (use_asan_unowned_ptr) {
132    sources += [
133      "pointers/raw_ptr_asan_unowned_impl.cc",
134      "pointers/raw_ptr_asan_unowned_impl.h",
135    ]
136  } else {
137    sources += [ "pointers/raw_ptr_noop_impl.h" ]
138    sources += [ "pointers/empty.cc" ]
139  }
140  if (use_partition_alloc) {
141    public_deps = [ ":partition_alloc" ]
142  }
143  deps = [ ":buildflags" ]
144
145  # See also: `partition_alloc_base/component_export.h`
146  defines = [ "IS_RAW_PTR_IMPL" ]
147
148  configs -= _remove_configs
149  configs += _add_configs
150  configs += [ ":dependants_extra_warnings" ]
151}
152
153# Changes the freelist implementation to use pointer offsets in lieu
154# of full-on pointers. Defaults to false, which implies the use of
155# "encoded next" freelist entry.
156#
157# Only usable when pointers are 64-bit.
158use_freelist_pool_offsets = has_64_bit_pointers && false
159
160buildflag_header("partition_alloc_buildflags") {
161  header = "partition_alloc_buildflags.h"
162
163  _record_alloc_info = false
164
165  # GWP-ASan is tied to BRP's "refcount in previous slot" mode, whose
166  # enablement is already gated on BRP enablement.
167  _enable_gwp_asan_support = put_ref_count_in_previous_slot
168
169  # Pools are a logical concept when address space is 32-bit.
170  _glue_core_pools = glue_core_pools && has_64_bit_pointers
171
172  # Pointer compression requires 64-bit pointers.
173  _enable_pointer_compression =
174      enable_pointer_compression_support && has_64_bit_pointers
175
176  # Force-enable live BRP in all processes, ignoring the canonical
177  # experiment state of `PartitionAllocBackupRefPtr`.
178  #
179  # This is not exposed as a GN arg as it is not meant to be used by
180  # developers - it is simply a compile-time hinge that should be
181  # set in the experimental build and then reverted immediately.
182  _force_all_process_brp = false
183
184  # TODO(crbug.com/1151236): Need to refactor the following buildflags.
185  # The buildflags (except RECORD_ALLOC_INFO) are used by both chrome and
186  # partition alloc. For partition alloc,
187  # gen/base/allocator/partition_allocator/src/partition_alloc/partition_alloc_buildflags.h
188  # defines and partition alloc includes the header file. For chrome,
189  # gen/base/allocator/buildflags.h defines and chrome includes.
190  flags = [
191    "HAS_64_BIT_POINTERS=$has_64_bit_pointers",
192
193    "USE_ALLOCATOR_SHIM=$use_allocator_shim",
194    "USE_PARTITION_ALLOC=$use_partition_alloc",
195    "USE_PARTITION_ALLOC_AS_MALLOC=$use_partition_alloc_as_malloc",
196
197    "ENABLE_BACKUP_REF_PTR_SUPPORT=$enable_backup_ref_ptr_support",
198    "ENABLE_BACKUP_REF_PTR_SLOW_CHECKS=$enable_backup_ref_ptr_slow_checks",
199    "ENABLE_BACKUP_REF_PTR_FEATURE_FLAG=$enable_backup_ref_ptr_feature_flag",
200    "ENABLE_DANGLING_RAW_PTR_CHECKS=$enable_dangling_raw_ptr_checks",
201    "ENABLE_DANGLING_RAW_PTR_FEATURE_FLAG=$enable_dangling_raw_ptr_feature_flag",
202    "ENABLE_DANGLING_RAW_PTR_PERF_EXPERIMENT=$enable_dangling_raw_ptr_perf_experiment",
203    "ENABLE_POINTER_SUBTRACTION_CHECK=$enable_pointer_subtraction_check",
204    "ENABLE_POINTER_ARITHMETIC_TRAIT_CHECK=$enable_pointer_arithmetic_trait_check",
205    "BACKUP_REF_PTR_POISON_OOB_PTR=$backup_ref_ptr_poison_oob_ptr",
206    "PUT_REF_COUNT_IN_PREVIOUS_SLOT=$put_ref_count_in_previous_slot",
207    "USE_ASAN_BACKUP_REF_PTR=$use_asan_backup_ref_ptr",
208    "USE_ASAN_UNOWNED_PTR=$use_asan_unowned_ptr",
209    "USE_HOOKABLE_RAW_PTR=$use_hookable_raw_ptr",
210    "ENABLE_GWP_ASAN_SUPPORT=$_enable_gwp_asan_support",
211    "FORCIBLY_ENABLE_BACKUP_REF_PTR_IN_ALL_PROCESSES=$_force_all_process_brp",
212
213    "FORCE_ENABLE_RAW_PTR_EXCLUSION=$force_enable_raw_ptr_exclusion",
214
215    "RECORD_ALLOC_INFO=$_record_alloc_info",
216    "USE_FREESLOT_BITMAP=$use_freeslot_bitmap",
217    "GLUE_CORE_POOLS=$_glue_core_pools",
218    "ENABLE_POINTER_COMPRESSION=$_enable_pointer_compression",
219    "ENABLE_SHADOW_METADATA_FOR_64_BITS_POINTERS=$enable_shadow_metadata",
220    "USE_FREELIST_POOL_OFFSETS=$use_freelist_pool_offsets",
221
222    "USE_STARSCAN=$use_starscan",
223    "PCSCAN_STACK_SUPPORTED=$pcscan_stack_supported",
224
225    "ENABLE_PKEYS=$enable_pkeys",
226    "ENABLE_THREAD_ISOLATION=$enable_pkeys",
227  ]
228}
229
230buildflag_header("raw_ptr_buildflags") {
231  header = "raw_ptr_buildflags.h"
232
233  flags = [
234    "RAW_PTR_ZERO_ON_CONSTRUCT=$raw_ptr_zero_on_construct",
235    "RAW_PTR_ZERO_ON_MOVE=$raw_ptr_zero_on_move",
236    "RAW_PTR_ZERO_ON_DESTRUCT=$raw_ptr_zero_on_destruct",
237  ]
238}
239
240buildflag_header("chromecast_buildflags") {
241  header = "chromecast_buildflags.h"
242
243  flags = [
244    "PA_IS_CAST_ANDROID=$is_cast_android",
245    "PA_IS_CASTOS=$is_castos",
246  ]
247}
248
249buildflag_header("chromeos_buildflags") {
250  header = "chromeos_buildflags.h"
251
252  flags = [ "PA_IS_CHROMEOS_ASH=$is_chromeos_ash" ]
253}
254
255buildflag_header("debugging_buildflags") {
256  header = "debugging_buildflags.h"
257  header_dir = rebase_path(".", "//") + "/partition_alloc_base/debug"
258
259  # Duplicates the setup Chromium uses to define `DCHECK_IS_ON()`,
260  # but avails it as a buildflag.
261  _dcheck_is_on = is_debug || dcheck_always_on
262
263  flags = [
264    "PA_DCHECK_IS_ON=$_dcheck_is_on",
265    "PA_EXPENSIVE_DCHECKS_ARE_ON=$enable_expensive_dchecks",
266    "PA_DCHECK_IS_CONFIGURABLE=$dcheck_is_configurable",
267    "PA_CAN_UNWIND_WITH_FRAME_POINTERS=$can_unwind_with_frame_pointers",
268  ]
269}
270
271group("buildflags") {
272  public_deps = [
273    ":chromecast_buildflags",
274    ":chromeos_buildflags",
275    ":debugging_buildflags",
276    ":partition_alloc_buildflags",
277    ":raw_ptr_buildflags",
278  ]
279  public_configs = [ ":public_includes" ]
280}
281
282if (is_clang_or_gcc) {
283  config("partition_alloc_implementation") {
284    # See also: `partition_alloc_base/component_export.h`
285    defines = [ "IS_PARTITION_ALLOC_IMPL" ]
286  }
287
288  config("partition_alloc_base_implementation") {
289    # See also: `partition_alloc_base/component_export.h`
290    defines = [ "IS_PARTITION_ALLOC_BASE_IMPL" ]
291  }
292
293  config("allocator_shim_implementation") {
294    # See also: `partition_alloc_base/component_export.h`
295    defines = [ "IS_ALLOCATOR_SHIM_IMPL" ]
296  }
297
298  config("memory_tagging") {
299    if (current_cpu == "arm64" &&
300        (is_linux || is_chromeos || is_android || is_fuchsia)) {
301      # base/ has access to the MTE intrinsics because it needs to use them,
302      # but they're not backwards compatible. Use base::CPU::has_mte()
303      # beforehand to confirm or use indirect functions (ifuncs) to select
304      # an MTE-specific implementation at dynamic link-time.
305      cflags = [
306        "-Xclang",
307        "-target-feature",
308        "-Xclang",
309        "+mte",
310      ]
311    }
312  }
313
314  # Used to shim malloc symbols on Android. see //base/allocator/README.md.
315  config("wrap_malloc_symbols") {
316    ldflags = [
317      "-Wl,-wrap,calloc",
318      "-Wl,-wrap,free",
319      "-Wl,-wrap,malloc",
320      "-Wl,-wrap,memalign",
321      "-Wl,-wrap,posix_memalign",
322      "-Wl,-wrap,pvalloc",
323      "-Wl,-wrap,realloc",
324      "-Wl,-wrap,valloc",
325
326      # Not allocating memory, but part of the API
327      "-Wl,-wrap,malloc_usable_size",
328
329      # <stdlib.h> functions
330      "-Wl,-wrap,realpath",
331
332      # <string.h> functions
333      "-Wl,-wrap,strdup",
334      "-Wl,-wrap,strndup",
335
336      # <unistd.h> functions
337      "-Wl,-wrap,getcwd",
338
339      # <stdio.h> functions
340      "-Wl,-wrap,asprintf",
341      "-Wl,-wrap,vasprintf",
342    ]
343  }
344
345  config("mac_no_default_new_delete_symbols") {
346    if (!is_component_build) {
347      # This is already set when we compile libc++, see
348      # buildtools/third_party/libc++/BUILD.gn. But it needs to be set here as
349      # well, since the shim defines the symbols, to prevent them being exported.
350      cflags = [ "-fvisibility-global-new-delete-hidden" ]
351    }
352  }
353
354  if (is_fuchsia) {
355    config("fuchsia_sync_lib") {
356      libs = [
357        "sync",  # Used by spinning_mutex.h.
358      ]
359    }
360  }
361
362  if (enable_pkeys && is_debug) {
363    config("no_stack_protector") {
364      cflags = [ "-fno-stack-protector" ]
365    }
366  }
367
368  group("partition_alloc") {
369    public_deps = [
370      ":allocator_base",
371      ":allocator_core",
372      ":allocator_shim",
373    ]
374  }
375
376  component("allocator_core") {
377    visibility = [ ":*" ]
378
379    sources = [
380      "address_pool_manager.cc",
381      "address_pool_manager.h",
382      "address_pool_manager_bitmap.cc",
383      "address_pool_manager_bitmap.h",
384      "address_pool_manager_types.h",
385      "address_space_randomization.cc",
386      "address_space_randomization.h",
387      "address_space_stats.h",
388      "allocation_guard.cc",
389      "allocation_guard.h",
390      "compressed_pointer.cc",
391      "compressed_pointer.h",
392      "dangling_raw_ptr_checks.cc",
393      "dangling_raw_ptr_checks.h",
394      "flags.h",
395      "freeslot_bitmap.h",
396      "freeslot_bitmap_constants.h",
397      "gwp_asan_support.cc",
398      "gwp_asan_support.h",
399      "lightweight_quarantine.cc",
400      "lightweight_quarantine.h",
401      "memory_reclaimer.cc",
402      "memory_reclaimer.h",
403      "oom.cc",
404      "oom.h",
405      "oom_callback.cc",
406      "oom_callback.h",
407      "page_allocator.cc",
408      "page_allocator.h",
409      "page_allocator_constants.h",
410      "page_allocator_internal.h",
411      "partition_address_space.cc",
412      "partition_address_space.h",
413      "partition_alloc-inl.h",
414      "partition_alloc.cc",
415      "partition_alloc.h",
416      "partition_alloc_allocation_data.h",
417      "partition_alloc_check.h",
418      "partition_alloc_config.h",
419      "partition_alloc_constants.h",
420      "partition_alloc_forward.h",
421      "partition_alloc_hooks.cc",
422      "partition_alloc_hooks.h",
423      "partition_bucket.cc",
424      "partition_bucket.h",
425      "partition_bucket_lookup.h",
426      "partition_cookie.h",
427      "partition_dcheck_helper.cc",
428      "partition_dcheck_helper.h",
429      "partition_direct_map_extent.h",
430      "partition_freelist_entry.cc",
431      "partition_freelist_entry.h",
432      "partition_lock.h",
433      "partition_oom.cc",
434      "partition_oom.h",
435      "partition_page.cc",
436      "partition_page.h",
437      "partition_page_constants.h",
438      "partition_ref_count.h",
439      "partition_root.cc",
440      "partition_root.h",
441      "partition_stats.cc",
442      "partition_stats.h",
443      "partition_superpage_extent_entry.h",
444      "partition_tls.h",
445      "random.cc",
446      "random.h",
447      "reservation_offset_table.cc",
448      "reservation_offset_table.h",
449      "reverse_bytes.h",
450      "spinning_mutex.cc",
451      "spinning_mutex.h",
452      "tagging.cc",
453      "tagging.h",
454      "thread_cache.cc",
455      "thread_cache.h",
456      "thread_isolation/alignment.h",
457      "thread_isolation/pkey.cc",
458      "thread_isolation/pkey.h",
459      "thread_isolation/thread_isolation.cc",
460      "thread_isolation/thread_isolation.h",
461      "yield_processor.h",
462    ]
463
464    if (use_starscan) {
465      sources += [
466        "starscan/logging.h",
467        "starscan/metadata_allocator.cc",
468        "starscan/metadata_allocator.h",
469        "starscan/pcscan.cc",
470        "starscan/pcscan.h",
471        "starscan/pcscan_internal.cc",
472        "starscan/pcscan_internal.h",
473        "starscan/pcscan_scheduling.cc",
474        "starscan/pcscan_scheduling.h",
475        "starscan/raceful_worklist.h",
476        "starscan/scan_loop.h",
477        "starscan/snapshot.cc",
478        "starscan/snapshot.h",
479        "starscan/stack/stack.cc",
480        "starscan/stack/stack.h",
481        "starscan/starscan_fwd.h",
482        "starscan/state_bitmap.h",
483        "starscan/stats_collector.cc",
484        "starscan/stats_collector.h",
485        "starscan/stats_reporter.h",
486        "starscan/write_protector.cc",
487        "starscan/write_protector.h",
488      ]
489    }
490
491    defines = []
492    if (is_win) {
493      sources += [
494        "page_allocator_internals_win.h",
495        "partition_tls_win.cc",
496      ]
497    } else if (is_posix) {
498      sources += [
499        "page_allocator_internals_posix.cc",
500        "page_allocator_internals_posix.h",
501      ]
502    } else if (is_fuchsia) {
503      sources += [ "page_allocator_internals_fuchsia.h" ]
504    }
505    if (is_android) {
506      # The Android NDK supports PR_MTE_* macros as of NDK r23.
507      if (android_ndk_major_version >= 23) {
508        defines += [ "HAS_PR_MTE_MACROS" ]
509      }
510    }
511    if (use_starscan) {
512      if (current_cpu == "x64") {
513        assert(pcscan_stack_supported)
514        sources += [ "starscan/stack/asm/x64/push_registers_asm.cc" ]
515      } else if (current_cpu == "x86") {
516        assert(pcscan_stack_supported)
517        sources += [ "starscan/stack/asm/x86/push_registers_asm.cc" ]
518      } else if (current_cpu == "arm") {
519        assert(pcscan_stack_supported)
520        sources += [ "starscan/stack/asm/arm/push_registers_asm.cc" ]
521      } else if (current_cpu == "arm64") {
522        assert(pcscan_stack_supported)
523        sources += [ "starscan/stack/asm/arm64/push_registers_asm.cc" ]
524      } else if (current_cpu == "riscv64") {
525        assert(pcscan_stack_supported)
526        sources += [ "starscan/stack/asm/riscv64/push_registers_asm.cc" ]
527      } else {
528        # To support a trampoline for another arch, please refer to v8/src/heap/base.
529        assert(!pcscan_stack_supported)
530      }
531    }
532    if (use_freelist_pool_offsets) {
533      sources += [ "pool_offset_freelist.h" ]
534    } else {
535      sources += [ "encoded_next_freelist.h" ]
536    }
537
538    public_deps = [
539      ":chromecast_buildflags",
540      ":chromeos_buildflags",
541      ":debugging_buildflags",
542      ":partition_alloc_buildflags",
543    ]
544
545    configs += [
546      ":partition_alloc_implementation",
547      ":memory_tagging",
548      "//build/config/compiler:wexit_time_destructors",
549    ]
550    deps = [ ":allocator_base" ]
551    public_configs = []
552    if (is_android) {
553      # tagging.cc requires __arm_mte_set_* functions.
554      deps += [ "//third_party/cpu_features:ndk_compat" ]
555    }
556    if (is_fuchsia) {
557      deps += [
558        "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.kernel:fuchsia.kernel_cpp",
559        "//third_party/fuchsia-sdk/sdk/pkg/component_incoming_cpp",
560      ]
561      public_deps += [
562        "//third_party/fuchsia-sdk/sdk/pkg/sync",
563        "//third_party/fuchsia-sdk/sdk/pkg/zx",
564      ]
565
566      # Needed for users of spinning_mutex.h, which for performance reasons,
567      # contains inlined calls to `libsync` inside the header file.
568      # It appends an entry to the "libs" section of the dependent target.
569      public_configs += [ ":fuchsia_sync_lib" ]
570    }
571
572    frameworks = []
573    if (is_mac) {
574      # SecTaskGetCodeSignStatus needs:
575      frameworks += [ "Security.framework" ]
576    }
577
578    if (is_apple) {
579      frameworks += [
580        "CoreFoundation.framework",
581        "Foundation.framework",
582      ]
583    }
584
585    configs -= _remove_configs
586    configs += _add_configs
587    configs += [ ":dependants_extra_warnings" ]
588
589    # We want to be able to test pkey mode without access to the default pkey.
590    # This is incompatible with stack protectors since the TLS won't be pkey-tagged.
591    if (enable_pkeys && is_debug) {
592      configs += [ ":no_stack_protector" ]
593    }
594  }
595
596  component("allocator_base") {
597    visibility = [ ":*" ]
598
599    sources = [
600      "partition_alloc_base/atomic_ref_count.h",
601      "partition_alloc_base/augmentations/compiler_specific.h",
602      "partition_alloc_base/bits.h",
603      "partition_alloc_base/check.cc",
604      "partition_alloc_base/check.h",
605      "partition_alloc_base/compiler_specific.h",
606      "partition_alloc_base/component_export.h",
607      "partition_alloc_base/cpu.cc",
608      "partition_alloc_base/cpu.h",
609      "partition_alloc_base/cxx20_is_constant_evaluated.h",
610      "partition_alloc_base/debug/alias.cc",
611      "partition_alloc_base/debug/alias.h",
612      "partition_alloc_base/debug/stack_trace.cc",
613      "partition_alloc_base/debug/stack_trace.h",
614      "partition_alloc_base/export_template.h",
615      "partition_alloc_base/immediate_crash.h",
616      "partition_alloc_base/log_message.cc",
617      "partition_alloc_base/log_message.h",
618      "partition_alloc_base/logging.cc",
619      "partition_alloc_base/logging.h",
620      "partition_alloc_base/memory/page_size.h",
621      "partition_alloc_base/memory/ref_counted.cc",
622      "partition_alloc_base/memory/ref_counted.h",
623      "partition_alloc_base/memory/scoped_policy.h",
624      "partition_alloc_base/memory/scoped_refptr.h",
625      "partition_alloc_base/no_destructor.h",
626      "partition_alloc_base/notreached.h",
627      "partition_alloc_base/numerics/checked_math.h",
628      "partition_alloc_base/numerics/checked_math_impl.h",
629      "partition_alloc_base/numerics/clamped_math.h",
630      "partition_alloc_base/numerics/clamped_math_impl.h",
631      "partition_alloc_base/numerics/safe_conversions.h",
632      "partition_alloc_base/numerics/safe_conversions_arm_impl.h",
633      "partition_alloc_base/numerics/safe_conversions_impl.h",
634      "partition_alloc_base/numerics/safe_math.h",
635      "partition_alloc_base/numerics/safe_math_arm_impl.h",
636      "partition_alloc_base/numerics/safe_math_clang_gcc_impl.h",
637      "partition_alloc_base/numerics/safe_math_shared_impl.h",
638      "partition_alloc_base/posix/eintr_wrapper.h",
639      "partition_alloc_base/process/process_handle.h",
640      "partition_alloc_base/rand_util.cc",
641      "partition_alloc_base/rand_util.h",
642      "partition_alloc_base/scoped_clear_last_error.h",
643      "partition_alloc_base/strings/cstring_builder.cc",
644      "partition_alloc_base/strings/cstring_builder.h",
645      "partition_alloc_base/strings/safe_sprintf.cc",
646      "partition_alloc_base/strings/safe_sprintf.h",
647      "partition_alloc_base/strings/string_util.cc",
648      "partition_alloc_base/strings/string_util.h",
649      "partition_alloc_base/strings/stringprintf.cc",
650      "partition_alloc_base/strings/stringprintf.h",
651      "partition_alloc_base/system/sys_info.h",
652      "partition_alloc_base/thread_annotations.h",
653      "partition_alloc_base/threading/platform_thread.cc",
654      "partition_alloc_base/threading/platform_thread.h",
655      "partition_alloc_base/threading/platform_thread_ref.h",
656      "partition_alloc_base/time/time.cc",
657      "partition_alloc_base/time/time.h",
658      "partition_alloc_base/time/time_override.cc",
659      "partition_alloc_base/time/time_override.h",
660      "partition_alloc_base/types/strong_alias.h",
661      "partition_alloc_base/win/win_handle_types.h",
662      "partition_alloc_base/win/win_handle_types_list.inc",
663      "partition_alloc_base/win/windows_types.h",
664    ]
665
666    if (is_win) {
667      sources += [
668        "partition_alloc_base/debug/stack_trace_win.cc",
669        "partition_alloc_base/memory/page_size_win.cc",
670        "partition_alloc_base/process/process_handle_win.cc",
671        "partition_alloc_base/rand_util_win.cc",
672        "partition_alloc_base/scoped_clear_last_error_win.cc",
673        "partition_alloc_base/threading/platform_thread_win.cc",
674        "partition_alloc_base/time/time_win.cc",
675      ]
676    } else if (is_posix) {
677      sources += [
678        "partition_alloc_base/debug/stack_trace_posix.cc",
679        "partition_alloc_base/files/file_util.h",
680        "partition_alloc_base/files/file_util_posix.cc",
681        "partition_alloc_base/memory/page_size_posix.cc",
682        "partition_alloc_base/posix/safe_strerror.cc",
683        "partition_alloc_base/posix/safe_strerror.h",
684        "partition_alloc_base/process/process_handle_posix.cc",
685        "partition_alloc_base/rand_util_posix.cc",
686        "partition_alloc_base/threading/platform_thread_internal_posix.h",
687        "partition_alloc_base/threading/platform_thread_posix.cc",
688        "partition_alloc_base/time/time_conversion_posix.cc",
689      ]
690
691      if (is_linux || is_chromeos) {
692        sources += [ "partition_alloc_base/debug/stack_trace_linux.cc" ]
693      }
694
695      if (is_android || is_chromeos_ash) {
696        sources += [ "partition_alloc_base/time/time_android.cc" ]
697      }
698      if (is_apple) {
699        # Request <dlfcn.h> to provide the `dladdr()` function. This is used to
700        # translate address to symbolic information.
701        defines = [ "HAVE_DLADDR" ]
702
703        sources += [
704          "partition_alloc_base/debug/stack_trace_mac.cc",
705          "partition_alloc_base/time/time_apple.mm",
706        ]
707      } else {
708        sources += [ "partition_alloc_base/time/time_now_posix.cc" ]
709      }
710    } else if (is_fuchsia) {
711      sources += [
712        "partition_alloc_base/fuchsia/fuchsia_logging.cc",
713        "partition_alloc_base/fuchsia/fuchsia_logging.h",
714        "partition_alloc_base/memory/page_size_posix.cc",
715        "partition_alloc_base/posix/safe_strerror.cc",
716        "partition_alloc_base/posix/safe_strerror.h",
717        "partition_alloc_base/rand_util_fuchsia.cc",
718        "partition_alloc_base/threading/platform_thread_internal_posix.h",
719        "partition_alloc_base/threading/platform_thread_posix.cc",
720        "partition_alloc_base/time/time_conversion_posix.cc",
721        "partition_alloc_base/time/time_fuchsia.cc",
722      ]
723    }
724    if (is_android) {
725      # Only android build requires native_library, and native_library depends
726      # on file_path. So file_path is added if is_android = true.
727      sources += [
728        "partition_alloc_base/debug/stack_trace_android.cc",
729        "partition_alloc_base/files/file_path.cc",
730        "partition_alloc_base/files/file_path.h",
731        "partition_alloc_base/native_library.cc",
732        "partition_alloc_base/native_library.h",
733        "partition_alloc_base/native_library_posix.cc",
734      ]
735    }
736    if (is_apple) {
737      # Apple-specific utilities
738      sources += [
739        "partition_alloc_base/apple/foundation_util.h",
740        "partition_alloc_base/apple/foundation_util.mm",
741        "partition_alloc_base/apple/mach_logging.cc",
742        "partition_alloc_base/apple/mach_logging.h",
743        "partition_alloc_base/apple/scoped_cftyperef.h",
744        "partition_alloc_base/apple/scoped_typeref.h",
745      ]
746      if (is_ios) {
747        sources += [
748          "partition_alloc_base/ios/ios_util.h",
749          "partition_alloc_base/ios/ios_util.mm",
750          "partition_alloc_base/system/sys_info_ios.mm",
751        ]
752      }
753      if (is_mac) {
754        sources += [
755          "partition_alloc_base/mac/mac_util.h",
756          "partition_alloc_base/mac/mac_util.mm",
757          "partition_alloc_base/system/sys_info_mac.mm",
758        ]
759      }
760    }
761
762    public_deps = [
763      ":chromecast_buildflags",
764      ":chromeos_buildflags",
765      ":debugging_buildflags",
766      ":partition_alloc_buildflags",
767    ]
768    public_configs = [ ":public_includes" ]
769    configs += [
770      ":partition_alloc_base_implementation",
771      "//build/config/compiler:wexit_time_destructors",
772    ]
773
774    deps = []
775    if (is_fuchsia) {
776      public_deps += [ "//third_party/fuchsia-sdk/sdk/pkg/fit" ]
777    }
778
779    frameworks = []
780    if (is_apple) {
781      frameworks += [
782        "CoreFoundation.framework",
783        "Foundation.framework",
784      ]
785    }
786
787    configs -= _remove_configs
788    configs += _add_configs
789    configs += [ ":dependants_extra_warnings" ]
790  }
791
792  component("allocator_shim") {
793    visibility = [ ":*" ]
794
795    sources = []
796    deps = []
797    all_dependent_configs = []
798    public_configs = [ ":public_includes" ]
799    configs += [
800      ":allocator_shim_implementation",
801      "//build/config/compiler:wexit_time_destructors",
802    ]
803    frameworks = []
804
805    configs -= _remove_configs
806    configs += _add_configs
807    configs += [ ":dependants_extra_warnings" ]
808
809    shim_headers = []
810    shim_sources = []
811
812    shim_sources += [ "shim/allocator_shim.cc" ]
813    shim_headers += [
814      "shim/allocator_shim.h",
815      "shim/allocator_shim_internals.h",
816    ]
817    if (use_partition_alloc) {
818      shim_sources += [
819        "shim/allocator_shim_default_dispatch_to_partition_alloc.cc",
820        "shim/nonscannable_allocator.cc",
821      ]
822      shim_headers += [
823        "shim/allocator_shim_default_dispatch_to_partition_alloc.h",
824        "shim/nonscannable_allocator.h",
825      ]
826    }
827    if (is_android) {
828      shim_headers += [
829        "shim/allocator_shim_override_cpp_symbols.h",
830        "shim/allocator_shim_override_linker_wrapped_symbols.h",
831      ]
832      if (use_allocator_shim) {
833        all_dependent_configs += [ ":wrap_malloc_symbols" ]
834      }
835    }
836    if (is_apple) {
837      shim_headers += [
838        "shim/allocator_shim_override_apple_default_zone.h",
839        "shim/allocator_shim_override_apple_symbols.h",
840        "shim/early_zone_registration_constants.h",
841        "shim/allocator_interception_apple.h",
842        "shim/malloc_zone_functions_apple.h",
843      ]
844      shim_sources += [
845        "shim/allocator_interception_apple.mm",
846        "shim/malloc_zone_functions_apple.cc",
847      ]
848      frameworks += [ "CoreFoundation.framework" ]
849
850      if (use_allocator_shim) {
851        configs += [ ":mac_no_default_new_delete_symbols" ]
852
853        # Do not compile with ARC because this target has to interface with
854        # low-level Objective-C and having ARC would interfere.
855        configs -= [ "//build/config/compiler:enable_arc" ]
856      }
857    }
858    if (is_chromeos || is_linux) {
859      shim_headers += [
860        "shim/allocator_shim_override_cpp_symbols.h",
861        "shim/allocator_shim_override_glibc_weak_symbols.h",
862        "shim/allocator_shim_override_libc_symbols.h",
863      ]
864    }
865    if (is_win) {
866      shim_headers += [
867        "shim/allocator_shim_override_ucrt_symbols_win.h",
868        "shim/winheap_stubs_win.h",
869      ]
870      shim_sources += [ "shim/winheap_stubs_win.cc" ]
871    }
872
873    if (!use_partition_alloc_as_malloc) {
874      if (is_android) {
875        shim_sources += [
876          "shim/allocator_shim_default_dispatch_to_linker_wrapped_symbols.cc",
877        ]
878      }
879      if (is_apple) {
880        shim_sources +=
881            [ "shim/allocator_shim_default_dispatch_to_apple_zoned_malloc.cc" ]
882      }
883      if (is_chromeos || is_linux) {
884        shim_sources += [ "shim/allocator_shim_default_dispatch_to_glibc.cc" ]
885      }
886      if (is_win) {
887        shim_sources += [ "shim/allocator_shim_default_dispatch_to_winheap.cc" ]
888      }
889    }
890
891    sources = shim_headers
892    if (use_allocator_shim) {
893      sources += shim_sources
894    } else {
895      # To avoid "lld-link: error: <root>: undefined symbol: _DllMainCRTStartup",
896      # at least one object file is required when linking allocator_shim.dll.
897      sources += [ "shim/empty.cc" ]
898    }
899
900    deps += [
901      ":allocator_base",
902      ":allocator_core",
903      ":buildflags",
904    ]
905  }
906}  # if (is_clang_or_gcc)
907# TODO(crbug.com/1151236): After making partition_alloc a standalone library,
908# move test code here. i.e. test("partition_alloc_tests") { ... } and
909# test("partition_alloc_perftests").
910