Skip to content

Jemalloc sneaking in even with force_alloc_system #43524

Closed
@vorner

Description

@vorner

Hello

I'm experimenting with some cross-compilation, using xargo. I have my own target description and a script that downloads SDK for the device and uses that to build the corresponding std.

If I enable jemalloc, I can compile a binary (with some other hacks) and it works. But I'd like to strip the size of the binary, so I'd prefer to use the system allocator instead. When I switch to use force_alloc_system and "exe-allocation-crate": "alloc_system" in the target description, it fails to link with bunch of missing references, like __rde_dealloc. Grepping the sources, these come from liballoc_jemalloc crate. So it seems, no matter what I do, some part of jemalloc (the rust part) gets pulled in, but the C part is not compiled.

Experimenting with older nightlies, the first broken version is ‒ the compilation with system allocator works in older ones (and produces ~130kB smaller binary):

rustc 1.20.0-nightly (696412de7 2017-07-06)
binary: rustc
commit-hash: 696412de7e4e119f8536686c643621115b90c775
commit-date: 2017-07-06
host: x86_64-unknown-linux-gnu
release: 1.20.0-nightly
LLVM version: 4.0

I have the code in this repository: https://github.com/vorner/xcompile. There's a build script that, when run, downloads the SDK (that one is a bit largish), copies current rust sources (yes, this needs rustup component add rust-src), patches them a little bit (I had some problems with libunwind) and compiles it. It doesn't clean things, so I always delete the sysroot and the sources between experiments (rm -rf ~/.xargo target rust-src).

There are two relevant (very similar) branches, with_jemalloc and with_sys_alloc.

I think this might be somewhat related to this report: #43510, but the observable effects are quite different.

I noticed there's that new #[global_allocator] attribute, and I'll read its documentation, but the force_alloc_system feature is still available, so I believe it wasn't the intention to deprecate it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-allocatorsArea: Custom and system allocatorsC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions