Skip to content

Commit f73e623

Browse files
committed
Auto merge of #121967 - nikic:libllvm-linker-script, r=<try>
Replace libLLVM symlink with linker script It turns out that the libLLVM-N.so -> libLLVM.so.N.1 symlink is also needed when projects like miri link against librustc_driver.so. As such, we have to distribute it in real rustup components like rustc-dev, rather than only for download-ci-llvm. To avoid actually distributing symlinks (which are not supported or not fully supported by the rustup infrastructure) replace it with a linker script that does the same thing instead. Fixes #121889. r? `@cuviper`
2 parents f7cb53e + 3501f4a commit f73e623

File tree

1 file changed

+15
-23
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+15
-23
lines changed

src/bootstrap/src/core/build_steps/dist.rs

+15-23
Original file line numberDiff line numberDiff line change
@@ -2021,12 +2021,7 @@ fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) {
20212021
}
20222022
}
20232023

2024-
fn install_llvm_file(
2025-
builder: &Builder<'_>,
2026-
source: &Path,
2027-
destination: &Path,
2028-
install_symlink: bool,
2029-
) {
2024+
fn install_llvm_file(builder: &Builder<'_>, source: &Path, destination: &Path) {
20302025
if builder.config.dry_run() {
20312026
return;
20322027
}
@@ -2035,11 +2030,15 @@ fn install_llvm_file(
20352030
// If we have a symlink like libLLVM-18.so -> libLLVM.so.18.1, install the target of the
20362031
// symlink, which is what will actually get loaded at runtime.
20372032
builder.install(&t!(fs::canonicalize(source)), destination, 0o644);
2038-
if install_symlink {
2039-
// If requested, also install the symlink. This is used by download-ci-llvm.
2040-
let full_dest = destination.join(source.file_name().unwrap());
2041-
builder.copy(&source, &full_dest);
2042-
}
2033+
2034+
// Replace the symlink itself with an equivalent linker script. This is used by
2035+
// download-ci-llvm and projects linking against librustc_driver.so. We don't use a
2036+
// symlink, as these are not allowed inside rustup components.
2037+
let link = t!(fs::read_link(source));
2038+
t!(std::fs::write(
2039+
destination.join(source.file_name().unwrap()),
2040+
format!("INPUT({})", link.display())
2041+
));
20432042
} else {
20442043
builder.install(&source, destination, 0o644);
20452044
}
@@ -2048,12 +2047,7 @@ fn install_llvm_file(
20482047
/// Maybe add LLVM object files to the given destination lib-dir. Allows either static or dynamic linking.
20492048
///
20502049
/// Returns whether the files were actually copied.
2051-
fn maybe_install_llvm(
2052-
builder: &Builder<'_>,
2053-
target: TargetSelection,
2054-
dst_libdir: &Path,
2055-
install_symlink: bool,
2056-
) -> bool {
2050+
fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) -> bool {
20572051
// If the LLVM was externally provided, then we don't currently copy
20582052
// artifacts into the sysroot. This is not necessarily the right
20592053
// choice (in particular, it will require the LLVM dylib to be in
@@ -2102,7 +2096,7 @@ fn maybe_install_llvm(
21022096
} else {
21032097
PathBuf::from(file)
21042098
};
2105-
install_llvm_file(builder, &file, dst_libdir, install_symlink);
2099+
install_llvm_file(builder, &file, dst_libdir);
21062100
}
21072101
!builder.config.dry_run()
21082102
} else {
@@ -2117,7 +2111,7 @@ pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: TargetSelection,
21172111
// dynamically linked; it is already included into librustc_llvm
21182112
// statically.
21192113
if builder.llvm_link_shared() {
2120-
maybe_install_llvm(builder, target, &dst_libdir, false);
2114+
maybe_install_llvm(builder, target, &dst_libdir);
21212115
}
21222116
}
21232117

@@ -2129,7 +2123,7 @@ pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection
21292123
// dynamically linked; it is already included into librustc_llvm
21302124
// statically.
21312125
if builder.llvm_link_shared() {
2132-
maybe_install_llvm(builder, target, &dst_libdir, false);
2126+
maybe_install_llvm(builder, target, &dst_libdir);
21332127
}
21342128
}
21352129

@@ -2224,8 +2218,6 @@ impl Step for RustDev {
22242218

22252219
let mut tarball = Tarball::new(builder, "rust-dev", &target.triple);
22262220
tarball.set_overlay(OverlayKind::LLVM);
2227-
// LLVM requires a shared object symlink to exist on some platforms.
2228-
tarball.permit_symlinks(true);
22292221

22302222
builder.ensure(crate::core::build_steps::llvm::Llvm { target });
22312223

@@ -2266,7 +2258,7 @@ impl Step for RustDev {
22662258
// of `rustc-dev` to support the inherited `-lLLVM` when using the
22672259
// compiler libraries.
22682260
let dst_libdir = tarball.image_dir().join("lib");
2269-
maybe_install_llvm(builder, target, &dst_libdir, true);
2261+
maybe_install_llvm(builder, target, &dst_libdir);
22702262
let link_type = if builder.llvm_link_shared() { "dynamic" } else { "static" };
22712263
t!(std::fs::write(tarball.image_dir().join("link-type.txt"), link_type), dst_libdir);
22722264

0 commit comments

Comments
 (0)