Skip to content

Rollup of 3 pull requests #112282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 4, 2023
Next Next commit
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.
  • Loading branch information
lqd committed Jun 3, 2023
commit 17d321cd11a938ac3eaeeded12969d6b83f9aa26
24 changes: 24 additions & 0 deletions src/bootstrap/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,30 @@ impl Step for Lld {
}
}

// LLD is built as an LLVM tool, but is distributed outside of the `llvm-tools` component,
// which impacts where it expects to find LLVM's shared library. This causes #80703.
//
// LLD is distributed at "$root/lib/rustlib/$host/bin/rust-lld", but the `libLLVM-*.so` it
// needs is distributed at "$root/lib". The default rpath of "$ORIGIN/../lib" points at the
// lib path for LLVM tools, not the one for rust binaries.
//
// (The `llvm-tools` component copies the .so there for the other tools, and with that
// component installed, one can successfully invoke `rust-lld` directly without rustup's
// `LD_LIBRARY_PATH` overrides)
//
if builder.config.rust_rpath
&& builder.config.llvm_link_shared()
&& target.contains("linux")
{
// So we inform LLD where it can find LLVM's libraries by adding an rpath entry to the
// expected parent `lib` directory.
//
// Be careful when changing this path, we need to ensure it's quoted or escaped:
// `$ORIGIN` would otherwise be expanded when the `LdFlags` are passed verbatim to
// cmake.
ldflags.push_all("-Wl,-rpath,'$ORIGIN/../../../'");
}

configure_cmake(builder, target, &mut cfg, true, ldflags, &[]);
configure_llvm(builder, target, &mut cfg);

Expand Down