From: Angus Lees Date: Sun, 19 Sep 2021 18:48:33 +0000 (+0100) Subject: Set DT_SONAME when building dylibs X-Git-Tag: archive/raspbian/1.59.0+dfsg1-1_deb11u3+rpi1~2^2^2~10 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=0eb91dc7454976378f4f78afaa32ea1514a1207f;p=rustc-mozilla.git Set DT_SONAME when building dylibs Forwarded: no In Rust, library filenames include a version-specific hash to help the run-time linker find the correct version. Unlike in C/C++, the compiler looks for all libraries matching a glob that ignores the hash and reads embedded metadata to work out versions, etc. The upshot is that there is no need for the usual "libfoo.so -> libfoo-1.2.3.so" symlink common with C/C++ when building with Rust, and no need to communicate an alternate filename to use at run-time vs compile time. If linking to a Rust dylib from C/C++ however, a "libfoo.so -> libfoo-$hash.so" symlink may well be useful and in this case DT_SONAME=libfoo-$hash.so would be required. More mundanely, various tools (eg: dpkg-shlibdeps) complain if they don't find DT_SONAME on shared libraries in public directories. This patch passes -Wl,-soname=$outfile when building dylibs (and using a GNU linker). Gbp-Pq: Name d-add-soname.patch --- diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 8bc4e6442..1e9d5835c 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1747,6 +1747,13 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( // OBJECT-FILES-NO, AUDIT-ORDER add_rpath_args(cmd, sess, codegen_results, out_filename); + if (crate_type == config::CrateType::Dylib || crate_type == config::CrateType::Cdylib) + && sess.target.linker_is_gnu { + let filename = String::from(out_filename.file_name().unwrap().to_str().unwrap()); + let soname = [String::from("-Wl,-soname=") + &filename]; + cmd.args(&soname); + } + // OBJECT-FILES-MAYBE, CUSTOMIZATION-POINT add_user_defined_link_args(cmd, sess, codegen_results);