diff options
author | xiaoyur347 <xiaoyur347@gmail.com> | 2013-12-20 09:02:49 +0800 |
---|---|---|
committer | xiaoyur347 <xiaoyur347@gmail.com> | 2013-12-20 09:02:49 +0800 |
commit | 7c4888515ed93347d4793fc066cd6048e519a197 (patch) | |
tree | b68c4f582981dce27434682be427124aa398dd82 | |
parent | 7bd193bca97d93b43ff6c824bc9f39227329312f (diff) | |
download | gperftools-7c4888515ed93347d4793fc066cd6048e519a197.tar.gz |
add uclibc support
* some variables defined with "char *" should be modified to "const char*"
* For uclibc, glibc's "void malloc_stats(void)" should be "void malloc_stats(FILE *)", is commented now.
* For uclibc, __sbrk is with attribute "hidden", so we use mmap allocator for uclibc.
-rwxr-xr-x[-rw-r--r--] | Makefile.am | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | src/heap-checker.cc | 5 | ||||
-rwxr-xr-x[-rw-r--r--] | src/heap-profiler.cc | 8 | ||||
-rwxr-xr-x[-rw-r--r--] | src/libc_override_gcc_and_weak.h | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | src/malloc_hook_mmap_linux.h | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | src/memory_region_map.cc | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | src/symbolize.cc | 6 | ||||
-rwxr-xr-x[-rw-r--r--] | src/system-alloc.cc | 5 |
8 files changed, 24 insertions, 9 deletions
diff --git a/Makefile.am b/Makefile.am index d269ed0..b0a9dfb 100644..100755 --- a/Makefile.am +++ b/Makefile.am @@ -662,7 +662,7 @@ if GCC malloc_extension_c_test_CFLAGS += -ansi endif GCC malloc_extension_c_test_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS) -malloc_extension_c_test_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS) +malloc_extension_c_test_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS) -lstdc++ endif !ENABLE_STATIC endif !MINGW diff --git a/src/heap-checker.cc b/src/heap-checker.cc index 1f8acf2..5a6a3de 100644..100755 --- a/src/heap-checker.cc +++ b/src/heap-checker.cc @@ -1652,8 +1652,13 @@ ssize_t HeapLeakChecker::ObjectsLeaked() const { // Save pid of main thread for using in naming dump files static int32 main_thread_pid = getpid(); #ifdef HAVE_PROGRAM_INVOCATION_NAME +#ifdef __UCLIBC__ +extern const char* program_invocation_name; +extern const char* program_invocation_short_name; +#else extern char* program_invocation_name; extern char* program_invocation_short_name; +#endif static const char* invocation_name() { return program_invocation_short_name; } static string invocation_path() { return program_invocation_name; } #else diff --git a/src/heap-profiler.cc b/src/heap-profiler.cc index 7d215c3..1da544d 100644..100755 --- a/src/heap-profiler.cc +++ b/src/heap-profiler.cc @@ -541,7 +541,13 @@ extern "C" void HeapProfilerDump(const char *reason) { // number is defined in the environment variable HEAPPROFILESIGNAL. static void HeapProfilerDumpSignal(int signal_number) { (void)signal_number; - HeapProfilerDump("signal"); + if (!heap_lock.TryLock()) { + return; + } + if (is_on && !dumping) { + DumpProfileLocked("signal"); + } + heap_lock.Unlock(); } diff --git a/src/libc_override_gcc_and_weak.h b/src/libc_override_gcc_and_weak.h index 642a53c..fe9db47 100644..100755 --- a/src/libc_override_gcc_and_weak.h +++ b/src/libc_override_gcc_and_weak.h @@ -82,7 +82,9 @@ extern "C" { void* pvalloc(size_t size) __THROW ALIAS(tc_pvalloc); int posix_memalign(void** r, size_t a, size_t s) __THROW ALIAS(tc_posix_memalign); +#ifndef __UCLIBC__ void malloc_stats(void) __THROW ALIAS(tc_malloc_stats); +#endif int mallopt(int cmd, int value) __THROW ALIAS(tc_mallopt); #ifdef HAVE_STRUCT_MALLINFO struct mallinfo mallinfo(void) __THROW ALIAS(tc_mallinfo); diff --git a/src/malloc_hook_mmap_linux.h b/src/malloc_hook_mmap_linux.h index 3c6cab4..54e5d87 100644..100755 --- a/src/malloc_hook_mmap_linux.h +++ b/src/malloc_hook_mmap_linux.h @@ -202,6 +202,7 @@ extern "C" void* mremap(void* old_addr, size_t old_size, size_t new_size, return result; } +#ifndef __UCLIBC__ // libc's version: extern "C" void* __sbrk(ptrdiff_t increment); @@ -212,6 +213,8 @@ extern "C" void* sbrk(ptrdiff_t increment) __THROW { return result; } +#endif + /*static*/void* MallocHook::UnhookedMMap(void *start, size_t length, int prot, int flags, int fd, off_t offset) { void* result; diff --git a/src/memory_region_map.cc b/src/memory_region_map.cc index 05ba3bf..e885859 100644..100755 --- a/src/memory_region_map.cc +++ b/src/memory_region_map.cc @@ -797,8 +797,6 @@ void MemoryRegionMap::MremapHook(const void* result, } } -extern "C" void* __sbrk(ptrdiff_t increment); // defined in libc - void MemoryRegionMap::SbrkHook(const void* result, ptrdiff_t increment) { RAW_VLOG(10, "Sbrk = 0x%" PRIxPTR " of %" PRIdS "", (uintptr_t)result, increment); if (result != reinterpret_cast<void*>(-1)) { diff --git a/src/symbolize.cc b/src/symbolize.cc index 88568fa..3530fca 100644..100755 --- a/src/symbolize.cc +++ b/src/symbolize.cc @@ -76,9 +76,13 @@ static string* g_pprof_path = new string(FLAGS_symbolize_pprof); // Returns NULL if we're on an OS where we can't get the invocation name. // Using a static var is ok because we're not called from a thread. -static char* GetProgramInvocationName() { +static const char* GetProgramInvocationName() { #if defined(HAVE_PROGRAM_INVOCATION_NAME) +#ifdef __UCLIBC__ + extern const char* program_invocation_name; // uclibc provides this +#else extern char* program_invocation_name; // gcc provides this +#endif return program_invocation_name; #elif defined(__MACH__) // We don't want to allocate memory for this since we may be diff --git a/src/system-alloc.cc b/src/system-alloc.cc index e09e072..0cbed80 100644..100755 --- a/src/system-alloc.cc +++ b/src/system-alloc.cc @@ -202,8 +202,7 @@ static const char mmap_name[] = "MmapSysAllocator"; void* SbrkSysAllocator::Alloc(size_t size, size_t *actual_size, size_t alignment) { -#ifndef HAVE_SBRK - failed_ = true; +#if !defined(HAVE_SBRK) || defined(__UCLIBC__) return NULL; #else // Check if we should use sbrk allocation. @@ -275,7 +274,6 @@ void* SbrkSysAllocator::Alloc(size_t size, size_t *actual_size, void* MmapSysAllocator::Alloc(size_t size, size_t *actual_size, size_t alignment) { #ifndef HAVE_MMAP - failed_ = true; return NULL; #else // Check if we should use mmap allocation. @@ -344,7 +342,6 @@ void* MmapSysAllocator::Alloc(size_t size, size_t *actual_size, void* DevMemSysAllocator::Alloc(size_t size, size_t *actual_size, size_t alignment) { #ifndef HAVE_MMAP - failed_ = true; return NULL; #else static bool initialized = false; |