Skip to content

Commit

Permalink
fix(trim-paths): trim working diretory from root DI node
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
weihanglo committed Dec 8, 2023
1 parent f84ef00 commit 4fa22f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 15 additions & 2 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions tests/run-make/split-debuginfo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4fa22f1

Please sign in to comment.