diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index cf78fc56b498c..99907dbc41a7c 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -851,9 +851,22 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>( // FIXME(#41252) Remove "clang LLVM" if we can get GDB and LLVM to play nice. let producer = format!("clang LLVM ({rustc_producer})"); - 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!(?name_in_debuginfo, "build_compile_unit_di_node"); + + // Path of working directory in the root DI node seems to be embedded in + // executables. Hence, we trim them when the scope of `unsplit-debuginfo` + // is present, as if it is kinda a "unsplit" debuginfo. + use rustc_session::config::RemapPathScopeComponents; + use rustc_session::RemapFileNameExt; + let work_dir = tcx + .sess + .opts + .working_dir + .for_scope(tcx.sess, RemapPathScopeComponents::UNSPLIT_DEBUGINFO) + .to_string_lossy(); + debug!(?work_dir, "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/tests/run-make/split-debuginfo/Makefile b/tests/run-make/split-debuginfo/Makefile index d417fd147bff0..9338d658c5084 100644 --- a/tests/run-make/split-debuginfo/Makefile +++ b/tests/run-make/split-debuginfo/Makefile @@ -28,7 +28,7 @@ packed-remapped-scope: [ -d $(TMPDIR)/foo.dSYM ] # As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948 dsymutil -s $(TMPDIR)/foo | grep $(TMPDIR) || exit 1 # expected: `grep $(TMPDIR)` to exit 1 - dsymutil -s $(TMPDIR)/foo | grep $(HERE) || exit 1 # expected: `grep $(HERE)` to exit 1 + dsymutil -s $(TMPDIR)/foo | (! grep $(HERE)) || exit 1 rm -rf $(TMPDIR)/foo.dSYM rm $(TMPDIR)/$(call BIN,foo) @@ -64,7 +64,7 @@ unpacked-remapped-scope: [ ! -d $(TMPDIR)/foo.dSYM ] # As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948 dsymutil -s $(TMPDIR)/foo | grep $(TMPDIR) || exit 1 # expected: `grep $(TMPDIR)` to exit 1 - dsymutil -s $(TMPDIR)/foo | grep $(HERE) || exit 1 # expected: `grep $(HERE)` to exit 1 + dsymutil -s $(TMPDIR)/foo | (! grep $(HERE)) || exit 1 rm $(TMPDIR)/*.o rm $(TMPDIR)/$(call BIN,foo) @@ -210,7 +210,7 @@ packed-remapped-scope: --remap-path-prefix $(HERE)=/b \ -Z remap-path-scope=object foo.rs -g readelf -wi $(TMPDIR)/foo | (! grep $(TMPDIR)) || exit 1 - readelf -wi $(TMPDIR)/foo | grep $(HERE) || exit 1 # expected: `grep $(HERE)` to exit 1 + readelf -wi $(TMPDIR)/foo | (! grep $(HERE)) || exit 1 ls $(TMPDIR)/*.o && exit 1 || exit 0 ls $(TMPDIR)/*.dwo && exit 1 || exit 0 rm $(TMPDIR)/foo.dwp @@ -380,7 +380,7 @@ unpacked-remapped-scope: --remap-path-prefix $(HERE)=/b \ -Z remap-path-scope=object foo.rs -g readelf -wi $(TMPDIR)/foo | (! grep $(TMPDIR)) || exit 1 - readelf -wi $(TMPDIR)/foo | grep $(HERE) || exit 1 # expected: `grep $(HERE)` to exit 1 + readelf -wi $(TMPDIR)/foo | (! grep $(HERE)) || exit 1 rm $(TMPDIR)/*.o ls $(TMPDIR)/*.dwo && exit 1 || exit 0 ls $(TMPDIR)/*.dwp && exit 1 || exit 0