Giter Club home page Giter Club logo

jemallocator's Introduction

jemallocator

Travis-CI Status Appveyor Status Latest Version docs

Links against jemalloc and provides a Jemalloc unit type that implements the allocator APIs and can be set as the #[global_allocator]

Overview

The jemalloc support ecosystem consists of the following crates:

  • jemalloc-sys: builds and links against jemalloc exposing raw C bindings to it.
  • jemallocator: provides the Jemalloc type which implements the GlobalAlloc and Alloc traits.
  • jemalloc-ctl: high-level wrapper over jemalloc's control and introspection APIs (the mallctl*() family of functions and the MALLCTL NAMESPACE)'

Documentation

To use jemallocator add it as a dependency:

# Cargo.toml
[dependencies]

[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = "0.3.2"

To set jemallocator::Jemalloc as the global allocator add this to your project:

# main.rs
#[cfg(not(target_env = "msvc"))]
use jemallocator::Jemalloc;

#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;

And that's it! Once you've defined this static then jemalloc will be used for all allocations requested by Rust code in the same program.

Platform support

The following table describes the supported platforms:

  • build: does the library compile for the target?
  • run: do jemallocator and jemalloc-sys tests pass on the target?
  • jemalloc: do jemalloc's tests pass on the target?
  • valgrind: do the tests pass under valgrind?

Tier 1 targets are tested on all Rust channels (stable, beta, and nightly). All other targets are only tested on Rust nightly.

Linux targets: build run jemalloc valgrind
aarch64-unknown-linux-gnu
arm-unknown-linux-gnueabi
armv7-unknown-linux-gnueabi
i586-unknown-linux-gnu
i686-unknown-linux-gnu (tier 1)
mips-unknown-linux-gnu
mipsel-unknown-linux-musl
mips64-unknown-linux-gnuabi64
mips64el-unknown-linux-gnuabi64
powerpc-unknown-linux-gnu
powerpc64-unknown-linux-gnu
powerpc64le-unknown-linux-gnu
x86_64-unknown-linux-gnu (tier 1)
MacOSX targets: build run jemalloc valgrind
x86_64-apple-darwin (tier 1)
i686-apple-darwin (tier 1)
Windows targets: build run jemalloc valgrind
x86_64-pc-windows-msvc (tier 1)
i686-pc-windows-msvc (tier 1)
x86_64-pc-windows-gnu (tier 1)
i686-pc-windows-gnu (tier 1)
Android targets: build run jemalloc valgrind
aarch64-linux-android
x86_64-linux-android

Features

The jemallocator crate re-exports the features of the jemalloc-sys dependency.

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in jemallocator by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

jemallocator's People

Contributors

alexcrichton avatar angelonfira avatar arthurprs avatar athre0z avatar brson avatar busyjay avatar davidmcneil avatar dependabot[bot] avatar erichdongubler avatar fitzgen avatar frewsxcv avatar gnzlbg avatar imp avatar king6cong avatar kmindg avatar seth-priya avatar sfackler avatar simonsapin avatar slightlyoutofphase avatar valpackett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jemallocator's Issues

Control debug-info in jemalloc-sys

We should check that -C debug-info=N is appropriately forwarded to -gN when building jemalloc in jemalloc-sys. Debug symbols can have a big impact on binary size.

How to let jemalloc overrides system allocator

This crate builds jemalloc with an explicit prefix, which prevents it from overriding system allocator widely used behind FFI. So for a program that uses a lot of C/C++ APIs, it's hard to make it get benefits from jemalloc.

Also note that the build-in rust jemalloc allocator only uses prefix when it has to.

Any ideas?

Update version number in readme

The most recent release is 0.3.0 but the readme still shows:

[dependencies]
jemallocator = "0.1.8"

Maybe add a comment next to the version number in Cargo.toml as a reminder to bump the version number in the readme when releasing breaking changes.

merge jemalloc-ctl into jemallocator?

https://github.com/sfackler/jemalloc-ctl provides a typed interface to the diagnostic/control features jemalloc supports. Currently, it just asserts that the right symbols exist, but once global allocators stabilize it seems like it'd make way more sense for these APIs to live in the allocator crate itself.

Seem reasonable? I can make a PR if so.

Including jemallocator-global doesn't actually enable jemalloc on MacOS X

I took an existing program, added a dependency on jemallocator-global in its Cargo.toml, built it with --release, and ran it under a profiler (Instruments). Observed: The profiler found stacks under libsystem_malloc.dylib. Expected: stacks under a statically linked jemalloc.

Depending directly on the jemallocator crate instead, and declaring a #[global_allocator] static Jemalloc in the binary crate, works fine.

I'm using stable Rust 1.37: rustc 1.37.0 (eae3437df 2019-08-13)

Install fails on Ubuntu 20.04 LTS: failed to run custom build command for jemalloc-sys v0.3.2

I'm not a Rust or C++ programmer, I just use a few tools written in Rust. One of them (fd-find) depends on jemallocator ^0.3.0 and does not build on a new Ubuntu 20.04 LTS VM on Digital Ocean.

Not sure if this is just a Digital Ocean thing, or just an Ubuntu 20.04 thing, or something new in Linux kernel 5.4.0 but I thought I would at least report it in case it is useful to you.

rustc -V
rustc 1.41.0

uname -a
Linux u20do 5.4.0-26-generic #30-Ubuntu SMP Mon Apr 20 16:58:30 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

When I ran my usual cargo install of handy command line tools:

cargo install exa fd-find rage ripgrep tokei

...everything installed except fd-find, which died here:

error: failed to run custom build command for `jemalloc-sys v0.3.2`

Caused by:
  process didn't exit successfully: `/tmp/cargo-installV44NLx/release/build/jemalloc-sys-d759d258588d996a/build-script-build` (exit code: 101)
--- stdout
TARGET=x86_64-unknown-linux-gnu
HOST=x86_64-unknown-linux-gnu
NUM_JOBS=2
OUT_DIR="/tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out"
BUILD_DIR="/tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out/build"
SRC_DIR="/root/.cargo/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.3.2"
OPT_LEVEL = Some("3")
TARGET = Some("x86_64-unknown-linux-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
CC_x86_64-unknown-linux-gnu = None
CC_x86_64_unknown_linux_gnu = None
HOST_CC = None
CC = None
CFLAGS_x86_64-unknown-linux-gnu = None
CFLAGS_x86_64_unknown_linux_gnu = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
CC="cc"
CFLAGS="-O3 -ffunction-sections -fdata-sections -fPIC -m64 -Wall"
JEMALLOC_REPO_DIR="jemalloc"
JEMALLOC_SRC_DIR="/tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out/jemalloc"
cargo:rustc-cfg=prefixed
--with-jemalloc-prefix=_rjem_
running: "sh" "/tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out/jemalloc/configure" "--disable-cxx" "--with-jemalloc-prefix=_rjem_" "--with-private-namespace=_rjem_" "--host=x86_64-unknown-linux-gnu" "--build=x86_64-unknown-linux-gnu" "--prefix=/tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out"
checking for xsltproc... false
checking for x86_64-unknown-linux-gnu-gcc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking whether compiler is cray... no
checking whether compiler supports -std=gnu11... yes
checking whether compiler supports -Wall... yes
checking whether compiler supports -Wshorten-64-to-32... no
checking whether compiler supports -Wsign-compare... yes
checking whether compiler supports -Wundef... yes
checking whether compiler supports -Wno-format-zero-length... yes
checking whether compiler supports -pipe... yes
checking whether compiler supports -g3... yes
checking how to run the C preprocessor... cc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking whether byte ordering is bigendian... no
checking size of void *... 8
checking size of int... 4
checking size of long... 8
checking size of long long... 8
checking size of intmax_t... 8
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking whether pause instruction is compilable... yes
checking number of significant virtual address bits... 48
checking for x86_64-unknown-linux-gnu-ar... no
checking for ar... ar
checking for x86_64-unknown-linux-gnu-nm... no
checking for nm... nm
checking for gawk... gawk
checking malloc.h usability... yes
checking malloc.h presence... yes
checking for malloc.h... yes
checking whether malloc_usable_size definition can use const argument... no
checking for library containing log... -lm
checking whether __attribute__ syntax is compilable... yes
checking whether compiler supports -fvisibility=hidden... yes
checking whether compiler supports -fvisibility=hidden... no
checking whether compiler supports -Werror... yes
checking whether compiler supports -herror_on_warning... no
checking whether tls_model attribute is compilable... yes
checking whether compiler supports -Werror... yes
checking whether compiler supports -herror_on_warning... no
checking whether alloc_size attribute is compilable... yes
checking whether compiler supports -Werror... yes
checking whether compiler supports -herror_on_warning... no
checking whether format(gnu_printf, ...) attribute is compilable... yes
checking whether compiler supports -Werror... yes
checking whether compiler supports -herror_on_warning... no
checking whether format(printf, ...) attribute is compilable... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for x86_64-unknown-linux-gnu-ranlib... no
checking for ranlib... ranlib
checking for ld... /usr/bin/ld
checking for autoconf... false
checking for memalign... yes
checking for valloc... yes
checking whether compiler supports -O3... yes
checking whether compiler supports -O3... no
checking whether compiler supports -funroll-loops... yes
checking configured backtracing method... N/A
checking for sbrk... yes
checking whether utrace(2) is compilable... no
checking whether a program using __builtin_unreachable is compilable... yes
checking whether a program using __builtin_ffsl is compilable... yes
checking LG_PAGE... 12
Missing VERSION file, and unable to generate it; creating bogus VERSION
checking pthread.h usability... yes
checking pthread.h presence... yes
checking for pthread.h... yes
checking for pthread_create in -lpthread... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking for dlsym... no
checking for dlsym in -ldl... yes
checking whether pthread_atfork(3) is compilable... yes
checking whether pthread_setname_np(3) is compilable... yes
checking for library containing clock_gettime... none required
checking whether clock_gettime(CLOCK_MONOTONIC_COARSE, ...) is compilable... yes
checking whether clock_gettime(CLOCK_MONOTONIC, ...) is compilable... yes
checking whether mach_absolute_time() is compilable... no
checking whether compiler supports -Werror... yes
checking whether syscall(2) is compilable... yes
checking for secure_getenv... yes
checking for sched_getcpu... yes
checking for sched_setaffinity... yes
checking for issetugid... no
checking for _malloc_thread_cleanup... no
checking for _pthread_mutex_init_calloc_cb... no
checking for TLS... yes
checking whether C11 atomics is compilable... yes
checking whether GCC __atomic atomics is compilable... yes
checking whether GCC __sync atomics is compilable... yes
checking whether Darwin OSAtomic*() is compilable... no
checking whether madvise(2) is compilable... yes
checking whether madvise(..., MADV_FREE) is compilable... yes
checking whether madvise(..., MADV_DONTNEED) is compilable... yes
checking whether madvise(..., MADV_DO[NT]DUMP) is compilable... yes
checking whether madvise(..., MADV_[NO]HUGEPAGE) is compilable... yes
checking whether to force 32-bit __sync_{add,sub}_and_fetch()... no
checking whether to force 64-bit __sync_{add,sub}_and_fetch()... no
checking for __builtin_clz... yes
checking whether Darwin os_unfair_lock_*() is compilable... no
checking whether Darwin OSSpin*() is compilable... no
checking whether glibc malloc hook is compilable... yes
checking whether glibc memalign hook is compilable... yes
checking whether pthreads adaptive mutexes is compilable... yes
checking whether compiler supports -D_GNU_SOURCE... yes
checking whether compiler supports -Werror... yes
checking whether compiler supports -herror_on_warning... no
checking whether strerror_r returns char with gnu source is compilable... yes
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating jemalloc.pc
config.status: creating doc/html.xsl
config.status: creating doc/manpages.xsl
config.status: creating doc/jemalloc.xml
config.status: creating include/jemalloc/jemalloc_macros.h
config.status: creating include/jemalloc/jemalloc_protos.h
config.status: creating include/jemalloc/jemalloc_typedefs.h
config.status: creating include/jemalloc/internal/jemalloc_preamble.h
config.status: creating test/test.sh
config.status: creating test/include/test/jemalloc_test.h
config.status: creating config.stamp
config.status: creating bin/jemalloc-config
config.status: creating bin/jemalloc.sh
config.status: creating bin/jeprof
config.status: creating include/jemalloc/jemalloc_defs.h
config.status: creating include/jemalloc/internal/jemalloc_internal_defs.h
config.status: creating test/include/test/jemalloc_test_defs.h
config.status: executing include/jemalloc/internal/public_symbols.txt commands
config.status: executing include/jemalloc/internal/private_symbols.awk commands
config.status: executing include/jemalloc/internal/private_symbols_jet.awk commands
config.status: executing include/jemalloc/internal/public_namespace.h commands
config.status: executing include/jemalloc/internal/public_unnamespace.h commands
config.status: executing include/jemalloc/internal/size_classes.h commands
config.status: executing include/jemalloc/jemalloc_protos_jet.h commands
config.status: executing include/jemalloc/jemalloc_rename.h commands
config.status: executing include/jemalloc/jemalloc_mangle.h commands
config.status: executing include/jemalloc/jemalloc_mangle_jet.h commands
config.status: executing include/jemalloc/jemalloc.h commands
===============================================================================
jemalloc version   : 0.0.0-0-g0000000000000000000000000000000000000000
library revision   : 2

CONFIG             : --disable-cxx --with-jemalloc-prefix=_rjem_ --with-private-namespace=_rjem_ --host=x86_64-unknown-linux-gnu --build=x86_64-unknown-linux-gnu --prefix=/tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out build_alias=x86_64-unknown-linux-gnu host_alias=x86_64-unknown-linux-gnu CC=cc 'CFLAGS=-O3 -ffunction-sections -fdata-sections -fPIC -m64 -Wall' 'LDFLAGS=-O3 -ffunction-sections -fdata-sections -fPIC -m64 -Wall' 'CPPFLAGS=-O3 -ffunction-sections -fdata-sections -fPIC -m64 -Wall'
CC                 : cc
CONFIGURE_CFLAGS   : -std=gnu11 -Wall -Wsign-compare -Wundef -Wno-format-zero-length -pipe -g3 -fvisibility=hidden -O3 -funroll-loops
SPECIFIED_CFLAGS   : -O3 -ffunction-sections -fdata-sections -fPIC -m64 -Wall
EXTRA_CFLAGS       : 
CPPFLAGS           : -O3 -ffunction-sections -fdata-sections -fPIC -m64 -Wall -D_GNU_SOURCE -D_REENTRANT
CXX                : 
CONFIGURE_CXXFLAGS : 
SPECIFIED_CXXFLAGS : 
EXTRA_CXXFLAGS     : 
LDFLAGS            : -O3 -ffunction-sections -fdata-sections -fPIC -m64 -Wall
EXTRA_LDFLAGS      : 
DSO_LDFLAGS        : -shared -Wl,-soname,$(@F)
LIBS               : -lm  -lpthread -ldl
RPATH_EXTRA        : 

XSLTPROC           : false
XSLROOT            : 

PREFIX             : /tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out
BINDIR             : /tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out/bin
DATADIR            : /tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out/share
INCLUDEDIR         : /tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out/include
LIBDIR             : /tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out/lib
MANDIR             : /tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out/share/man

srcroot            : /tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out/jemalloc/
abs_srcroot        : /tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out/jemalloc/
objroot            : 
abs_objroot        : /tmp/cargo-installV44NLx/release/build/jemalloc-sys-56dc7991905ffd59/out/build/

JEMALLOC_PREFIX    : _rjem_
JEMALLOC_PRIVATE_NAMESPACE
                   : _rjem_je_
install_suffix     : 
malloc_conf        : 
autogen            : 0
debug              : 0
stats              : 1
prof               : 0
prof-libunwind     : 0
prof-libgcc        : 0
prof-gcc           : 0
fill               : 1
utrace             : 0
xmalloc            : 0
log                : 0
lazy_lock          : 0
cache-oblivious    : 1
cxx                : 0
===============================================================================
running: "make" "srcroot=../jemalloc/" "-j" "2"

--- stderr
thread 'main' panicked at 'failed to execute command: No such file or directory (os error 2)', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.3.2/build.rs:389:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

warning: build failed, waiting for other jobs to finish...
error: failed to compile `fd-find v8.0.0`, intermediate artifacts can be found at `/tmp/cargo-installV44NLx`

Caused by:
  build failed

Published crate fails to compile tests due to absence of jemalloc-ctl

As part of my efforts to improve linux vendorization of rust crates, which includes the ability to test a crate, I've stumbled onto this problem:

jemallocator-0.3.2 $ cargo test
    Updating crates.io index
  Downloaded jemalloc-sys v0.3.2
  Downloaded cc v1.0.47
  Downloaded fs_extra v1.1.0
   Compiling proc-macro2 v1.0.6
   Compiling unicode-xid v0.2.0
   Compiling syn v1.0.8
   Compiling cc v1.0.47
   Compiling fs_extra v1.1.0
   Compiling libc v0.2.65
   Compiling jemalloc-sys v0.3.2
   Compiling quote v1.0.2
   Compiling proc-macro-hack v0.5.11
   Compiling paste-impl v0.1.6
   Compiling paste v0.1.6
   Compiling jemallocator v0.3.2 (/home/kent/.cpanm/work/1574930033.31685/jemallocator-0.3.2)
error[E0463]: can't find crate for `jemalloc_ctl`
 --> tests/malloctl.rs:1:1
  |
1 | extern crate jemalloc_ctl;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error[E0463]: can't find crate for `jemalloc_ctl`
 --> tests/background_thread_defaults.rs:3:1
  |
3 | extern crate jemalloc_ctl;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `jemallocator`.
warning: build failed, waiting for other jobs to finish...
error: could not compile `jemallocator`.
warning: build failed, waiting for other jobs to finish...
error: build failed

Ideally, one of these solutions should be employed:

  • tests that require jemalloc-ctl are also pruned from the published crate to avoid spurious failures
  • jemalloc-ctl is declared a dev-dependency on the published crate
  • Some kind of glue is published in the crate to avoid the needed dependency.

thread 'main' has overflowed its stack

To reproduce:

cargo test -vv  -p jemalloc-sys

returns

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Abort trap: 6

on pretty much every target on travis. I can also reproduce locally.

Shall we add a crate that sets up jemalloc as the global allocator?

Every user needs to do the dance of:

#![feature(global_allocator)]

extern crate jemallocator;

use jemallocator::Jemalloc;

#[global_allocator]
static A: Jemalloc = Jemalloc;

Maybe it would be worth it to have a single crate, e.g., global_allocator_jemalloc, that does it, so that users only need to write:

extern crate global_allocator_jemalloc;

jemallocator in cdylib ?

Hello !

I'm working on a lib, and I get a 20% speed up in my tests when using jemallocator instead of the default allocator, with a marginal loss in memory usage.

But I have not found how to use it when building a lib with crate-type = ["cdylib"] and pyo3.
Currently, I get cannot allocate memory in static TLS block when importing the lib from python.
Google did not help me ..

Any tips ?
Thanks a lot !

crash on macOS 10.15 (Catalina) beta 8 19A558d

cargo run --release will crash when using jemallocator.
I tried on two machines running macOS 10.15 beta, both will produce the same result.

#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

fn main() {
    println!("Hello, world!");
}

got output:

fish: 'cargo run --release' terminated by signal SIGSEGV (Address boundary error)

backtrace is:

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00000001000328fd hello-jemalloctor`_rjem_je_tcache_bin_flush_small [inlined] atomic_load_p(a=0x0000000000000000, mo=atomic_memory_order_relaxed) at atomic.h:55:1 [
opt]
    frame #1: 0x00000001000328fd hello-jemalloctor`_rjem_je_tcache_bin_flush_small [inlined] rtree_leaf_elm_bits_read(tsdn=<unavailable>, rtree=<unavailable>, elm=0x00000000000000
00, dependent=true) at rtree.h:175 [opt]
    frame #2: 0x00000001000328fd hello-jemalloctor`_rjem_je_tcache_bin_flush_small [inlined] rtree_leaf_elm_extent_read(tsdn=<unavailable>, rtree=<unavailable>, elm=0x000000000000
0000, dependent=true) at rtree.h:214 [opt]
    frame #3: 0x00000001000328fd hello-jemalloctor`_rjem_je_tcache_bin_flush_small [inlined] rtree_extent_read(tsdn=0x0000000100064420, rtree=<unavailable>, rtree_ctx=<unavailable
>, key=<unavailable>, dependent=true) at rtree.h:423 [opt]
    frame #4: 0x00000001000328c9 hello-jemalloctor`_rjem_je_tcache_bin_flush_small [inlined] iealloc(tsdn=0x0000000100064420) at jemalloc_internal_inlines_b.h:82 [opt]
    frame #5: 0x00000001000328c9 hello-jemalloctor`_rjem_je_tcache_bin_flush_small(tsd=0x0000000100064420, tcache=<unavailable>, tbin=0x00000001000645f0, binind=0, rem=0) at tcach
