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