@@ -14,7 +14,7 @@ use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
1414use rustc_middle:: middle:: dependency_format:: Linkage ;
1515use rustc_middle:: ty:: TyCtxt ;
1616use 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 } ;
1818use rustc_session:: Session ;
1919use rustc_span:: symbol:: Symbol ;
2020use rustc_target:: spec:: { LinkerFlavor , LldFlavor } ;
@@ -122,7 +122,7 @@ pub trait Linker {
122122 fn optimize ( & mut self ) ;
123123 fn pgo_gen ( & mut self ) ;
124124 fn control_flow_guard ( & mut self ) ;
125- fn debuginfo ( & mut self ) ;
125+ fn debuginfo ( & mut self , strip : Strip ) ;
126126 fn no_default_libraries ( & mut self ) ;
127127 fn build_dylib ( & mut self , out_filename : & Path ) ;
128128 fn build_static_executable ( & mut self ) ;
@@ -392,15 +392,16 @@ impl<'a> Linker for GccLinker<'a> {
392392 self . sess . warn ( "Windows Control Flow Guard is not supported by this linker." ) ;
393393 }
394394
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" ) ;
402400 }
403- } ;
401+ Strip :: Symbols => {
402+ self . linker_arg ( "--strip-all" ) ;
403+ }
404+ }
404405 }
405406
406407 fn no_default_libraries ( & mut self ) {
@@ -686,29 +687,37 @@ impl<'a> Linker for MsvcLinker<'a> {
686687 self . cmd . arg ( "/guard:cf" ) ;
687688 }
688689
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+ }
705714 }
706715 }
707- Err ( err) => {
708- self . sess . warn ( & format ! ( "error enumerating natvis directory: {}" , err) ) ;
709- }
710716 }
711717 }
718+ Strip :: Debuginfo | Strip :: Symbols => {
719+ self . cmd . arg ( "/DEBUG:NONE" ) ;
720+ }
712721 }
713722 }
714723
@@ -889,7 +898,7 @@ impl<'a> Linker for EmLinker<'a> {
889898 self . sess . warn ( "Windows Control Flow Guard is not supported by this linker." ) ;
890899 }
891900
892- fn debuginfo ( & mut self ) {
901+ fn debuginfo ( & mut self , _strip : Strip ) {
893902 // Preserve names or generate source maps depending on debug info
894903 self . cmd . arg ( match self . sess . opts . debuginfo {
895904 DebugInfo :: None => "-g0" ,
@@ -1081,7 +1090,17 @@ impl<'a> Linker for WasmLd<'a> {
10811090
10821091 fn pgo_gen ( & mut self ) { }
10831092
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+ }
10851104
10861105 fn control_flow_guard ( & mut self ) {
10871106 self . sess . warn ( "Windows Control Flow Guard is not supported by this linker." ) ;
@@ -1184,7 +1203,7 @@ impl<'a> Linker for PtxLinker<'a> {
11841203 self . cmd . arg ( "-L" ) . arg ( path) ;
11851204 }
11861205
1187- fn debuginfo ( & mut self ) {
1206+ fn debuginfo ( & mut self , _strip : Strip ) {
11881207 self . cmd . arg ( "--debug" ) ;
11891208 }
11901209
0 commit comments