From bf640cd740fe38f6f10faa8683e8361fee971aba Mon Sep 17 00:00:00 2001 From: Aliaksey Kandratsenka Date: Mon, 20 Feb 2017 14:51:27 -0800 Subject: [PATCH] rename sys allocator's sys_alloc symbol to tcmalloc_sys_alloc Since we're not building with hidden visibility, symbols of other DSOs can interpose our symbols. And sys_alloc is just too generic name. And in fact erlang runtime has sys_alloc function. Which means we're trying to write to it's first bytes as part of initializing system allocator and crash. This should fix issue #843. --- src/system-alloc.cc | 6 +++--- src/system-alloc.h | 2 +- src/tcmalloc.cc | 4 ++-- src/windows/system-alloc.cc | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/system-alloc.cc b/src/system-alloc.cc index 084009c89..6b59e1140 100755 --- a/src/system-alloc.cc +++ b/src/system-alloc.cc @@ -122,7 +122,7 @@ static size_t pagesize = 0; #endif // The current system allocator -SysAllocator* sys_alloc = NULL; +SysAllocator* tcmalloc_sys_alloc = NULL; // Number of bytes taken from system. size_t TCMalloc_SystemTaken = 0; @@ -484,7 +484,7 @@ void InitSystemAllocators(void) { sdef->SetChildAllocator(mmap, 1, mmap_name); } - sys_alloc = tc_get_sysalloc_override(sdef); + tcmalloc_sys_alloc = tc_get_sysalloc_override(sdef); } void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size, @@ -507,7 +507,7 @@ void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size, actual_size = &actual_size_storage; } - void* result = sys_alloc->Alloc(size, actual_size, alignment); + void* result = tcmalloc_sys_alloc->Alloc(size, actual_size, alignment); if (result != NULL) { CHECK_CONDITION( CheckAddressBits( diff --git a/src/system-alloc.h b/src/system-alloc.h index 8233f96e5..655d47080 100644 --- a/src/system-alloc.h +++ b/src/system-alloc.h @@ -84,7 +84,7 @@ extern PERFTOOLS_DLL_DECL void TCMalloc_SystemCommit(void* start, size_t length); // The current system allocator. -extern PERFTOOLS_DLL_DECL SysAllocator* sys_alloc; +extern PERFTOOLS_DLL_DECL SysAllocator* tcmalloc_sys_alloc; // Number of bytes taken from system. extern PERFTOOLS_DLL_DECL size_t TCMalloc_SystemTaken; diff --git a/src/tcmalloc.cc b/src/tcmalloc.cc index 5f643395f..6d79f7ecc 100644 --- a/src/tcmalloc.cc +++ b/src/tcmalloc.cc @@ -750,12 +750,12 @@ class TCMallocImplementation : public MallocExtension { virtual SysAllocator* GetSystemAllocator() { SpinLockHolder h(Static::pageheap_lock()); - return sys_alloc; + return tcmalloc_sys_alloc; } virtual void SetSystemAllocator(SysAllocator* alloc) { SpinLockHolder h(Static::pageheap_lock()); - sys_alloc = alloc; + tcmalloc_sys_alloc = alloc; } virtual void ReleaseToSystem(size_t num_bytes) { diff --git a/src/windows/system-alloc.cc b/src/windows/system-alloc.cc index 9537745b8..ea1f17d95 100644 --- a/src/windows/system-alloc.cc +++ b/src/windows/system-alloc.cc @@ -46,7 +46,7 @@ static SpinLock spinlock(SpinLock::LINKER_INITIALIZED); // The current system allocator declaration -SysAllocator* sys_alloc = NULL; +SysAllocator* tcmalloc_sys_alloc = NULL; // Number of bytes taken from system. size_t TCMalloc_SystemTaken = 0; @@ -121,7 +121,7 @@ SysAllocator* tc_get_sysalloc_override(SysAllocator *def) static bool system_alloc_inited = false; void InitSystemAllocators(void) { VirtualSysAllocator *alloc = new (virtual_space) VirtualSysAllocator(); - sys_alloc = tc_get_sysalloc_override(alloc); + tcmalloc_sys_alloc = tc_get_sysalloc_override(alloc); } extern PERFTOOLS_DLL_DECL @@ -134,7 +134,7 @@ void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size, system_alloc_inited = true; } - void* result = sys_alloc->Alloc(size, actual_size, alignment); + void* result = tcmalloc_sys_alloc->Alloc(size, actual_size, alignment); if (result != NULL) { if (actual_size) { TCMalloc_SystemTaken += *actual_size;