Skip to content

Commit 930905c

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 a55de2b commit 930905c

File tree

2 files changed

+58
-56
lines changed

2 files changed

+58
-56
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

+43-54
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,17 @@ packed-remapped-object-scope:
3131
# binary contains remapped paths
3232
# FIXME: As of 2023-12, `OSO` cannot be trimmed. See rust-lang/rust#116948
3333
(! grep --text $(REMAPPED_OUT) $(TMPDIR)/foo) || exit 1
34-
# FIXME: `SO` in the root debuginfo compile unit didn't get trimed. See rust-lang/rust#116948
35-
(! grep --text $(REMAPPED_CWD) $(TMPDIR)/foo) || exit 1
34+
grep --text $(REMAPPED_CWD) $(TMPDIR)/foo || exit 1
3635

3736
# binary contains no original paths
3837
# FIXME: As of 2023-12, `OSO` cannot be trimmed. See rust-lang/rust#116948
3938
grep --text $(TMPDIR) $(TMPDIR)/foo || exit 1
40-
# FIXME: `SO` in the root debuginfo compile unit didn't get trimed. See rust-lang/rust#116948
41-
grep --text $(HERE) $(TMPDIR)/foo || exit 1
39+
(! grep --text $(HERE) $(TMPDIR)/foo) || exit 1
4240

4341
# dSYM bundle contains no remapped paths
4442
(! grep --text $(REMAPPED_OUT) $(TMPDIR)/foo.dSYM/Contents/Resources/DWARF/foo) || exit 1
45-
(! grep --text $(REMAPPED_CWD) $(TMPDIR)/foo.dSYM/Contents/Resources/DWARF/foo) || exit 1
43+
# FIXME: dSYM bundle contains `DW_AT_comp_dir` in debug symbol, which shouldn't be remapped.
44+
grep --text $(REMAPPED_CWD) $(TMPDIR)/foo.dSYM/Contents/Resources/DWARF/foo
4645

4746
# dSYM bundle contains original paths
4847
grep --text $(HERE) $(TMPDIR)/foo.dSYM/Contents/Resources/DWARF/foo || exit 1
@@ -92,22 +91,20 @@ packed-remapped-split-debuginfo-scope:
9291

9392
# binary contains no remapped paths
9493
(! grep --text $(REMAPPED_OUT) $(TMPDIR)/foo) || exit 1
95-
# FIXME: binary contains `N_SO` (SO) in debug symbol, which got remapped.
96-
nm -pa $(TMPDIR)/foo | grep " SO " | grep $(REMAPPED_CWD) || exit 1
97-
nm -pa $(TMPDIR)/foo | grep --invert-match " SO " | (! grep $(REMAPPED_CWD)) || exit 1
94+
(! grep --text $(REMAPPED_CWD) $(TMPDIR)/foo) || exit 1
9895

9996
# binary contains original paths
10097
# FIXME: As of 2023-12, `OSO` cannot be trimmed. See rust-lang/rust#116948
10198
grep --text $(TMPDIR) $(TMPDIR)/foo || exit 1
102-
# FIXME: binary contains `N_SO` (SO) in debug symbol, which got remapped.
103-
(! grep --text $(HERE) $(TMPDIR)/foo) || exit 1
99+
grep --text $(HERE) $(TMPDIR)/foo || exit 1
104100

105101
## dSYM bundle contains remapped paths
106102
grep --text $(REMAPPED_CWD) $(TMPDIR)/foo.dSYM/Contents/Resources/DWARF/foo || exit 1
107103

108104
## dSYM bundle contains no original paths
109105
(! grep --text $(TMPDIR) $(TMPDIR)/foo.dSYM/Contents/Resources/DWARF/foo) || exit 1
110-
(! grep --text $(HERE) $(TMPDIR)/foo.dSYM/Contents/Resources/DWARF/foo) || exit 1
106+
# FIXME: dSYM bundle contains `DW_AT_comp_dir` in debug symbol, which should be remapped.
107+
grep --text $(HERE) $(TMPDIR)/foo.dSYM/Contents/Resources/DWARF/foo
111108

112109
rm -rf $(TMPDIR)/foo.dSYM
113110
rm $(TMPDIR)/$(call BIN,foo)
@@ -129,18 +126,17 @@ unpacked-remapped-object-scope:
129126
# binary contains remapped paths
130127
# FIXME: As of 2023-12, `OSO` cannot be trimmed. See rust-lang/rust#116948
131128
(! grep --text $(REMAPPED_OUT) $(TMPDIR)/foo) || exit 1
132-
# FIXME: `SO` in the root debuginfo compile unit didn't get trimed. See rust-lang/rust#116948
133-
(! grep --text $(REMAPPED_CWD) $(TMPDIR)/foo) || exit 1
129+
grep --text $(REMAPPED_CWD) $(TMPDIR)/foo || exit 1
134130

