0

base/allocator: Fix the allocator shim installation

Fixes the installation of allocator shim at //base/BUILD.gn
in the following way.

1. Hook the standard allocator functions.
Add appropriate allocator_shim_override_xxx according to
the platform so that we hook the standard allocators.

2. Add the default dispatcher of the allocator functions.
Add appropriate allocator_shim_default_dispatch_to_xxx
according to our own allocator (PartitionAlloc, TCMalloc)
or, if we use the system allocator, according to the platform
(glibc, MacZonedMalloc, WinHeap, etc.).

This is a logical and comprehensive way to install the
appropriate allocator hooks and shim.

Bug: 998048
Change-Id: Id3d5b5708a94f7894971d2131c83b17f6eada096
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392189
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Benoit L <lizeb@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805752}
This commit is contained in:
Yuki Shiino
2020-09-10 15:18:07 +00:00
committed by Commit Bot
parent 1dcacd3f1a
commit 45322cd11d
2 changed files with 38 additions and 22 deletions

@ -1304,38 +1304,47 @@ component("base") {
"allocator/allocator_shim_override_cpp_symbols.h",
"allocator/allocator_shim_override_libc_symbols.h",
]
if (is_android) {
sources +=
[ "allocator/allocator_shim_override_linker_wrapped_symbols.h" ]
all_dependent_configs += [ "//base/allocator:wrap_malloc_symbols" ]
}
if (is_apple) {
sources += [ "allocator/allocator_shim_override_mac_symbols.h" ]
}
if (is_chromeos || is_linux) {
sources += [ "allocator/allocator_shim_override_glibc_weak_symbols.h" ]
}
if (is_win) {
sources += [
"allocator/allocator_shim_default_dispatch_to_winheap.cc",
"allocator/allocator_shim_override_ucrt_symbols_win.h",
"allocator/winheap_stubs_win.cc",
"allocator/winheap_stubs_win.h",
]
} else if ((is_linux || is_chromeos) && use_allocator == "tcmalloc") {
sources += [
"allocator/allocator_shim_default_dispatch_to_tcmalloc.cc",
"allocator/allocator_shim_override_glibc_weak_symbols.h",
]
deps += [ "//base/allocator:tcmalloc" ]
} else if ((is_linux || is_chromeos) && use_allocator == "none") {
sources += [ "allocator/allocator_shim_default_dispatch_to_glibc.cc" ]
} else if ((is_linux || is_chromeos || is_android) &&
use_allocator == "partition") {
}
if (use_allocator == "partition") {
sources +=
[ "allocator/allocator_shim_default_dispatch_to_partition_alloc.cc" ]
} else if (is_android) {
sources +=
[ "allocator/allocator_shim_override_linker_wrapped_symbols.h" ]
all_dependent_configs += [ "//base/allocator:wrap_malloc_symbols" ]
if (use_allocator == "none") {
} else if (use_allocator == "tcmalloc") {
sources += [ "allocator/allocator_shim_default_dispatch_to_tcmalloc.cc" ]
deps += [ "//base/allocator:tcmalloc" ]
} else if (use_allocator == "none") {
if (is_android) {
sources += [ "allocator/allocator_shim_default_dispatch_to_linker_wrapped_symbols.cc" ]
}
} else if (is_apple) {
sources += [
"allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.cc",
"allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.h",
"allocator/allocator_shim_override_mac_symbols.h",
]
if (is_apple) {
sources += [
"allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.cc",
"allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.h",
]
}
if (is_chromeos || is_linux) {
sources += [ "allocator/allocator_shim_default_dispatch_to_glibc.cc" ]
}
if (is_win) {
sources += [ "allocator/allocator_shim_default_dispatch_to_winheap.cc" ]
}
}
}

@ -5,6 +5,8 @@
#ifndef BASE_ALLOCATOR_ALLOCATOR_SHIM_INTERNALS_H_
#define BASE_ALLOCATOR_ALLOCATOR_SHIM_INTERNALS_H_
#include "build/build_config.h"
#if defined(__GNUC__)
#include <sys/cdefs.h> // for __THROW
@ -39,6 +41,11 @@
// impression that they can hook the allocator.
#define SHIM_ALWAYS_EXPORT __attribute__((visibility("default"), noinline))
#elif defined(OS_WIN) // __GNUC__
#define __THROW
#define SHIM_ALWAYS_EXPORT __declspec(noinline)
#endif // __GNUC__
#endif // BASE_ALLOCATOR_ALLOCATOR_SHIM_INTERNALS_H_