Skip to content

Commit 8027dd9

Browse files
authored
Rollup merge of #113710 - loongarch-rs:fix-rpath, r=clubby789
Fix rpath for libdir is specified ## What does this PR try to resolve? When building the Rust toolchain with `--libdir=lib64`, the executable tools such as `rustc` cannot find shared libraries. ```bash ./configure --prefix=/ --libdir=lib64 DESTDIR=/tmp/rust ./x.py install ``` ``` $ /tmp/rust/bin/rustc rustc: error while loading shared libraries: librustc_driver-13f1fd1bc7f7000d.so: cannot open shared object file: No such file or directory ``` This issue is caused by the link args `-Wl,rpath` being different from `--libdir`. ``` $ readelf -d /tmp/rust/bin/rustc | grep RUNPATH 0x000000000000001d (RUNPATH) Library runpath: [$ORIGIN/../lib] ``` ## How to resolve? When setting the rpath, get it from sysroot libdir relative path. After this patch: ``` $ readelf -d /tmp/rust/bin/rustc | grep RUNPATH 0x000000000000001d (RUNPATH) Library runpath: [$ORIGIN/../lib64] ```
2 parents 0646a5d + e326e1a commit 8027dd9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/bootstrap/builder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,17 +1629,18 @@ impl<'a> Builder<'a> {
16291629
// fun to pass a flag to a tool to pass a flag to pass a flag to a tool
16301630
// to change a flag in a binary?
16311631
if self.config.rpath_enabled(target) && util::use_host_linker(target) {
1632+
let libdir = self.sysroot_libdir_relative(compiler).to_str().unwrap();
16321633
let rpath = if target.contains("apple") {
16331634
// Note that we need to take one extra step on macOS to also pass
16341635
// `-Wl,-instal_name,@rpath/...` to get things to work right. To
16351636
// do that we pass a weird flag to the compiler to get it to do
16361637
// so. Note that this is definitely a hack, and we should likely
16371638
// flesh out rpath support more fully in the future.
16381639
rustflags.arg("-Zosx-rpath-install-name");
1639-
Some("-Wl,-rpath,@loader_path/../lib")
1640+
Some(format!("-Wl,-rpath,@loader_path/../{}", libdir))
16401641
} else if !target.contains("windows") && !target.contains("aix") {
16411642
rustflags.arg("-Clink-args=-Wl,-z,origin");
1642-
Some("-Wl,-rpath,$ORIGIN/../lib")
1643+
Some(format!("-Wl,-rpath,$ORIGIN/../{}", libdir))
16431644
} else {
16441645
None
16451646
};

0 commit comments

Comments
 (0)