@@ -51,7 +51,7 @@ fn main() {
5151 // time). This can probably be removed in the future
5252 if !target. contains ( "wasm32" ) && !target. contains ( "nvptx" ) && !target. starts_with ( "riscv" ) {
5353 #[ cfg( feature = "c" ) ]
54- c:: compile ( & llvm_target) ;
54+ c:: compile ( & llvm_target, & target ) ;
5555 }
5656 }
5757
@@ -121,13 +121,28 @@ mod c {
121121 }
122122
123123 /// 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 ) {
125125 let target_arch = env:: var ( "CARGO_CFG_TARGET_ARCH" ) . unwrap ( ) ;
126126 let target_env = env:: var ( "CARGO_CFG_TARGET_ENV" ) . unwrap ( ) ;
127127 let target_os = env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) ;
128128 let target_vendor = env:: var ( "CARGO_CFG_TARGET_VENDOR" ) . unwrap ( ) ;
129+ let mut consider_float_intrinsics = true ;
129130 let cfg = & mut cc:: Build :: new ( ) ;
130131
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+
131146 cfg. warnings ( false ) ;
132147
133148 if target_env == "msvc" {
@@ -166,34 +181,39 @@ mod c {
166181 ( "__cmpdi2" , "cmpdi2.c" ) ,
167182 ( "__ctzdi2" , "ctzdi2.c" ) ,
168183 ( "__ctzsi2" , "ctzsi2.c" ) ,
169- ( "__divdc3" , "divdc3.c" ) ,
170- ( "__divsc3" , "divsc3.c" ) ,
171- ( "__divxc3" , "divxc3.c" ) ,
172- ( "__extendhfsf2" , "extendhfsf2.c" ) ,
173184 ( "__int_util" , "int_util.c" ) ,
174- ( "__muldc3" , "muldc3.c" ) ,
175- ( "__mulsc3" , "mulsc3.c" ) ,
176185 ( "__mulvdi3" , "mulvdi3.c" ) ,
177186 ( "__mulvsi3" , "mulvsi3.c" ) ,
178- ( "__mulxc3" , "mulxc3.c" ) ,
179- ( "__negdf2" , "negdf2.c" ) ,
180187 ( "__negdi2" , "negdi2.c" ) ,
181- ( "__negsf2" , "negsf2.c" ) ,
182188 ( "__negvdi2" , "negvdi2.c" ) ,
183189 ( "__negvsi2" , "negvsi2.c" ) ,
184190 ( "__paritydi2" , "paritydi2.c" ) ,
185191 ( "__paritysi2" , "paritysi2.c" ) ,
186192 ( "__popcountdi2" , "popcountdi2.c" ) ,
187193 ( "__popcountsi2" , "popcountsi2.c" ) ,
188- ( "__powixf2" , "powixf2.c" ) ,
189194 ( "__subvdi3" , "subvdi3.c" ) ,
190195 ( "__subvsi3" , "subvsi3.c" ) ,
191- ( "__truncdfhf2" , "truncdfhf2.c" ) ,
192- ( "__truncdfsf2" , "truncdfsf2.c" ) ,
193- ( "__truncsfhf2" , "truncsfhf2.c" ) ,
194196 ( "__ucmpdi2" , "ucmpdi2.c" ) ,
195197 ] ) ;
196198
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+
197217 // When compiling in rustbuild (the rust-lang/rust repo) this library
198218 // also needs to satisfy intrinsics that jemalloc or C in general may
199219 // need, so include a few more that aren't typically needed by
@@ -214,12 +234,15 @@ mod c {
214234 ( "__ffsti2" , "ffsti2.c" ) ,
215235 ( "__mulvti3" , "mulvti3.c" ) ,
216236 ( "__negti2" , "negti2.c" ) ,
217- ( "__negvti2" , "negvti2.c" ) ,
218237 ( "__parityti2" , "parityti2.c" ) ,
219238 ( "__popcountti2" , "popcountti2.c" ) ,
220239 ( "__subvti3" , "subvti3.c" ) ,
221240 ( "__ucmpti2" , "ucmpti2.c" ) ,
222241 ] ) ;
242+
243+ if consider_float_intrinsics {
244+ sources. extend ( & [ ( "__negvti2" , "negvti2.c" ) ] ) ;
245+ }
223246 }
224247
225248 if target_vendor == "apple" {
@@ -372,7 +395,7 @@ mod c {
372395 ] ) ;
373396 }
374397
375- if target_arch == "aarch64" {
398+ if target_arch == "aarch64" && consider_float_intrinsics {
376399 sources. extend ( & [
377400 ( "__comparetf2" , "comparetf2.c" ) ,
378401 ( "__extenddftf2" , "extenddftf2.c" ) ,
0 commit comments