Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply path remapping to DW_AT_GNU_dwo_name when producing split DWARF #91566

Merged
merged 8 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -901,17 +904,14 @@ pub(crate) unsafe fn codegen(
.generic_activity_with_arg("LLVM_module_codegen_emit_obj", &module.name[..]);

let dwo_out = cgcx.output_filenames.temp_path_dwo(module_name);
let dwo_out = match cgcx.split_debuginfo {
davidtwco marked this conversation as resolved.
Show resolved Hide resolved
// Don't change how DWARF is emitted in single mode (or when disabled).
SplitDebuginfo::Off | SplitDebuginfo::Packed => None,
let dwo_out = if cgcx.target_can_use_split_dwarf
&& cgcx.split_debuginfo != SplitDebuginfo::Off
{
// Emit (a subset of the) DWARF into a separate file in split mode.
SplitDebuginfo::Unpacked => {
if cgcx.target_can_use_split_dwarf {
Some(dwo_out.as_path())
} else {
None
}
}
Some(dwo_out.as_path())
} else {
// Don't change how DWARF is emitted in single mode (or when disabled).
None
};

with_codegen(tm, llmod, config.no_builtins, |cpm| {
Expand Down Expand Up @@ -948,7 +948,7 @@ pub(crate) unsafe fn codegen(

Ok(module.into_compiled_module(
config.emit_obj != EmitObj::None,
cgcx.target_can_use_split_dwarf && cgcx.split_debuginfo == SplitDebuginfo::Unpacked,
davidtwco marked this conversation as resolved.
Show resolved Hide resolved
cgcx.target_can_use_split_dwarf && cgcx.split_debuginfo != SplitDebuginfo::Off,
config.emit_bc,
&cgcx.output_filenames,
))
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
19 changes: 14 additions & 5 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<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(dwo_files);

let mut new_path = sess.get_tools_search_paths(false);
if let Some(path) = env::var_os("PATH") {
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion src/test/run-make-fulldeps/split-dwarf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)