linker: Use --as-needed by default when linker supports it
This commit is contained in:
@@ -1651,6 +1651,12 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
|
||||
cmd.add_eh_frame_header();
|
||||
}
|
||||
|
||||
// NO-OPT-OUT, OBJECT-FILES-NO
|
||||
// Avoid linking to dynamic libraries unless they satisfy some undefined symbols
|
||||
// at the point at which they are specified on the command line.
|
||||
// Must be passed before any dynamic libraries.
|
||||
cmd.add_as_needed();
|
||||
|
||||
// NO-OPT-OUT, OBJECT-FILES-NO
|
||||
if crt_objects_fallback {
|
||||
cmd.no_crt_objects();
|
||||
|
||||
@@ -130,6 +130,7 @@ pub trait Linker {
|
||||
fn group_end(&mut self);
|
||||
fn linker_plugin_lto(&mut self);
|
||||
fn add_eh_frame_header(&mut self) {}
|
||||
fn add_as_needed(&mut self) {}
|
||||
fn finalize(&mut self);
|
||||
}
|
||||
|
||||
@@ -641,6 +642,12 @@ impl<'a> Linker for GccLinker<'a> {
|
||||
fn add_eh_frame_header(&mut self) {
|
||||
self.linker_arg("--eh-frame-hdr");
|
||||
}
|
||||
|
||||
fn add_as_needed(&mut self) {
|
||||
if self.sess.target.linker_is_gnu {
|
||||
self.linker_arg("--as-needed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MsvcLinker<'a> {
|
||||
|
||||
Reference in New Issue
Block a user