Skip to content

Commit 731bbc8

Browse files
petrochenkovcuviper
authored andcommitted
linker: Fix weak lang item linking with combination windows-gnu + LLD + LTO
(cherry picked from commit acf51e1)
1 parent b1fb60e commit 731bbc8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2698,7 +2698,7 @@ fn relevant_lib(sess: &Session, lib: &NativeLib) -> bool {
26982698
}
26992699
}
27002700

2701-
fn are_upstream_rust_objects_already_included(sess: &Session) -> bool {
2701+
pub(crate) fn are_upstream_rust_objects_already_included(sess: &Session) -> bool {
27022702
match sess.lto() {
27032703
config::Lto::Fat => true,
27042704
config::Lto::Thin => {

compiler/rustc_codegen_ssa/src/base.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::back::link::are_upstream_rust_objects_already_included;
12
use crate::back::metadata::create_compressed_metadata_file;
23
use crate::back::write::{
34
compute_per_cgu_lto_type, start_async_codegen, submit_codegened_module_to_llvm,
@@ -854,10 +855,14 @@ impl CrateInfo {
854855

855856
// Handle circular dependencies in the standard library.
856857
// See comment before `add_linked_symbol_object` function for the details.
857-
// With msvc-like linkers it's both unnecessary (they support circular dependencies),
858-
// and causes linking issues (when weak lang item symbols are "privatized" by LTO).
858+
// If global LTO is enabled then almost everything (*) is glued into a single object file,
859+
// so this logic is not necessary and can cause issues on some targets (due to weak lang
860+
// item symbols being "privatized" to that object file), so we disable it.
861+
// (*) Native libs, and `#[compiler_builtins]` and `#[no_builtins]` crates are not glued,
862+
// and we assume that they cannot define weak lang items. This is not currently enforced
863+
// by the compiler, but that's ok because all this stuff is unstable anyway.
859864
let target = &tcx.sess.target;
860-
if !target.is_like_msvc {
865+
if !are_upstream_rust_objects_already_included(tcx.sess) {
861866
let missing_weak_lang_items: FxHashSet<&Symbol> = info
862867
.used_crates
863868
.iter()

0 commit comments

Comments
 (0)