@@ -4,7 +4,7 @@ use rustc_middle::mir::{Body, InlineAsmOperand};
4
4
use rustc_middle:: ty:: layout:: { HasTyCtxt , HasTypingEnv , LayoutOf } ;
5
5
use rustc_middle:: ty:: { Instance , TyCtxt } ;
6
6
use rustc_middle:: { bug, ty} ;
7
- use rustc_target :: asm :: InlineAsmArch ;
7
+ use rustc_span :: sym ;
8
8
9
9
use crate :: common;
10
10
use crate :: traits:: { AsmCodegenMethods , BuilderMethods , GlobalAsmOperandRef , MiscCodegenMethods } ;
@@ -31,7 +31,8 @@ pub(crate) fn codegen_naked_asm<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
31
31
operands. iter ( ) . map ( |op| inline_to_global_operand :: < Bx > ( cx, instance, op) ) . collect ( ) ;
32
32
33
33
let item_data = cx. codegen_unit ( ) . items ( ) . get ( & MonoItem :: Fn ( instance) ) . unwrap ( ) ;
34
- let ( begin, end) = crate :: mir:: naked_asm:: prefix_and_suffix ( cx. tcx ( ) , instance, item_data) ;
34
+ let name = cx. mangled_name ( instance) ;
35
+ let ( begin, end) = prefix_and_suffix ( cx. tcx ( ) , instance, & name, item_data) ;
35
36
36
37
let mut template_vec = Vec :: new ( ) ;
37
38
template_vec. push ( rustc_ast:: ast:: InlineAsmTemplatePiece :: String ( begin. into ( ) ) ) ;
@@ -108,7 +109,7 @@ impl AsmBinaryFormat {
108
109
fn from_target ( target : & rustc_target:: spec:: Target ) -> Self {
109
110
if target. is_like_windows {
110
111
Self :: Coff
111
- } else if target. options . vendor == "apple" {
112
+ } else if target. is_like_osx {
112
113
Self :: Macho
113
114
} else {
114
115
Self :: Elf
@@ -119,33 +120,29 @@ impl AsmBinaryFormat {
119
120
fn prefix_and_suffix < ' tcx > (
120
121
tcx : TyCtxt < ' tcx > ,
121
122
instance : Instance < ' tcx > ,
123
+ asm_name : & str ,
122
124
item_data : & MonoItemData ,
123
125
) -> ( String , String ) {
124
126
use std:: fmt:: Write ;
125
127
126
- let target = & tcx. sess . target ;
127
- let target_arch = tcx. sess . asm_arch ;
128
-
129
- let is_arm = target. arch == "arm" ;
130
- let is_thumb = is_arm && target. llvm_target . contains ( "thumb" ) ;
131
-
132
- let mangle = ( target. is_like_windows && matches ! ( target_arch, Some ( InlineAsmArch :: X86 ) ) )
133
- || target. options . vendor == "apple" ;
134
-
135
- let asm_name = format ! ( "{}{}" , if mangle { "_" } else { "" } , tcx. symbol_name( instance) . name) ;
128
+ let is_arm = tcx. sess . target . arch == "arm" ;
129
+ let is_thumb = tcx. sess . unstable_target_features . contains ( & sym:: thumb_mode) ;
136
130
137
131
let attrs = tcx. codegen_fn_attrs ( instance. def_id ( ) ) ;
138
132
let link_section = attrs. link_section . map ( |symbol| symbol. as_str ( ) . to_string ( ) ) ;
133
+ let align = attrs. alignment . map ( |a| a. bytes ( ) ) . unwrap_or ( 4 ) ;
139
134
135
+ // See https://sourceware.org/binutils/docs/as/ARM-Directives.html for info on these directives.
136
+ // In particular, `.arm` can also be written `.code 32` and `.thumb` as `.code 16`.
140
137
let ( arch_prefix, arch_suffix) = if is_arm {
141
138
(
142
139
match attrs. instruction_set {
143
140
None => match is_thumb {
144
141
true => ".thumb\n .thumb_func" ,
145
142
false => ".arm" ,
146
143
} ,
147
- Some ( InstructionSetAttr :: ArmA32 ) => ".arm" ,
148
144
Some ( InstructionSetAttr :: ArmT32 ) => ".thumb\n .thumb_func" ,
145
+ Some ( InstructionSetAttr :: ArmA32 ) => ".arm" ,
149
146
} ,
150
147
match is_thumb {
151
148
true => ".thumb" ,
@@ -173,7 +170,7 @@ fn prefix_and_suffix<'tcx>(
173
170
} ;
174
171
175
172
writeln ! ( begin, ".pushsection {section},\" ax\" , {progbits}" ) . unwrap ( ) ;
176
- writeln ! ( begin, ".balign 4 " ) . unwrap ( ) ;
173
+ writeln ! ( begin, ".balign {align} " ) . unwrap ( ) ;
177
174
writeln ! ( begin, ".globl {asm_name}" ) . unwrap ( ) ;
178
175
if let Visibility :: Hidden = item_data. visibility {
179
176
writeln ! ( begin, ".hidden {asm_name}" ) . unwrap ( ) ;
@@ -194,7 +191,7 @@ fn prefix_and_suffix<'tcx>(
194
191
AsmBinaryFormat :: Macho => {
195
192
let section = link_section. unwrap_or ( "__TEXT,__text" . to_string ( ) ) ;
196
193
writeln ! ( begin, ".pushsection {},regular,pure_instructions" , section) . unwrap ( ) ;
197
- writeln ! ( begin, ".balign 4 " ) . unwrap ( ) ;
194
+ writeln ! ( begin, ".balign {align} " ) . unwrap ( ) ;
198
195
writeln ! ( begin, ".globl {asm_name}" ) . unwrap ( ) ;
199
196
if let Visibility :: Hidden = item_data. visibility {
200
197
writeln ! ( begin, ".private_extern {asm_name}" ) . unwrap ( ) ;
@@ -210,7 +207,7 @@ fn prefix_and_suffix<'tcx>(
210
207
AsmBinaryFormat :: Coff => {
211
208
let section = link_section. unwrap_or ( format ! ( ".text.{asm_name}" ) ) ;
212
209
writeln ! ( begin, ".pushsection {},\" xr\" " , section) . unwrap ( ) ;
213
- writeln ! ( begin, ".balign 4 " ) . unwrap ( ) ;
210
+ writeln ! ( begin, ".balign {align} " ) . unwrap ( ) ;
214
211
writeln ! ( begin, ".globl {asm_name}" ) . unwrap ( ) ;
215
212
writeln ! ( begin, ".def {asm_name}" ) . unwrap ( ) ;
216
213
writeln ! ( begin, ".scl 2" ) . unwrap ( ) ;
0 commit comments