@@ -6,6 +6,7 @@ use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
66use rustc_middle:: mir:: InlineAsmOperand ;
77use rustc_span:: sym;
88use rustc_target:: asm:: * ;
9+ use target_lexicon:: BinaryFormat ;
910
1011use crate :: prelude:: * ;
1112
@@ -43,7 +44,9 @@ pub(crate) fn codegen_inline_asm<'tcx>(
4344) {
4445 // FIXME add .eh_frame unwind info directives
4546
46- if !template. is_empty ( ) {
47+ if !template. is_empty ( )
48+ && ( cfg ! ( not( feature = "inline_asm" ) ) || fx. tcx . sess . target . is_like_windows )
49+ {
4750 // Used by panic_abort
4851 if template[ 0 ] == InlineAsmTemplatePiece :: String ( "int $$0x29" . to_string ( ) ) {
4952 fx. bcx . ins ( ) . trap ( TrapCode :: User ( 1 ) ) ;
@@ -589,11 +592,29 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
589592 }
590593
591594 fn generate_asm_wrapper ( & self , asm_name : & str ) -> String {
595+ let binary_format = crate :: target_triple ( self . tcx . sess ) . binary_format ;
596+
592597 let mut generated_asm = String :: new ( ) ;
593- writeln ! ( generated_asm, ".globl {}" , asm_name) . unwrap ( ) ;
594- writeln ! ( generated_asm, ".type {},@function" , asm_name) . unwrap ( ) ;
595- writeln ! ( generated_asm, ".section .text.{},\" ax\" ,@progbits" , asm_name) . unwrap ( ) ;
596- writeln ! ( generated_asm, "{}:" , asm_name) . unwrap ( ) ;
598+ match binary_format {
599+ BinaryFormat :: Elf => {
600+ writeln ! ( generated_asm, ".globl {}" , asm_name) . unwrap ( ) ;
601+ writeln ! ( generated_asm, ".type {},@function" , asm_name) . unwrap ( ) ;
602+ writeln ! ( generated_asm, ".section .text.{},\" ax\" ,@progbits" , asm_name) . unwrap ( ) ;
603+ writeln ! ( generated_asm, "{}:" , asm_name) . unwrap ( ) ;
604+ }
605+ BinaryFormat :: Macho => {
606+ writeln ! ( generated_asm, ".globl _{}" , asm_name) . unwrap ( ) ;
607+ writeln ! ( generated_asm, "_{}:" , asm_name) . unwrap ( ) ;
608+ }
609+ BinaryFormat :: Coff => {
610+ writeln ! ( generated_asm, ".globl {}" , asm_name) . unwrap ( ) ;
611+ writeln ! ( generated_asm, "{}:" , asm_name) . unwrap ( ) ;
612+ }
613+ _ => self
614+ . tcx
615+ . sess
616+ . fatal ( format ! ( "Unsupported binary format for inline asm: {binary_format:?}" ) ) ,
617+ }
597618
598619 let is_x86 = matches ! ( self . arch, InlineAsmArch :: X86 | InlineAsmArch :: X86_64 ) ;
599620
@@ -690,8 +711,19 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
690711 if is_x86 {
691712 generated_asm. push_str ( ".att_syntax\n " ) ;
692713 }
693- writeln ! ( generated_asm, ".size {name}, .-{name}" , name = asm_name) . unwrap ( ) ;
694- generated_asm. push_str ( ".text\n " ) ;
714+
715+ match binary_format {
716+ BinaryFormat :: Elf => {
717+ writeln ! ( generated_asm, ".size {name}, .-{name}" , name = asm_name) . unwrap ( ) ;
718+ generated_asm. push_str ( ".text\n " ) ;
719+ }
720+ BinaryFormat :: Macho | BinaryFormat :: Coff => { }
721+ _ => self
722+ . tcx
723+ . sess
724+ . fatal ( format ! ( "Unsupported binary format for inline asm: {binary_format:?}" ) ) ,
725+ }
726+
695727 generated_asm. push_str ( "\n \n " ) ;
696728
697729 generated_asm
0 commit comments