diff options
| author | bors <bors@rust-lang.org> | 2021-02-23 10:02:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-02-23 10:02:16 +0000 |
| commit | 446d4533e89db04f9568be4199e56b5fce0d176d (patch) | |
| tree | d92d9b66adc9e9d7ac8a1cc022187799297cc4fd | |
| parent | cd64446196a02e593c5f50b8d863161306da43f7 (diff) | |
| parent | 925ed4828d06f298ad0a6fa32550bbefeee72bd1 (diff) | |
| download | rust-446d4533e89db04f9568be4199e56b5fce0d176d.tar.gz rust-446d4533e89db04f9568be4199e56b5fce0d176d.zip | |
Auto merge of #82102 - nagisa:nagisa/fix-dwo-name, r=davidtwco
Set path of the compile unit to the source directory As part of the effort to implement split dwarf debug info, we ended up setting the compile unit location to the output directory rather than the source directory. Furthermore, it seems like we failed to remap the prefixes for this as well! The desired behaviour is to instead set the `DW_AT_GNU_dwo_name` to a path relative to compiler's working directory. This still allows debuggers to find the split dwarf files, while not changing the behaviour of the code that is compiling with regular debug info, and not changing the compiler's behaviour with regards to reproducibility. Fixes #82074 cc `@alexcrichton` `@davidtwco`
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/back/write.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs | 19 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/write.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_session/src/config.rs | 11 | ||||
| m--------- | src/llvm-project | 0 | ||||
| -rw-r--r-- | src/test/codegen/debug-compile-unit-path.rs | 9 | ||||
| -rw-r--r-- | src/test/run-make-fulldeps/split-debuginfo/Makefile | 2 | ||||
| -rw-r--r-- | src/test/run-make-fulldeps/split-dwarf/Makefile | 1 |
8 files changed, 25 insertions, 21 deletions
diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 5f8a11ab94e..c224da7885b 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -94,7 +94,7 @@ pub fn create_informational_target_machine(sess: &Session) -> &'static mut llvm: pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut llvm::TargetMachine { let split_dwarf_file = if tcx.sess.target_can_use_split_dwarf() { tcx.output_filenames(LOCAL_CRATE) - .split_dwarf_filename(tcx.sess.split_debuginfo(), Some(mod_name)) + .split_dwarf_path(tcx.sess.split_debuginfo(), Some(mod_name)) } else { None }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 6e7c0b3e347..d935fc83b72 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -979,7 +979,7 @@ pub fn compile_unit_metadata( // The OSX linker has an idiosyncrasy where it will ignore some debuginfo // if multiple object files with the same `DW_AT_name` are linked together. // As a workaround we generate unique names for each object file. Those do - // not correspond to an actual source file but that should be harmless. + // not correspond to an actual source file but that is harmless. if tcx.sess.target.is_like_osx { name_in_debuginfo.push("@"); name_in_debuginfo.push(codegen_unit_name); @@ -992,17 +992,17 @@ pub fn compile_unit_metadata( let producer = format!("clang LLVM ({})", rustc_producer); let name_in_debuginfo = name_in_debuginfo.to_string_lossy(); + let work_dir = tcx.sess.working_dir.0.to_string_lossy(); let flags = "\0"; - let out_dir = &tcx.output_filenames(LOCAL_CRATE).out_directory; let split_name = if tcx.sess.target_can_use_split_dwarf() { tcx.output_filenames(LOCAL_CRATE) - .split_dwarf_filename(tcx.sess.split_debuginfo(), Some(codegen_unit_name)) + .split_dwarf_path(tcx.sess.split_debuginfo(), Some(codegen_unit_name)) + .map(|f| out_dir.join(f)) } else { None } .unwrap_or_default(); - let out_dir = out_dir.to_str().unwrap(); let split_name = split_name.to_str().unwrap(); // FIXME(#60020): @@ -1024,12 +1024,12 @@ pub fn compile_unit_metadata( assert!(tcx.sess.opts.debuginfo != DebugInfo::None); unsafe { - let file_metadata = llvm::LLVMRustDIBuilderCreateFile( + let compile_unit_file = llvm::LLVMRustDIBuilderCreateFile( debug_context.builder, name_in_debuginfo.as_ptr().cast(), name_in_debuginfo.len(), - out_dir.as_ptr().cast(), - out_dir.len(), + work_dir.as_ptr().cast(), + work_dir.len(), llvm::ChecksumKind::None, ptr::null(), 0, @@ -1038,12 +1038,15 @@ pub fn compile_unit_metadata( let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit( debug_context.builder, DW_LANG_RUST, - file_metadata, + compile_unit_file, producer.as_ptr().cast(), producer.len(), tcx.sess.opts.optimize != config::OptLevel::No, flags.as_ptr().cast(), 0, + // NB: this doesn't actually have any perceptible effect, it seems. LLVM will instead + // put the path supplied to `MCSplitDwarfFile` into the debug info of the final + // output(s). split_name.as_ptr().cast(), split_name.len(), kind, diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index f5ae406faec..09549d0cca9 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -288,7 +288,7 @@ impl TargetMachineFactoryConfig { module_name: &str, ) -> TargetMachineFactoryConfig { let split_dwarf_file = if cgcx.target_can_use_split_dwarf { - cgcx.output_filenames.split_dwarf_filename(cgcx.split_debuginfo, Some(module_name)) + cgcx.output_filenames.split_dwarf_path(cgcx.split_debuginfo, Some(module_name)) } else { None }; diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index e4f7e140281..81d6c3bbdbb 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -667,17 +667,6 @@ impl OutputFilenames { path } - /// Returns the name of the Split DWARF file - this can differ depending on which Split DWARF - /// mode is being used, which is the logic that this function is intended to encapsulate. - pub fn split_dwarf_filename( - &self, - split_debuginfo_kind: SplitDebuginfo, - cgu_name: Option<&str>, - ) -> Option<PathBuf> { - self.split_dwarf_path(split_debuginfo_kind, cgu_name) - .map(|path| path.strip_prefix(&self.out_directory).unwrap_or(&path).to_path_buf()) - } - /// Returns the path for the Split DWARF file - this can differ depending on which Split DWARF /// mode is being used, which is the logic that this function is intended to encapsulate. pub fn split_dwarf_path( diff --git a/src/llvm-project b/src/llvm-project -Subproject 70d09f218d1c84fedabdb74881e214dacd5b0c3 +Subproject 2a054c1e4fb04756b7f0509eeae63289db0df88 diff --git a/src/test/codegen/debug-compile-unit-path.rs b/src/test/codegen/debug-compile-unit-path.rs new file mode 100644 index 00000000000..fcb66e08576 --- /dev/null +++ b/src/test/codegen/debug-compile-unit-path.rs @@ -0,0 +1,9 @@ +// compile-flags: -g --remap-path-prefix={{cwd}}=/cwd/ --remap-path-prefix={{src-base}}=/base/ +// ignore-tidy-linelength +// +// Ensure that we remap the compile unit directory and that we set it to the compilers current +// working directory and not something else. +#![crate_type="rlib"] + +// CHECK-DAG: [[FILE:![0-9]*]] = !DIFile(filename: "/base/debug-compile-unit-path.rs{{.*}}", directory: "/cwd/") +// CHECK-DAG: {{![0-9]*}} = distinct !DICompileUnit({{.*}}file: [[FILE]] diff --git a/src/test/run-make-fulldeps/split-debuginfo/Makefile b/src/test/run-make-fulldeps/split-debuginfo/Makefile index e8e62efe01c..c89f2ae8349 100644 --- a/src/test/run-make-fulldeps/split-debuginfo/Makefile +++ b/src/test/run-make-fulldeps/split-debuginfo/Makefile @@ -1,5 +1,7 @@ -include ../tools.mk +# min-llvm-version: 11.0 + all: off packed unpacked ifeq ($(UNAME),Darwin) diff --git a/src/test/run-make-fulldeps/split-dwarf/Makefile b/src/test/run-make-fulldeps/split-dwarf/Makefile index 93dfc8e76a9..e89cc1b2ede 100644 --- a/src/test/run-make-fulldeps/split-dwarf/Makefile +++ b/src/test/run-make-fulldeps/split-dwarf/Makefile @@ -1,6 +1,7 @@ -include ../tools.mk # only-linux +# min-llvm-version: 11.0 all: $(RUSTC) -Z unstable-options -C split-debuginfo=packed foo.rs -g |
