diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index cf78fc56b498c..bead3b2b38e00 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -846,7 +846,6 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>( name_in_debuginfo.push("@"); name_in_debuginfo.push(codegen_unit_name); - debug!("build_compile_unit_di_node: {:?}", name_in_debuginfo); let rustc_producer = format!("rustc version {}", tcx.sess.cfg_version); // FIXME(#41252) Remove "clang LLVM" if we can get GDB and LLVM to play nice. let producer = format!("clang LLVM ({rustc_producer})"); @@ -854,6 +853,9 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>( use rustc_session::RemapFileNameExt; let name_in_debuginfo = name_in_debuginfo.to_string_lossy(); let work_dir = tcx.sess.opts.working_dir.for_codegen(tcx.sess).to_string_lossy(); + debug!(?work_dir, "build_compile_unit_di_node"); + debug!(?name_in_debuginfo, "build_compile_unit_di_node"); + let flags = "\0"; let output_filenames = tcx.output_filenames(()); let split_name = if tcx.sess.target_can_use_split_dwarf() { diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 57a535d8c105f..a12d501e12ed6 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1255,6 +1255,15 @@ impl Session { prefer_remapped |= has_split_debuginfo; } + if self.target.is_like_osx && remap_path_scopes.contains(RemapPathScopeComponents::OBJECT) { + // HACK: Even when when debuginfo is splitted, + // `SO` debug symbols are still embedded in executables on macOS. + // Therefore, we trim them when the scope of `object` is present, + // as it is expected no path embedded in final executables + // when `object` scope applied. + prefer_remapped |= true; + } + prefer_remapped } diff --git a/tests/run-make/split-debuginfo/Makefile b/tests/run-make/split-debuginfo/Makefile index a893a59a71253..c3e95a446a170 100644 --- a/tests/run-make/split-debuginfo/Makefile +++ b/tests/run-make/split-debuginfo/Makefile @@ -24,7 +24,7 @@ packed-remapped-scope: -Z remap-path-scope=object foo.rs -g ls $(TMPDIR)/*.o && exit 1 || exit 0 [ -d $(TMPDIR)/foo.dSYM ] - dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | grep $(HERE) || exit 1 # expected behavior is (! grep ...) + dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (! grep $(HERE)) || exit 1 # As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948 dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | grep $(TMPDIR) || exit 1 # expected behavior is (! grep ...) rm -rf $(TMPDIR)/foo.dSYM @@ -56,7 +56,7 @@ unpacked-remapped-scope: -Z remap-path-scope=object foo.rs -g ls $(TMPDIR)/*.o [ ! -d $(TMPDIR)/foo.dSYM ] - dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (grep $(HERE)) || exit 1 # expected behavior is (! grep ...) + dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (! grep $(HERE)) || exit 1 # As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948 dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | (grep $(TMPDIR)) || exit 1 # expected behavior is (! grep ...) rm $(TMPDIR)/*.o