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 https://github.com/rust-lang/rust/issues/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
This commit is contained in:
commit
6f13ea0d1a
5 changed files with 29 additions and 6 deletions
|
@ -37,6 +37,7 @@ impl OwnedTargetMachine {
|
||||||
relax_elf_relocations: bool,
|
relax_elf_relocations: bool,
|
||||||
use_init_array: bool,
|
use_init_array: bool,
|
||||||
split_dwarf_file: &CStr,
|
split_dwarf_file: &CStr,
|
||||||
|
output_obj_file: &CStr,
|
||||||
debug_info_compression: &CStr,
|
debug_info_compression: &CStr,
|
||||||
force_emulated_tls: bool,
|
force_emulated_tls: bool,
|
||||||
args_cstr_buff: &[u8],
|
args_cstr_buff: &[u8],
|
||||||
|
@ -68,6 +69,7 @@ impl OwnedTargetMachine {
|
||||||
relax_elf_relocations,
|
relax_elf_relocations,
|
||||||
use_init_array,
|
use_init_array,
|
||||||
split_dwarf_file.as_ptr(),
|
split_dwarf_file.as_ptr(),
|
||||||
|
output_obj_file.as_ptr(),
|
||||||
debug_info_compression.as_ptr(),
|
debug_info_compression.as_ptr(),
|
||||||
force_emulated_tls,
|
force_emulated_tls,
|
||||||
args_cstr_buff.as_ptr() as *const c_char,
|
args_cstr_buff.as_ptr() as *const c_char,
|
||||||
|
|
|
@ -100,7 +100,7 @@ pub fn write_output_file<'ll>(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_informational_target_machine(sess: &Session) -> OwnedTargetMachine {
|
pub fn create_informational_target_machine(sess: &Session) -> OwnedTargetMachine {
|
||||||
let config = TargetMachineFactoryConfig { split_dwarf_file: None };
|
let config = TargetMachineFactoryConfig { split_dwarf_file: None, output_obj_file: None };
|
||||||
// Can't use query system here quite yet because this function is invoked before the query
|
// Can't use query system here quite yet because this function is invoked before the query
|
||||||
// system/tcx is set up.
|
// system/tcx is set up.
|
||||||
let features = llvm_util::global_llvm_features(sess, false);
|
let features = llvm_util::global_llvm_features(sess, false);
|
||||||
|
@ -118,7 +118,11 @@ pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> OwnedTargetMach
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let config = TargetMachineFactoryConfig { split_dwarf_file };
|
|
||||||
|
let output_obj_file =
|
||||||
|
Some(tcx.output_filenames(()).temp_path(OutputType::Object, Some(mod_name)));
|
||||||
|
let config = TargetMachineFactoryConfig { split_dwarf_file, output_obj_file };
|
||||||
|
|
||||||
target_machine_factory(
|
target_machine_factory(
|
||||||
&tcx.sess,
|
&tcx.sess,
|
||||||
tcx.backend_optimization_level(()),
|
tcx.backend_optimization_level(()),
|
||||||
|
@ -256,9 +260,13 @@ pub fn target_machine_factory(
|
||||||
let debuginfo_compression = SmallCStr::new(&debuginfo_compression);
|
let debuginfo_compression = SmallCStr::new(&debuginfo_compression);
|
||||||
|
|
||||||
Arc::new(move |config: TargetMachineFactoryConfig| {
|
Arc::new(move |config: TargetMachineFactoryConfig| {
|
||||||
let split_dwarf_file =
|
let path_to_cstring_helper = |path: Option<PathBuf>| -> CString {
|
||||||
path_mapping.map_prefix(config.split_dwarf_file.unwrap_or_default()).0;
|
let path = path_mapping.map_prefix(path.unwrap_or_default()).0;
|
||||||
let split_dwarf_file = CString::new(split_dwarf_file.to_str().unwrap()).unwrap();
|
CString::new(path.to_str().unwrap()).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
let split_dwarf_file = path_to_cstring_helper(config.split_dwarf_file);
|
||||||
|
let output_obj_file = path_to_cstring_helper(config.output_obj_file);
|
||||||
|
|
||||||
OwnedTargetMachine::new(
|
OwnedTargetMachine::new(
|
||||||
&triple,
|
&triple,
|
||||||
|
@ -279,6 +287,7 @@ pub fn target_machine_factory(
|
||||||
relax_elf_relocations,
|
relax_elf_relocations,
|
||||||
use_init_array,
|
use_init_array,
|
||||||
&split_dwarf_file,
|
&split_dwarf_file,
|
||||||
|
&output_obj_file,
|
||||||
&debuginfo_compression,
|
&debuginfo_compression,
|
||||||
force_emulated_tls,
|
force_emulated_tls,
|
||||||
&args_cstr_buff,
|
&args_cstr_buff,
|
||||||
|
|
|
@ -2133,6 +2133,7 @@ extern "C" {
|
||||||
RelaxELFRelocations: bool,
|
RelaxELFRelocations: bool,
|
||||||
UseInitArray: bool,
|
UseInitArray: bool,
|
||||||
SplitDwarfFile: *const c_char,
|
SplitDwarfFile: *const c_char,
|
||||||
|
OutputObjFile: *const c_char,
|
||||||
DebugInfoCompression: *const c_char,
|
DebugInfoCompression: *const c_char,
|
||||||
ForceEmulatedTls: bool,
|
ForceEmulatedTls: bool,
|
||||||
ArgsCstrBuff: *const c_char,
|
ArgsCstrBuff: *const c_char,
|
||||||
|
|
|
@ -286,6 +286,10 @@ pub struct TargetMachineFactoryConfig {
|
||||||
/// so the path to the dwarf object has to be provided when we create the target machine.
|
/// so the path to the dwarf object has to be provided when we create the target machine.
|
||||||
/// This can be ignored by backends which do not need it for their Split DWARF support.
|
/// This can be ignored by backends which do not need it for their Split DWARF support.
|
||||||
pub split_dwarf_file: Option<PathBuf>,
|
pub split_dwarf_file: Option<PathBuf>,
|
||||||
|
|
||||||
|
/// The name of the output object file. Used for setting OutputFilenames in target options
|
||||||
|
/// so that LLVM can emit the CodeView S_OBJNAME record in pdb files
|
||||||
|
pub output_obj_file: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TargetMachineFactoryConfig {
|
impl TargetMachineFactoryConfig {
|
||||||
|
@ -302,7 +306,10 @@ impl TargetMachineFactoryConfig {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
TargetMachineFactoryConfig { split_dwarf_file }
|
|
||||||
|
let output_obj_file =
|
||||||
|
Some(cgcx.output_filenames.temp_path(OutputType::Object, Some(module_name)));
|
||||||
|
TargetMachineFactoryConfig { split_dwarf_file, output_obj_file }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -416,6 +416,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
|
||||||
bool RelaxELFRelocations,
|
bool RelaxELFRelocations,
|
||||||
bool UseInitArray,
|
bool UseInitArray,
|
||||||
const char *SplitDwarfFile,
|
const char *SplitDwarfFile,
|
||||||
|
const char *OutputObjFile,
|
||||||
const char *DebugInfoCompression,
|
const char *DebugInfoCompression,
|
||||||
bool ForceEmulatedTls,
|
bool ForceEmulatedTls,
|
||||||
const char *ArgsCstrBuff, size_t ArgsCstrBuffLen) {
|
const char *ArgsCstrBuff, size_t ArgsCstrBuffLen) {
|
||||||
|
@ -448,6 +449,9 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
|
||||||
if (SplitDwarfFile) {
|
if (SplitDwarfFile) {
|
||||||
Options.MCOptions.SplitDwarfFile = SplitDwarfFile;
|
Options.MCOptions.SplitDwarfFile = SplitDwarfFile;
|
||||||
}
|
}
|
||||||
|
if (OutputObjFile) {
|
||||||
|
Options.ObjectFilenameForDebug = OutputObjFile;
|
||||||
|
}
|
||||||
#if LLVM_VERSION_GE(16, 0)
|
#if LLVM_VERSION_GE(16, 0)
|
||||||
if (!strcmp("zlib", DebugInfoCompression) && llvm::compression::zlib::isAvailable()) {
|
if (!strcmp("zlib", DebugInfoCompression) && llvm::compression::zlib::isAvailable()) {
|
||||||
Options.CompressDebugSections = DebugCompressionType::Zlib;
|
Options.CompressDebugSections = DebugCompressionType::Zlib;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue