Add .comment section with producer name

Fixes #1211
This commit is contained in:
bjorn3 2022-12-15 13:57:13 +00:00
parent d74e5b6cc7
commit d841f93855
2 changed files with 22 additions and 6 deletions

View File

@ -20,6 +20,14 @@
pub(crate) use emit::{DebugReloc, DebugRelocName}; pub(crate) use emit::{DebugReloc, DebugRelocName};
pub(crate) use unwind::UnwindContext; pub(crate) use unwind::UnwindContext;
pub(crate) fn producer() -> String {
format!(
"cg_clif (rustc {}, cranelift {})",
rustc_interface::util::rustc_version_str().unwrap_or("unknown version"),
cranelift_codegen::VERSION,
)
}
pub(crate) struct DebugContext { pub(crate) struct DebugContext {
endian: RunTimeEndian, endian: RunTimeEndian,
@ -57,11 +65,7 @@ pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa) -> Self {
let mut dwarf = DwarfUnit::new(encoding); let mut dwarf = DwarfUnit::new(encoding);
let producer = format!( let producer = producer();
"cg_clif (rustc {}, cranelift {})",
rustc_interface::util::rustc_version_str().unwrap_or("unknown version"),
cranelift_codegen::VERSION,
);
let comp_dir = tcx let comp_dir = tcx
.sess .sess
.opts .opts

View File

@ -169,10 +169,22 @@ fn emit_cgu(
fn emit_module( fn emit_module(
output_filenames: &OutputFilenames, output_filenames: &OutputFilenames,
prof: &SelfProfilerRef, prof: &SelfProfilerRef,
object: cranelift_object::object::write::Object<'_>, mut object: cranelift_object::object::write::Object<'_>,
kind: ModuleKind, kind: ModuleKind,
name: String, name: String,
) -> Result<CompiledModule, String> { ) -> Result<CompiledModule, String> {
if object.format() == cranelift_object::object::BinaryFormat::Elf {
let comment_section = object.add_section(
Vec::new(),
b".comment".to_vec(),
cranelift_object::object::SectionKind::OtherString,
);
let mut producer = vec![0];
producer.extend(crate::debuginfo::producer().as_bytes());
producer.push(0);
object.set_section_data(comment_section, producer, 1);
}
let tmp_file = output_filenames.temp_path(OutputType::Object, Some(&name)); let tmp_file = output_filenames.temp_path(OutputType::Object, Some(&name));
let mut file = match File::create(&tmp_file) { let mut file = match File::create(&tmp_file) {
Ok(file) => file, Ok(file) => file,