Skip to content

Commit 10d6124

Browse files
committed
fix(trim-paths): remove SO symbols when unsplit-debuginfo specified
`SO` (`N_SO`) debug symbols are always embedded in the executables on macOS even when debuginfo is splitted. Here is a hack that when the scope of `unsplit-debuginfo` is present, we trim them before passing the rustc working directory to LLVM when creating `DIFile`. (After all `SO` symbols are are sort of "unsplit" debuginfo")
1 parent b5bed8f commit 10d6124

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,18 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
853853

854854
use rustc_session::RemapFileNameExt;
855855
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();
856+
let work_dir = if tcx.sess.target.is_like_osx {
857+
// `SO` (`N_SO`) debug symbols are always embedded in the executables on macOS even when
858+
// debuginfo is splitted. Here is a hack that when the scope of `unsplit-debuginfo` is
859+
// present, we trim them. (They are sort of "unsplit" debuginfo")
860+
use rustc_session::config::RemapPathScopeComponents;
861+
tcx.sess.opts.working_dir.for_scope(tcx.sess, RemapPathScopeComponents::UNSPLIT_DEBUGINFO)
862+
} else {
863+
tcx.sess.opts.working_dir.for_codegen(tcx.sess)
864+
}
865+
.to_string_lossy();
866+
debug!(?work_dir);
867+
857868
let flags = "\0";
858869
let output_filenames = tcx.output_filenames(());
859870
let split_name = if tcx.sess.target_can_use_split_dwarf() {

tests/run-make/split-debuginfo/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ packed-remapped-scope:
2424
-Z remap-path-scope=object foo.rs -g
2525
ls $(TMPDIR)/*.o && exit 1 || exit 0
2626
[ -d $(TMPDIR)/foo.dSYM ]
27-
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | grep $(HERE) || exit 1 # expected behavior is (! grep ...)
27+
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (! grep $(HERE)) || exit 1
2828
# As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948
2929
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | grep $(TMPDIR) || exit 1 # expected behavior is (! grep ...)
3030
rm -rf $(TMPDIR)/foo.dSYM
@@ -56,7 +56,7 @@ unpacked-remapped-scope:
5656
-Z remap-path-scope=object foo.rs -g
5757
ls $(TMPDIR)/*.o
5858
[ ! -d $(TMPDIR)/foo.dSYM ]
59-
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (grep $(HERE)) || exit 1 # expected behavior is (! grep ...)
59+
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (! grep $(HERE)) || exit 1
6060
# As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948
6161
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | (grep $(TMPDIR)) || exit 1 # expected behavior is (! grep ...)
6262
rm $(TMPDIR)/*.o

0 commit comments

Comments
 (0)