Skip to content

Commit 674cdaf

Browse files
committed
fix(trim-paths): remove SO symbols for object scope
Even when when debuginfo is splitted, `SO` debug symbols are still embedded in executables on macOS. Therefore, we trim them when the scope of `object` is present, as it is expected no path embedded in final executables when `object` scope applied.
1 parent 3a9c9fe commit 674cdaf

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -846,14 +846,16 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
846846
name_in_debuginfo.push("@");
847847
name_in_debuginfo.push(codegen_unit_name);
848848

849-
debug!("build_compile_unit_di_node: {:?}", name_in_debuginfo);
850849
let rustc_producer = format!("rustc version {}", tcx.sess.cfg_version);
851850
// FIXME(#41252) Remove "clang LLVM" if we can get GDB and LLVM to play nice.
852851
let producer = format!("clang LLVM ({rustc_producer})");
853852

854853
use rustc_session::RemapFileNameExt;
855854
let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
856855
let work_dir = tcx.sess.opts.working_dir.for_codegen(tcx.sess).to_string_lossy();
856+
debug!(?work_dir, "build_compile_unit_di_node");
857+
debug!(?name_in_debuginfo, "build_compile_unit_di_node");
858+
857859
let flags = "\0";
858860
let output_filenames = tcx.output_filenames(());
859861
let split_name = if tcx.sess.target_can_use_split_dwarf() {

compiler/rustc_session/src/session.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,15 @@ impl Session {
12551255
prefer_remapped |= has_split_debuginfo;
12561256
}
12571257

1258+
if self.target.is_like_osx && remap_path_scopes.contains(RemapPathScopeComponents::OBJECT) {
1259+
// HACK: Even when when debuginfo is splitted,
1260+
// `SO` debug symbols are still embedded in executables on macOS.
1261+
// Therefore, we trim them when the scope of `object` is present,
1262+
// as it is expected no path embedded in final executables
1263+
// when `object` scope applied.
1264+
prefer_remapped |= true;
1265+
}
1266+
12581267
prefer_remapped
12591268
}
12601269

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)