about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-03-10 21:15:45 +0100
committerGitHub <noreply@github.com>2023-03-10 21:15:45 +0100
commitb23a3a36ed0bf8d749c4b1e9becd516950f2cdd2 (patch)
treeb57a6c5885f4e029463dcf824ea7f98c9db26552
parent82e675061c28fe99db0c94058164a3485357250a (diff)
parentf2c81bb1c0316e59d73280712e839f8decddaa1a (diff)
downloadrust-b23a3a36ed0bf8d749c4b1e9becd516950f2cdd2.tar.gz
rust-b23a3a36ed0bf8d749c4b1e9becd516950f2cdd2.zip
Rollup merge of #108017 - chbaker0:fix-105967, r=chbaker0
Add `--no-undefined-version` link flag and fix associated breakage

LLVM upstream sets `--no-undefined-version` by default in lld: https://reviews.llvm.org/D135402.

Due to a bug in how version scripts are generated, this breaks the `dylib` output type for most crates. See https://github.com/rust-lang/rust/issues/105967#issuecomment-1428671533 for details.

This PR adds the flag to gcc flavor linkers in anticipation of this LLVM change rolling in, and patches `rustc` to not attempt to export `__rust_*` allocator symbols when they weren't generated.

Fixes #105967
-rw-r--r--src/allocator.rs28
1 files changed, 10 insertions, 18 deletions
diff --git a/src/allocator.rs b/src/allocator.rs
index 1c73957ca57..2c246ceb37d 100644
--- a/src/allocator.rs
+++ b/src/allocator.rs
@@ -4,6 +4,7 @@
 use crate::prelude::*;
 
 use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
+use rustc_codegen_ssa::base::allocator_kind_for_codegen;
 use rustc_session::config::OomStrategy;
 use rustc_span::symbol::sym;
 
@@ -13,24 +14,15 @@ pub(crate) fn codegen(
     module: &mut impl Module,
     unwind_context: &mut UnwindContext,
 ) -> bool {
-    let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
-        use rustc_middle::middle::dependency_format::Linkage;
-        list.iter().any(|&linkage| linkage == Linkage::Dynamic)
-    });
-    if any_dynamic_crate {
-        false
-    } else if let Some(kind) = tcx.allocator_kind(()) {
-        codegen_inner(
-            module,
-            unwind_context,
-            kind,
-            tcx.alloc_error_handler_kind(()).unwrap(),
-            tcx.sess.opts.unstable_opts.oom,
-        );
-        true
-    } else {
-        false
-    }
+    let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
+    codegen_inner(
+        module,
+        unwind_context,
+        kind,
+        tcx.alloc_error_handler_kind(()).unwrap(),
+        tcx.sess.opts.unstable_opts.oom,
+    );
+    true
 }
 
 fn codegen_inner(