Skip to content

Commit 96b8729

Browse files
committed
Move linker code to the Linker trait instead.
1 parent e155ecd commit 96b8729

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

Diff for: src/librustc_trans/back/link.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -1085,20 +1085,8 @@ fn link_args(cmd: &mut Linker,
10851085
cmd.build_static_executable();
10861086
}
10871087

1088-
// If we're doing PGO generation stuff and on a GNU-like linker, use the
1089-
// "-u" flag to properly pull in the profiler runtime bits.
1090-
//
1091-
// This is because LLVM otherwise won't add the needed initialization for us
1092-
// on Linux (though the extra flag should be harmless if it does).
1093-
//
1094-
// See https://reviews.llvm.org/D14033 and https://reviews.llvm.org/D14030.
1095-
//
1096-
// Though it may be worth to try to revert those changes upstream, since the
1097-
// overhead of the initialization should be minor.
1098-
if sess.opts.debugging_opts.pgo_gen.is_some() &&
1099-
sess.target.target.options.linker_is_gnu
1100-
{
1101-
cmd.args(&["-u".to_owned(), "__llvm_profile_runtime".to_owned()]);
1088+
if sess.opts.debugging_opts.pgo_gen.is_some() {
1089+
cmd.pgo_gen();
11021090
}
11031091

11041092
// FIXME (#2397): At some point we want to rpath our guesses as to

Diff for: src/librustc_trans/back/linker.rs

+30
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub trait Linker {
117117
fn partial_relro(&mut self);
118118
fn no_relro(&mut self);
119119
fn optimize(&mut self);
120+
fn pgo_gen(&mut self);
120121
fn debuginfo(&mut self);
121122
fn no_default_libraries(&mut self);
122123
fn build_dylib(&mut self, out_filename: &Path);
@@ -280,6 +281,24 @@ impl<'a> Linker for GccLinker<'a> {
280281
}
281282
}
282283

284+
fn pgo_gen(&mut self) {
285+
if !self.sess.target.target.options.linker_is_gnu { return }
286+
287+
// If we're doing PGO generation stuff and on a GNU-like linker, use the
288+
// "-u" flag to properly pull in the profiler runtime bits.
289+
//
290+
// This is because LLVM otherwise won't add the needed initialization
291+
// for us on Linux (though the extra flag should be harmless if it
292+
// does).
293+
//
294+
// See https://reviews.llvm.org/D14033 and https://reviews.llvm.org/D14030.
295+
//
296+
// Though it may be worth to try to revert those changes upstream, since
297+
// the overhead of the initialization should be minor.
298+
self.cmd.arg("-u");
299+
self.cmd.arg("__llvm_profile_runtime");
300+
}
301+
283302
fn debuginfo(&mut self) {
284303
// Don't do anything special here for GNU-style linkers.
285304
}
@@ -509,6 +528,10 @@ impl<'a> Linker for MsvcLinker<'a> {
509528
// Needs more investigation of `/OPT` arguments
510529
}
511530

531+
fn pgo_gen(&mut self) {
532+
// Nothing needed here.
533+
}
534+
512535
fn debuginfo(&mut self) {
513536
// This will cause the Microsoft linker to generate a PDB file
514537
// from the CodeView line tables in the object files.
@@ -712,6 +735,10 @@ impl<'a> Linker for EmLinker<'a> {
712735
self.cmd.args(&["--memory-init-file", "0"]);
713736
}
714737

738+
fn pgo_gen(&mut self) {
739+
// noop, but maybe we need something like the gnu linker?
740+
}
741+
715742
fn debuginfo(&mut self) {
716743
// Preserve names or generate source maps depending on debug info
717744
self.cmd.arg(match self.sess.opts.debuginfo {
@@ -877,6 +904,9 @@ impl Linker for WasmLd {
877904
fn optimize(&mut self) {
878905
}
879906

907+
fn pgo_gen(&mut self) {
908+
}
909+
880910
fn debuginfo(&mut self) {
881911
}
882912

0 commit comments

Comments
 (0)