Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4fa22f1

Browse files
committedDec 8, 2023
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 f84ef00 commit 4fa22f1

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
@@ -851,9 +851,22 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
851851
// FIXME(#41252) Remove "clang LLVM" if we can get GDB and LLVM to play nice.
852852
let producer = format!("clang LLVM ({rustc_producer})");
853853

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

‎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)
Please sign in to comment.