Skip to content

Commit e15a22c

Browse files
committed
fix(trim-paths): trim working diretory from root 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.
1 parent 872e10d commit e15a22c

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,22 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
852852
// FIXME(#41252) Remove "clang LLVM" if we can get GDB and LLVM to play nice.
853853
let producer = format!("clang LLVM ({rustc_producer})");
854854

855-
use rustc_session::RemapFileNameExt;
856855
let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
857-
let work_dir = tcx.sess.opts.working_dir.for_codegen(tcx.sess).to_string_lossy();
856+
debug!(?name_in_debuginfo, "build_compile_unit_di_node");
857+
858+
// Path of working directory in the root DI node seems to be embedded in
859+
// executables. Hence, we trim them when the scope of `unsplit-debuginfo`
860+
// is present, as if it is kinda a "unsplit" debuginfo.
861+
use rustc_session::config::RemapPathScopeComponents;
862+
use rustc_session::RemapFileNameExt;
863+
let work_dir = tcx
864+
.sess
865+
.opts
866+
.working_dir
867+
.for_scope(tcx.sess, RemapPathScopeComponents::UNSPLIT_DEBUGINFO)
868+
.to_string_lossy();
869+
debug!(?work_dir, "build_compile_unit_di_node");
870+
858871
let output_filenames = tcx.output_filenames(());
859872
let split_name = if tcx.sess.target_can_use_split_dwarf() {
860873
output_filenames

tests/run-make/split-debuginfo/Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ packed-remapped-scope:
2828
[ -d $(TMPDIR)/foo.dSYM ]
2929
# As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948
3030
dsymutil -s $(TMPDIR)/foo | grep $(TMPDIR) || exit 1 # expected: `grep $(TMPDIR)` to exit 1
31-
dsymutil -s $(TMPDIR)/foo | grep $(HERE) || exit 1 # expected: `grep $(HERE)` to exit 1
31+
dsymutil -s $(TMPDIR)/foo | (! grep $(HERE)) || exit 1
3232
rm -rf $(TMPDIR)/foo.dSYM
3333
rm $(TMPDIR)/$(call BIN,foo)
3434

@@ -64,7 +64,7 @@ unpacked-remapped-scope:
6464
[ ! -d $(TMPDIR)/foo.dSYM ]
6565
# As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948
6666
dsymutil -s $(TMPDIR)/foo | grep $(TMPDIR) || exit 1 # expected: `grep $(TMPDIR)` to exit 1
67-
dsymutil -s $(TMPDIR)/foo | grep $(HERE) || exit 1 # expected: `grep $(HERE)` to exit 1
67+
dsymutil -s $(TMPDIR)/foo | (! grep $(HERE)) || exit 1
6868
rm $(TMPDIR)/*.o
6969
rm $(TMPDIR)/$(call BIN,foo)
7070

@@ -210,7 +210,7 @@ packed-remapped-scope:
210210
--remap-path-prefix $(HERE)=/b \
211211
-Z remap-path-scope=object foo.rs -g
212212
readelf -wi $(TMPDIR)/foo | (! grep $(TMPDIR)) || exit 1
213-
readelf -wi $(TMPDIR)/foo | grep $(HERE) || exit 1 # expected: `grep $(HERE)` to exit 1
213+
readelf -wi $(TMPDIR)/foo | (! grep $(HERE)) || exit 1
214214
ls $(TMPDIR)/*.o && exit 1 || exit 0
215215
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
216216
rm $(TMPDIR)/foo.dwp
@@ -380,7 +380,7 @@ unpacked-remapped-scope:
380380
--remap-path-prefix $(HERE)=/b \
381381
-Z remap-path-scope=object foo.rs -g
382382
readelf -wi $(TMPDIR)/foo | (! grep $(TMPDIR)) || exit 1
383-
readelf -wi $(TMPDIR)/foo | grep $(HERE) || exit 1 # expected: `grep $(HERE)` to exit 1
383+
readelf -wi $(TMPDIR)/foo | (! grep $(HERE)) || exit 1
384384
rm $(TMPDIR)/*.o
385385
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
386386
ls $(TMPDIR)/*.dwp && exit 1 || exit 0

0 commit comments

Comments
 (0)