Skip to content

Cannot use alloc_system allocator for binary #44510

Closed
@mssun

Description

@mssun

According to the the book, we can override default allocator of a binary from jemelloc to system allocator by:

#![feature(alloc_system)]

extern crate alloc_system;

fn main() {
    let a = Box::new(4); // Allocates from the system allocator.
    println!("{}", a);
}

This feature works in previous nightly (back to Rust 1.9.0 and 1.11.0-nightly a967611 2016-05-30) according to this this blog, but it was broken in recent nightly versions.

I try to compile this code with cargo build --release, and here is the result:

$ ls -alh target/release/hello
-rwxrwxr-x 2 mssun mssun 3.9M Sep 11 22:44 target/release/hello

$ strings target/release/hello | grep je_malloc
je_malloc_mutex_prefork
je_malloc_printf
je_malloc_message malloc_message
je_malloc malloc
je_malloc_mutex_postfork_parent
je_malloc_conf malloc_conf
je_malloc_stats_print malloc_stats_print
je_malloc_mutex_unlock
je_mallocx mallocx
je_malloc_mutex_boot
je_malloc_mutex_postfork_child
je_malloc_mutex_init
je_malloc_mutex_lock
je_malloc_usable_size malloc_usable_size
je_malloc_tsd_boot0
je_malloc_tsd_boot1
je_malloc_strtoumax
je_malloc_write
je_malloc_mutex_assert_owner
je_malloc_mutex_assert_not_owner
je_malloc_snprintf
je_malloc_cprintf
je_malloc_tsd_cleanup_register
je_malloc_tsd_malloc
je_malloc_tsd_dalloc
je_malloc_tsd_no_cleanup
je_malloc_vsnprintf
je_malloc_vcprintf
je_malloc_mutex_init
je_malloc_tsd_boot0
je_malloc_printf
je_malloc_mutex_prefork
je_malloc_mutex_postfork_child
je_malloc_mutex_postfork_parent
je_malloc_mutex_boot
je_malloc_cprintf
je_malloc_tsd_boot1
je_malloc_snprintf
je_malloc_write
je_malloc_strtoumax
je_malloc_vsnprintf
je_malloc_tsd_no_cleanup
je_malloc_vcprintf

The binary should not this large, the strings results indicate that je_malloc is still used as the allocator.

Meta

rustc --version --verbose:
rustc 1.22.0-nightly (ca94c75 2017-09-10)
binary: rustc
commit-hash: ca94c75
commit-date: 2017-09-10
host: x86_64-unknown-linux-gnu
release: 1.22.0-nightly
LLVM version: 4.0

Metadata

Metadata

Assignees

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.P-highHigh priority

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions