Skip to content

Commit 1c42199

Browse files
authored
Rollup merge of #91566 - cbeuw:remap-dwo-name, r=davidtwco
Apply path remapping to DW_AT_GNU_dwo_name when producing split DWARF `--remap-path-prefix` doesn't apply to paths to `.o` (in case of packed) or `.dwo` (in case of unpacked) files in `DW_AT_GNU_dwo_name`. GCC also has this bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91888
2 parents d3f3004 + 5e481d0 commit 1c42199

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,11 @@ pub fn target_machine_factory(
205205
let use_init_array =
206206
!sess.opts.debugging_opts.use_ctors_section.unwrap_or(sess.target.use_ctors_section);
207207

208+
let path_mapping = sess.source_map().path_mapping().clone();
209+
208210
Arc::new(move |config: TargetMachineFactoryConfig| {
209-
let split_dwarf_file = config.split_dwarf_file.unwrap_or_default();
211+
let split_dwarf_file =
212+
path_mapping.map_prefix(config.split_dwarf_file.unwrap_or_default()).0;
210213
let split_dwarf_file = CString::new(split_dwarf_file.to_str().unwrap()).unwrap();
211214

212215
let tm = unsafe {

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1055,11 +1055,11 @@ pub fn compile_unit_metadata(
10551055
let work_dir = tcx.sess.opts.working_dir.to_string_lossy(FileNameDisplayPreference::Remapped);
10561056
let flags = "\0";
10571057
let output_filenames = tcx.output_filenames(());
1058-
let out_dir = &output_filenames.out_directory;
10591058
let split_name = if tcx.sess.target_can_use_split_dwarf() {
10601059
output_filenames
10611060
.split_dwarf_path(tcx.sess.split_debuginfo(), Some(codegen_unit_name))
1062-
.map(|f| out_dir.join(f))
1061+
// We get a path relative to the working directory from split_dwarf_path
1062+
.map(|f| tcx.sess.source_map().path_mapping().map_prefix(f).0)
10631063
} else {
10641064
None
10651065
}

compiler/rustc_codegen_ssa/src/back/link.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use cc::windows_registry;
3232
use regex::Regex;
3333
use tempfile::Builder as TempFileBuilder;
3434

35-
use std::ffi::OsString;
35+
use std::ffi::{OsStr, OsString};
3636
use std::lazy::OnceCell;
3737
use std::path::{Path, PathBuf};
3838
use std::process::{ExitStatus, Output, Stdio};
@@ -504,17 +504,19 @@ fn escape_stdout_stderr_string(s: &[u8]) -> String {
504504

505505
const LLVM_DWP_EXECUTABLE: &'static str = "rust-llvm-dwp";
506506

507-
/// Invoke `llvm-dwp` (shipped alongside rustc) to link `dwo` files from Split DWARF into a `dwp`
507+
/// Invoke `llvm-dwp` (shipped alongside rustc) to link debuginfo in object files into a `dwp`
508508
/// file.
509-
fn link_dwarf_object<'a>(sess: &'a Session, executable_out_filename: &Path) {
509+
fn link_dwarf_object<'a, I>(sess: &'a Session, executable_out_filename: &Path, object_files: I)
510+
where
511+
I: IntoIterator<Item: AsRef<OsStr>>,
512+
{
510513
info!("preparing dwp to {}.dwp", executable_out_filename.to_str().unwrap());
511514

512515
let dwp_out_filename = executable_out_filename.with_extension("dwp");
513516
let mut cmd = Command::new(LLVM_DWP_EXECUTABLE);
514-
cmd.arg("-e");
515-
cmd.arg(executable_out_filename);
516517
cmd.arg("-o");
517518
cmd.arg(&dwp_out_filename);
519+
cmd.args(object_files);
518520

519521
let mut new_path = sess.get_tools_search_paths(false);
520522
if let Some(path) = env::var_os("PATH") {
@@ -898,7 +900,14 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
898900
SplitDebuginfo::Packed if sess.target.is_like_msvc => {}
899901

900902
// ... and otherwise we're processing a `*.dwp` packed dwarf file.
901-
SplitDebuginfo::Packed => link_dwarf_object(sess, &out_filename),
903+
// We cannot rely on the .o paths in the exectuable because they may have been
904+
// remapped by --remap-path-prefix and therefore invalid. So we need to provide
905+
// the .o paths explicitly
906+
SplitDebuginfo::Packed => link_dwarf_object(
907+
sess,
908+
&out_filename,
909+
codegen_results.modules.iter().filter_map(|m| m.object.as_ref()),
910+
),
902911
}
903912

904913
let strip = strip_value(sess);

src/test/run-make-fulldeps/split-dwarf/Makefile

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22

33
# only-linux
44

5-
all:
5+
all: packed remapped
6+
7+
remapped:
8+
$(RUSTC) -Z unstable-options -C split-debuginfo=packed -C debuginfo=2 --remap-path-prefix $(TMPDIR)=/a foo.rs -g
9+
objdump -Wi $(TMPDIR)/foo | grep DW_AT_GNU_dwo_name | (! grep $(TMPDIR)) || exit 1
10+
11+
$(RUSTC) -Z unstable-options -C split-debuginfo=unpacked -C debuginfo=2 --remap-path-prefix $(TMPDIR)=/a foo.rs -g
12+
objdump -Wi $(TMPDIR)/foo | grep DW_AT_GNU_dwo_name | (! grep $(TMPDIR)) || exit 1
13+
14+
packed:
615
$(RUSTC) -Z unstable-options -C split-debuginfo=packed -C debuginfo=2 foo.rs -g
716
rm $(TMPDIR)/foo.dwp
817
rm $(TMPDIR)/$(call BIN,foo)

0 commit comments

Comments
 (0)