@@ -420,9 +420,11 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
420
420
rust_main_def_id : DefId ,
421
421
entry_type : EntryFnType ,
422
422
) -> Bx :: Function {
423
- // The entry function is either `int main(void)` or `int main(int argc, char **argv)`,
424
- // depending on whether the target needs `argc` and `argv` to be passed in.
425
- let llfty = if cx. sess ( ) . target . main_needs_argc_argv {
423
+ // The entry function is either `int main(void)` or `int main(int argc, char **argv)`, or
424
+ // `Status efi_main(Handle hd, SystemTable *st)` depending on the target.
425
+ let llfty = if cx. sess ( ) . target . os . contains ( "uefi" ) {
426
+ cx. type_func ( & [ cx. type_ptr ( ) , cx. type_ptr ( ) ] , cx. type_isize ( ) )
427
+ } else if cx. sess ( ) . target . main_needs_argc_argv {
426
428
cx. type_func ( & [ cx. type_int ( ) , cx. type_ptr ( ) ] , cx. type_int ( ) )
427
429
} else {
428
430
cx. type_func ( & [ ] , cx. type_int ( ) )
@@ -485,8 +487,12 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
485
487
} ;
486
488
487
489
let result = bx. call ( start_ty, None , None , start_fn, & args, None ) ;
488
- let cast = bx. intcast ( result, cx. type_int ( ) , true ) ;
489
- bx. ret ( cast) ;
490
+ if cx. sess ( ) . target . os . contains ( "uefi" ) {
491
+ bx. ret ( result) ;
492
+ } else {
493
+ let cast = bx. intcast ( result, cx. type_int ( ) , true ) ;
494
+ bx. ret ( cast) ;
495
+ }
490
496
491
497
llfn
492
498
}
@@ -497,7 +503,18 @@ fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
497
503
cx : & ' a Bx :: CodegenCx ,
498
504
bx : & mut Bx ,
499
505
) -> ( Bx :: Value , Bx :: Value ) {
500
- if cx. sess ( ) . target . main_needs_argc_argv {
506
+ if cx. sess ( ) . target . os . contains ( "uefi" ) {
507
+ // Params for UEFI
508
+ let param_handle = bx. get_param ( 0 ) ;
509
+ let param_system_table = bx. get_param ( 1 ) ;
510
+ let arg_argc = bx. const_int ( cx. type_isize ( ) , 2 ) ;
511
+ let arg_argv = bx. alloca ( cx. type_array ( cx. type_i8p ( ) , 2 ) , Align :: ONE ) ;
512
+ bx. store ( param_handle, arg_argv, Align :: ONE ) ;
513
+ let arg_argv_el1 =
514
+ bx. gep ( cx. type_ptr_to ( cx. type_i8 ( ) ) , arg_argv, & [ bx. const_int ( cx. type_int ( ) , 1 ) ] ) ;
515
+ bx. store ( param_system_table, arg_argv_el1, Align :: ONE ) ;
516
+ ( arg_argc, arg_argv)
517
+ } else if cx. sess ( ) . target . main_needs_argc_argv {
501
518
// Params from native `main()` used as args for rust start function
502
519
let param_argc = bx. get_param ( 0 ) ;
503
520
let param_argv = bx. get_param ( 1 ) ;
@@ -549,7 +566,11 @@ pub fn allocator_kind_for_codegen(tcx: TyCtxt<'_>) -> Option<AllocatorKind> {
549
566
use rustc_middle:: middle:: dependency_format:: Linkage ;
550
567
list. iter ( ) . any ( |& linkage| linkage == Linkage :: Dynamic )
551
568
} ) ;
552
- if any_dynamic_crate { None } else { tcx. allocator_kind ( ( ) ) }
569
+ if any_dynamic_crate {
570
+ None
571
+ } else {
572
+ tcx. allocator_kind ( ( ) )
573
+ }
553
574
}
554
575
555
576
pub fn codegen_crate < B : ExtraBackendMethods > (
0 commit comments