Skip to content

Commit 0da5800

Browse files
committed
Auto merge of #76810 - Mark-Simulacrum:fix-lld-macos, r=alexcrichton
Don't dynamically link LLVM tools unless rustc is too This PR initially tried to support link-shared on all of our target platforms (other than Windows), but ran into a number of difficulties: * LLVM doesn't really support a shared link on macOS (llvm-config runs into problems with the version suffix) * LLVM doesn't seem to support a shared link when cross-compiling (the libLLVM.so ends up empty and symbols are not found) So, this PR has now been revised such that we don't attempt to dynamically link LLVM tools (even if that would, otherwise, be supported) on targets where LLVM is statically linked to rustc. Currently that's basically everything except for x86_64-unknown-linux-gnu (where we dynamically link to avoid rerunning ThinLTO in each stage). Follow-up to #76708. Fixes #76698.
2 parents e0bc267 + 389b7ff commit 0da5800

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

src/bootstrap/dist.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -2400,14 +2400,11 @@ fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir
24002400
return;
24012401
}
24022402

2403-
// On macOS for some reason the llvm-config binary behaves differently and
2404-
// and fails on missing .a files if run without --link-shared. If run with
2405-
// that option, it still fails, but because we only ship a libLLVM.dylib
2406-
// rather than libLLVM-11-rust-....dylib file.
2407-
//
2408-
// For now just don't use llvm-config here on macOS; that will fail to
2409-
// support CI-built LLVM, but until we work out the different behavior that
2410-
// is fine as it is off by default.
2403+
// On macOS, rustc (and LLVM tools) link to an unversioned libLLVM.dylib
2404+
// instead of libLLVM-11-rust-....dylib, as on linux. It's not entirely
2405+
// clear why this is the case, though. llvm-config will emit the versioned
2406+
// paths and we don't want those in the sysroot (as we're expecting
2407+
// unversioned paths).
24112408
if target.contains("apple-darwin") {
24122409
let src_libdir = builder.llvm_out(target).join("lib");
24132410
let llvm_dylib_path = src_libdir.join("libLLVM.dylib");

src/bootstrap/native.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ impl Step for Llvm {
128128
Err(m) => m,
129129
};
130130

131-
if builder.config.llvm_link_shared && target.contains("windows") {
132-
panic!("shared linking to LLVM is not currently supported on Windows");
131+
if builder.config.llvm_link_shared
132+
&& (target.contains("windows") || target.contains("apple-darwin"))
133+
{
134+
panic!("shared linking to LLVM is not currently supported on {}", target.triple);
133135
}
134136

135137
builder.info(&format!("Building LLVM for {}", target));
@@ -208,7 +210,10 @@ impl Step for Llvm {
208210
// which saves both memory during parallel links and overall disk space
209211
// for the tools. We don't do this on every platform as it doesn't work
210212
// equally well everywhere.
211-
if builder.llvm_link_tools_dynamically(target) {
213+
//
214+
// If we're not linking rustc to a dynamic LLVM, though, then don't link
215+
// tools to it.
216+
if builder.llvm_link_tools_dynamically(target) && builder.config.llvm_link_shared {
212217
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
213218
}
214219

src/ci/run.sh

-7
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,6 @@ if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then
7575
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.remap-debuginfo"
7676
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --debuginfo-level-std=1"
7777

78-
# If we're distributing binaries, we want a shared LLVM link. We're already
79-
# going to link LLVM to the LLVM tools dynamically, so we need to ship a
80-
# libLLVM library anyway.
81-
if !isWindows; then
82-
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set llvm.link-shared=true"
83-
fi
84-
8578
if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then
8679
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions"
8780
elif [ "$DEPLOY_ALT" != "" ]; then

0 commit comments

Comments
 (0)