e.c:117 [opt]
    frame #6: 0x0000000100034782 hello-jemalloctor`tcache_flush_cache(tsd=0x0000000100064420, tcache=0x00000001000645e0) at tcache.c:463:3 [opt]
    frame #7: 0x0000000100034ba1 hello-jemalloctor`tcache_destroy(tsd=0x0000000100064420, tcache=0x00000001000645e0, tsd_tcache=<unavailable>) at tcache.c:493:2 [opt]
    frame #8: 0x0000000100035df1 hello-jemalloctor`_rjem_je_tsd_cleanup [inlined] tsd_do_data_cleanup(tsd=0x0000000100064420) at tsd.c:209:2 [opt]
    frame #9: 0x0000000100035dcc hello-jemalloctor`_rjem_je_tsd_cleanup(arg=0x0000000100064420) at tsd.c:234 [opt]
    frame #10: 0x0000000100036146 hello-jemalloctor`_rjem_je_malloc_tsd_boot1 [inlined] tsd_boot1 at tsd_generic.h:108:2 [opt]
    frame #11: 0x0000000100036114 hello-jemalloctor`_rjem_je_malloc_tsd_boot1 at tsd.c:273 [opt]
    frame #12: 0x0000000100008216 hello-jemalloctor`jemalloc_constructor [inlined] malloc_init_hard at jemalloc.c:1552:2 [opt]
    frame #13: 0x0000000100007fa1 hello-jemalloctor`jemalloc_constructor [inlined] malloc_init at jemalloc.c:217 [opt]
    frame #14: 0x0000000100007fa1 hello-jemalloctor`jemalloc_constructor at jemalloc.c:3184 [opt]
    frame #15: 0x00000001002c6615 dyld`ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 539
    frame #16: 0x00000001002c6a3a dyld`ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 40
    frame #17: 0x00000001002c1913 dyld`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageL
