Skip to content

Commit c34047c

Browse files
committed
Fix CI failures on windows and aarch64-linux
1 parent b672715 commit c34047c

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2403,6 +2403,14 @@ fn add_upstream_rust_crates<'a>(
24032403
bundle: Some(false),
24042404
whole_archive: Some(false) | None,
24052405
} => {
2406+
// HACK/FIXME: Fixup a circular dependency between libgcc and libc
2407+
// with glibc. This logic should be moved to the libc crate.
2408+
if sess.target.os == "linux"
2409+
&& sess.target.env == "gnu"
2410+
&& name == "c"
2411+
{
2412+
cmd.link_staticlib("gcc", false);
2413+
}
24062414
cmd.link_staticlib(name, lib.verbatim.unwrap_or(false));
24072415
}
24082416
NativeLibKind::LinkArg => {

compiler/rustc_codegen_ssa/src/base.rs

+28-20
Original file line numberDiff line numberDiff line change
@@ -849,26 +849,34 @@ impl CrateInfo {
849849

850850
// Handle circular dependencies in the standard library.
851851
// See comment before `add_linked_symbol_object` function for the details.
852-
let missing_weak_lang_items: FxHashSet<&Symbol> = info
853-
.used_crates
854-
.iter()
855-
.flat_map(|cnum| {
856-
tcx.missing_lang_items(*cnum)
857-
.iter()
858-
.filter(|l| lang_items::required(tcx, **l))
859-
.filter_map(|item| WEAK_ITEMS_SYMBOLS.get(item))
860-
})
861-
.collect();
862-
info.linked_symbols
863-
.iter_mut()
864-
.filter(|(crate_type, _)| !matches!(crate_type, CrateType::Rlib | CrateType::Staticlib))
865-
.for_each(|(_, linked_symbols)| {
866-
linked_symbols.extend(
867-
missing_weak_lang_items
852+
// With msvc-like linkers it's both unnecessary (they support circular dependencies),
853+
// and causes linking issues (when weak lang item symbols are "privatized" by LTO).
854+
let target = &tcx.sess.target;
855+
if !target.is_like_msvc {
856+
let missing_weak_lang_items: FxHashSet<&Symbol> = info
857+
.used_crates
858+
.iter()
859+
.flat_map(|cnum| {
860+
tcx.missing_lang_items(*cnum)
868861
.iter()
869-
.map(|item| (item.to_string(), SymbolExportKind::Text)),
870-
)
871-
});
862+
.filter(|l| lang_items::required(tcx, **l))
863+
.filter_map(|item| WEAK_ITEMS_SYMBOLS.get(item))
864+
})
865+
.collect();
866+
let prefix = if target.is_like_windows && target.arch == "x86" { "_" } else { "" };
867+
info.linked_symbols
868+
.iter_mut()
869+
.filter(|(crate_type, _)| {
870+
!matches!(crate_type, CrateType::Rlib | CrateType::Staticlib)
871+
})
872+
.for_each(|(_, linked_symbols)| {
873+
linked_symbols.extend(
874+
missing_weak_lang_items
875+
.iter()
876+
.map(|item| (format!("{prefix}{item}"), SymbolExportKind::Text)),
877+
)
878+
});
879+
}
872880

873881
let embed_visualizers = tcx.sess.crate_types().iter().any(|&crate_type| match crate_type {
874882
CrateType::Executable | CrateType::Dylib | CrateType::Cdylib => {
@@ -888,7 +896,7 @@ impl CrateInfo {
888896
}
889897
});
890898

891-
if tcx.sess.target.is_like_msvc && embed_visualizers {
899+
if target.is_like_msvc && embed_visualizers {
892900
info.natvis_debugger_visualizers =
893901
collect_debugger_visualizers_transitive(tcx, DebuggerVisualizerType::Natvis);
894902
}

0 commit comments

Comments
 (0)