@@ -762,31 +762,38 @@ fn pointer_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
762
762
}
763
763
764
764
pub fn compile_unit_metadata ( scc : & SharedCrateContext ,
765
+ codegen_unit_name : & str ,
765
766
debug_context : & CrateDebugContext ,
766
767
sess : & Session )
767
768
-> DIDescriptor {
768
- let compile_unit_name = match sess. local_crate_source_file {
769
- None => fallback_path ( scc) ,
770
- Some ( ref path) => {
771
- CString :: new ( & path[ ..] ) . unwrap ( )
772
- }
769
+ let mut name_in_debuginfo = match sess. local_crate_source_file {
770
+ Some ( ref path) => path. clone ( ) ,
771
+ None => scc. tcx ( ) . crate_name ( LOCAL_CRATE ) . to_string ( ) ,
773
772
} ;
774
773
775
- debug ! ( "compile_unit_metadata: {:?}" , compile_unit_name) ;
774
+ // The OSX linker has an idiosyncrasy where it will ignore some debuginfo
775
+ // if multiple object files with the same DW_AT_name are linked together.
776
+ // As a workaround we generate unique names for each object file. Those do
777
+ // not correspond to an actual source file but that should be harmless.
778
+ if scc. sess ( ) . target . target . options . is_like_osx {
779
+ name_in_debuginfo. push_str ( "@" ) ;
780
+ name_in_debuginfo. push_str ( codegen_unit_name) ;
781
+ }
782
+
783
+ debug ! ( "compile_unit_metadata: {:?}" , name_in_debuginfo) ;
776
784
// FIXME(#41252) Remove "clang LLVM" if we can get GDB and LLVM to play nice.
777
785
let producer = format ! ( "clang LLVM (rustc version {})" ,
778
786
( option_env!( "CFG_VERSION" ) ) . expect( "CFG_VERSION" ) ) ;
779
787
780
- let compile_unit_name = compile_unit_name. as_ptr ( ) ;
781
-
788
+ let name_in_debuginfo = CString :: new ( name_in_debuginfo) . unwrap ( ) ;
782
789
let work_dir = CString :: new ( & sess. working_dir . 0 [ ..] ) . unwrap ( ) ;
783
790
let producer = CString :: new ( producer) . unwrap ( ) ;
784
791
let flags = "\0 " ;
785
792
let split_name = "\0 " ;
786
793
787
794
unsafe {
788
795
let file_metadata = llvm:: LLVMRustDIBuilderCreateFile (
789
- debug_context. builder , compile_unit_name , work_dir. as_ptr ( ) ) ;
796
+ debug_context. builder , name_in_debuginfo . as_ptr ( ) , work_dir. as_ptr ( ) ) ;
790
797
791
798
return llvm:: LLVMRustDIBuilderCreateCompileUnit (
792
799
debug_context. builder ,
@@ -798,10 +805,6 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext,
798
805
0 ,
799
806
split_name. as_ptr ( ) as * const _ )
800
807
} ;
801
-
802
- fn fallback_path ( scc : & SharedCrateContext ) -> CString {
803
- CString :: new ( scc. tcx ( ) . crate_name ( LOCAL_CRATE ) . to_string ( ) ) . unwrap ( )
804
- }
805
808
}
806
809
807
810
struct MetadataCreationResult {
0 commit comments