oader::UninitedUpwards&) + 493
    frame #18: 0x00000001002c067c dyld`ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUp
wards&) + 188
    frame #19: 0x00000001002c071c dyld`ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 82
    frame #20: 0x00000001002af4b2 dyld`dyld::initializeMainExecutable() + 199
    frame #21: 0x00000001002b4aab dyld`dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 6760
    frame #22: 0x00000001002ae227 dyld`dyldbootstrap::start(dyld3::MachOLoaded const*, int, char const**, dyld3::MachOLoaded const*, unsigned long*) + 453
    frame #23: 0x00000001002ae025 dyld`_dyld_start + 37

maybe it's a bug of macOS, I found a similar issue https://bugzilla.mozilla.org/show_bug.cgi?id=1570451#c41

Tag releases

It's unclear what commit the 0.3.0 release corresponds to, and what changes are in it from 0.1.

"multiple definition" linking errors when not using #[global_allocator]

#![feature(allocator_api)]

extern crate jemallocator;

#[test]
fn it_works() {
    use std::heap::{Alloc, Layout};
    unsafe {
        jemallocator::Jemalloc.alloc(Layout::from_size_align(8, 8).unwrap()).unwrap();
    }
}

This fails to link, with multiple errors errors like:

liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:13:
    multiple definition of `je_opt_abort'
target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.bss.je_opt_abort+0x0): 
   first defined here

It looks like --with-jemalloc-prefix=_rjem_ only applies to some of the exported symbols.

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/tmp/aa/target/debug/deps/aa-b4c485d64ce0b6a4.aa0.rust-cgu.o" "/tmp/aa/target/debug/deps/aa-b4c485d64ce0b6a4.aa1.rust-cgu.o" "/tmp/aa/target/debug/deps/aa-b4c485d64ce0b6a4.aa2.rust-cgu.o" "/tmp/aa/target/debug/deps/aa-b4c485d64ce0b6a4.aa3.rust-cgu.o" "/tmp/aa/target/debug/deps/aa-b4c485d64ce0b6a4.aa4.rust-cgu.o" "/tmp/aa/target/debug/deps/aa-b4c485d64ce0b6a4.aa5.rust-cgu.o" "/tmp/aa/target/debug/deps/aa-b4c485d64ce0b6a4.aa6.rust-cgu.o" "/tmp/aa/target/debug/deps/aa-b4c485d64ce0b6a4.aa7.rust-cgu.o" "/tmp/aa/target/debug/deps/aa-b4c485d64ce0b6a4.aa8.rust-cgu.o" "/tmp/aa/target/debug/deps/aa-b4c485d64ce0b6a4.aa9.rust-cgu.o" "-o" "/tmp/aa/target/debug/deps/aa-b4c485d64ce0b6a4" "/tmp/aa/target/debug/deps/aa-b4c485d64ce0b6a4.crate.allocator.rust-cgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "-L" "/tmp/aa/target/debug/deps" "-L" "/tmp/aa/target/debug/build/jemalloc-sys-74ac90ce2f71ae9c/out/build/lib" "-L" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/tmp/aa/target/debug/deps/libjemallocator-9de92a62195969df.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libtest-2a2464906ee040c2.rlib" "/tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-9eb2ee64f73b4edd.rlib" "/tmp/aa/target/debug/deps/liblibc-751b8a4883188c3c.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libterm-d6ef70b20c432429.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-9fa6cff435eff1ad.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-904757edb9acaea9.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-1e0fcb962c8d0be9.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_system-0aa3ebd79d16ee77.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-505a55492a0f5fad.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-938ec8effbd92202.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_unicode-aba0777e9ef6c93a.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-7129b2d2574b5bbd.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-9a06ab7f8e3fb42f.rlib" "/home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-631a0c99491b069e.rlib" "-Wl,-Bdynamic" "-l" "pthread" "-l" "util" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "pthread" "-l" "gcc_s" "-l" "c" "-l" "m" "-l" "rt" "-l" "pthread" "-l" "util"
  = note: /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:13: multiple definition of `je_opt_abort'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.bss.je_opt_abort+0x0): first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:47: multiple definition of `je_opt_narenas'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.bss.je_opt_narenas+0x0): first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:27: multiple definition of `je_opt_junk_alloc'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.bss.je_opt_junk_alloc+0x0): first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:34: multiple definition of `je_opt_junk_free'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.bss.je_opt_junk_free+0x0): first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:20: multiple definition of `je_opt_junk'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.data.rel.local.je_opt_junk+0x0): first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:42: multiple definition of `je_opt_quarantine'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.bss.je_opt_quarantine+0x0): first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:43: multiple definition of `je_opt_redzone'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.bss.je_opt_redzone+0x0): first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:46: multiple definition of `je_opt_zero'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.bss.je_opt_zero+0x0): first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:114: multiple definition of `je_size2index_tab'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.rodata.je_size2index_tab+0x0): first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:106: multiple definition of `je_index2size_tab'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.rodata.je_index2size_tab+0x0): first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_a0get':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:352: multiple definition of `je_a0get'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:349: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_a0dalloc':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:363: multiple definition of `je_a0dalloc'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:363: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_bootstrap_free':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:402: multiple definition of `je_bootstrap_free'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:400: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_atomic_add_uint32':
          /checkout/src/liballoc_jemalloc/../jemalloc/include/jemalloc/internal/atomic.h:300: multiple definition of `je_narenas_total_get'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:431: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_arena_init':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:466: multiple definition of `je_arena_init'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:466: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_jemalloc_postfork_child':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:2902: multiple definition of `je_jemalloc_postfork_child'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:2902: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_jemalloc_postfork_parent':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:2873: multiple definition of `je_jemalloc_postfork_parent'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:2873: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_jemalloc_prefork':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:2818: multiple definition of `je_jemalloc_prefork'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:2818: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:44: multiple definition of `je_opt_utrace'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.bss.je_opt_utrace+0x0): first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:45: multiple definition of `je_opt_xmalloc'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.bss.je_opt_xmalloc+0x0): first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_a0malloc':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:356: multiple definition of `je_a0malloc'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:356: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_bootstrap_malloc':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:376: multiple definition of `je_bootstrap_malloc'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:376: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_bootstrap_calloc':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:389: multiple definition of `je_bootstrap_calloc'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:386: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_arena_migrate':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:494: multiple definition of `je_arena_migrate'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:494: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_arena_tdata_get_hard':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:519: multiple definition of `je_arena_tdata_get_hard'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:519: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_arena_choose_hard':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:596: multiple definition of `je_arena_choose_hard'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:596: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_thread_allocated_cleanup':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:685: multiple definition of `je_thread_allocated_cleanup'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:685: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_thread_deallocated_cleanup':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:692: multiple definition of `je_thread_deallocated_cleanup'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:692: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_iarena_cleanup':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:699: multiple definition of `je_iarena_cleanup'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:699: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_arena_cleanup':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:709: multiple definition of `je_arena_cleanup'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:709: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_tsd_arenas_tdata_get':
          /checkout/src/liballoc_jemalloc/../jemalloc/include/jemalloc/internal/tsd.h:757: multiple definition of `je_arenas_tdata_cleanup'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:719: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_narenas_tdata_cleanup':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:734: multiple definition of `je_narenas_tdata_cleanup'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:734: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o): In function `je_arenas_tdata_bypass_cleanup':
          /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:741: multiple definition of `je_arenas_tdata_bypass_cleanup'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):/home/simon/tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.3/jemalloc/src/jemalloc.c:741: first defined here
          /home/simon/tmp/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5bd7876eddb07973.rlib(jemalloc.pic.o):/checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:93: multiple definition of `je_pind2sz_tab'
          /tmp/aa/target/debug/deps/libjemalloc_sys-b89035b55982147c.rlib(jemalloc.pic.o):(.rodata.je_pind2sz_tab+0x0): first defined here
          collect2: error: ld returned 1 exit status

