From f150ab3277c5ce2b154201e2205cd2e10cb8eb36 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 18 Oct 2022 23:11:46 +0200 Subject: [PATCH] Improve code generating inline ASM --- src/asm.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/asm.rs b/src/asm.rs index 486c7a3f5cb..6dea20e4008 100644 --- a/src/asm.rs +++ b/src/asm.rs @@ -706,7 +706,10 @@ fn codegen_global_asm(&self, template: &[InlineAsmTemplatePiece], operands: &[Gl && options.contains(InlineAsmOptions::ATT_SYNTAX); // Build the template string - let mut template_str = String::new(); + let mut template_str = ".pushsection .text\n".to_owned(); + if att_dialect { + template_str.push_str(".att_syntax\n"); + } for piece in template { match *piece { InlineAsmTemplatePiece::String(ref string) => { @@ -754,15 +757,11 @@ fn codegen_global_asm(&self, template: &[InlineAsmTemplatePiece], operands: &[Gl } } - let template_str = - if att_dialect { - format!(".att_syntax\n\t{}\n\t.intel_syntax noprefix", template_str) - } - else { - template_str - }; + if att_dialect { + template_str.push_str("\n\t.intel_syntax noprefix"); + } // NOTE: seems like gcc will put the asm in the wrong section, so set it to .text manually. - let template_str = format!(".pushsection .text\n{}\n.popsection", template_str); + template_str.push_str("\n.popsection"); self.context.add_top_level_asm(None, &template_str); } }