Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
2261154
core: add Peekable::next_if_map
kennytm Jul 10, 2025
bbf08d8
add a test with incorrect `if let`-`super let` drop order
dianne Aug 13, 2025
8fc3938
fix scope of `super let` bindings within `if let`
dianne Aug 13, 2025
52063ae
stabilize path_add_extension
hanna-kruppe Aug 10, 2025
8dbdb17
On binding not present in all patterns, suggest potential typo
estebank Aug 24, 2025
bcfc9b5
inline at the callsite & warn when target features mismatch
Jamesbarford Aug 21, 2025
fc7de99
Ensure we emit an allocator shim when only some crate types need one
bjorn3 Aug 28, 2025
1d30900
Fix typo in comment
bjorn3 Aug 28, 2025
f4888c2
Correctly handle different crate types disagreeing if the allocator s…
bjorn3 Aug 28, 2025
bd0ea61
Add test for typo in or-pattern binding
estebank Aug 29, 2025
cb9cd8f
On binding not present in all patterns, look at consts and unit struc…
estebank Aug 30, 2025
00f6fe1
On unused binding in pattern, suggest unit struct/variant with simila…
estebank Aug 30, 2025
3355f4b
Suggest constant on unused binding in a pattern
estebank Aug 30, 2025
86085b4
Avoid unnecessary suggestion in or-pattern
estebank Aug 30, 2025
a44b180
add `#[must_use]` to `array::repeat`
joboet Aug 31, 2025
0711bba
Ignore test when dylibs are not supported
bjorn3 Aug 31, 2025
5e9b655
Correct typo in `rustc_errors` comment
smoelius Sep 2, 2025
5b43244
Add LSX accelerated implementation for source file analysis
heiher Aug 28, 2025
a8537ab
Remove special implementation of `PartialEq` for `InvisibleOrigin` ou…
Kobzol Sep 1, 2025
5d9f8fc
llvm: nvptx: Layout update to match LLVM
maurer Sep 2, 2025
5a9e2e4
docs(std): add missing closing code block fences in doc comments
AudaciousAxiom Sep 2, 2025
43873db
test(rustdoc): show the wrong `--emit` precedence
weihanglo Sep 2, 2025
af0d6f1
compiletest: cygwin follows windows in using PATH for dynamic libraries
jeremyd2019 Sep 2, 2025
d9dc20c
raw_vec.rs: Remove superfluous fn alloc_guard
btj Aug 22, 2025
0fa93a3
Disallow frontmatter in `--cfg` and `--check-cfg` arguments
Urgau Sep 2, 2025
c5dd32e
fix(rustdoc): match rustc `--emit` precedence
weihanglo Sep 2, 2025
df5896a
Rename `ToolRustc` to `ToolRustcPrivate`
Kobzol Sep 2, 2025
f19c33e
Split distcheck logic into functions
Kobzol Sep 2, 2025
df2caed
refactor tests to use TestCtx
Shourya742 Sep 3, 2025
c4a5408
Make test parallel
Shourya742 Sep 3, 2025
9f3fe40
remove thread option from self-test invocation
Shourya742 Sep 3, 2025
5c4b61b
don't uppercase error messages
scrabsha Sep 1, 2025
fe90610
Check `rustc-dev` in `distcheck`
Kobzol Sep 2, 2025
a5f52a9
Uncomment code to add scraped rustdoc examples in loaded paths
GuillaumeGomez Sep 3, 2025
e7674cb
rustdoc-search: add test case for indexing every item type
notriddle Sep 2, 2025
fcc413f
htmldocck: fix a bug in relative paths / globs
notriddle Sep 2, 2025
c914c47
Add `read_buf` equivalents for positioned reads
niklasf Apr 29, 2025
fea27a6
triagebot: configure some pings when certain attributes are used
RalfJung Sep 3, 2025
2d20ee7
support keyword-based mentions in tidy
RalfJung Sep 3, 2025
f073f64
Rollup merge of #140459 - niklasf:feature/read-buf-at, r=tgross35
Zalathar Sep 4, 2025
732802c
Rollup merge of #143725 - kennytm:peekable_next_if_map, r=jhpratt
Zalathar Sep 4, 2025
98f6887
Rollup merge of #145209 - hanna-kruppe:path_add_extension, r=tgross35
Zalathar Sep 4, 2025
cd59ee7
Rollup merge of #145342 - dianne:if-let-super-let, r=nnethercote
Zalathar Sep 4, 2025
d71a9b6
Rollup merge of #145750 - btj:drop-alloc-guard, r=tgross35
Zalathar Sep 4, 2025
3a6ae11
Rollup merge of #145827 - estebank:issue-51976, r=jackh726
Zalathar Sep 4, 2025
f90cc35
Rollup merge of #145932 - JamieCunliffe:target-feature-inlining, r=ja…
Zalathar Sep 4, 2025
6c77c4c
Rollup merge of #145962 - bjorn3:linkage_fixes, r=WaffleLapkin
Zalathar Sep 4, 2025
2952b99
Rollup merge of #145963 - heiher:src-analysis-lsx, r=lqd
Zalathar Sep 4, 2025
c7a11f4
Rollup merge of #146054 - joboet:array-repeat-must_use, r=ibraheemdev
Zalathar Sep 4, 2025
57e8a53
Rollup merge of #146090 - Kobzol:invisible-origin-eq, r=petrochenkov
Zalathar Sep 4, 2025
6f490f7
Rollup merge of #146112 - scrabsha:push-utkysktvulto, r=WaffleLapkin
Zalathar Sep 4, 2025
5848328
Rollup merge of #146120 - smoelius:patch-3, r=lqd
Zalathar Sep 4, 2025
1456b67
Rollup merge of #146124 - Kobzol:distcheck-ext, r=jieyouxu
Zalathar Sep 4, 2025
9867486
Rollup merge of #146127 - Kobzol:rename-tool-rustc, r=jieyouxu
Zalathar Sep 4, 2025
3b365d8
Rollup merge of #146131 - notriddle:rustdoc-search-load-itemtype-test…
Zalathar Sep 4, 2025
a1469aa
Rollup merge of #146134 - maurer:nvptx-sync, r=durin42
Zalathar Sep 4, 2025
b27c94a
Rollup merge of #146136 - AudaciousAxiom:docs/missing-closing-code-bl…
Zalathar Sep 4, 2025
10cbfe6
Rollup merge of #146137 - Urgau:cfg-disallow-frontmatter, r=fmease
Zalathar Sep 4, 2025
9214b18
Rollup merge of #146140 - jeremyd2019:patch-1, r=jieyouxu
Zalathar Sep 4, 2025
8fc568e
Rollup merge of #146150 - weihanglo:rustdoc-emit, r=aDotInTheVoid
Zalathar Sep 4, 2025
8b2a64f
Rollup merge of #146155 - Shourya742:2025-09-03-make-test-run-paralle…
Zalathar Sep 4, 2025
c81fffa
Rollup merge of #146161 - GuillaumeGomez:loaded-paths-scraped-example…
Zalathar Sep 4, 2025
11ea573
Rollup merge of #146172 - RalfJung:triagebot-keyword-mentions, r=Urgau
Zalathar Sep 4, 2025
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
Prev Previous commit
Next Next commit
Ensure we emit an allocator shim when only some crate types need one
  • Loading branch information
