@@ -14,7 +14,7 @@ use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
14
14
use rustc_middle:: middle:: dependency_format:: Linkage ;
15
15
use rustc_middle:: ty:: TyCtxt ;
16
16
use rustc_serialize:: { json, Encoder } ;
17
- use rustc_session:: config:: { self , CrateType , DebugInfo , LinkerPluginLto , Lto , OptLevel } ;
17
+ use rustc_session:: config:: { self , CrateType , DebugInfo , LinkerPluginLto , Lto , OptLevel , Strip } ;
18
18
use rustc_session:: Session ;
19
19
use rustc_span:: symbol:: Symbol ;
20
20
use rustc_target:: spec:: { LinkerFlavor , LldFlavor } ;
@@ -122,7 +122,7 @@ pub trait Linker {
122
122
fn optimize ( & mut self ) ;
123
123
fn pgo_gen ( & mut self ) ;
124
124
fn control_flow_guard ( & mut self ) ;
125
- fn debuginfo ( & mut self ) ;
125
+ fn debuginfo ( & mut self , strip : Strip ) ;
126
126
fn no_default_libraries ( & mut self ) ;
127
127
fn build_dylib ( & mut self , out_filename : & Path ) ;
128
128
fn build_static_executable ( & mut self ) ;
@@ -392,15 +392,16 @@ impl<'a> Linker for GccLinker<'a> {
392
392
self . sess . warn ( "Windows Control Flow Guard is not supported by this linker." ) ;
393
393
}
394
394
395
- fn debuginfo ( & mut self ) {
396
- if let DebugInfo :: None = self . sess . opts . debuginfo {
397
- // If we are building without debuginfo enabled and we were called with
398
- // `-Zstrip-debuginfo-if-disabled=yes`, tell the linker to strip any debuginfo
399
- // found when linking to get rid of symbols from libstd.
400
- if self . sess . opts . debugging_opts . strip_debuginfo_if_disabled {
401
- self . linker_arg ( "-S" ) ;
395
+ fn debuginfo ( & mut self , strip : Strip ) {
396
+ match strip {
397
+ Strip :: None => { }
398
+ Strip :: Debuginfo => {
399
+ self . linker_arg ( "--strip-debug" ) ;
402
400
}
403
- } ;
401
+ Strip :: Symbols => {
402
+ self . linker_arg ( "--strip-all" ) ;
403
+ }
404
+ }
404
405
}
405
406
406
407
fn no_default_libraries ( & mut self ) {
@@ -686,29 +687,37 @@ impl<'a> Linker for MsvcLinker<'a> {
686
687
self . cmd . arg ( "/guard:cf" ) ;
687
688
}
688
689
689
- fn debuginfo ( & mut self ) {
690
- // This will cause the Microsoft linker to generate a PDB file
691
- // from the CodeView line tables in the object files.
692
- self . cmd . arg ( "/DEBUG" ) ;
693
-
694
- // This will cause the Microsoft linker to embed .natvis info into the PDB file
695
- let natvis_dir_path = self . sess . sysroot . join ( "lib\\ rustlib\\ etc" ) ;
696
- if let Ok ( natvis_dir) = fs:: read_dir ( & natvis_dir_path) {
697
- for entry in natvis_dir {
698
- match entry {
699
- Ok ( entry) => {
700
- let path = entry. path ( ) ;
701
- if path. extension ( ) == Some ( "natvis" . as_ref ( ) ) {
702
- let mut arg = OsString :: from ( "/NATVIS:" ) ;
703
- arg. push ( path) ;
704
- self . cmd . arg ( arg) ;
690
+ fn debuginfo ( & mut self , strip : Strip ) {
691
+ match strip {
692
+ Strip :: None => {
693
+ // This will cause the Microsoft linker to generate a PDB file
694
+ // from the CodeView line tables in the object files.
695
+ self . cmd . arg ( "/DEBUG" ) ;
696
+
697
+ // This will cause the Microsoft linker to embed .natvis info into the PDB file
698
+ let natvis_dir_path = self . sess . sysroot . join ( "lib\\ rustlib\\ etc" ) ;
699
+ if let Ok ( natvis_dir) = fs:: read_dir ( & natvis_dir_path) {
700
+ for entry in natvis_dir {
701
+ match entry {
702
+ Ok ( entry) => {
703
+ let path = entry. path ( ) ;
704
+ if path. extension ( ) == Some ( "natvis" . as_ref ( ) ) {
705
+ let mut arg = OsString :: from ( "/NATVIS:" ) ;
706
+ arg. push ( path) ;
707
+ self . cmd . arg ( arg) ;
708
+ }
709
+ }
710
+ Err ( err) => {
711
+ self . sess
712
+ . warn ( & format ! ( "error enumerating natvis directory: {}" , err) ) ;
713
+ }
705
714
}
706
715
}
707
- Err ( err) => {
708
- self . sess . warn ( & format ! ( "error enumerating natvis directory: {}" , err) ) ;
709
- }
710
716
}
711
717
}
718
+ Strip :: Debuginfo | Strip :: Symbols => {
719
+ self . cmd . arg ( "/DEBUG:NONE" ) ;
720
+ }
712
721
}
713
722
}
714
723
@@ -889,7 +898,7 @@ impl<'a> Linker for EmLinker<'a> {
889
898
self . sess . warn ( "Windows Control Flow Guard is not supported by this linker." ) ;
890
899
}
891
900
892
- fn debuginfo ( & mut self ) {
901
+ fn debuginfo ( & mut self , _strip : Strip ) {
893
902
// Preserve names or generate source maps depending on debug info
894
903
self . cmd . arg ( match self . sess . opts . debuginfo {
895
904
DebugInfo :: None => "-g0" ,
@@ -1081,7 +1090,17 @@ impl<'a> Linker for WasmLd<'a> {
1081
1090
1082
1091
fn pgo_gen ( & mut self ) { }
1083
1092
1084
- fn debuginfo ( & mut self ) { }
1093
+ fn debuginfo ( & mut self , strip : Strip ) {
1094
+ match strip {
1095
+ Strip :: None => { }
1096
+ Strip :: Debuginfo => {
1097
+ self . cmd . arg ( "--strip-debug" ) ;
1098
+ }
1099
+ Strip :: Symbols => {
1100
+ self . cmd . arg ( "--strip-all" ) ;
1101
+ }
1102
+ }
1103
+ }
1085
1104
1086
1105
fn control_flow_guard ( & mut self ) {
1087
1106
self . sess . warn ( "Windows Control Flow Guard is not supported by this linker." ) ;
@@ -1184,7 +1203,7 @@ impl<'a> Linker for PtxLinker<'a> {
1184
1203
self . cmd . arg ( "-L" ) . arg ( path) ;
1185
1204
}
1186
1205
1187
- fn debuginfo ( & mut self ) {
1206
+ fn debuginfo ( & mut self , _strip : Strip ) {
1188
1207
self . cmd . arg ( "--debug" ) ;
1189
1208
}
1190
1209
0 commit comments