Skip to content

Commit

Permalink
fix(trim-paths): remove SO symbols for object scope
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
weihanglo committed Dec 5, 2023
1 parent 3a9c9fe commit 674cdaf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,14 +846,16 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
name_in_debuginfo.push("@");
name_in_debuginfo.push(codegen_unit_name);

debug!("build_compile_unit_di_node: {:?}", name_in_debuginfo);
let rustc_producer = format!("rustc version {}", tcx.sess.cfg_version);
// 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!(?work_dir, "build_compile_unit_di_node");
debug!(?name_in_debuginfo, "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
9 changes: 9 additions & 0 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,15 @@ impl Session {
prefer_remapped |= has_split_debuginfo;
}

if self.target.is_like_osx && remap_path_scopes.contains(RemapPathScopeComponents::OBJECT) {
// HACK: 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.
prefer_remapped |= true;
}

prefer_remapped
}

Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/split-debuginfo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ packed-remapped-scope:
-Z remap-path-scope=object foo.rs -g
ls $(TMPDIR)/*.o && exit 1 || exit 0
[ -d $(TMPDIR)/foo.dSYM ]
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | grep $(HERE) || exit 1 # expected behavior is (! grep ...)
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (! grep $(HERE)) || exit 1
# As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | grep $(TMPDIR) || exit 1 # expected behavior is (! grep ...)
rm -rf $(TMPDIR)/foo.dSYM
Expand Down Expand Up @@ -56,7 +56,7 @@ unpacked-remapped-scope:
-Z remap-path-scope=object foo.rs -g
ls $(TMPDIR)/*.o
[ ! -d $(TMPDIR)/foo.dSYM ]
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (grep $(HERE)) || exit 1 # expected behavior is (! grep ...)
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (! grep $(HERE)) || exit 1
# As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | (grep $(TMPDIR)) || exit 1 # expected behavior is (! grep ...)
rm $(TMPDIR)/*.o
Expand Down

0 comments on commit 674cdaf

Please sign in to comment.