Only pass --[no-]gc-sections if linker is GNU ld.

LinkerFlavor::Gcc does not always mean GNU ld specifically. And in the
case of at least the solaris ld in illumos, that flag is unrecognized
and will cause the linking step to fail.
This commit is contained in:
Luqman Aden 2021-05-13 16:55:33 -07:00
parent 6d395a1c29
commit 3fe1d7f789

View file

@ -469,7 +469,7 @@ impl<'a> Linker for GccLinker<'a> {
// eliminate the metadata. If we're building an executable, however,
// --gc-sections drops the size of hello world from 1.8MB to 597K, a 67%
// reduction.
} else if !keep_metadata {
} else if self.sess.target.linker_is_gnu && !keep_metadata {
self.linker_arg("--gc-sections");
}
}
@ -477,9 +477,7 @@ impl<'a> Linker for GccLinker<'a> {
fn no_gc_sections(&mut self) {
if self.sess.target.is_like_osx {
self.linker_arg("-no_dead_strip");
} else if self.sess.target.is_like_solaris {
self.linker_arg("-zrecord");
} else {
} else if self.sess.target.linker_is_gnu {
self.linker_arg("--no-gc-sections");
}
}