Rollup merge of #53290 - whitequark:fix-35741, r=nagisa
Make LLVM emit assembly comments with -Z asm-comments Fixes #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 ```
This commit is contained in:
commit
47f66e7372
3 changed files with 9 additions and 2 deletions
|
@ -180,6 +180,8 @@ pub fn target_machine_factory(sess: &Session, find_features: bool)
|
||||||
let is_pie_binary = !find_features && is_pie_binary(sess);
|
let is_pie_binary = !find_features && is_pie_binary(sess);
|
||||||
let trap_unreachable = sess.target.target.options.trap_unreachable;
|
let trap_unreachable = sess.target.target.options.trap_unreachable;
|
||||||
|
|
||||||
|
let asm_comments = sess.asm_comments();
|
||||||
|
|
||||||
Arc::new(move || {
|
Arc::new(move || {
|
||||||
let tm = unsafe {
|
let tm = unsafe {
|
||||||
llvm::LLVMRustCreateTargetMachine(
|
llvm::LLVMRustCreateTargetMachine(
|
||||||
|
@ -193,6 +195,7 @@ pub fn target_machine_factory(sess: &Session, find_features: bool)
|
||||||
fdata_sections,
|
fdata_sections,
|
||||||
trap_unreachable,
|
trap_unreachable,
|
||||||
singlethread,
|
singlethread,
|
||||||
|
asm_comments,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1455,7 +1455,8 @@ extern "C" {
|
||||||
FunctionSections: bool,
|
FunctionSections: bool,
|
||||||
DataSections: bool,
|
DataSections: bool,
|
||||||
TrapUnreachable: bool,
|
TrapUnreachable: bool,
|
||||||
Singlethread: bool)
|
Singlethread: bool,
|
||||||
|
AsmComments: bool)
|
||||||
-> Option<&'static mut TargetMachine>;
|
-> Option<&'static mut TargetMachine>;
|
||||||
pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
|
pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
|
||||||
pub fn LLVMRustAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>, M: &'a Module);
|
pub fn LLVMRustAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>, M: &'a Module);
|
||||||
|
|
|
@ -366,7 +366,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
|
||||||
bool PositionIndependentExecutable, bool FunctionSections,
|
bool PositionIndependentExecutable, bool FunctionSections,
|
||||||
bool DataSections,
|
bool DataSections,
|
||||||
bool TrapUnreachable,
|
bool TrapUnreachable,
|
||||||
bool Singlethread) {
|
bool Singlethread,
|
||||||
|
bool AsmComments) {
|
||||||
|
|
||||||
auto OptLevel = fromRust(RustOptLevel);
|
auto OptLevel = fromRust(RustOptLevel);
|
||||||
auto RM = fromRust(RustReloc);
|
auto RM = fromRust(RustReloc);
|
||||||
|
@ -393,6 +394,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
|
||||||
}
|
}
|
||||||
Options.DataSections = DataSections;
|
Options.DataSections = DataSections;
|
||||||
Options.FunctionSections = FunctionSections;
|
Options.FunctionSections = FunctionSections;
|
||||||
|
Options.MCOptions.AsmVerbose = AsmComments;
|
||||||
|
Options.MCOptions.PreserveAsmComments = AsmComments;
|
||||||
|
|
||||||
if (TrapUnreachable) {
|
if (TrapUnreachable) {
|
||||||
// Tell LLVM to codegen `unreachable` into an explicit trap instruction.
|
// Tell LLVM to codegen `unreachable` into an explicit trap instruction.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue