Skip to content

Commit 1a652fa

Browse files
committed
Handle new LLVM soname
LLVM now includes the minor version in the soname, and also changed the names of shared object files. libLLVM-18.so is now a symlink to libLLVM.so.18.1. We need to make some changes to support this: First, we need to run the installed llvm-config binary, rather than the one from the build directory. This is because the symlink does not exist in the build directory, but llvm-config requires it. This looks like an LLVM bug to me, but it's probably a good idea to use the installed version anyway. Second, when installing LLVM into the libdir, we need to install the target of the symlink, ans this is what will get loaded at runtime. However, the rust-dev component in particular also needs to distribute the symlink itself, as download-ci-llvm will end up invoking llvm-config, which requires the symlink to exist. The symlink is not shipped in other components.
1 parent 4b55e17 commit 1a652fa

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

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

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

2024-
fn install_llvm_file(builder: &Builder<'_>, source: &Path, destination: &Path) {
2024+
fn install_llvm_file(
2025+
builder: &Builder<'_>,
2026+
source: &Path,
2027+
destination: &Path,
2028+
install_symlink: bool,
2029+
) {
20252030
if builder.config.dry_run() {
20262031
return;
20272032
}
20282033

2029-
builder.install(source, destination, 0o644);
2034+
if source.is_symlink() {
2035+
// If we have a symlink like libLLVM-18.so -> libLLVM.so.18.1, install the target of the
2036+
// symlink, which is what will actually get loaded at runtime.
2037+
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+
}
2043+
} else {
2044+
builder.install(&source, destination, 0o644);
2045+
}
20302046
}
20312047

20322048
/// Maybe add LLVM object files to the given destination lib-dir. Allows either static or dynamic linking.
20332049
///
20342050
/// Returns whether the files were actually copied.
2035-
fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) -> bool {
2051+
fn maybe_install_llvm(
2052+
builder: &Builder<'_>,
2053+
target: TargetSelection,
2054+
dst_libdir: &Path,
2055+
install_symlink: bool,
2056+
) -> bool {
20362057
// If the LLVM was externally provided, then we don't currently copy
20372058
// artifacts into the sysroot. This is not necessarily the right
20382059
// choice (in particular, it will require the LLVM dylib to be in
@@ -2081,7 +2102,7 @@ fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir
20812102
} else {
20822103
PathBuf::from(file)
20832104
};
2084-
install_llvm_file(builder, &file, dst_libdir);
2105+
install_llvm_file(builder, &file, dst_libdir, install_symlink);
20852106
}
20862107
!builder.config.dry_run()
20872108
} else {
@@ -2096,7 +2117,7 @@ pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: TargetSelection,
20962117
// dynamically linked; it is already included into librustc_llvm
20972118
// statically.
20982119
if builder.llvm_link_shared() {
2099-
maybe_install_llvm(builder, target, &dst_libdir);
2120+
maybe_install_llvm(builder, target, &dst_libdir, false);
21002121
}
21012122
}
21022123

@@ -2108,7 +2129,7 @@ pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection
21082129
// dynamically linked; it is already included into librustc_llvm
21092130
// statically.
21102131
if builder.llvm_link_shared() {
2111-
maybe_install_llvm(builder, target, &dst_libdir);
2132+
maybe_install_llvm(builder, target, &dst_libdir, false);
21122133
}
21132134
}
21142135

@@ -2203,6 +2224,8 @@ impl Step for RustDev {
22032224

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

22072230
builder.ensure(crate::core::build_steps::llvm::Llvm { target });
22082231

@@ -2243,7 +2266,7 @@ impl Step for RustDev {
22432266
// of `rustc-dev` to support the inherited `-lLLVM` when using the
22442267
// compiler libraries.
22452268
let dst_libdir = tarball.image_dir().join("lib");
2246-
maybe_install_llvm(builder, target, &dst_libdir);
2269+
maybe_install_llvm(builder, target, &dst_libdir, true);
22472270
let link_type = if builder.llvm_link_shared() { "dynamic" } else { "static" };
22482271
t!(std::fs::write(tarball.image_dir().join("link-type.txt"), link_type), dst_libdir);
22492272

src/bootstrap/src/core/build_steps/llvm.rs

-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ pub fn prebuilt_llvm_config(
9898
let out_dir = builder.llvm_out(target);
9999

100100
let mut llvm_config_ret_dir = builder.llvm_out(builder.config.build);
101-
if (!builder.config.build.is_msvc() || builder.ninja()) && !builder.config.llvm_from_ci {
102-
llvm_config_ret_dir.push("build");
103-
}
104101
llvm_config_ret_dir.push("bin");
105102
let build_llvm_config = llvm_config_ret_dir.join(exe("llvm-config", builder.config.build));
106103
let llvm_cmake_dir = out_dir.join("lib/cmake/llvm");

src/tools/opt-dist/src/main.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ fn execute_pipeline(
270270
})?;
271271

272272
let libdir = env.build_artifacts().join("stage2").join("lib");
273-
let llvm_lib = io::find_file_in_dir(&libdir, "libLLVM", ".so")?;
273+
// The actual name will be something like libLLVM.so.18.1-rust-dev.
274+
let llvm_lib = io::find_file_in_dir(&libdir, "libLLVM.so", "")?;
274275

275276
log::info!("Optimizing {llvm_lib} with BOLT");
276277

0 commit comments

Comments
 (0)