bjorn3 committed Aug 29, 2025
commit fc7de9979e418b0ea467bb2833b07486d7c54940
17 changes: 13 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use super::linker::{self, Linker};
use super::metadata::{MetadataPosition, create_wrapper_file};
use super::rpath::{self, RPathConfig};
use super::{apple, versioned_llvm_target};
use crate::base::needs_allocator_shim_for_linking;
use crate::{
CodegenResults, CompiledModule, CrateInfo, NativeLib, errors, looks_like_rust_object_file,
};
Expand Down Expand Up @@ -2080,9 +2081,17 @@ fn add_local_crate_regular_objects(cmd: &mut dyn Linker, codegen_results: &Codeg
}

/// Add object files for allocator code linked once for the whole crate tree.
fn add_local_crate_allocator_objects(cmd: &mut dyn Linker, codegen_results: &CodegenResults) {
if let Some(obj) = codegen_results.allocator_module.as_ref().and_then(|m| m.object.as_ref()) {
cmd.add_object(obj);
fn add_local_crate_allocator_objects(
cmd: &mut dyn Linker,
codegen_results: &CodegenResults,
crate_type: CrateType,
) {
if needs_allocator_shim_for_linking(&codegen_results.crate_info.dependency_formats, crate_type)
{
if let Some(obj) = codegen_results.allocator_module.as_ref().and_then(|m| m.object.as_ref())
{
cmd.add_object(obj);
}
}
}

Expand Down Expand Up @@ -2281,7 +2290,7 @@ fn linker_with_args(
codegen_results,
metadata,
);
add_local_crate_allocator_objects(cmd, codegen_results);
add_local_crate_allocator_objects(cmd, codegen_results, crate_type);

// Avoid linking to dynamic libraries unless they satisfy some undefined symbols
// at the point at which they are specified on the command line.
Expand Down
27 changes: 22 additions & 5 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rustc_hir::lang_items::LangItem;
use rustc_hir::{ItemId, Target};
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc_middle::middle::debugger_visualizer::{DebuggerVisualizerFile, DebuggerVisualizerType};
use rustc_middle::middle::dependency_format::Dependencies;
use rustc_middle::middle::exported_symbols::{self, SymbolExportKind};
use rustc_middle::middle::lang_items;
use rustc_middle::mir::BinOp;
Expand Down Expand Up @@ -630,14 +631,30 @@ pub fn allocator_kind_for_codegen(tcx: TyCtxt<'_>) -> Option<AllocatorKind> {
// If the crate doesn't have an `allocator_kind` set then there's definitely
// no shim to generate. Otherwise we also check our dependency graph for all
// our output crate types. If anything there looks like its a `Dynamic`
// linkage, then it's already got an allocator shim and we'll be using that
// one instead. If nothing exists then it's our job to generate the
// allocator!
let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
// linkage for all crate types we may link as, then it's already got an
// allocator shim and we'll be using that one instead. If nothing exists
// then it's our job to generate the allocator! If crate types disagree
// about whether an allocator shim is necessary or not, we generate one
// and let needs_allocator_shim_for_linking decide at link time whether or
// not to use it for any particular linker invocation.
let all_crate_types_any_dynamic_crate = tcx.dependency_formats(()).iter().all(|(_, list)| {
use rustc_middle::middle::dependency_format::Linkage;
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
});
if any_dynamic_crate { None } else { tcx.allocator_kind(()) }
if all_crate_types_any_dynamic_crate { None } else { tcx.allocator_kind(()) }
}

/// Decide if this particular crate type needs an allocator shim linked in.
/// This may return true even when allocator_kind_for_codegen returns false. In
/// this case no allocator shim shall be linked.
pub(crate) fn needs_allocator_shim_for_linking(
dependency_formats: &Dependencies,
crate_type: CrateType,
) -> bool {
use rustc_middle::middle::dependency_format::Linkage;
let any_dynamic_crate =
dependency_formats[&crate_type].iter().any(|&linkage| linkage == Linkage::Dynamic);
!any_dynamic_crate
}

pub fn codegen_crate<B: ExtraBackendMethods>(
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/linking/mixed-allocator-shim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ build-pass
//@ compile-flags: --crate-type staticlib,dylib -Zstaticlib-prefer-dynamic
//@ no-prefer-dynamic

// Test that compiling for multiple crate types in a single compilation with
// mismatching allocator shim requirements doesn't result in the allocator shim
// missing entirely.
// In this particular test the dylib crate type will statically link libstd and
// thus need an allocator shim, while the staticlib crate type will dynamically
// link libstd and thus not need an allocator shim.
// The -Zstaticlib-prefer-dynamic flag could be avoided by doing it the other
// way around, but testing that the staticlib correctly has the allocator shim
// in that case would require a run-make test instead.

pub fn foo() {}