Skip to content

Commit 66fd1eb

Browse files
committed
Make LLVM emit assembly comments with -Z asm-comments.
Fixes #35741.
1 parent 0aa8d03 commit 66fd1eb

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/librustc_codegen_llvm/back/write.rs

+3
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ pub fn target_machine_factory(sess: &Session, find_features: bool)
182182
let is_pie_binary = !find_features && is_pie_binary(sess);
183183
let trap_unreachable = sess.target.target.options.trap_unreachable;
184184

185+
let asm_comments = sess.asm_comments();
186+
185187
Arc::new(move || {
186188
let tm = unsafe {
187189
llvm::LLVMRustCreateTargetMachine(
@@ -195,6 +197,7 @@ pub fn target_machine_factory(sess: &Session, find_features: bool)
195197
fdata_sections,
196198
trap_unreachable,
197199
singlethread,
200+
asm_comments,
198201
)
199202
};
200203

src/librustc_codegen_llvm/llvm/ffi.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,8 @@ extern "C" {
14551455
FunctionSections: bool,
14561456
DataSections: bool,
14571457
TrapUnreachable: bool,
1458-
Singlethread: bool)
1458+
Singlethread: bool,
1459+
AsmComments: bool)
14591460
-> Option<&'static mut TargetMachine>;
14601461
pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
14611462
pub fn LLVMRustAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>, M: &'a Module);

src/rustllvm/PassWrapper.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
366366
bool PositionIndependentExecutable, bool FunctionSections,
367367
bool DataSections,
368368
bool TrapUnreachable,
369-
bool Singlethread) {
369+
bool Singlethread,
370+
bool AsmComments) {
370371

371372
auto OptLevel = fromRust(RustOptLevel);
372373
auto RM = fromRust(RustReloc);
@@ -393,6 +394,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
393394
}
394395
Options.DataSections = DataSections;
395396
Options.FunctionSections = FunctionSections;
397+
Options.MCOptions.AsmVerbose = AsmComments;
398+
Options.MCOptions.PreserveAsmComments = AsmComments;
396399

397400
if (TrapUnreachable) {
398401
// Tell LLVM to codegen `unreachable` into an explicit trap instruction.

0 commit comments

Comments
 (0)