Skip to content

Commit 203450f

Browse files
authored
Rollup merge of rust-lang#53290 - whitequark:fix-35741, r=nagisa
Make LLVM emit assembly comments with -Z asm-comments Fixes rust-lang#35741, and makes `-Z asm-comments` actually do something useful. Before: ``` .section .text.main,"ax",@progbits .globl main .p2align 4, 0x90 .type main,@function main: .cfi_startproc pushq %rax .cfi_def_cfa_offset 16 movslq %edi, %rax leaq _ZN1t4main17he95a7d4f1843730eE(%rip), %rdi movq %rsi, (%rsp) movq %rax, %rsi movq (%rsp), %rdx callq _ZN3std2rt10lang_start17h3121da83b2bc3697E movl %eax, %ecx movl %ecx, %eax popq %rcx .cfi_def_cfa_offset 8 retq .Lfunc_end8: .size main, .Lfunc_end8-main .cfi_endproc ``` After: ``` .section .text.main,"ax",@progbits .globl main # -- Begin function main .p2align 4, 0x90 .type main,@function main: # @main .cfi_startproc # %bb.0: pushq %rax .cfi_def_cfa_offset 16 movslq %edi, %rax leaq _ZN1t4main17he95a7d4f1843730eE(%rip), %rdi movq %rsi, (%rsp) # 8-byte Spill movq %rax, %rsi movq (%rsp), %rdx # 8-byte Reload callq _ZN3std2rt10lang_start17h3121da83b2bc3697E movl %eax, %ecx movl %ecx, %eax popq %rcx .cfi_def_cfa_offset 8 retq .Lfunc_end8: .size main, .Lfunc_end8-main .cfi_endproc # -- End function ```
2 parents f6493dd + 66fd1eb commit 203450f

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
@@ -180,6 +180,8 @@ pub fn target_machine_factory(sess: &Session, find_features: bool)
180180
let is_pie_binary = !find_features && is_pie_binary(sess);
181181
let trap_unreachable = sess.target.target.options.trap_unreachable;
182182

183+
let asm_comments = sess.asm_comments();
184+
183185
Arc::new(move || {
184186
let tm = unsafe {
185187
llvm::LLVMRustCreateTargetMachine(
@@ -193,6 +195,7 @@ pub fn target_machine_factory(sess: &Session, find_features: bool)
193195
fdata_sections,
194196
trap_unreachable,
195197
singlethread,
198+
asm_comments,
196199
)
197200
};
198201

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)