Only add an automatic SONAME for Rust dylibs
This commit is contained in:
parent
fa724e5d8c
commit
f46057bf1c
@ -2490,7 +2490,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);
|
add_relro_args(cmd, sess);
|
||||||
|
|
||||||
|
@ -275,7 +275,12 @@ pub(crate) trait Linker {
|
|||||||
fn is_cc(&self) -> bool {
|
fn is_cc(&self) -> bool {
|
||||||
false
|
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) {
|
fn link_dylib_by_name(&mut self, _name: &str, _verbatim: bool, _as_needed: bool) {
|
||||||
bug!("dylib linked with unsupported linker")
|
bug!("dylib linked with unsupported linker")
|
||||||
}
|
}
|
||||||
@ -396,7 +401,7 @@ fn push_linker_plugin_lto_args(&mut self, plugin_path: Option<&OsStr>) {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// On mac we need to tell the linker to let this library be rpathed
|
||||||
if self.sess.target.is_like_osx {
|
if self.sess.target.is_like_osx {
|
||||||
if !self.is_ld {
|
if !self.is_ld {
|
||||||
@ -427,7 +432,7 @@ fn build_dylib(&mut self, out_filename: &Path) {
|
|||||||
let mut out_implib = OsString::from("--out-implib=");
|
let mut out_implib = OsString::from("--out-implib=");
|
||||||
out_implib.push(out_filename.with_file_name(implib_name));
|
out_implib.push(out_filename.with_file_name(implib_name));
|
||||||
self.link_arg(out_implib);
|
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`
|
// 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
|
// instead of the full path, so the library can be later found in some other
|
||||||
// location than that specific path.
|
// location than that specific path.
|
||||||
@ -474,7 +479,12 @@ fn is_cc(&self) -> bool {
|
|||||||
!self.is_ld
|
!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 {
|
match output_kind {
|
||||||
LinkOutputKind::DynamicNoPicExe => {
|
LinkOutputKind::DynamicNoPicExe => {
|
||||||
if !self.is_ld && self.is_gnu {
|
if !self.is_ld && self.is_gnu {
|
||||||
@ -509,10 +519,10 @@ fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path)
|
|||||||
self.link_args(&["-static", "-pie", "--no-dynamic-linker", "-z", "text"]);
|
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 => {
|
LinkOutputKind::StaticDylib => {
|
||||||
self.link_or_cc_arg("-static");
|
self.link_or_cc_arg("-static");
|
||||||
self.build_dylib(out_filename);
|
self.build_dylib(crate_type, out_filename);
|
||||||
}
|
}
|
||||||
LinkOutputKind::WasiReactorExe => {
|
LinkOutputKind::WasiReactorExe => {
|
||||||
self.link_args(&["--entry", "_initialize"]);
|
self.link_args(&["--entry", "_initialize"]);
|
||||||
@ -866,7 +876,12 @@ fn cmd(&mut self) -> &mut Command {
|
|||||||
&mut self.cmd
|
&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 {
|
match output_kind {
|
||||||
LinkOutputKind::DynamicNoPicExe
|
LinkOutputKind::DynamicNoPicExe
|
||||||
| LinkOutputKind::DynamicPicExe
|
| LinkOutputKind::DynamicPicExe
|
||||||
@ -1124,7 +1139,13 @@ fn is_cc(&self) -> bool {
|
|||||||
true
|
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) {
|
fn link_dylib_by_name(&mut self, name: &str, _verbatim: bool, _as_needed: bool) {
|
||||||
// Emscripten always links statically
|
// Emscripten always links statically
|
||||||
@ -1273,7 +1294,12 @@ fn cmd(&mut self) -> &mut Command {
|
|||||||
&mut self.cmd
|
&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 {
|
match output_kind {
|
||||||
LinkOutputKind::DynamicNoPicExe
|
LinkOutputKind::DynamicNoPicExe
|
||||||
| LinkOutputKind::DynamicPicExe
|
| LinkOutputKind::DynamicPicExe
|
||||||
@ -1422,7 +1448,13 @@ fn cmd(&mut self) -> &mut Command {
|
|||||||
&mut self.cmd
|
&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) {
|
fn link_staticlib_by_name(&mut self, name: &str, _verbatim: bool, whole_archive: bool) {
|
||||||
self.hint_static();
|
self.hint_static();
|
||||||
@ -1568,7 +1600,12 @@ fn cmd(&mut self) -> &mut Command {
|
|||||||
&mut self.cmd
|
&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 {
|
match output_kind {
|
||||||
LinkOutputKind::DynamicDylib => {
|
LinkOutputKind::DynamicDylib => {
|
||||||
self.hint_dynamic();
|
self.hint_dynamic();
|
||||||
@ -1775,7 +1812,13 @@ fn cmd(&mut self) -> &mut Command {
|
|||||||
&mut self.cmd
|
&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) {
|
fn link_staticlib_by_name(&mut self, _name: &str, _verbatim: bool, _whole_archive: bool) {
|
||||||
panic!("staticlibs not supported")
|
panic!("staticlibs not supported")
|
||||||
@ -1841,7 +1884,13 @@ fn cmd(&mut self) -> &mut Command {
|
|||||||
&mut self.cmd
|
&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) {
|
fn link_staticlib_by_name(&mut self, _name: &str, _verbatim: bool, _whole_archive: bool) {
|
||||||
panic!("staticlibs not supported")
|
panic!("staticlibs not supported")
|
||||||
@ -1912,7 +1961,13 @@ fn cmd(&mut self) -> &mut Command {
|
|||||||
&mut self.cmd
|
&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) {
|
fn link_staticlib_by_name(&mut self, _name: &str, _verbatim: bool, _whole_archive: bool) {
|
||||||
panic!("staticlibs not supported")
|
panic!("staticlibs not supported")
|
||||||
|
@ -7,12 +7,16 @@
|
|||||||
use run_make_support::{cmd, run_in_tmpdir, rustc};
|
use run_make_support::{cmd, run_in_tmpdir, rustc};
|
||||||
|
|
||||||
fn main() {
|
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(|| {
|
run_in_tmpdir(|| {
|
||||||
rustc().crate_name("foo").crate_type("dylib").input("foo.rs").run();
|
// Rust dylibs should get a relative SONAME
|
||||||
cmd("readelf")
|
check("dylib").assert_stdout_contains("Library soname: [libfoo.so]");
|
||||||
.arg("-d")
|
});
|
||||||
.arg("libfoo.so")
|
run_in_tmpdir(|| {
|
||||||
.run()
|
// C dylibs should not implicitly get any SONAME
|
||||||
.assert_stdout_contains("Library soname: [libfoo.so]");
|
check("cdylib").assert_stdout_not_contains("Library soname:");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user