Only add an automatic SONAME for Rust dylibs
(cherry picked from commit f46057bf1c)
This commit is contained in:
parent
6a3b69c6b0
commit
6917db611d
3 changed files with 80 additions and 21 deletions
|
|
@ -2493,7 +2493,7 @@ fn add_order_independent_options(
|
|||
}
|
||||
}
|
||||
|
||||
cmd.set_output_kind(link_output_kind, out_filename);
|
||||
cmd.set_output_kind(link_output_kind, crate_type, out_filename);
|
||||
|
||||
add_relro_args(cmd, sess);
|
||||
|
||||
|
|
|
|||
|
|
@ -266,7 +266,12 @@ pub trait Linker {
|
|||
fn is_cc(&self) -> bool {
|
||||
false
|
||||
}
|
||||
fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path);
|
||||
fn set_output_kind(
|
||||
&mut self,
|
||||
output_kind: LinkOutputKind,
|
||||
crate_type: CrateType,
|
||||
out_filename: &Path,
|
||||
);
|
||||
fn link_dylib_by_name(&mut self, _name: &str, _verbatim: bool, _as_needed: bool) {
|
||||
bug!("dylib linked with unsupported linker")
|
||||
}
|
||||
|
|
@ -387,7 +392,7 @@ impl<'a> GccLinker<'a> {
|
|||
]);
|
||||
}
|
||||
|
||||
fn build_dylib(&mut self, out_filename: &Path) {
|
||||
fn build_dylib(&mut self, crate_type: CrateType, out_filename: &Path) {
|
||||
// On mac we need to tell the linker to let this library be rpathed
|
||||
if self.sess.target.is_like_osx {
|
||||
if !self.is_ld {
|
||||
|
|
@ -418,7 +423,7 @@ impl<'a> GccLinker<'a> {
|
|||
let mut out_implib = OsString::from("--out-implib=");
|
||||
out_implib.push(out_filename.with_file_name(implib_name));
|
||||
self.link_arg(out_implib);
|
||||
} else {
|
||||
} else if crate_type == CrateType::Dylib {
|
||||
// When dylibs are linked by a full path this value will get into `DT_NEEDED`
|
||||
// instead of the full path, so the library can be later found in some other
|
||||
// location than that specific path.
|
||||
|
|
@ -465,7 +470,12 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
!self.is_ld
|
||||
}
|
||||
|
||||
fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path) {
|
||||
fn set_output_kind(
|
||||
&mut self,
|
||||
output_kind: LinkOutputKind,
|
||||
crate_type: CrateType,
|
||||
out_filename: &Path,
|
||||
) {
|
||||
match output_kind {
|
||||
LinkOutputKind::DynamicNoPicExe => {
|
||||
if !self.is_ld && self.is_gnu {
|
||||
|
|
@ -500,10 +510,10 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
self.link_args(&["-static", "-pie", "--no-dynamic-linker", "-z", "text"]);
|
||||
}
|
||||
}
|
||||
LinkOutputKind::DynamicDylib => self.build_dylib(out_filename),
|
||||
LinkOutputKind::DynamicDylib => self.build_dylib(crate_type, out_filename),
|
||||
LinkOutputKind::StaticDylib => {
|
||||
self.link_or_cc_arg("-static");
|
||||
self.build_dylib(out_filename);
|
||||
self.build_dylib(crate_type, out_filename);
|
||||
}
|
||||
LinkOutputKind::WasiReactorExe => {
|
||||
self.link_args(&["--entry", "_initialize"]);
|
||||
|
|
@ -859,7 +869,12 @@ impl<'a> Linker for MsvcLinker<'a> {
|
|||
&mut self.cmd
|
||||
}
|
||||
|
||||
fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path) {
|
||||
fn set_output_kind(
|
||||
&mut self,
|
||||
output_kind: LinkOutputKind,
|
||||
_crate_type: CrateType,
|
||||
out_filename: &Path,
|
||||
) {
|
||||
match output_kind {
|
||||
LinkOutputKind::DynamicNoPicExe
|
||||
| LinkOutputKind::DynamicPicExe
|
||||
|
|
@ -1111,7 +1126,13 @@ impl<'a> Linker for EmLinker<'a> {
|
|||
true
|
||||
}
|
||||
|
||||
fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
|
||||
fn set_output_kind(
|
||||
&mut self,
|
||||
_output_kind: LinkOutputKind,
|
||||
_crate_type: CrateType,
|
||||
_out_filename: &Path,
|
||||
) {
|
||||
}
|
||||
|
||||
fn link_dylib_by_name(&mut self, name: &str, _verbatim: bool, _as_needed: bool) {
|
||||
// Emscripten always links statically
|
||||
|
|
@ -1260,7 +1281,12 @@ impl<'a> Linker for WasmLd<'a> {
|
|||
&mut self.cmd
|
||||
}
|
||||
|
||||
fn set_output_kind(&mut self, output_kind: LinkOutputKind, _out_filename: &Path) {
|
||||
fn set_output_kind(
|
||||
&mut self,
|
||||
output_kind: LinkOutputKind,
|
||||
_crate_type: CrateType,
|
||||
_out_filename: &Path,
|
||||
) {
|
||||
match output_kind {
|
||||
LinkOutputKind::DynamicNoPicExe
|
||||
| LinkOutputKind::DynamicPicExe
|
||||
|
|
@ -1409,7 +1435,13 @@ impl<'a> Linker for L4Bender<'a> {
|
|||
&mut self.cmd
|
||||
}
|
||||
|
||||
fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
|
||||
fn set_output_kind(
|
||||
&mut self,
|
||||
_output_kind: LinkOutputKind,
|
||||
_crate_type: CrateType,
|
||||
_out_filename: &Path,
|
||||
) {
|
||||
}
|
||||
|
||||
fn link_staticlib_by_name(&mut self, name: &str, _verbatim: bool, whole_archive: bool) {
|
||||
self.hint_static();
|
||||
|
|
@ -1556,7 +1588,12 @@ impl<'a> Linker for AixLinker<'a> {
|
|||
&mut self.cmd
|
||||
}
|
||||
|
||||
fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path) {
|
||||
fn set_output_kind(
|
||||
&mut self,
|
||||
output_kind: LinkOutputKind,
|
||||
_crate_type: CrateType,
|
||||
out_filename: &Path,
|
||||
) {
|
||||
match output_kind {
|
||||
LinkOutputKind::DynamicDylib => {
|
||||
self.hint_dynamic();
|
||||
|
|
@ -1763,7 +1800,13 @@ impl<'a> Linker for PtxLinker<'a> {
|
|||
&mut self.cmd
|
||||
}
|
||||
|
||||
fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
|
||||
fn set_output_kind(
|
||||
&mut self,
|
||||
_output_kind: LinkOutputKind,
|
||||
_crate_type: CrateType,
|
||||
_out_filename: &Path,
|
||||
) {
|
||||
}
|
||||
|
||||
fn link_staticlib_by_name(&mut self, _name: &str, _verbatim: bool, _whole_archive: bool) {
|
||||
panic!("staticlibs not supported")
|
||||
|
|
@ -1829,7 +1872,13 @@ impl<'a> Linker for LlbcLinker<'a> {
|
|||
&mut self.cmd
|
||||
}
|
||||
|
||||
fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
|
||||
fn set_output_kind(
|
||||
&mut self,
|
||||
_output_kind: LinkOutputKind,
|
||||
_crate_type: CrateType,
|
||||
_out_filename: &Path,
|
||||
) {
|
||||
}
|
||||
|
||||
fn link_staticlib_by_name(&mut self, _name: &str, _verbatim: bool, _whole_archive: bool) {
|
||||
panic!("staticlibs not supported")
|
||||
|
|
@ -1900,7 +1949,13 @@ impl<'a> Linker for BpfLinker<'a> {
|
|||
&mut self.cmd
|
||||
}
|
||||
|
||||
fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
|
||||
fn set_output_kind(
|
||||
&mut self,
|
||||
_output_kind: LinkOutputKind,
|
||||
_crate_type: CrateType,
|
||||
_out_filename: &Path,
|
||||
) {
|
||||
}
|
||||
|
||||
fn link_staticlib_by_name(&mut self, _name: &str, _verbatim: bool, _whole_archive: bool) {
|
||||
panic!("staticlibs not supported")
|
||||
|
|
|
|||
|
|
@ -7,12 +7,16 @@
|
|||
use run_make_support::{cmd, run_in_tmpdir, rustc};
|
||||
|
||||
fn main() {
|
||||
let check = |ty: &str| {
|
||||
rustc().crate_name("foo").crate_type(ty).input("foo.rs").run();
|
||||
cmd("readelf").arg("-d").arg("libfoo.so").run()
|
||||
};
|
||||
run_in_tmpdir(|| {
|
||||
rustc().crate_name("foo").crate_type("dylib").input("foo.rs").run();
|
||||
cmd("readelf")
|
||||
.arg("-d")
|
||||
.arg("libfoo.so")
|
||||
.run()
|
||||
.assert_stdout_contains("Library soname: [libfoo.so]");
|
||||
// Rust dylibs should get a relative SONAME
|
||||
check("dylib").assert_stdout_contains("Library soname: [libfoo.so]");
|
||||
});
|
||||
run_in_tmpdir(|| {
|
||||
// C dylibs should not implicitly get any SONAME
|
||||
check("cdylib").assert_stdout_not_contains("Library soname:");
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue