Improvements to initialization of linker_allocator
Make linker_allocator independent of the order of global constructors.
Bug: http://b/30483811
Change-Id: I18a323175661b8e1c9e398f2d6112f7a08d2cceb
Test: boot the device with I3ac91758a1a043146c65f2ae0f36fcfbe372c30f
diff --git a/linker/linker_allocator.h b/linker/linker_allocator.h
index 22a337a..8f90dbf 100644
--- a/linker/linker_allocator.h
+++ b/linker/linker_allocator.h
@@ -100,8 +100,7 @@
class LinkerSmallObjectAllocator {
public:
- LinkerSmallObjectAllocator();
- void init(uint32_t type, size_t block_size);
+ LinkerSmallObjectAllocator(uint32_t type, size_t block_size);
void* alloc();
void free(void* ptr);
@@ -124,7 +123,7 @@
class LinkerMemoryAllocator {
public:
- LinkerMemoryAllocator();
+ constexpr LinkerMemoryAllocator() : allocators_(nullptr), allocators_buf_() {}
void* alloc(size_t size);
// Note that this implementation of realloc never shrinks allocation
@@ -134,8 +133,10 @@
void* alloc_mmap(size_t size);
page_info* get_page_info(void* ptr);
LinkerSmallObjectAllocator* get_small_object_allocator(uint32_t type);
+ void initialize_allocators();
- LinkerSmallObjectAllocator allocators_[kSmallObjectAllocatorsCount];
+ LinkerSmallObjectAllocator* allocators_;
+ uint8_t allocators_buf_[sizeof(LinkerSmallObjectAllocator)*kSmallObjectAllocatorsCount];
};