Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 1 | From 696674a800cb6d2070897a565b92d7e63022a8f1 Mon Sep 17 00:00:00 2001 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Sun, 16 Jul 2017 15:51:28 -0700 |
| 4 | Subject: [PATCH] fix build with musl libc |
| 5 | |
| 6 | Patch from https://github.com/gperftools/gperftools/pull/765/ |
| 7 | |
| 8 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 9 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10 | --- |
| 11 | configure.ac | 1 + |
| 12 | src/malloc_hook_mmap_linux.h | 8 ++++++-- |
| 13 | 2 files changed, 7 insertions(+), 2 deletions(-) |
| 14 | |
| 15 | diff --git a/configure.ac b/configure.ac |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 16 | index 497103e..f9efc3e 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 17 | --- a/configure.ac |
| 18 | +++ b/configure.ac |
| 19 | @@ -188,6 +188,7 @@ AC_HEADER_STDC |
| 20 | AC_CHECK_TYPES([__int64]) # defined in some windows platforms |
| 21 | AC_CHECK_TYPES([struct mallinfo],,, [#include <malloc.h>]) |
| 22 | AC_CHECK_TYPES([Elf32_Versym],,, [#include <elf.h>]) # for vdso_support.h |
| 23 | +AC_CHECK_FUNCS(__sbrk) # for intercepting glibc memory allocator |
| 24 | AC_CHECK_FUNCS(sbrk) # for tcmalloc to get memory |
| 25 | AC_CHECK_FUNCS(geteuid) # for turning off services when run as root |
| 26 | AC_CHECK_FUNCS(fork) # for the pthread_atfork setup |
| 27 | diff --git a/src/malloc_hook_mmap_linux.h b/src/malloc_hook_mmap_linux.h |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 28 | index 2f6116f..0605855 100755 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 29 | --- a/src/malloc_hook_mmap_linux.h |
| 30 | +++ b/src/malloc_hook_mmap_linux.h |
| 31 | @@ -46,6 +46,10 @@ |
| 32 | #include <errno.h> |
| 33 | #include "base/linux_syscall_support.h" |
| 34 | |
| 35 | +#ifndef __GLIBC__ |
| 36 | +typedef off64_t __off64_t; |
| 37 | +#endif |
| 38 | + |
| 39 | // The x86-32 case and the x86-64 case differ: |
| 40 | // 32b has a mmap2() syscall, 64b does not. |
| 41 | // 64b and 32b have different calling conventions for mmap(). |
| 42 | @@ -168,7 +172,7 @@ extern "C" void* mmap64(void *start, size_t length, int prot, int flags, |
| 43 | return result; |
| 44 | } |
| 45 | |
| 46 | -# if !defined(__USE_FILE_OFFSET64) || !defined(__REDIRECT_NTH) |
| 47 | +# if defined(__GLIBC__) && (!defined(__USE_FILE_OFFSET64) || !defined(__REDIRECT_NTH)) |
| 48 | |
| 49 | extern "C" void* mmap(void *start, size_t length, int prot, int flags, |
| 50 | int fd, off_t offset) __THROW { |
| 51 | @@ -206,7 +210,7 @@ extern "C" void* mremap(void* old_addr, size_t old_size, size_t new_size, |
| 52 | return result; |
| 53 | } |
| 54 | |
| 55 | -#ifndef __UCLIBC__ |
| 56 | +#if HAVE___SBRK |
| 57 | // libc's version: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 58 | extern "C" void* __sbrk(intptr_t increment); |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 59 | |