aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDave Watson <davejwatson@fb.com>2016-10-28 13:51:52 -0700
committerJason Evans <jasone@canonware.com>2016-10-28 15:10:19 -0700
commited84764a2a6d766a74fa1df3223d69977d732510 (patch)
tree463ad868d8d013a102695c0318e7b641af55a5b0 /include
parentb99c72f3d29e3590ae81959922d0032a29dbace9 (diff)
downloadjemalloc-ed84764a2a6d766a74fa1df3223d69977d732510.tar.gz
Support static linking of jemalloc with glibc
glibc defines its malloc implementation with several weak and strong symbols: strong_alias (__libc_calloc, __calloc) weak_alias (__libc_calloc, calloc) strong_alias (__libc_free, __cfree) weak_alias (__libc_free, cfree) strong_alias (__libc_free, __free) strong_alias (__libc_free, free) strong_alias (__libc_malloc, __malloc) strong_alias (__libc_malloc, malloc) The issue is not with the weak symbols, but that other parts of glibc depend on __libc_malloc explicitly. Defining them in terms of jemalloc API's allows the linker to drop glibc's malloc.o completely from the link, and static linking no longer results in symbol collisions. Another wrinkle: jemalloc during initialization calls sysconf to get the number of CPU's. GLIBC allocates for the first time before setting up isspace (and other related) tables, which are used by sysconf. Instead, use the pthread API to get the number of CPUs with GLIBC, which seems to work. This resolves #442.
Diffstat (limited to 'include')
-rw-r--r--include/jemalloc/internal/jemalloc_internal_decls.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/include/jemalloc/internal/jemalloc_internal_decls.h b/include/jemalloc/internal/jemalloc_internal_decls.h
index 910b2fc..1d7f207 100644
--- a/include/jemalloc/internal/jemalloc_internal_decls.h
+++ b/include/jemalloc/internal/jemalloc_internal_decls.h
@@ -17,6 +17,9 @@
# include <sys/uio.h>
# endif
# include <pthread.h>
+# ifdef JEMALLOC_GLIBC_MALLOC_HOOK
+# include <sched.h>
+# endif
# include <errno.h>
# include <sys/time.h>
# include <time.h>