@@ -41,7 +41,7 @@ use rustc_session::Session;
4141use rustc_session:: config:: { CrateType , OutputFilenames , OutputType } ;
4242use rustc_session:: output:: out_filename;
4343use rustc_smir:: rustc_internal;
44- use rustc_span:: symbol :: Symbol ;
44+ use rustc_span:: { Symbol , sym } ;
4545use rustc_target:: spec:: PanicStrategy ;
4646use stable_mir:: CrateDef ;
4747use stable_mir:: mir:: mono:: { Instance , MonoItem } ;
@@ -252,21 +252,37 @@ impl CodegenBackend for GotocCodegenBackend {
252252 DEFAULT_LOCALE_RESOURCE
253253 }
254254
255- fn target_config ( & self , _sess : & Session ) -> TargetConfig {
255+ fn target_config ( & self , sess : & Session ) -> TargetConfig {
256+ // This code is adapted from the cranelift backend:
257+ // https://github.com/rust-lang/rust/blob/a124fb3cb7291d75872934f411d81fe298379ace/compiler/rustc_codegen_cranelift/src/lib.rs#L184
258+ let target_features = if sess. target . arch == "x86_64" && sess. target . os != "none" {
259+ // x86_64 mandates SSE2 support and rustc requires the x87 feature to be enabled
260+ vec ! [ sym:: sse, sym:: sse2, Symbol :: intern( "x87" ) ]
261+ } else if sess. target . arch == "aarch64" {
262+ match & * sess. target . os {
263+ "none" => vec ! [ ] ,
264+ // On macOS the aes, sha2 and sha3 features are enabled by default and ring
265+ // fails to compile on macOS when they are not present.
266+ "macos" => vec ! [ sym:: neon, sym:: aes, sym:: sha2, sym:: sha3] ,
267+ // AArch64 mandates Neon support
268+ _ => vec ! [ sym:: neon] ,
269+ }
270+ } else {
271+ vec ! [ ]
272+ } ;
273+ // FIXME do `unstable_target_features` properly
274+ let unstable_target_features = target_features. clone ( ) ;
275+
276+ let has_reliable_f128 = true ;
277+ let has_reliable_f16 = true ;
278+
256279 TargetConfig {
257- target_features : vec ! [ ] ,
258- unstable_target_features : vec ! [
259- Symbol :: intern( "sse" ) ,
260- Symbol :: intern( "neon" ) ,
261- Symbol :: intern( "x87" ) ,
262- Symbol :: intern( "sse2" ) ,
263- ] ,
264- // `true` is used as a default so backends need to acknowledge when they do not
265- // support the float types, rather than accidentally quietly skipping all tests.
266- has_reliable_f16 : true ,
267- has_reliable_f16_math : true ,
268- has_reliable_f128 : true ,
269- has_reliable_f128_math : true ,
280+ target_features,
281+ unstable_target_features,
282+ has_reliable_f16,
283+ has_reliable_f16_math : has_reliable_f16,
284+ has_reliable_f128,
285+ has_reliable_f128_math : has_reliable_f128,
270286 }
271287 }
272288
0 commit comments