jemalloc-sys fails to build with musl on Ubuntu 16.04

I'm not sure what the error means, but the relevant portion is here:

configure: WARNING: using cross tools not prefixed with host triplet
ar: `u' modifier ignored since `D' is the default (see `U')
/usr/bin/ld: /usr/lib/x86_64-linux-musl/libc.a(sysconf.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/lib/x86_64-linux-musl/libc.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [lib/libjemalloc.so.2] Error 1
make: *** Waiting for unfinished jobs....
ar: `u' modifier ignored since `D' is the default (see `U')
thread 'main' panicked at 'command did not execute successfully: "make" "srcroot=../jemalloc/" "-j" "2"
expected success, got: exit code: 2', /home/travis/.cargo/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.3.0/build.rs:370:9

You can see the full build failure here: https://travis-ci.org/BurntSushi/ripgrep/jobs/524197138

musl version is 1.1.9.

Any ideas on what's wrong? I can't reproduce this on my local system. (But I'm using musl 1.1.21 locally.)

Support release/debug build

Hi

Debug feature is really useful.
However looks like cargo currently does not support enabling/disabling features based on debug/release build mode. I'd like to have some workaround like some feature enabling transparent debug/release build.

I guess something like following would be enough:

if env::var("CARGO_FEATURE_AUTODEBUG").is_ok() {
        info!("CARGO_FEATURE_AUTODEBUG set");
        #[cfg(debug_assertions)]
        cmd.arg("--enable-debug");
    }

systest fails on master

cargo:rerun-if-changed=../jemalloc-sys/src/lib.rs
OPT_LEVEL = Some("0")
HOST = Some("x86_64-apple-darwin")
CC_x86_64-apple-darwin = None
CC_x86_64_apple_darwin = None
HOST_CC = None
CC = None
CFLAGS_x86_64-apple-darwin = None
CFLAGS_x86_64_apple_darwin = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3")
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/Users/sfackler/jemallocator/target/debug/build/jemalloc-sys-e3522fe24d80e112/out/include" "-Wall" "-Wextra" "-Wall" "-Wextra" "-Werror" "-Wno-unused-parameter" "-Wno-type-limits" "-Wno-address-of-packed-member" "-Wno-deprecated-declarations" "-o" "/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.o" "-c" "/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c"
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:340:34: error: field 'v' declared as a function
cargo:warning=                  extent_alloc_t v;
cargo:warning=                                 ^
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:354:60: error: function cannot return function type 'extent_alloc_t' (aka 'void *(struct extent_hooks_s *, void *, unsigned long, unsigned long, bool *, bool *, unsigned int)')
cargo:warning=             extent_alloc_t __test_roundtrip_extent_alloc_t(
cargo:warning=                                                           ^
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:378:24: error: incompatible pointer to integer conversion returning 'extent_alloc_t *' (aka 'void *(*)(struct extent_hooks_s *, void *, unsigned long, unsigned long, bool *, bool *, unsigned int)') from a function with result type 'int' [-Werror,-Wint-conversion]
cargo:warning=                return value;
cargo:warning=                       ^~~~~
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:389:35: error: field 'v' declared as a function
cargo:warning=                  extent_dalloc_t v;
cargo:warning=                                  ^
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:403:62: error: function cannot return function type 'extent_dalloc_t' (aka 'bool (struct extent_hooks_s *, void *, unsigned long, bool, unsigned int)')
cargo:warning=             extent_dalloc_t __test_roundtrip_extent_dalloc_t(
cargo:warning=                                                             ^
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:427:24: error: incompatible pointer to integer conversion returning 'extent_dalloc_t *' (aka 'bool (*)(struct extent_hooks_s *, void *, unsigned long, bool, unsigned int)') from a function with result type 'int' [-Werror,-Wint-conversion]
cargo:warning=                return value;
cargo:warning=                       ^~~~~
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:438:36: error: field 'v' declared as a function
cargo:warning=                  extent_destroy_t v;
cargo:warning=                                   ^
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:452:64: error: function cannot return function type 'extent_destroy_t' (aka 'void (struct extent_hooks_s *, void *, unsigned long, bool, unsigned int)')
cargo:warning=             extent_destroy_t __test_roundtrip_extent_destroy_t(
cargo:warning=                                                               ^
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:476:24: error: incompatible pointer to integer conversion returning 'extent_destroy_t *' (aka 'void (*)(struct extent_hooks_s *, void *, unsigned long, bool, unsigned int)') from a function with result type 'int' [-Werror,-Wint-conversion]
cargo:warning=                return value;
cargo:warning=                       ^~~~~
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:487:35: error: field 'v' declared as a function
cargo:warning=                  extent_commit_t v;
cargo:warning=                                  ^
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:501:62: error: function cannot return function type 'extent_commit_t' (aka 'bool (struct extent_hooks_s *, void *, unsigned long, unsigned long, unsigned long, unsigned int)')
cargo:warning=             extent_commit_t __test_roundtrip_extent_commit_t(
cargo:warning=                                                             ^
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:525:24: error: incompatible pointer to integer conversion returning 'extent_commit_t *' (aka 'bool (*)(struct extent_hooks_s *, void *, unsigned long, unsigned long, unsigned long, unsigned int)') from a function with result type 'int' [-Werror,-Wint-conversion]
cargo:warning=                return value;
cargo:warning=                       ^~~~~
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:536:37: error: field 'v' declared as a function
cargo:warning=                  extent_decommit_t v;
cargo:warning=                                    ^
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:550:66: error: function cannot return function type 'extent_decommit_t' (aka 'bool (struct extent_hooks_s *, void *, unsigned long, unsigned long, unsigned long, unsigned int)')
cargo:warning=             extent_decommit_t __test_roundtrip_extent_decommit_t(
cargo:warning=                                                                 ^
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:574:24: error: incompatible pointer to integer conversion returning 'extent_decommit_t *' (aka 'bool (*)(struct extent_hooks_s *, void *, unsigned long, unsigned long, unsigned long, unsigned int)') from a function with result type 'int' [-Werror,-Wint-conversion]
cargo:warning=                return value;
cargo:warning=                       ^~~~~
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:585:34: error: field 'v' declared as a function
cargo:warning=                  extent_purge_t v;
cargo:warning=                                 ^
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:599:60: error: function cannot return function type 'extent_purge_t' (aka 'bool (struct extent_hooks_s *, void *, unsigned long, unsigned long, unsigned long, unsigned int)')
cargo:warning=             extent_purge_t __test_roundtrip_extent_purge_t(
cargo:warning=                                                           ^
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:623:24: error: incompatible pointer to integer conversion returning 'extent_purge_t *' (aka 'bool (*)(struct extent_hooks_s *, void *, unsigned long, unsigned long, unsigned long, unsigned int)') from a function with result type 'int' [-Werror,-Wint-conversion]
cargo:warning=                return value;
cargo:warning=                       ^~~~~
cargo:warning=/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c:634:34: error: field 'v' declared as a function
cargo:warning=                  extent_split_t v;
cargo:warning=                                 ^
cargo:warning=fatal error: too many errors emitted, stopping now [-ferror-limit=]
cargo:warning=20 errors generated.
exit code: 1

--- stderr
rust version: 1.36.0


error occurred: Command "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/Users/sfackler/jemallocator/target/debug/build/jemalloc-sys-e3522fe24d80e112/out/include" "-Wall" "-Wextra" "-Wall" "-Wextra" "-Werror" "-Wno-unused-parameter" "-Wno-type-limits" "-Wno-address-of-packed-member" "-Wno-deprecated-declarations" "-o" "/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.o" "-c" "/Users/sfackler/jemallocator/target/debug/build/systest-0d9e0e3ebe0e45b7/out/all.c" with args "cc" did not execute successfully (status code exit code: 1).

strdup is not handled properly

Hi, when using this crate as custom memory allocator, the memory pointer returned by strdup can't be freed by libc::free. It seems jemalloc replace libc::free with its implementation, but strdup still uses default malloc. Am I missing any thing here?

nallocx in jemalloc-sys should be LLVM::ReadOnly + LLVM::NoUnwind

But currently isn't, and AFAIK there isn't a way to annotate FFI functions with these attributes.

This might explain why the benchmark for alloc_excess when the result is not used performs worse than alloc. The compiler doesn't know that nallocx does not have side-effects, and as a consequence it cannot eliminate the call.

doesn't build successfully on win10 with both msvc and gnu targets

I'm trying to build nom on win10 and jemallocator-sys is a dependency which fails to build.
Here is what I did:

C:\WINDOWS\system32>"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.0
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

cd C:\Users\davidm.cargo\registry\src\github.com-1ecc6299db9ec823\jemalloc-sys-0.1.8>

cargo build --release --verbose --verbose --target=x86_64-pc-windows-gnu
error: failed to run custom build command for `jemalloc-sys v0.1.8 (C:\Users\davidm\.cargo\registry\src\github.com-1ecc6299db9ec823\jemalloc-sys-0.1.8)`

Caused by:
  process didn't exit successfully: `C:\Users\davidm\.cargo\registry\src\github.com-1ecc6299db9ec823\jemalloc-sys-0.1.8\target\release\build\jemalloc-sys-9566d0968475bffa\build-script-build` (exit code: 101)
--- stdout
TARGET=x86_64-pc-windows-gnu
HOST=x86_64-pc-windows-msvc
NUM_JOBS=4
OUT_DIR="C:\\Users\\davidm\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\jemalloc-sys-0.1.8\\target\\x86_64-pc-windows-gnu\\release\\build\\jemalloc-sys-833b49275cddfd09\\out"
BUILD_DIR="C:\\Users\\davidm\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\jemalloc-sys-0.1.8\\target\\x86_64-pc-windows-gnu\\release\\build\\jemalloc-sys-833b49275cddfd09\\out\\build"
SRC_DIR="C:\\Users\\davidm\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\jemalloc-sys-0.1.8"
OPT_LEVEL = Some("3")
TARGET = Some("x86_64-pc-windows-gnu")
HOST = Some("x86_64-pc-windows-msvc")
CC_x86_64-pc-windows-gnu = None
CC_x86_64_pc_windows_gnu = None
TARGET_CC = None
CC = None
CFLAGS_x86_64-pc-windows-gnu = None
CFLAGS_x86_64_pc_windows_gnu = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,mmx,sse,sse2")
CC="gcc.exe"
CFLAGS="-O3 -ffunction-sections -fdata-sections -m64 -Wall"
JEMALLOC_SRC_DIR="C:\\Users\\davidm\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\jemalloc-sys-0.1.8\\target\\x86_64-pc-windows-gnu\\release\\build\\jemalloc-sys-833b49275cddfd09\\out\\jemalloc"
cargo:rustc-cfg=prefixed
JEMALLOC PREFIX SET TO: _rjem_
running: "sh" "/c/Users/davidm/.cargo/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.8/target/x86_64-pc-windows-gnu/release/build/jemalloc-sys-833b49275cddfd09/out/jemalloc/configure" "--disable-cxx" "--with-jemalloc-prefix=_rjem_" "--with-private-namespace=_r
jem_" "--host=x86_64-w64-mingw32" "--build=x86_64-pc-win32" "--prefix=C:\\Users\\davidm\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\jemalloc-sys-0.1.8\\target\\x86_64-pc-windows-gnu\\release\\build\\jemalloc-sys-833b49275cddfd09\\out"
checking for xsltproc... false
checking for x86_64-w64-mingw32-gcc... gcc.exe
checking whether the C compiler works... no

--- stderr
configure: error: in `/c/Users/davidm/.cargo/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.8/target/x86_64-pc-windows-gnu/release/build/jemalloc-sys-833b49275cddfd09/out/build':
configure: error: C compiler cannot create executables
See `config.log' for more details
thread 'main' panicked at 'command did not execute successfully: "sh" "/c/Users/davidm/.cargo/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.1.8/target/x86_64-pc-windows-gnu/release/build/jemalloc-sys-833b49275cddfd09/out/jemalloc/configure" "--disable-cxx" "--w
ith-jemalloc-prefix=_rjem_" "--with-private-namespace=_rjem_" "--host=x86_64-w64-mingw32" "--build=x86_64-pc-win32" "--prefix=C:\\Users\\davidm\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\jemalloc-sys-0.1.8\\target\\x86_64-pc-windows-gnu\\release\\build\\jemallo
c-sys-833b49275cddfd09\\out"
expected success, got: exit code: 77', build.rs:289:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
cargo build --release --verbose --verbose
     Running `C:\Users\davidm\.cargo\registry\src\github.com-1ecc6299db9ec823\jemalloc-sys-0.1.8\target\release\build\jemalloc-sys-9566d0968475bffa\build-script-build`
[jemalloc-sys 0.1.8] TARGET=x86_64-pc-windows-msvc
[jemalloc-sys 0.1.8] HOST=x86_64-pc-windows-msvc
[jemalloc-sys 0.1.8] NUM_JOBS=4
[jemalloc-sys 0.1.8] OUT_DIR="C:\\Users\\davidm\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\jemalloc-sys-0.1.8\\target\\release\\build\\jemalloc-sys-da4c6f7da1e98082\\out"
[jemalloc-sys 0.1.8] BUILD_DIR="C:\\Users\\davidm\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\jemalloc-sys-0.1.8\\target\\release\\build\\jemalloc-sys-da4c6f7da1e98082\\out\\build"
[jemalloc-sys 0.1.8] SRC_DIR="C:\\Users\\davidm\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\jemalloc-sys-0.1.8"
[jemalloc-sys 0.1.8] thread 'main' panicked at 'jemalloc does not support target: x86_64-pc-windows-msvc', build.rs:58:13
[jemalloc-sys 0.1.8] note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: failed to run custom build command for `jemalloc-sys v0.1.8 (C:\Users\davidm\.cargo\registry\src\github.com-1ecc6299db9ec823\jemalloc-sys-0.1.8)`

Caused by:
  process didn't exit successfully: `C:\Users\davidm\.cargo\registry\src\github.com-1ecc6299db9ec823\jemalloc-sys-0.1.8\target\release\build\jemalloc-sys-9566d0968475bffa\build-script-build` (exit code: 101)
--- stdout
TARGET=x86_64-pc-windows-msvc
HOST=x86_64-pc-windows-msvc
NUM_JOBS=4
OUT_DIR="C:\\Users\\davidm\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\jemalloc-sys-0.1.8\\target\\release\\build\\jemalloc-sys-da4c6f7da1e98082\\out"
BUILD_DIR="C:\\Users\\davidm\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\jemalloc-sys-0.1.8\\target\\release\\build\\jemalloc-sys-da4c6f7da1e98082\\out\\build"
SRC_DIR="C:\\Users\\davidm\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\jemalloc-sys-0.1.8"

--- stderr
thread 'main' panicked at 'jemalloc does not support target: x86_64-pc-windows-msvc', build.rs:58:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

jemalloc-sys: version macro being 0

The jemalloc.h produced by jemalloc-sys contain the following macros:

#define JEMALLOC_VERSION "0.0.0-0-g0000000000000000000000000000000000000000"
#define JEMALLOC_VERSION_MAJOR 0
#define JEMALLOC_VERSION_MINOR 0
#define JEMALLOC_VERSION_BUGFIX 0
#define JEMALLOC_VERSION_NREV 0
#define JEMALLOC_VERSION_GID "0000000000000000000000000000000000000000"

where for example JEMALLOC_VERSION_MAJOR should be 5 (for jemalloc 5.1.0). This will break c/c++ code that use the header to detect jemalloc version. Reproducible on master and jemalloc-sys:0.3.2. It was fine with jemalloc-sys:1.7.0.

Is sdallocx safe to call with a null pointer?

With recent changes to an application, I am running into the error memory allocation of n bytes failed (where n is a small number eg. 5, 1, 4) when using jemallocator. The application works fine when using the system allocator.

Running jemalloc in debug mode reveals that it is failing the assert that sdallocx was not called with a null pointer.

The jemalloc-sys docs imply it is safe to call sdallocx with a null pointer (it states "no action occurs"). I cannot find anything in jemalloc docs to confirm this, and by the assert in the code it appears as if it is explicitly not allowed.

Modifying sdallocx to simply return when called with a null pointer appears to fix the issue, but I am not sure of the ramifications of this change.

I apologize for not having a minimal example with which to replicate. The scenario in which the error occurs is fairly involved.

Support for more page sizes

When running on the iPhone 8, which has a page size of 16KB, I get the error message <jemalloc>: Unsupported system page size, and then my program segfaults when trying to access the allocated memory. One solution to this would be to use the --with-lg-page=<lg-page> flag, perhaps as a feature flag like with https://github.com/alexcrichton/jemallocator#feature-flags?

Increased virtual memory use

Switching to this crate with #[global_allocator] apparently caused Servo to consume 7x more virtual memory than with alloc_jemalloc: servo/servo#19010. This seems surprising since the same jemalloc code is used ultimately, and its compilation options don’t seem to be significantly different. Or maybe I missed something?

systest depends on libc 0.1, fails on ppc64le

cargo run --target $TARGET --manifest-path systest/Cargo.toml command is failing on ppc64le because systest depend on an older version of libc - 0.1, that is not supported on Power.

I tried to update the version of libc in systest/Cargo.toml to 0.2, however that in turn leads to the following failure:
root@ee2039143bce:~/jemallocator# cargo run --target $TARGET --manifest-path systest/Cargo.toml
Compiling gcc v0.3.51
Compiling unicode-xid v0.0.3
Compiling libc v0.2.26
Compiling winapi v0.2.8
Compiling winapi-build v0.1.1
Compiling rustc-serialize v0.3.24
Compiling log v0.3.8
Compiling kernel32-sys v0.2.2
Compiling jemalloc-sys v0.1.1 (file:///root/jemallocator/jemalloc-sys)
Compiling term v0.2.14
Compiling bitflags v0.3.3
Compiling syntex_syntax v0.27.0
Compiling ctest v0.1.4
Compiling systest v0.1.0 (file:///root/jemallocator/systest)
error[E0432]: unresolved import std::heap::System
--> systest/src/main.rs:7:5
|
7 | use std::heap::System;
| ^^^^^^^^^^^^^^^^^ Could not find heap in std

error[E0554]: #[feature] may not be used on the stable release channel
--> systest/src/main.rs:2:1
|
2 | #![feature(global_allocator, allocator_api)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: The attribute global_allocator is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
--> systest/src/main.rs:9:1
|
9 | #[global_allocator]
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

error: Could not compile systest.

I will continue investigating this further.

Rust-specific size-class optimizations

@davidtgoldblatt mentioned on gitter:

there's an optimization that Rust can do that C can't btw

Since rust always passes in the alignment, it can support more size classes than C can
(e.g. 24 or 40 byte size classes, say)

Because most allocations only need 8-byte alignment, but conservatively (given only size) we need to provide 16 (on, say, x86) for any allocation >= 16 bytes

So you could tweak the size class logic if (e.g.) --enable-size-thing is passed to configure

We haven't tried it, but it ought to give a pretty good-sized win (based on the lock contention stats on the small size classes, and from the tcmalloc experience)


Ideally, we would gather telemetry information for this first (e.g. running servo or rustc), and then figure out whether it makes sense to add extra size-classes by default.

Segfault during process initialization if not registered as a global allocator

I'm updating jemalloc-ctl to talk to jemallocator, and ran into a crash. If jemallocator isn't registered as the global allocator but jemalloc-sys is linked into the process, cargo test crashes on startup.

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x200000)
  * frame #0: 0x00000001000acd01 jemalloc_ctl-86ee533eb4cc44b1`je_pages_map(addr=&0x0, size=2097152, commit=&0x200000) at pages.c:43 [opt]
    frame #1: 0x000000010006da6a jemalloc_ctl-86ee533eb4cc44b1`je_extent_alloc_mmap(new_addr=&0x0, size=2097152, alignment=2097152, zero=&0x7ffeefbfad77, commit=&0x7ffeefbfad76) at extent_mmap.c:24
    frame #2: 0x000000010004c54b jemalloc_ctl-86ee533eb4cc44b1`base_map(tsdn=&0x0, extent_hooks=&0x1000f0618, ind=0, size=2097152) at base.c:41
    frame #3: 0x000000010004b278 jemalloc_ctl-86ee533eb4cc44b1`base_block_alloc(tsdn=&0x0, base=&0x0, extent_hooks=&0x1000f0618, ind=0, pind_last=&0x7ffeefbfc7ac, extent_sn_next=&0x7ffeefbfc7a0, size=2000, alignment=16) at base.c:270
    frame #4: 0x000000010004aeff jemalloc_ctl-86ee533eb4cc44b1`je_base_new(tsdn=&0x0, ind=0, extent_hooks=&0x1000f0618) at base.c:353
    frame #5: 0x000000010004c39e jemalloc_ctl-86ee533eb4cc44b1`je_base_boot(tsdn=&0x0) at base.c:512
    frame #6: 0x0000000100045825 jemalloc_ctl-86ee533eb4cc44b1`malloc_init_hard_a0_locked at jemalloc.c:1294
    frame #7: 0x0000000100047dcf jemalloc_ctl-86ee533eb4cc44b1`malloc_init_hard at jemalloc.c:1517
    frame #8: 0x0000000100045771 jemalloc_ctl-86ee533eb4cc44b1`jemalloc_constructor [inlined] malloc_init at jemalloc.c:217
    frame #9: 0x0000000100045754 jemalloc_ctl-86ee533eb4cc44b1`jemalloc_constructor at jemalloc.c:3184
    frame #10: 0x00000001003ada7a dyld`ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 420
    frame #11: 0x00000001003adcaa dyld`ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 40
    frame #12: 0x00000001003a91cc dyld`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 330
    frame #13: 0x00000001003a8302 dyld`ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 134
    frame #14: 0x00000001003a8396 dyld`ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 74
    frame #15: 0x0000000100399567 dyld`dyld::initializeMainExecutable() + 196
    frame #16: 0x000000010039e239 dyld`dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 7242
    frame #17: 0x00000001003983d4 dyld`dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) + 453
    frame #18: 0x00000001003981d2 dyld`_dyld_start + 54

You can see this by removing these lines: https://github.com/sfackler/jemalloc-ctl/blob/07ebe3619aad4742723bb9347cfd46916c6213c4/src/lib.rs#L86-L88

Unclear how to enable profiling

I'm trying to get jemalloc to do heap profiling by configuring it in the environment:

export MALLOC_CONF=prof:true,lg_prof_interval:30,lg_prof_sample:17

Profiling is enabled:

[dependencies.jemallocator]
version = "*"
features = ["profiling"]

I do not see the expected output as described here. Is this expected to work when using this crate?

Future of jemallocator

I think that we should move jemallocator into the nursery, and have rustc use it instead of the current liballoc_jemalloc implementation.

That would make it much easier for us to contribute to liballoc_jemalloc, add benchmarks, etc.

For example, I have my own fork of jemallocator here: https://github.com/gnzlbg/jemallocator where I have added benchmarks (in the gbg branches) that I would like to contribute to liballoc_jemalloc upstream, but then running does benchmarks becomes really painful (typically requires at least a stage1 compiler, etc.).

Another thing that the current jemallocator setup easily allows is to improve jemalloc itself. For example, in the gbg3 branch I test jemallocator with my own jemalloc fork and by slightly tweaking jemallocs API I am able to to show some nice speed-ups.

I wouldn't have been able to do any of this if I would have had to hack in liballoc_jemalloc within the compiler itself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.