@@ -117,6 +117,7 @@ pub trait Linker {
117
117
fn partial_relro ( & mut self ) ;
118
118
fn no_relro ( & mut self ) ;
119
119
fn optimize ( & mut self ) ;
120
+ fn pgo_gen ( & mut self ) ;
120
121
fn debuginfo ( & mut self ) ;
121
122
fn no_default_libraries ( & mut self ) ;
122
123
fn build_dylib ( & mut self , out_filename : & Path ) ;
@@ -280,6 +281,24 @@ impl<'a> Linker for GccLinker<'a> {
280
281
}
281
282
}
282
283
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
+
283
302
fn debuginfo ( & mut self ) {
284
303
// Don't do anything special here for GNU-style linkers.
285
304
}
@@ -509,6 +528,10 @@ impl<'a> Linker for MsvcLinker<'a> {
509
528
// Needs more investigation of `/OPT` arguments
510
529
}
511
530
531
+ fn pgo_gen ( & mut self ) {
532
+ // Nothing needed here.
533
+ }
534
+
512
535
fn debuginfo ( & mut self ) {
513
536
// This will cause the Microsoft linker to generate a PDB file
514
537
// from the CodeView line tables in the object files.
@@ -712,6 +735,10 @@ impl<'a> Linker for EmLinker<'a> {
712
735
self . cmd . args ( & [ "--memory-init-file" , "0" ] ) ;
713
736
}
714
737
738
+ fn pgo_gen ( & mut self ) {
739
+ // noop, but maybe we need something like the gnu linker?
740
+ }
741
+
715
742
fn debuginfo ( & mut self ) {
716
743
// Preserve names or generate source maps depending on debug info
717
744
self . cmd . arg ( match self . sess . opts . debuginfo {
@@ -877,6 +904,9 @@ impl Linker for WasmLd {
877
904
fn optimize ( & mut self ) {
878
905
}
879
906
907
+ fn pgo_gen ( & mut self ) {
908
+ }
909
+
880
910
fn debuginfo ( & mut self ) {
881
911
}
882
912
0 commit comments