Skip to content

Commit

Permalink
Fix CI failures on windows and aarch64-linux
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Sep 6, 2022
1 parent b672715 commit c34047c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
8 changes: 8 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,14 @@ fn add_upstream_rust_crates<'a>(
bundle: Some(false),
whole_archive: Some(false) | None,
} => {
// HACK/FIXME: Fixup a circular dependency between libgcc and libc
// with glibc. This logic should be moved to the libc crate.
if sess.target.os == "linux"
&& sess.target.env == "gnu"
&& name == "c"
{
cmd.link_staticlib("gcc", false);
}
cmd.link_staticlib(name, lib.verbatim.unwrap_or(false));
}
NativeLibKind::LinkArg => {
Expand Down
48 changes: 28 additions & 20 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,26 +849,34 @@ impl CrateInfo {

// Handle circular dependencies in the standard library.
// See comment before `add_linked_symbol_object` function for the details.
let missing_weak_lang_items: FxHashSet<&Symbol> = info
.used_crates
.iter()
.flat_map(|cnum| {
tcx.missing_lang_items(*cnum)
.iter()
.filter(|l| lang_items::required(tcx, **l))
.filter_map(|item| WEAK_ITEMS_SYMBOLS.get(item))
})
.collect();
info.linked_symbols
.iter_mut()
.filter(|(crate_type, _)| !matches!(crate_type, CrateType::Rlib | CrateType::Staticlib))
.for_each(|(_, linked_symbols)| {
linked_symbols.extend(
missing_weak_lang_items
// With msvc-like linkers it's both unnecessary (they support circular dependencies),
// and causes linking issues (when weak lang item symbols are "privatized" by LTO).
let target = &tcx.sess.target;
if !target.is_like_msvc {
let missing_weak_lang_items: FxHashSet<&Symbol> = info
.used_crates
.iter()
.flat_map(|cnum| {
tcx.missing_lang_items(*cnum)
.iter()
.map(|item| (item.to_string(), SymbolExportKind::Text)),
)
});
.filter(|l| lang_items::required(tcx, **l))
.filter_map(|item| WEAK_ITEMS_SYMBOLS.get(item))
})
.collect();
let prefix = if target.is_like_windows && target.arch == "x86" { "_" } else { "" };
info.linked_symbols
.iter_mut()
.filter(|(crate_type, _)| {
!matches!(crate_type, CrateType::Rlib | CrateType::Staticlib)
})
.for_each(|(_, linked_symbols)| {
linked_symbols.extend(
missing_weak_lang_items
.iter()
.map(|item| (format!("{prefix}{item}"), SymbolExportKind::Text)),
)
});
}

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

if tcx.sess.target.is_like_msvc && embed_visualizers {
if target.is_like_msvc && embed_visualizers {
info.natvis_debugger_visualizers =
collect_debugger_visualizers_transitive(tcx, DebuggerVisualizerType::Natvis);
}
Expand Down

0 comments on commit c34047c

Please sign in to comment.