Using jemalloc with static link

Colin Hercus colin at
Fri Jul 19 00:41:41 PDT 2013


I am trying to test a HPC appl'n with jemalloc to see if it can reduce
memory fragmentation and slow memory growth of a long running
multi-threaded app.

This application is statically linked as it's not open source and we need
one binary distribution to run on multiple Linux versions.

If I configure jemalloc without a jemalloc prefix (je_) and link with
-static -ljemalloc I get linker errors for multiply defined symbols

g++  -m64 -Wl,--eh-frame-hdr -o ./bin/xxxx ./obj/xxxx.o  .....   -static
-pthread -lcrypto -lz -lbz2 -ldl  -ljemalloc -lunwind
In function `dlfcn_globallookup':
In function `__libc_free':
(.text+0x56b0): multiple definition of `free'
jemalloc.o:/wd5/downloads/malloc/jemalloc-3.4.0/src/jemalloc.c:1254: first
defined here
In function `__libc_malloc':
(.text+0x50d0): multiple definition of `malloc'
jemalloc.o:/wd5/downloads/malloc/jemalloc-3.4.0/src/jemalloc.c:857: first
defined here
In function `__libc_realloc':
(.text+0x57a0): multiple definition of `realloc'
jemalloc.o:/wd5/downloads/malloc/jemalloc-3.4.0/src/jemalloc.c:1105: first
defined here

If I build with a prefix of je_ then linking is okay but memory allocation
is via glibc malloc. The same is true if I dynamically link without a

Is there any simple easy way to get je_malloc to hook itself in as a
replacement for malloc the way tcmalloc does?

Any help appreciated.

Thanks, Colin
PS. I have googled for an answer and I really do need to statically link.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the jemalloc-discuss mailing list