@@ -762,31 +762,38 @@ fn pointer_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
762762}
763763
764764pub fn compile_unit_metadata ( scc : & SharedCrateContext ,
765+ codegen_unit_name : & str ,
765766 debug_context : & CrateDebugContext ,
766767 sess : & Session )
767768 -> 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 ( ) ,
773772 } ;
774773
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) ;
776784 // FIXME(#41252) Remove "clang LLVM" if we can get GDB and LLVM to play nice.
777785 let producer = format ! ( "clang LLVM (rustc version {})" ,
778786 ( option_env!( "CFG_VERSION" ) ) . expect( "CFG_VERSION" ) ) ;
779787
780- let compile_unit_name = compile_unit_name. as_ptr ( ) ;
781-
788+ let name_in_debuginfo = CString :: new ( name_in_debuginfo) . unwrap ( ) ;
782789 let work_dir = CString :: new ( & sess. working_dir . 0 [ ..] ) . unwrap ( ) ;
783790 let producer = CString :: new ( producer) . unwrap ( ) ;
784791 let flags = "\0 " ;
785792 let split_name = "\0 " ;
786793
787794 unsafe {
788795 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 ( ) ) ;
790797
791798 return llvm:: LLVMRustDIBuilderCreateCompileUnit (
792799 debug_context. builder ,
@@ -798,10 +805,6 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext,
798805 0 ,
799806 split_name. as_ptr ( ) as * const _ )
800807 } ;
801-
802- fn fallback_path ( scc : & SharedCrateContext ) -> CString {
803- CString :: new ( scc. tcx ( ) . crate_name ( LOCAL_CRATE ) . to_string ( ) ) . unwrap ( )
804- }
805808}
806809
807810struct MetadataCreationResult {
0 commit comments