Skip to content

Commit 9c61c72

Browse files
committed
rustc_trans: Fix PGO generation linking on Linux by adding the relevant linker commands.
See the linked LLVM reviews for the clang counter-parts. Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
1 parent 99127ab commit 9c61c72

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/librustc_trans/back/link.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,20 @@ 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.cg.pgo_gen.is_some() && sess.target.target.options.linker_is_gnu {
1099+
cmd.args(&["-u".to_owned(), "__llvm_profile_runtime".to_owned()]);
1100+
}
1101+
10881102
// FIXME (#2397): At some point we want to rpath our guesses as to
10891103
// where extern libraries might live, based on the
10901104
// addl_lib_search_paths

0 commit comments

Comments
 (0)