Skip to content

Commit 17d321c

Browse files
committed
rust-lld: add rpath to the root LLVM shared lib
rust-lld is not located in the same directory as the other binaries that point to ../lib, but in a deeper directory in lib. So we need to point a few layers up for rust-lld to find the LLVM shared library without rustup's LD_LIBRARY_PATH overrides.
1 parent 7d5b746 commit 17d321c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/bootstrap/llvm.rs

+24
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,30 @@ impl Step for Lld {
834834
}
835835
}
836836

837+
// LLD is built as an LLVM tool, but is distributed outside of the `llvm-tools` component,
838+
// which impacts where it expects to find LLVM's shared library. This causes #80703.
839+
//
840+
// LLD is distributed at "$root/lib/rustlib/$host/bin/rust-lld", but the `libLLVM-*.so` it
841+
// needs is distributed at "$root/lib". The default rpath of "$ORIGIN/../lib" points at the
842+
// lib path for LLVM tools, not the one for rust binaries.
843+
//
844+
// (The `llvm-tools` component copies the .so there for the other tools, and with that
845+
// component installed, one can successfully invoke `rust-lld` directly without rustup's
846+
// `LD_LIBRARY_PATH` overrides)
847+
//
848+
if builder.config.rust_rpath
849+
&& builder.config.llvm_link_shared()
850+
&& target.contains("linux")
851+
{
852+
// So we inform LLD where it can find LLVM's libraries by adding an rpath entry to the
853+
// expected parent `lib` directory.
854+
//
855+
// Be careful when changing this path, we need to ensure it's quoted or escaped:
856+
// `$ORIGIN` would otherwise be expanded when the `LdFlags` are passed verbatim to
857+
// cmake.
858+
ldflags.push_all("-Wl,-rpath,'$ORIGIN/../../../'");
859+
}
860+
837861
configure_cmake(builder, target, &mut cfg, true, ldflags, &[]);
838862
configure_llvm(builder, target, &mut cfg);
839863

0 commit comments

Comments
 (0)