@@ -21,6 +21,7 @@ use rustc_middle::ty::{self, TyCtxt};
21
21
use rustc_session:: config:: { OutputFilenames , OutputType } ;
22
22
use rustc_session:: cstore:: MetadataLoaderDyn ;
23
23
use rustc_session:: Session ;
24
+ use rustc_target:: abi:: Endian ;
24
25
use rustc_target:: spec:: PanicStrategy ;
25
26
use std:: collections:: BTreeMap ;
26
27
use std:: io:: BufWriter ;
@@ -57,6 +58,7 @@ impl CodegenBackend for GotocCodegenBackend {
57
58
) -> Box < dyn Any > {
58
59
super :: utils:: init ( ) ;
59
60
61
+ check_target ( & tcx. sess ) ;
60
62
check_options ( & tcx. sess , need_metadata_module) ;
61
63
62
64
let codegen_units: & ' tcx [ CodegenUnit < ' _ > ] = tcx. collect_and_partition_mono_items ( ( ) ) . 1 ;
@@ -184,7 +186,46 @@ impl CodegenBackend for GotocCodegenBackend {
184
186
}
185
187
}
186
188
189
+ fn check_target ( session : & Session ) {
190
+ // The requirement below is needed to build a valid CBMC machine model
191
+ // in function `machine_model_from_session` from
192
+ // src/kani-compiler/src/codegen_cprover_gotoc/context/goto_ctx.rs
193
+ let is_linux_target = session. target . llvm_target == "x86_64-unknown-linux-gnu" ;
194
+ // Comparison with `x86_64-apple-darwin` does not work well because the LLVM
195
+ // target may become `x86_64-apple-macosx10.7.0` (or similar) and fail
196
+ let is_darwin_target = session. target . llvm_target . starts_with ( "x86_64-apple-" ) ;
197
+
198
+ if !is_linux_target && !is_darwin_target {
199
+ let err_msg = format ! (
200
+ "Kani requires the target platform to be `x86_64-unknown-linux-gnu` or `x86_64-apple-darwin`, but it is {}" ,
201
+ & session. target. llvm_target
202
+ ) ;
203
+ session. err ( & err_msg) ;
204
+ }
205
+
206
+ session. abort_if_errors ( ) ;
207
+ }
208
+
187
209
fn check_options ( session : & Session , need_metadata_module : bool ) {
210
+ // The requirements for `min_global_align` and `endian` are needed to build
211
+ // a valid CBMC machine model in function `machine_model_from_session` from
212
+ // src/kani-compiler/src/codegen_cprover_gotoc/context/goto_ctx.rs
213
+ match session. target . options . min_global_align {
214
+ Some ( 1 ) => ( ) ,
215
+ Some ( align) => {
216
+ let err_msg = format ! (
217
+ "Kani requires the target architecture option `min_global_align` to be 1, but it is {}." ,
218
+ align
219
+ ) ;
220
+ session. err ( & err_msg) ;
221
+ }
222
+ _ => ( ) ,
223
+ }
224
+
225
+ if session. target . options . endian != Endian :: Little {
226
+ session. err ( "Kani requires the target architecture option `endian` to be `little`." ) ;
227
+ }
228
+
188
229
if !session. overflow_checks ( ) {
189
230
session. err ( "Kani requires overflow checks in order to provide a sound analysis." ) ;
190
231
}
0 commit comments