Move linker code to the Linker trait instead.
This commit is contained in:
parent
e155ecdc97
commit
96b87296ce
2 changed files with 32 additions and 14 deletions
|
@ -1085,20 +1085,8 @@ fn link_args(cmd: &mut Linker,
|
||||||
cmd.build_static_executable();
|
cmd.build_static_executable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're doing PGO generation stuff and on a GNU-like linker, use the
|
if sess.opts.debugging_opts.pgo_gen.is_some() {
|
||||||
// "-u" flag to properly pull in the profiler runtime bits.
|
cmd.pgo_gen();
|
||||||
//
|
|
||||||
// This is because LLVM otherwise won't add the needed initialization for us
|
|
||||||
// on Linux (though the extra flag should be harmless if it does).
|
|
||||||
//
|
|
||||||
// See https://reviews.llvm.org/D14033 and https://reviews.llvm.org/D14030.
|
|
||||||
//
|
|
||||||
// Though it may be worth to try to revert those changes upstream, since the
|
|
||||||
// overhead of the initialization should be minor.
|
|
||||||
if sess.opts.debugging_opts.pgo_gen.is_some() &&
|
|
||||||
sess.target.target.options.linker_is_gnu
|
|
||||||
{
|
|
||||||
cmd.args(&["-u".to_owned(), "__llvm_profile_runtime".to_owned()]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME (#2397): At some point we want to rpath our guesses as to
|
// FIXME (#2397): At some point we want to rpath our guesses as to
|
||||||
|
|
|
@ -117,6 +117,7 @@ pub trait Linker {
|
||||||
fn partial_relro(&mut self);
|
fn partial_relro(&mut self);
|
||||||
fn no_relro(&mut self);
|
fn no_relro(&mut self);
|
||||||
fn optimize(&mut self);
|
fn optimize(&mut self);
|
||||||
|
fn pgo_gen(&mut self);
|
||||||
fn debuginfo(&mut self);
|
fn debuginfo(&mut self);
|
||||||
fn no_default_libraries(&mut self);
|
fn no_default_libraries(&mut self);
|
||||||
fn build_dylib(&mut self, out_filename: &Path);
|
fn build_dylib(&mut self, out_filename: &Path);
|
||||||
|
@ -280,6 +281,24 @@ impl<'a> Linker for GccLinker<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pgo_gen(&mut self) {
|
||||||
|
if !self.sess.target.target.options.linker_is_gnu { return }
|
||||||
|
|
||||||
|
// If we're doing PGO generation stuff and on a GNU-like linker, use the
|
||||||
|
// "-u" flag to properly pull in the profiler runtime bits.
|
||||||
|
//
|
||||||
|
// This is because LLVM otherwise won't add the needed initialization
|
||||||
|
// for us on Linux (though the extra flag should be harmless if it
|
||||||
|
// does).
|
||||||
|
//
|
||||||
|
// See https://reviews.llvm.org/D14033 and https://reviews.llvm.org/D14030.
|
||||||
|
//
|
||||||
|
// Though it may be worth to try to revert those changes upstream, since
|
||||||
|
// the overhead of the initialization should be minor.
|
||||||
|
self.cmd.arg("-u");
|
||||||
|
self.cmd.arg("__llvm_profile_runtime");
|
||||||
|
}
|
||||||
|
|
||||||
fn debuginfo(&mut self) {
|
fn debuginfo(&mut self) {
|
||||||
// Don't do anything special here for GNU-style linkers.
|
// Don't do anything special here for GNU-style linkers.
|
||||||
}
|
}
|
||||||
|
@ -509,6 +528,10 @@ impl<'a> Linker for MsvcLinker<'a> {
|
||||||
// Needs more investigation of `/OPT` arguments
|
// Needs more investigation of `/OPT` arguments
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pgo_gen(&mut self) {
|
||||||
|
// Nothing needed here.
|
||||||
|
}
|
||||||
|
|
||||||
fn debuginfo(&mut self) {
|
fn debuginfo(&mut self) {
|
||||||
// This will cause the Microsoft linker to generate a PDB file
|
// This will cause the Microsoft linker to generate a PDB file
|
||||||
// from the CodeView line tables in the object files.
|
// from the CodeView line tables in the object files.
|
||||||
|
@ -712,6 +735,10 @@ impl<'a> Linker for EmLinker<'a> {
|
||||||
self.cmd.args(&["--memory-init-file", "0"]);
|
self.cmd.args(&["--memory-init-file", "0"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pgo_gen(&mut self) {
|
||||||
|
// noop, but maybe we need something like the gnu linker?
|
||||||
|
}
|
||||||
|
|
||||||
fn debuginfo(&mut self) {
|
fn debuginfo(&mut self) {
|
||||||
// Preserve names or generate source maps depending on debug info
|
// Preserve names or generate source maps depending on debug info
|
||||||
self.cmd.arg(match self.sess.opts.debuginfo {
|
self.cmd.arg(match self.sess.opts.debuginfo {
|
||||||
|
@ -877,6 +904,9 @@ impl Linker for WasmLd {
|
||||||
fn optimize(&mut self) {
|
fn optimize(&mut self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pgo_gen(&mut self) {
|
||||||
|
}
|
||||||
|
|
||||||
fn debuginfo(&mut self) {
|
fn debuginfo(&mut self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue