@@ -14,7 +14,7 @@ use rustc_session::utils::NativeLibKind;
1414use rustc_session:: { filesearch, Session } ;
1515use rustc_span:: symbol:: Symbol ;
1616use rustc_target:: spec:: crt_objects:: { CrtObjects , CrtObjectsFallback } ;
17- use rustc_target:: spec:: { LinkOutputKind , LinkerFlavor , LldFlavor } ;
17+ use rustc_target:: spec:: { LinkOutputKind , LinkerFlavor , LldFlavor , SplitDebuginfo } ;
1818use rustc_target:: spec:: { PanicStrategy , RelocModel , RelroLevel , Target } ;
1919
2020use super :: archive:: ArchiveBuilder ;
@@ -99,9 +99,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
9999 path. as_ref ( ) ,
100100 target_cpu,
101101 ) ;
102- if sess. opts . debugging_opts . split_dwarf == config:: SplitDwarfKind :: Split {
103- link_dwarf_object ( sess, & out_filename) ;
104- }
105102 }
106103 }
107104 if sess. opts . json_artifact_notifications {
@@ -828,29 +825,43 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
828825 }
829826 }
830827
831- // On macOS, debuggers need this utility to get run to do some munging of
832- // the symbols. Note, though, that if the object files are being preserved
833- // for their debug information there's no need for us to run dsymutil.
834- if sess. target . is_like_osx
835- && sess. opts . debuginfo != DebugInfo :: None
836- && !preserve_objects_for_their_debuginfo ( sess)
837- {
838- let prog = Command :: new ( "dsymutil" ) . arg ( out_filename) . output ( ) ;
839- match prog {
840- Ok ( prog) => {
841- if !prog. status . success ( ) {
842- let mut output = prog. stderr . clone ( ) ;
843- output. extend_from_slice ( & prog. stdout ) ;
844- sess. struct_warn ( & format ! (
845- "processing debug info with `dsymutil` failed: {}" ,
846- prog. status
847- ) )
848- . note ( & escape_string ( & output) )
849- . emit ( ) ;
828+ match sess. split_debuginfo ( ) {
829+ // If split debug information is disabled or located in individual files
830+ // there's nothing to do here.
831+ SplitDebuginfo :: Off | SplitDebuginfo :: Unpacked => { }
832+
833+ // If packed split-debuginfo is requested, but the final compilation
834+ // doesn't actually have any debug information, then we skip this step.
835+ SplitDebuginfo :: Packed if sess. opts . debuginfo == DebugInfo :: None => { }
836+
837+ // On macOS the external `dsymutil` tool is used to create the packed
838+ // debug information. Note that this will read debug information from
839+ // the objects on the filesystem which we'll clean up later.
840+ SplitDebuginfo :: Packed if sess. target . is_like_osx => {
841+ let prog = Command :: new ( "dsymutil" ) . arg ( out_filename) . output ( ) ;
842+ match prog {
843+ Ok ( prog) => {
844+ if !prog. status . success ( ) {
845+ let mut output = prog. stderr . clone ( ) ;
846+ output. extend_from_slice ( & prog. stdout ) ;
847+ sess. struct_warn ( & format ! (
848+ "processing debug info with `dsymutil` failed: {}" ,
849+ prog. status
850+ ) )
851+ . note ( & escape_string ( & output) )
852+ . emit ( ) ;
853+ }
850854 }
855+ Err ( e) => sess. fatal ( & format ! ( "unable to run `dsymutil`: {}" , e) ) ,
851856 }
852- Err ( e) => sess. fatal ( & format ! ( "unable to run `dsymutil`: {}" , e) ) ,
853857 }
858+
859+ // On MSVC packed debug information is produced by the linker itself so
860+ // there's no need to do anything else here.
861+ SplitDebuginfo :: Packed if sess. target . is_like_msvc => { }
862+
863+ // ... and otherwise we're processing a `*.dwp` packed dwarf file.
864+ SplitDebuginfo :: Packed => link_dwarf_object ( sess, & out_filename) ,
854865 }
855866}
856867
@@ -1050,28 +1061,9 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> bool {
10501061 return false ;
10511062 }
10521063
1053- // Single mode keeps debuginfo in the same object file, but in such a way that it it skipped
1054- // by the linker - so it's expected that when codegen units are linked together that this
1055- // debuginfo would be lost without keeping around the temps.
1056- if sess. opts . debugging_opts . split_dwarf == config:: SplitDwarfKind :: Single {
1057- return true ;
1058- }
1059-
1060- // If we're on OSX then the equivalent of split dwarf is turned on by
1061- // default. The final executable won't actually have any debug information
1062- // except it'll have pointers to elsewhere. Historically we've always run
1063- // `dsymutil` to "link all the dwarf together" but this is actually sort of
1064- // a bummer for incremental compilation! (the whole point of split dwarf is
1065- // that you don't do this sort of dwarf link).
1066- //
1067- // Basically as a result this just means that if we're on OSX and we're
1068- // *not* running dsymutil then the object files are the only source of truth
1069- // for debug information, so we must preserve them.
1070- if sess. target . is_like_osx {
1071- return !sess. opts . debugging_opts . run_dsymutil ;
1072- }
1073-
1074- false
1064+ // "unpacked" split debuginfo means that we leave object files as the
1065+ // debuginfo is found in the original object files themselves
1066+ sess. split_debuginfo ( ) == SplitDebuginfo :: Unpacked
10751067}
10761068
10771069pub fn archive_search_paths ( sess : & Session ) -> Vec < PathBuf > {
@@ -2211,8 +2203,13 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
22112203 return ;
22122204 }
22132205 } ;
2214- let arch_name = llvm_target. split ( '-' ) . next ( ) . expect ( "LLVM target must have a hyphen" ) ;
2215- cmd. args ( & [ "-arch" , arch_name, "-isysroot" , & sdk_root, "-Wl,-syslibroot" , & sdk_root] ) ;
2206+ if llvm_target. contains ( "macabi" ) {
2207+ cmd. args ( & [ "-target" , llvm_target] )
2208+ } else {
2209+ let arch_name = llvm_target. split ( '-' ) . next ( ) . expect ( "LLVM target must have a hyphen" ) ;
2210+ cmd. args ( & [ "-arch" , arch_name] )
2211+ }
2212+ cmd. args ( & [ "-isysroot" , & sdk_root, "-Wl,-syslibroot" , & sdk_root] ) ;
22162213}
22172214
22182215fn get_apple_sdk_root ( sdk_name : & str ) -> Result < String , String > {
0 commit comments