diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-06-25 10:07:01 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-08-14 15:13:10 -0700 |
| commit | 45bf1ed1a1123122ded05ae2eedaf0f190e52726 (patch) | |
| tree | 5065451271cbd7ea8b58d751f079072b72b4ad9e /src/test/compile-fail/allocator-rust-dylib-is-jemalloc.rs | |
| parent | e7261f3ab60e0d1e6c808004ecd25c88e04f3683 (diff) | |
rustc: Allow changing the default allocator
This commit is an implementation of [RFC 1183][rfc] which allows swapping out the default allocator on nightly Rust. No new stable surface area should be added as a part of this commit. [rfc]: https://github.com/rust-lang/rfcs/pull/1183 Two new attributes have been added to the compiler: * `#![needs_allocator]` - this is used by liballoc (and likely only liballoc) to indicate that it requires an allocator crate to be in scope. * `#![allocator]` - this is a indicator that the crate is an allocator which can satisfy the `needs_allocator` attribute above. The ABI of the allocator crate is defined to be a set of symbols that implement the standard Rust allocation/deallocation functions. The symbols are not currently checked for exhaustiveness or typechecked. There are also a number of restrictions on these crates: * An allocator crate cannot transitively depend on a crate that is flagged as needing an allocator (e.g. allocator crates can't depend on liballoc). * There can only be one explicitly linked allocator in a final image. * If no allocator is explicitly requested one will be injected on behalf of the compiler. Binaries and Rust dylibs will use jemalloc by default where available and staticlibs/other dylibs will use the system allocator by default. Two allocators are provided by the distribution by default, `alloc_system` and `alloc_jemalloc` which operate as advertised. Closes #27389
Diffstat (limited to 'src/test/compile-fail/allocator-rust-dylib-is-jemalloc.rs')
| -rw-r--r-- | src/test/compile-fail/allocator-rust-dylib-is-jemalloc.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/test/compile-fail/allocator-rust-dylib-is-jemalloc.rs b/src/test/compile-fail/allocator-rust-dylib-is-jemalloc.rs new file mode 100644 index 00000000000..224d9379ee1 --- /dev/null +++ b/src/test/compile-fail/allocator-rust-dylib-is-jemalloc.rs @@ -0,0 +1,26 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-msvc everything is the system allocator on msvc +// aux-build:allocator-dylib2.rs +// error-pattern: cannot link together two allocators + +// Ensure that rust dynamic libraries use jemalloc as their allocator, verifying +// by linking in the system allocator here and ensuring that we get a complaint. + +#![feature(alloc_system)] + +extern crate allocator_dylib2; +extern crate alloc_system; + +fn main() { + allocator_dylib2::foo(); +} + |
