Skip to content

Commit 6f13ea0

Browse files
committed
Auto merge of #115704 - nebulark:s_object, r=nagisa
Pass name of object file to LLVM so it can correctly emit S_OBJNAME in pdb files on Windows This should be the remaining fix to close #96475 Setting ObjectFilenameForDebug in llvm::TargetOptions, so llvm it can emit S_OBJNAME in pdb files on Windows. Without a proper pdb parsing I am not able to add a unit test for this. The string is already appearing in the pdb file so I cannot just use grep. `@rustbot` label: +A-debuginfo
2 parents 7bf47a4 + 91544e6 commit 6f13ea0

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl OwnedTargetMachine {
3737
relax_elf_relocations: bool,
3838
use_init_array: bool,
3939
split_dwarf_file: &CStr,
40+
output_obj_file: &CStr,
4041
debug_info_compression: &CStr,
4142
force_emulated_tls: bool,
4243
args_cstr_buff: &[u8],
@@ -68,6 +69,7 @@ impl OwnedTargetMachine {
6869
relax_elf_relocations,
6970
use_init_array,
7071
split_dwarf_file.as_ptr(),
72+
output_obj_file.as_ptr(),
7173
debug_info_compression.as_ptr(),
7274
force_emulated_tls,
7375
args_cstr_buff.as_ptr() as *const c_char,

compiler/rustc_codegen_llvm/src/back/write.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub fn write_output_file<'ll>(
100100
}
101101

102102
pub fn create_informational_target_machine(sess: &Session) -> OwnedTargetMachine {
103-
let config = TargetMachineFactoryConfig { split_dwarf_file: None };
103+
let config = TargetMachineFactoryConfig { split_dwarf_file: None, output_obj_file: None };
104104
// Can't use query system here quite yet because this function is invoked before the query
105105
// system/tcx is set up.
106106
let features = llvm_util::global_llvm_features(sess, false);
@@ -118,7 +118,11 @@ pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> OwnedTargetMach
118118
} else {
119119
None
120120
};
121-
let config = TargetMachineFactoryConfig { split_dwarf_file };
121+
122+
let output_obj_file =
123+
Some(tcx.output_filenames(()).temp_path(OutputType::Object, Some(mod_name)));
124+
let config = TargetMachineFactoryConfig { split_dwarf_file, output_obj_file };
125+
122126
target_machine_factory(
123127
&tcx.sess,
124128
tcx.backend_optimization_level(()),
@@ -256,9 +260,13 @@ pub fn target_machine_factory(
256260
let debuginfo_compression = SmallCStr::new(&debuginfo_compression);
257261

258262
Arc::new(move |config: TargetMachineFactoryConfig| {
259-
let split_dwarf_file =
260-
path_mapping.map_prefix(config.split_dwarf_file.unwrap_or_default()).0;
261-
let split_dwarf_file = CString::new(split_dwarf_file.to_str().unwrap()).unwrap();
263+
let path_to_cstring_helper = |path: Option<PathBuf>| -> CString {
264+
let path = path_mapping.map_prefix(path.unwrap_or_default()).0;
265+
CString::new(path.to_str().unwrap()).unwrap()
266+
};
267+
268+
let split_dwarf_file = path_to_cstring_helper(config.split_dwarf_file);
269+
let output_obj_file = path_to_cstring_helper(config.output_obj_file);
262270

263271
OwnedTargetMachine::new(
264272
&triple,
@@ -279,6 +287,7 @@ pub fn target_machine_factory(
279287
relax_elf_relocations,
280288
use_init_array,
281289
&split_dwarf_file,
290+
&output_obj_file,
282291
&debuginfo_compression,
283292
force_emulated_tls,
284293
&args_cstr_buff,

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,7 @@ extern "C" {
21332133
RelaxELFRelocations: bool,
21342134
UseInitArray: bool,
21352135
SplitDwarfFile: *const c_char,
2136+
OutputObjFile: *const c_char,
21362137
DebugInfoCompression: *const c_char,
21372138
ForceEmulatedTls: bool,
21382139
ArgsCstrBuff: *const c_char,

compiler/rustc_codegen_ssa/src/back/write.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ pub struct TargetMachineFactoryConfig {
286286
/// so the path to the dwarf object has to be provided when we create the target machine.
287287
/// This can be ignored by backends which do not need it for their Split DWARF support.
288288
pub split_dwarf_file: Option<PathBuf>,
289+
290+
/// The name of the output object file. Used for setting OutputFilenames in target options
291+
/// so that LLVM can emit the CodeView S_OBJNAME record in pdb files
292+
pub output_obj_file: Option<PathBuf>,
289293
}
290294

291295
impl TargetMachineFactoryConfig {
@@ -302,7 +306,10 @@ impl TargetMachineFactoryConfig {
302306
} else {
303307
None
304308
};
305-
TargetMachineFactoryConfig { split_dwarf_file }
309+
310+
let output_obj_file =
311+
Some(cgcx.output_filenames.temp_path(OutputType::Object, Some(module_name)));
312+
TargetMachineFactoryConfig { split_dwarf_file, output_obj_file }
306313
}
307314
}
308315

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
416416
bool RelaxELFRelocations,
417417
bool UseInitArray,
418418
const char *SplitDwarfFile,
419+
const char *OutputObjFile,
419420
const char *DebugInfoCompression,
420421
bool ForceEmulatedTls,
421422
const char *ArgsCstrBuff, size_t ArgsCstrBuffLen) {
@@ -448,6 +449,9 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
448449
if (SplitDwarfFile) {
449450
Options.MCOptions.SplitDwarfFile = SplitDwarfFile;
450451
}
452+
if (OutputObjFile) {
453+
Options.ObjectFilenameForDebug = OutputObjFile;
454+
}
451455
#if LLVM_VERSION_GE(16, 0)
452456
if (!strcmp("zlib", DebugInfoCompression) && llvm::compression::zlib::isAvailable()) {
453457
Options.CompressDebugSections = DebugCompressionType::Zlib;

0 commit comments

Comments
 (0)