Skip to content

Commit 5ffa67d

Browse files
committed
Auto merge of #103092 - petrochenkov:weaklto, r=wesleywiser
linker: Fix weak lang item linking with combination windows-gnu + LLD + LTO In #100404 this logic was originally disabled for MSVC due to issues with LTO, but the same issues appear on windows-gnu with LLD because that LLD uses the same underlying logic as MSVC LLD, just with re-syntaxed command line options. So this PR just disables it for LTO builds in general.
2 parents 542febd + acf51e1 commit 5ffa67d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Diff for: compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2715,7 +2715,7 @@ fn relevant_lib(sess: &Session, lib: &NativeLib) -> bool {
27152715
}
27162716
}
27172717

2718-
fn are_upstream_rust_objects_already_included(sess: &Session) -> bool {
2718+
pub(crate) fn are_upstream_rust_objects_already_included(sess: &Session) -> bool {
27192719
match sess.lto() {
27202720
config::Lto::Fat => true,
27212721
config::Lto::Thin => {

Diff for: 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,
@@ -892,10 +893,14 @@ impl CrateInfo {
892893

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

0 commit comments

Comments
 (0)