Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,12 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
}
}

match flavor {
RlibFlavor::Normal => {}
RlibFlavor::StaticlibBase => {
let obj = codegen_results.allocator_module.as_ref().and_then(|m| m.object.as_ref());
if let Some(obj) = obj {
ab.add_file(obj);
}
if flavor == RlibFlavor::StaticlibBase
|| sess.opts.debugging_opts.force_allocator_shim.unwrap_or(false)
{
let obj = codegen_results.allocator_module.as_ref().and_then(|m| m.object.as_ref());
if let Some(obj) = obj {
ab.add_file(obj);
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ fn test_debugging_options_tracking_hash() {
tracked!(drop_tracking, true);
tracked!(dual_proc_macros, true);
tracked!(fewer_names, Some(true));
tracked!(force_allocator_shim, Some(false));
tracked!(force_unstable_if_unmarked, true);
tracked!(fuel, Some(("abc".to_string(), 99)));
tracked!(function_sections, Some(false));
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,9 @@ impl<'a> CrateLoader<'a> {
// if our compilation session actually needs an allocator based on what
// we're emitting.
let all_rlib = self.sess.crate_types().iter().all(|ct| matches!(*ct, CrateType::Rlib));
if all_rlib {
let force_allocator_shim =
self.sess.opts.debugging_opts.force_allocator_shim.unwrap_or(false);
if all_rlib && !force_allocator_shim {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,8 @@ options! {
fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],
"reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \
(default: no)"),
force_allocator_shim: Option<bool> = (None, parse_opt_bool, [TRACKED],
"force generation of an allocator shim"),
force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
"force all crates to be `rustc_private` unstable (default: no)"),
fuel: Option<(String, u64)> = (None, parse_optimization_fuel, [TRACKED],
Expand Down
12 changes: 12 additions & 0 deletions src/test/run-make/force-allocator-shim/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-include ../../run-make-fulldeps/tools.mk

# Tests that the `-Z force-allocator-shim` flag causes an allocator shim to be
# generated when expected.

all:
$(RUSTC) foo.rs --crate-type rlib -Z force-allocator-shim
nm $(TMPDIR)/libfoo.rlib | $(CGREP) "__rust_alloc" && \
nm $(TMPDIR)/libfoo.rlib | $(CGREP) "__rust_alloc_error_handler" && \
nm $(TMPDIR)/libfoo.rlib | $(CGREP) "__rust_alloc_zeroed" && \
nm $(TMPDIR)/libfoo.rlib | $(CGREP) "__rust_dealloc" && \
nm $(TMPDIR)/libfoo.rlib | $(CGREP) "__rust_realloc"
1 change: 1 addition & 0 deletions src/test/run-make/force-allocator-shim/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub fn foo() {}