Skip to content

Commit 0f16237

Browse files
committed
Pass name of object file to LLVM so it can correctly emit S_OBJNAME
1 parent 5ede940 commit 0f16237

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

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

101101
pub fn create_informational_target_machine(sess: &Session) -> &'static mut llvm::TargetMachine {
102-
let config = TargetMachineFactoryConfig { split_dwarf_file: None };
102+
let config = TargetMachineFactoryConfig { split_dwarf_file: None, output_obj_file: None };
103103
// Can't use query system here quite yet because this function is invoked before the query
104104
// system/tcx is set up.
105105
let features = llvm_util::global_llvm_features(sess, false);
@@ -117,7 +117,11 @@ pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut ll
117117
} else {
118118
None
119119
};
120-
let config = TargetMachineFactoryConfig { split_dwarf_file };
120+
121+
let output_obj_file =
122+
Some(tcx.output_filenames(()).temp_path(OutputType::Object, Some(mod_name)));
123+
let config = TargetMachineFactoryConfig { split_dwarf_file, output_obj_file };
124+
121125
target_machine_factory(
122126
&tcx.sess,
123127
tcx.backend_optimization_level(()),
@@ -255,9 +259,13 @@ pub fn target_machine_factory(
255259
let debuginfo_compression = SmallCStr::new(&debuginfo_compression);
256260

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

262270
let tm = unsafe {
263271
llvm::LLVMRustCreateTargetMachine(
@@ -279,6 +287,7 @@ pub fn target_machine_factory(
279287
relax_elf_relocations,
280288
use_init_array,
281289
split_dwarf_file.as_ptr(),
290+
output_obj_file.as_ptr(),
282291
debuginfo_compression.as_ptr(),
283292
force_emulated_tls,
284293
args_cstr_buff.as_ptr() as *const c_char,

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2131,6 +2131,7 @@ extern "C" {
21312131
RelaxELFRelocations: bool,
21322132
UseInitArray: bool,
21332133
SplitDwarfFile: *const c_char,
2134+
OutputObjFile: *const c_char,
21342135
DebugInfoCompression: *const c_char,
21352136
ForceEmulatedTls: bool,
21362137
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
@@ -410,6 +410,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
410410
bool RelaxELFRelocations,
411411
bool UseInitArray,
412412
const char *SplitDwarfFile,
413+
const char *OutputObjFile,
413414
const char *DebugInfoCompression,
414415
bool ForceEmulatedTls,
415416
const char *ArgsCstrBuff, size_t ArgsCstrBuffLen) {
@@ -442,6 +443,9 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
442443
if (SplitDwarfFile) {
443444
Options.MCOptions.SplitDwarfFile = SplitDwarfFile;
444445
}
446+
if (OutputObjFile) {
447+
Options.ObjectFilenameForDebug = OutputObjFile;
448+
}
445449
#if LLVM_VERSION_GE(16, 0)
446450
if (!strcmp("zlib", DebugInfoCompression) && llvm::compression::zlib::isAvailable()) {
447451
Options.CompressDebugSections = DebugCompressionType::Zlib;

0 commit comments

Comments
 (0)