Skip to content

Commit d841f93

Browse files
committed
Add .comment section with producer name
Fixes rust-lang#1211
1 parent d74e5b6 commit d841f93

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/debuginfo/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ use indexmap::IndexSet;
2020
pub(crate) use emit::{DebugReloc, DebugRelocName};
2121
pub(crate) use unwind::UnwindContext;
2222

23+
pub(crate) fn producer() -> String {
24+
format!(
25+
"cg_clif (rustc {}, cranelift {})",
26+
rustc_interface::util::rustc_version_str().unwrap_or("unknown version"),
27+
cranelift_codegen::VERSION,
28+
)
29+
}
30+
2331
pub(crate) struct DebugContext {
2432
endian: RunTimeEndian,
2533

@@ -57,11 +65,7 @@ impl DebugContext {
5765

5866
let mut dwarf = DwarfUnit::new(encoding);
5967

60-
let producer = format!(
61-
"cg_clif (rustc {}, cranelift {})",
62-
rustc_interface::util::rustc_version_str().unwrap_or("unknown version"),
63-
cranelift_codegen::VERSION,
64-
);
68+
let producer = producer();
6569
let comp_dir = tcx
6670
.sess
6771
.opts

src/driver/aot.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,22 @@ fn emit_cgu(
169169
fn emit_module(
170170
output_filenames: &OutputFilenames,
171171
prof: &SelfProfilerRef,
172-
object: cranelift_object::object::write::Object<'_>,
172+
mut object: cranelift_object::object::write::Object<'_>,
173173
kind: ModuleKind,
174174
name: String,
175175
) -> Result<CompiledModule, String> {
176+
if object.format() == cranelift_object::object::BinaryFormat::Elf {
177+
let comment_section = object.add_section(
178+
Vec::new(),
179+
b".comment".to_vec(),
180+
cranelift_object::object::SectionKind::OtherString,
181+
);
182+
let mut producer = vec![0];
183+
producer.extend(crate::debuginfo::producer().as_bytes());
184+
producer.push(0);
185+
object.set_section_data(comment_section, producer, 1);
186+
}
187+
176188
let tmp_file = output_filenames.temp_path(OutputType::Object, Some(&name));
177189
let mut file = match File::create(&tmp_file) {
178190
Ok(file) => file,

0 commit comments

Comments
 (0)