about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-12-18 14:49:38 +0100
committerGitHub <noreply@github.com>2021-12-18 14:49:38 +0100
commit1c42199c8f62a4b4df6c71a047b28d1cbb075c7f (patch)
treecaf29580777bb9efb0c9200a8ab92029cd682555
parentd3f300477b89e70dd42379ba53c0e8ff74e9c694 (diff)
parent5e481d07d2f962cda0bdb76a1e6c19d99c1be847 (diff)
downloadrust-1c42199c8f62a4b4df6c71a047b28d1cbb075c7f.tar.gz
rust-1c42199c8f62a4b4df6c71a047b28d1cbb075c7f.zip
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
-rw-r--r--compiler/rustc_codegen_llvm/src/back/write.rs5
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs4
-rw-r--r--compiler/rustc_codegen_ssa/src/back/link.rs21
-rw-r--r--src/test/run-make-fulldeps/split-dwarf/Makefile11
4 files changed, 31 insertions, 10 deletions
diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs
index 3fceb2ac4ed..224fcb66df8 100644
--- a/compiler/rustc_codegen_llvm/src/back/write.rs
+++ b/compiler/rustc_codegen_llvm/src/back/write.rs
@@ -205,8 +205,11 @@ pub fn target_machine_factory(
     let use_init_array =
         !sess.opts.debugging_opts.use_ctors_section.unwrap_or(sess.target.use_ctors_section);
 
+    let path_mapping = sess.source_map().path_mapping().clone();
+
     Arc::new(move |config: TargetMachineFactoryConfig| {
-        let split_dwarf_file = config.split_dwarf_file.unwrap_or_default();
+        let split_dwarf_file =
+            path_mapping.map_prefix(config.split_dwarf_file.unwrap_or_default()).0;
         let split_dwarf_file = CString::new(split_dwarf_file.to_str().unwrap()).unwrap();
 
         let tm = unsafe {
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
index cc39332d198..c2d4621661f 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
@@ -1055,11 +1055,11 @@ pub fn compile_unit_metadata(
     let work_dir = tcx.sess.opts.working_dir.to_string_lossy(FileNameDisplayPreference::Remapped);
     let flags = "\0";
     let output_filenames = tcx.output_filenames(());
-    let out_dir = &output_filenames.out_directory;
     let split_name = if tcx.sess.target_can_use_split_dwarf() {
         output_filenames
             .split_dwarf_path(tcx.sess.split_debuginfo(), Some(codegen_unit_name))
-            .map(|f| out_dir.join(f))
+            // We get a path relative to the working directory from split_dwarf_path
+            .map(|f| tcx.sess.source_map().path_mapping().map_prefix(f).0)
     } else {
         None
     }
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index e29c109f12d..6271d75e635 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -32,7 +32,7 @@ use cc::windows_registry;
 use regex::Regex;
 use tempfile::Builder as TempFileBuilder;
 
-use std::ffi::OsString;
+use std::ffi::{OsStr, OsString};
 use std::lazy::OnceCell;
 use std::path::{Path, PathBuf};
 use std::process::{ExitStatus, Output, Stdio};
@@ -504,17 +504,19 @@ fn escape_stdout_stderr_string(s: &[u8]) -> String {
 
 const LLVM_DWP_EXECUTABLE: &'static str = "rust-llvm-dwp";
 
-/// Invoke `llvm-dwp` (shipped alongside rustc) to link `dwo` files from Split DWARF into a `dwp`
+/// Invoke `llvm-dwp` (shipped alongside rustc) to link debuginfo in object files into a `dwp`
 /// file.
-fn link_dwarf_object<'a>(sess: &'a Session, executable_out_filename: &Path) {
+fn link_dwarf_object<'a, I>(sess: &'a Session, executable_out_filename: &Path, object_files: I)
+where
+    I: IntoIterator<Item: AsRef<OsStr>>,
+{
     info!("preparing dwp to {}.dwp", executable_out_filename.to_str().unwrap());
 
     let dwp_out_filename = executable_out_filename.with_extension("dwp");
     let mut cmd = Command::new(LLVM_DWP_EXECUTABLE);
-    cmd.arg("-e");
-    cmd.arg(executable_out_filename);
     cmd.arg("-o");
     cmd.arg(&dwp_out_filename);
+    cmd.args(object_files);
 
     let mut new_path = sess.get_tools_search_paths(false);
     if let Some(path) = env::var_os("PATH") {
@@ -898,7 +900,14 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
         SplitDebuginfo::Packed if sess.target.is_like_msvc => {}
 
         // ... and otherwise we're processing a `*.dwp` packed dwarf file.
-        SplitDebuginfo::Packed => link_dwarf_object(sess, &out_filename),
+        // We cannot rely on the .o paths in the exectuable because they may have been
+        // remapped by --remap-path-prefix and therefore invalid. So we need to provide
+        // the .o paths explicitly
+        SplitDebuginfo::Packed => link_dwarf_object(
+            sess,
+            &out_filename,
+            codegen_results.modules.iter().filter_map(|m| m.object.as_ref()),
+        ),
     }
 
     let strip = strip_value(sess);
diff --git a/src/test/run-make-fulldeps/split-dwarf/Makefile b/src/test/run-make-fulldeps/split-dwarf/Makefile
index ef61ff04501..eef04c767fb 100644
--- a/src/test/run-make-fulldeps/split-dwarf/Makefile
+++ b/src/test/run-make-fulldeps/split-dwarf/Makefile
@@ -2,7 +2,16 @@
 
 # only-linux
 
-all:
+all: packed remapped
+
+remapped:
+	$(RUSTC) -Z unstable-options -C split-debuginfo=packed -C debuginfo=2 --remap-path-prefix $(TMPDIR)=/a foo.rs -g
+	objdump -Wi $(TMPDIR)/foo | grep DW_AT_GNU_dwo_name | (! grep $(TMPDIR)) || exit 1
+
+	$(RUSTC) -Z unstable-options -C split-debuginfo=unpacked -C debuginfo=2 --remap-path-prefix $(TMPDIR)=/a foo.rs -g
+	objdump -Wi $(TMPDIR)/foo | grep DW_AT_GNU_dwo_name | (! grep $(TMPDIR)) || exit 1
+
+packed:
 	$(RUSTC) -Z unstable-options -C split-debuginfo=packed -C debuginfo=2 foo.rs -g
 	rm $(TMPDIR)/foo.dwp
 	rm $(TMPDIR)/$(call BIN,foo)