Set DT_SONAME when building dylibs
authorAngus Lees <gus@debian.org>
Fri, 22 Oct 2021 22:29:14 +0000 (23:29 +0100)
committerXimin Luo <infinity0@debian.org>
Fri, 22 Oct 2021 22:29:14 +0000 (23:29 +0100)
commitcdc37426876d096ea7e98e6add72f893eddfe0ca
tree62bba097893c5aa8579262eb8c54d5ba7ee3f3cb
parentc08f0ab97c2696c7f204d45e5ccbdc2dbd2bc7f9
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-rustc-add-soname.patch
compiler/rustc_codegen_ssa/src/back/link.rs