@@ -51,7 +51,7 @@ fn main() {
51
51
// time). This can probably be removed in the future
52
52
if !target. contains ( "wasm32" ) && !target. contains ( "nvptx" ) && !target. starts_with ( "riscv" ) {
53
53
#[ cfg( feature = "c" ) ]
54
- c:: compile ( & llvm_target) ;
54
+ c:: compile ( & llvm_target, & target ) ;
55
55
}
56
56
}
57
57
@@ -121,13 +121,28 @@ mod c {
121
121
}
122
122
123
123
/// Compile intrinsics from the compiler-rt C source code
124
- pub fn compile ( llvm_target : & [ & str ] ) {
124
+ pub fn compile ( llvm_target : & [ & str ] , target : & String ) {
125
125
let target_arch = env:: var ( "CARGO_CFG_TARGET_ARCH" ) . unwrap ( ) ;
126
126
let target_env = env:: var ( "CARGO_CFG_TARGET_ENV" ) . unwrap ( ) ;
127
127
let target_os = env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) ;
128
128
let target_vendor = env:: var ( "CARGO_CFG_TARGET_VENDOR" ) . unwrap ( ) ;
129
+ let mut consider_float_intrinsics = true ;
129
130
let cfg = & mut cc:: Build :: new ( ) ;
130
131
132
+ // AArch64 GCCs exit with an error condition when they encounter any kind of floating point
133
+ // code if the `nofp` and/or `nosimd` compiler flags have been set.
134
+ //
135
+ // Therefore, evaluate if those flags are present and set a boolean that causes any
136
+ // compiler-rt intrinsics that contain floating point source to be excluded for this target.
137
+ if target_arch == "aarch64" {
138
+ let cflags_key = String :: from ( "CFLAGS_" ) + & ( target. to_owned ( ) . replace ( "-" , "_" ) ) ;
139
+ if let Ok ( cflags_value) = env:: var ( cflags_key) {
140
+ if cflags_value. contains ( "+nofp" ) || cflags_value. contains ( "+nosimd" ) {
141
+ consider_float_intrinsics = false ;
142
+ }
143
+ }
144
+ }
145
+
131
146
cfg. warnings ( false ) ;
132
147
133
148
if target_env == "msvc" {
@@ -166,34 +181,39 @@ mod c {
166
181
( "__cmpdi2" , "cmpdi2.c" ) ,
167
182
( "__ctzdi2" , "ctzdi2.c" ) ,
168
183
( "__ctzsi2" , "ctzsi2.c" ) ,
169
- ( "__divdc3" , "divdc3.c" ) ,
170
- ( "__divsc3" , "divsc3.c" ) ,
171
- ( "__divxc3" , "divxc3.c" ) ,
172
- ( "__extendhfsf2" , "extendhfsf2.c" ) ,
173
184
( "__int_util" , "int_util.c" ) ,
174
- ( "__muldc3" , "muldc3.c" ) ,
175
- ( "__mulsc3" , "mulsc3.c" ) ,
176
185
( "__mulvdi3" , "mulvdi3.c" ) ,
177
186
( "__mulvsi3" , "mulvsi3.c" ) ,
178
- ( "__mulxc3" , "mulxc3.c" ) ,
179
- ( "__negdf2" , "negdf2.c" ) ,
180
187
( "__negdi2" , "negdi2.c" ) ,
181
- ( "__negsf2" , "negsf2.c" ) ,
182
188
( "__negvdi2" , "negvdi2.c" ) ,
183
189
( "__negvsi2" , "negvsi2.c" ) ,
184
190
( "__paritydi2" , "paritydi2.c" ) ,
185
191
( "__paritysi2" , "paritysi2.c" ) ,
186
192
( "__popcountdi2" , "popcountdi2.c" ) ,
187
193
( "__popcountsi2" , "popcountsi2.c" ) ,
188
- ( "__powixf2" , "powixf2.c" ) ,
189
194
( "__subvdi3" , "subvdi3.c" ) ,
190
195
( "__subvsi3" , "subvsi3.c" ) ,
191
- ( "__truncdfhf2" , "truncdfhf2.c" ) ,
192
- ( "__truncdfsf2" , "truncdfsf2.c" ) ,
193
- ( "__truncsfhf2" , "truncsfhf2.c" ) ,
194
196
( "__ucmpdi2" , "ucmpdi2.c" ) ,
195
197
] ) ;
196
198
199
+ if consider_float_intrinsics {
200
+ sources. extend ( & [
201
+ ( "__divdc3" , "divdc3.c" ) ,
202
+ ( "__divsc3" , "divsc3.c" ) ,
203
+ ( "__divxc3" , "divxc3.c" ) ,
204
+ ( "__extendhfsf2" , "extendhfsf2.c" ) ,
205
+ ( "__muldc3" , "muldc3.c" ) ,
206
+ ( "__mulsc3" , "mulsc3.c" ) ,
207
+ ( "__mulxc3" , "mulxc3.c" ) ,
208
+ ( "__negdf2" , "negdf2.c" ) ,
209
+ ( "__negsf2" , "negsf2.c" ) ,
210
+ ( "__powixf2" , "powixf2.c" ) ,
211
+ ( "__truncdfhf2" , "truncdfhf2.c" ) ,
212
+ ( "__truncdfsf2" , "truncdfsf2.c" ) ,
213
+ ( "__truncsfhf2" , "truncsfhf2.c" ) ,
214
+ ] ) ;
215
+ }
216
+
197
217
// When compiling in rustbuild (the rust-lang/rust repo) this library
198
218
// also needs to satisfy intrinsics that jemalloc or C in general may
199
219
// need, so include a few more that aren't typically needed by
@@ -214,12 +234,15 @@ mod c {
214
234
( "__ffsti2" , "ffsti2.c" ) ,
215
235
( "__mulvti3" , "mulvti3.c" ) ,
216
236
( "__negti2" , "negti2.c" ) ,
217
- ( "__negvti2" , "negvti2.c" ) ,
218
237
( "__parityti2" , "parityti2.c" ) ,
219
238
( "__popcountti2" , "popcountti2.c" ) ,
220
239
( "__subvti3" , "subvti3.c" ) ,
221
240
( "__ucmpti2" , "ucmpti2.c" ) ,
222
241
] ) ;
242
+
243
+ if consider_float_intrinsics {
244
+ sources. extend ( & [ ( "__negvti2" , "negvti2.c" ) ] ) ;
245
+ }
223
246
}
224
247
225
248
if target_vendor == "apple" {
@@ -372,7 +395,7 @@ mod c {
372
395
] ) ;
373
396
}
374
397
375
- if target_arch == "aarch64" {
398
+ if target_arch == "aarch64" && consider_float_intrinsics {
376
399
sources. extend ( & [
377
400
( "__comparetf2" , "comparetf2.c" ) ,
378
401
( "__extenddftf2" , "extenddftf2.c" ) ,
0 commit comments