Skip to content

Commit

Permalink
linker: Fix weak lang item linking with combination windows-gnu + LLD…
Browse files Browse the repository at this point in the history
… + LTO
  • Loading branch information
petrochenkov committed Oct 15, 2022
1 parent b8c35ca commit acf51e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2690,7 +2690,7 @@ fn relevant_lib(sess: &Session, lib: &NativeLib) -> bool {
}
}

fn are_upstream_rust_objects_already_included(sess: &Session) -> bool {
pub(crate) fn are_upstream_rust_objects_already_included(sess: &Session) -> bool {
match sess.lto() {
config::Lto::Fat => true,
config::Lto::Thin => {
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::back::link::are_upstream_rust_objects_already_included;
use crate::back::metadata::create_compressed_metadata_file;
use crate::back::write::{
compute_per_cgu_lto_type, start_async_codegen, submit_codegened_module_to_llvm,
Expand Down Expand Up @@ -892,10 +893,14 @@ impl CrateInfo {

// Handle circular dependencies in the standard library.
// See comment before `add_linked_symbol_object` function for the details.
// 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).
// If global LTO is enabled then almost everything (*) is glued into a single object file,
// so this logic is not necessary and can cause issues on some targets (due to weak lang
// item symbols being "privatized" to that object file), so we disable it.
// (*) Native libs, and `#[compiler_builtins]` and `#[no_builtins]` crates are not glued,
// and we assume that they cannot define weak lang items. This is not currently enforced
// by the compiler, but that's ok because all this stuff is unstable anyway.
let target = &tcx.sess.target;
if !target.is_like_msvc {
if !are_upstream_rust_objects_already_included(tcx.sess) {
let missing_weak_lang_items: FxHashSet<&Symbol> = info
.used_crates
.iter()
Expand Down

0 comments on commit acf51e1

Please sign in to comment.