Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
  1. Define a set of symbols (rust_malloc, rust_free, etc) which correspond to the APIs specified in heap::allocate. The liballoc library will call these symbols directly. Note that this means that each of the symbols take information like the size of allocations and such.
  2. Create two shim libraries which implement these rust_foo allocation-related functions. Each shim is shipped with the compiler in the form of a static library. One shim will redirect to libc, the other shim will bundle an unprefixed jemalloc build along with shims to redirect to jemalloc.
  3. Intermediate artifacts (rlibs) do not resolve this dependency, they're just left dangling.
  4. When producing a "final artifact", rustc by default links in one of two shims:
    • If we're producing a staticlib or a dylib, link the libc malloc shim.
    • If we're producing an exe and one or more dependencies are rust dylibs, link the libc malloc shim
    • If we're producing an exe and all dependencies are rlibs link the jemalloc shim.

The final link step will be optional, and one could link in any compliant allocator at that time if so desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.