@@ -14,7 +14,7 @@ use rustc_session::utils::NativeLibKind;
14
14
use rustc_session:: { filesearch, Session } ;
15
15
use rustc_span:: symbol:: Symbol ;
16
16
use rustc_target:: spec:: crt_objects:: { CrtObjects , CrtObjectsFallback } ;
17
- use rustc_target:: spec:: { LinkOutputKind , LinkerFlavor , LldFlavor } ;
17
+ use rustc_target:: spec:: { LinkOutputKind , LinkerFlavor , LldFlavor , SplitDebuginfo } ;
18
18
use rustc_target:: spec:: { PanicStrategy , RelocModel , RelroLevel , Target } ;
19
19
20
20
use super :: archive:: ArchiveBuilder ;
@@ -99,9 +99,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
99
99
path. as_ref ( ) ,
100
100
target_cpu,
101
101
) ;
102
- if sess. opts . debugging_opts . split_dwarf == config:: SplitDwarfKind :: Split {
103
- link_dwarf_object ( sess, & out_filename) ;
104
- }
105
102
}
106
103
}
107
104
if sess. opts . json_artifact_notifications {
@@ -828,29 +825,43 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
828
825
}
829
826
}
830
827
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
+ }
850
854
}
855
+ Err ( e) => sess. fatal ( & format ! ( "unable to run `dsymutil`: {}" , e) ) ,
851
856
}
852
- Err ( e) => sess. fatal ( & format ! ( "unable to run `dsymutil`: {}" , e) ) ,
853
857
}
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) ,
854
865
}
855
866
}
856
867
@@ -1050,28 +1061,9 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> bool {
1050
1061
return false ;
1051
1062
}
1052
1063
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
1075
1067
}
1076
1068
1077
1069
pub fn archive_search_paths ( sess : & Session ) -> Vec < PathBuf > {
@@ -2211,8 +2203,13 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
2211
2203
return ;
2212
2204
}
2213
2205
} ;
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] ) ;
2216
2213
}
2217
2214
2218
2215
fn get_apple_sdk_root ( sdk_name : & str ) -> Result < String , String > {
0 commit comments