135131
# binary contains no original paths
136132
# FIXME: As of 2023-12, `OSO` cannot be trimmed. See rust-lang/rust#116948
137133
grep --text $(TMPDIR) $(TMPDIR)/foo || exit 1
138-
# FIXME: `SO` in the root debuginfo compile unit didn't get trimed. See rust-lang/rust#116948
139-
grep --text $(HERE) $(TMPDIR)/foo || exit 1
134+
(! grep --text $(HERE) $(TMPDIR)/foo) || exit 1
140135

141136
# object file contains no remapped paths
142137
(! grep --text $(REMAPPED_OUT) $(TMPDIR)/foo.*.o) || exit 1
143-
(! grep --text $(REMAPPED_CWD) $(TMPDIR)/foo.*.o) || exit 1
138+
# FIXME: object file contains `DW_AT_comp_dir` in debug symbol, which should be remapped.
139+
grep --text $(REMAPPED_CWD) $(TMPDIR)/foo.*.o || exit 1
144140

145141
# object file contains original paths
146142
grep --text $(HERE) $(TMPDIR)/foo.*.o || exit 1
@@ -190,21 +186,19 @@ unpacked-remapped-split-debuginfo-scope:
190186

191187
# binary contains no remapped paths
192188
(! grep --text $(REMAPPED_OUT) $(TMPDIR)/foo) || exit 1
193-
# FIXME: binary contains `N_SO` (SO) in debug symbol, which got remapped.
194-
nm -pa $(TMPDIR)/foo | grep " SO " | grep $(REMAPPED_CWD) || exit 1
195-
nm -pa $(TMPDIR)/foo | grep --invert-match " SO " | (! grep $(REMAPPED_CWD)) || exit 1
189+
(! grep --text $(REMAPPED_CWD) $(TMPDIR)/foo) || exit 1
196190

197191
# binary contains original paths
198192
grep --text $(TMPDIR) $(TMPDIR)/foo || exit 1
199-
# FIXME: binary contains `N_SO` (SO) in debug symbol, which got remapped.
200-
(! grep --text $(HERE) $(TMPDIR)/foo) || exit 1
193+
grep --text $(HERE) $(TMPDIR)/foo || exit 1
201194

202195
# object file contains remapped paths
203196
grep --text $(REMAPPED_CWD) $(TMPDIR)/foo.*.o || exit 1
204197

205198
# object file contains no original paths
206199
(! grep --text $(TMPDIR) $(TMPDIR)/foo.*.o) || exit 1
207-
(! grep --text $(HERE) $(TMPDIR)/foo.*.o) || exit 1
200+
# FIXME: object file contains `DW_AT_comp_dir` in debug symbol, which should be remapped.
201+
grep --text $(HERE) $(TMPDIR)/foo.*.o || exit 1
208202

