@@ -22,6 +22,7 @@ use rustc_session::config::{self, DebugInfo};
2222use rustc_span:: {
2323 BytePos , Pos , SourceFile , SourceFileAndLine , SourceFileHash , Span , StableSourceFileId , Symbol ,
2424} ;
25+ use rustc_target:: spec:: DebuginfoKind ;
2526use smallvec:: SmallVec ;
2627use tracing:: debug;
2728
@@ -93,29 +94,31 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
9394
9495 pub ( crate ) fn finalize ( & self , sess : & Session ) {
9596 unsafe { llvm:: LLVMRustDIBuilderFinalize ( self . builder ) } ;
96- if !sess. target . is_like_msvc {
97- // Debuginfo generation in LLVM by default uses a higher
98- // version of dwarf than macOS currently understands. We can
99- // instruct LLVM to emit an older version of dwarf, however,
100- // for macOS to understand. For more info see #11352
101- // This can be overridden using --llvm-opts -dwarf-version,N.
102- // Android has the same issue (#22398)
103- let dwarf_version =
104- sess. opts . unstable_opts . dwarf_version . unwrap_or ( sess. target . default_dwarf_version ) ;
105- llvm:: add_module_flag_u32 (
106- self . llmod ,
107- llvm:: ModuleFlagMergeBehavior :: Warning ,
108- "Dwarf Version" ,
109- dwarf_version,
110- ) ;
111- } else {
112- // Indicate that we want CodeView debug information on MSVC
113- llvm:: add_module_flag_u32 (
114- self . llmod ,
115- llvm:: ModuleFlagMergeBehavior :: Warning ,
116- "CodeView" ,
117- 1 ,
118- ) ;
97+
98+ match sess. target . debuginfo_kind {
99+ DebuginfoKind :: Dwarf | DebuginfoKind :: DwarfDsym => {
100+ // Debuginfo generation in LLVM by default uses a higher
101+ // version of dwarf than macOS currently understands. We can
102+ // instruct LLVM to emit an older version of dwarf, however,
103+ // for macOS to understand. For more info see #11352
104+ // This can be overridden using --llvm-opts -dwarf-version,N.
105+ // Android has the same issue (#22398)
106+ llvm:: add_module_flag_u32 (
107+ self . llmod ,
108+ llvm:: ModuleFlagMergeBehavior :: Warning ,
109+ "Dwarf Version" ,
110+ sess. dwarf_version ( ) ,
111+ ) ;
112+ }
113+ DebuginfoKind :: Pdb => {
114+ // Indicate that we want CodeView debug information
115+ llvm:: add_module_flag_u32 (
116+ self . llmod ,
117+ llvm:: ModuleFlagMergeBehavior :: Warning ,
118+ "CodeView" ,
119+ 1 ,
120+ ) ;
121+ }
119122 }
120123
121124 // Prevent bitcode readers from deleting the debug info.
0 commit comments