build_config.md 4.7 KB

Build Config

PartitionAlloc’s behavior and operation can be influenced by many different settings. Broadly, these are controlled at the top-level by GN args, which propagate via buildflags and #defined clauses.

*** promo Most of what you’ll want to know exists between

*** aside While Chromium promotes the #if BUILDFLAG(FOO) construct, some of PartitionAlloc’s behavior is governed by compound conditions #defined in partition_alloc_config.h.


Select GN Args

use_partition_alloc

Defines whether PartitionAlloc is at all available.

Setting this false will entirely remove PartitionAlloc from the Chromium build. You probably do not want this.

*** note Back when PartitionAlloc was the dedicated allocator in Blink, disabling it was logically identical to wholly disabling it in Chromium. This GN arg organically grew in scope with the advent of PartitionAlloc-Everywhere and must be true as a prerequisite for enabling PA-E.


use_allocator

Does nothing special when value is "none". Enables PartitionAlloc-Everywhere (PA-E) when value is "partition".

*** note

  • While «everywhere» (in «PartitionAlloc-Everywhere») tautologically includes Blink where PartitionAlloc originated, setting use_allocator = "none" does not disable PA usage in Blink.
  • use_allocator = "partition" internally sets use_partition_alloc_as_malloc = true, which must not be confused with use_partition_alloc (see above). ***

use_backup_ref_ptr

Specifies BackupRefPtr as the implementation for base::raw_ptr<T> when true. See the MiraclePtr documentation.

*** aside BRP requires support from PartitionAlloc, so use_backup_ref_ptr also compiles the relevant code into PA. However, this arg does not govern whether or not BRP is actually enabled at runtime - that functionality is controlled by a Finch flag.


Note: Component Builds

When working on PartitionAlloc, know that is_debug defaults to implying is_component_build, which interferes with the allocator shim. A typical set of GN args should include

is_debug = true
is_component_build = false

Conversely, build configurations that have is_component_build = true without explicitly specifying PA-specific args will not build with PA-E enabled.

Notable Macros

There is an ongoing effort to break out PartitionAlloc into a standalone library. Once PartitionAlloc stands alone from the larger Chrome build apparatus, the code loses access to some macros. This is not an immediate concern, but the team needs to decide either

  • how to propagate these macros in place, or
  • how to remove them, replacing them with PA-specific build config.

A non-exhaustive list of work items:

  • OFFICIAL_BUILD - influences crash macros and PA_THREAD_CACHE_ALLOC_STATS. These are conceptually distinct enough to be worth separating into dedicated build controls.
  • IS_PARTITION_ALLOC_IMPL - must be defined when PartitionAlloc is built as a shared library. This is required to export symbols.
  • COMPONENT_BUILD - component builds (as per //docs/component_build.md) must #define COMPONENT_BUILD. Additionally, to build Win32, invoker must #define WIN32.
  • MEMORY_TOOL_REPLACES_ALLOCATOR
  • *_SANITIZER - mainly influences unit tests.

TODO(crbug.com/1151236): don’t PA_COMPONENT_EXPORT() functions defined under partition_alloc_base/.

*** note Over time, the above list should evolve into a list of macros / GN args that influence PartitionAlloc’s behavior.