209203
rm $(TMPDIR)/*.o
210204
rm $(TMPDIR)/$(call BIN,foo)
@@ -366,14 +360,12 @@ packed-remapped-object-scope:
366360

367361
# binary contains remapped paths
368362
grep --text $(REMAPPED_OUT) $(TMPDIR)/foo || exit 1
369-
# FIXME: binary contains `DW_AT_comp_dir` in debug symbol, which should be remapped.
370-
(! grep --text $(REMAPPED_CWD) $(TMPDIR)/foo) || exit 1
363+
grep --text $(REMAPPED_CWD) $(TMPDIR)/foo || exit 1
371364

372365
# binary contains no original paths
373366
(! grep --text $(TMPDIR) $(TMPDIR)/foo) || exit 1
374-
# FIXME: bnary contains `DW_AT_comp_dir` in debug symbol, which should be remapped.
375-
readelf -wi $(TMPDIR)/foo | grep "DW_AT_comp_dir" | grep $(HERE) || exit 1
376-
readelf -wi $(TMPDIR)/foo | grep --invert-match "DW_AT_comp_dir" | (! grep $(HERE)) || exit 1
367+
# FIXME: binary contains `.debug-line` in debug symbol, which didn't get remapped.
368+
readelf -wl $(TMPDIR)/foo | grep $(HERE) || exit 1
377369

378370
# dwp contains no remapped paths
379371
(! grep --text $(REMAPPED_CWD) $(TMPDIR)/foo.dwp) || exit 1
@@ -434,14 +426,13 @@ packed-remapped-split-debuginfo-scope:
434426
# binary contains remapped dwo path
435427
readelf -wi $(TMPDIR)/foo | grep "DW_AT_GNU_dwo_name" | grep $(REMAPPED_OUT) || exit 1
436428
readelf -wi $(TMPDIR)/foo | grep --invert-match "DW_AT_GNU_dwo_name" | (! grep $(REMAPPED_OUT)) || exit 1
437-
# FIXME: binary contains `DW_AT_comp_dir` in debug symbol, which got remapped.
438-
readelf -wi $(TMPDIR)/foo | grep "DW_AT_comp_dir" | grep $(REMAPPED_CWD) || exit 1
439-
readelf -wi $(TMPDIR)/foo | grep --invert-match "DW_AT_comp_dir" | (! grep $(REMAPPED_CWD)) || exit 1
429+
# binary contains no remapped cwd path
430+
# FIXME: binary contains `.debug-line` in debug symbol, which got remapped.
431+
readelf -wl $(TMPDIR)/foo | grep $(REMAPPED_CWD) || exit 1
440432

441433
# binary contains no original --out-dir (DW_AT_GNU_dwo_name was remapped)
442434
(! grep --text $(TMPDIR) $(TMPDIR)/foo) || exit 1
443-
# FIXME: binary contains `DW_AT_comp_dir` in debug symbol, which got remapped.
444-
(! grep --text $(HERE) $(TMPDIR)/foo) || exit 1
435+
grep --text $(HERE) $(TMPDIR)/foo || exit 1
445436

446437
# dwp contains remapped paths
447438
grep --text $(REMAPPED_OUT) $(TMPDIR)/foo.dwp || exit 1
@@ -634,14 +625,12 @@ unpacked-remapped-object-scope-split:
634625

635626
# binary contains remapped paths
636627
grep --text $(REMAPPED_OUT) $(TMPDIR)/foo || exit 1
637-
# FIXME: binary should contains no cwd but now it got `DW_AT_comp_dir`
638-
(! grep --text $(REMAPPED_CWD) $(TMPDIR)/foo) || exit 1
628+
grep --text $(REMAPPED_CWD) $(TMPDIR)/foo || exit 1
639629

640630
# binary contains no original paths
641631
(! grep --text $(TMPDIR) $(TMPDIR)/foo) || exit 1
642-
# FIXME: binary contains `DW_AT_comp_dir` in debug symbol, which didn't get remapped.
643-
readelf -wi $(TMPDIR)/foo | grep "DW_AT_comp_dir" | grep $(HERE) || exit 1
644-
readelf -wi $(TMPDIR)/foo | grep --invert-match "DW_AT_comp_dir" | (! grep $(HERE)) || exit 1
632+
# FIXME: binary contains `.debug-line` in debug symbol, which didn't get remapped.
633+
readelf -wl $(TMPDIR)/foo | grep $(HERE) || exit 1
645634

646635
# dwo contains no remapped paths
647636
(! grep --text $(REMAPPED_CWD) $(TMPDIR)/foo.*.dwo) || exit 1
@@ -672,17 +661,16 @@ unpacked-remapped-object-scope-single:
672661

673662
# binary contains remapped paths
674663
grep --text $(REMAPPED_OUT) $(TMPDIR)/foo || exit 1
675-
# FIXME: binary should contains no cwd but now it got `DW_AT_comp_dir`
676-
(! grep --text $(REMAPPED_CWD) $(TMPDIR)/foo) || exit 1
664+
grep --text $(REMAPPED_CWD) $(TMPDIR)/foo || exit 1
677665

678666
# binary contains no original paths
679667
(! grep --text $(TMPDIR) $(TMPDIR)/foo) || exit 1
680-
# FIXME: binary contains `DW_AT_comp_dir` in debug symbol, which didn't get remapped.
681-
readelf -wi $(TMPDIR)/foo | grep "DW_AT_comp_dir" | grep $(HERE) || exit 1
682-
readelf -wi $(TMPDIR)/foo | grep --invert-match "DW_AT_comp_dir" | (! grep $(HERE)) || exit 1
668+
# FIXME: binary contains `.debug-line` in debug symbol, which didn't get remapped.
669+
readelf -wl $(TMPDIR)/foo | grep $(HERE) || exit 1
683670

684671
# object file contains no remapped paths
685-
(! grep --text $(REMAPPED_CWD) $(TMPDIR)/foo.*.o) || exit 1
672+
# FIXME: object file contains `.debug-line` in debug symbol, which didn't get remapped.
673+
readelf -wl $(TMPDIR)/foo | grep $(HERE) || exit 1
686674
# FIXME: object file contains `DW_AT_GNU_dwo_name` in debug symbol, which got remapped.
687675
readelf -wi $(TMPDIR)/foo.*.o | grep "DW_AT_GNU_dwo_name" | grep $(REMAPPED_OUT) || exit 1
688676
readelf -wi $(TMPDIR)/foo.*.o | grep --invert-match "DW_AT_GNU_dwo_name" | (! grep $(REMAPPED_OUT)) || exit 1
@@ -779,14 +767,14 @@ unpacked-remapped-split-debuginfo-scope-split:
779767
# binary contains remapped dwo path
780768
readelf -wi $(TMPDIR)/foo | grep "DW_AT_GNU_dwo_name" | grep $(REMAPPED_OUT) || exit 1
781769
readelf -wi $(TMPDIR)/foo | grep --invert-match "DW_AT_GNU_dwo_name" | (! grep $(REMAPPED_OUT)) || exit 1
782-
# FIXME: binary contains `DW_AT_comp_dir` in debug symbol, which got remapped.
783-
readelf -wi $(TMPDIR)/foo | grep "DW_AT_comp_dir" | grep $(REMAPPED_CWD) || exit 1
784-
readelf -wi $(TMPDIR)/foo | grep --invert-match "DW_AT_comp_dir" | (! grep $(REMAPPED_CWD)) || exit 1
770+
# binary contains no remapped cwd path
771+
# FIXME: binary contains `.debug-line` in debug symbol, which got remapped.
772+
readelf -wl $(TMPDIR)/foo | grep $(REMAPPED_CWD) || exit 1
785773

786774
# binary contains no original --out-dir (DW_AT_GNU_dwo_name was remapped)
787775
(! grep --text $(TMPDIR) $(TMPDIR)/foo) || exit 1
788-
# FIXME: binary contains `DW_AT_comp_dir` in debug symbol, which got remapped.
789-
(! grep --text $(HERE) $(TMPDIR)/foo) || exit 1
776+
# binary contains original cwd path
777+
grep --text $(HERE) $(TMPDIR)/foo || exit 1
790778

791779
# dwo contains remapped paths
792780
grep --text $(REMAPPED_OUT) $(TMPDIR)/foo.*.dwo || exit 1
@@ -814,21 +802,22 @@ unpacked-remapped-split-debuginfo-scope-single:
814802
# binary contains remapped dwo path
815803
readelf -wi $(TMPDIR)/foo | grep "DW_AT_GNU_dwo_name" | grep $(REMAPPED_OUT) || exit 1
816804
readelf -wi $(TMPDIR)/foo | grep --invert-match "DW_AT_GNU_dwo_name" | (! grep $(REMAPPED_OUT)) || exit 1
817-
# FIXME: binary contains `DW_AT_comp_dir` in debug symbol, which got remapped.
818-
readelf -wi $(TMPDIR)/foo | grep "DW_AT_comp_dir" | grep $(REMAPPED_CWD) || exit 1
819-
readelf -wi $(TMPDIR)/foo | grep --invert-match "DW_AT_comp_dir" | (! grep $(REMAPPED_CWD)) || exit 1
805+
# binary contains no remapped cwd path
806+
# FIXME: binary contains `.debug-line` in debug symbol, which got remapped.
807+
readelf -wl $(TMPDIR)/foo | grep $(REMAPPED_CWD) || exit 1
820808

821809
# binary contains no original --out-dir (DW_AT_GNU_dwo_name was remapped)
822810
(! grep --text $(TMPDIR) $(TMPDIR)/foo) || exit 1
823-
# FIXME: binary contains `DW_AT_comp_dir` in debug symbol, which got remapped.
824-
(! grep --text $(HERE) $(TMPDIR)/foo) || exit 1
811+
# binary contains original cwd path
812+
grep --text $(HERE) $(TMPDIR)/foo || exit 1
825813

826814
# object file contains remapped paths
827815
grep --text $(REMAPPED_OUT) $(TMPDIR)/foo.*.o || exit 1
828816

829817
# object file contains no original paths
830818
(! grep --text $(TMPDIR) $(TMPDIR)/foo.*.o) || exit 1
831-
(! grep --text $(HERE) $(TMPDIR)/foo.*.o) || exit 1
819+
# FIXME: object file contains `DW_AT_comp_dir` in debug symbol, which should be remapped.
820+
grep --text $(HERE) $(TMPDIR)/foo.*.o || exit 1
832821

833822
rm $(TMPDIR)/*.o
834823
ls $(TMPDIR)/*.dwo && exit 1 || exit 0

0 commit comments

Comments
 (0)