From 4abed5000b73efdbf12fda2148aa14185461b370 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Mon, 6 Dec 2021 13:46:14 +0000 Subject: [PATCH] Provide .dwo paths to llvm-dwp explicitly --- compiler/rustc_codegen_ssa/src/back/link.rs | 19 ++++++++++++++----- .../run-make-fulldeps/split-dwarf/Makefile | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 638b2a7b5a9..1d0e661fc0a 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -35,7 +35,7 @@ use object::{Architecture, BinaryFormat, Endianness, FileFlags, SectionFlags, Se 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}; @@ -639,15 +639,17 @@ 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` /// 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, dwo_files: I) +where + I: IntoIterator>, +{ 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(dwo_files); let mut new_path = sess.get_tools_search_paths(false); if let Some(path) = env::var_os("PATH") { @@ -1031,7 +1033,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 .dwo paths in the exectuable because they may have been + // remapped by --remap-path-prefix and therefore invalid. So we need to provide + // the .dwo paths explicitly + SplitDebuginfo::Packed => link_dwarf_object( + sess, + &out_filename, + codegen_results.modules.iter().filter_map(|m| m.dwarf_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 5fef8eac352..c5f649a13b4 100644 --- a/src/test/run-make-fulldeps/split-dwarf/Makefile +++ b/src/test/run-make-fulldeps/split-dwarf/Makefile @@ -5,10 +5,10 @@ all: packed remapped remapped: - $(RUSTC) -Z unstable-options -C split-debuginfo=packed -C debuginfo=2 --remap-path-prefix $$PWD= foo.rs -g + $(RUSTC) -Z unstable-options -C split-debuginfo=packed -C debuginfo=2 --remap-path-prefix $$PWD=/a foo.rs -g objdump -Wi $(TMPDIR)/foo | grep $$PWD && exit 1 || exit 0 - $(RUSTC) -Z unstable-options -C split-debuginfo=unpacked -C debuginfo=2 --remap-path-prefix $$PWD= foo.rs -g + $(RUSTC) -Z unstable-options -C split-debuginfo=unpacked -C debuginfo=2 --remap-path-prefix $$PWD=/a foo.rs -g objdump -Wi $(TMPDIR)/foo | grep $$PWD && exit 1 || exit 0 packed: