@@ -420,9 +420,11 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
420420 rust_main_def_id : DefId ,
421421 entry_type : EntryFnType ,
422422 ) -> 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 {
426428 cx. type_func ( & [ cx. type_int ( ) , cx. type_ptr ( ) ] , cx. type_int ( ) )
427429 } else {
428430 cx. type_func ( & [ ] , cx. type_int ( ) )
@@ -485,8 +487,12 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
485487 } ;
486488
487489 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+ }
490496
491497 llfn
492498 }
@@ -497,7 +503,18 @@ fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
497503 cx : & ' a Bx :: CodegenCx ,
498504 bx : & mut Bx ,
499505) -> ( 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 {
501518 // Params from native `main()` used as args for rust start function
502519 let param_argc = bx. get_param ( 0 ) ;
503520 let param_argv = bx. get_param ( 1 ) ;
@@ -549,7 +566,11 @@ pub fn allocator_kind_for_codegen(tcx: TyCtxt<'_>) -> Option<AllocatorKind> {
549566 use rustc_middle:: middle:: dependency_format:: Linkage ;
550567 list. iter ( ) . any ( |& linkage| linkage == Linkage :: Dynamic )
551568 } ) ;
552- if any_dynamic_crate { None } else { tcx. allocator_kind ( ( ) ) }
569+ if any_dynamic_crate {
570+ None
571+ } else {
572+ tcx. allocator_kind ( ( ) )
573+ }
553574}
554575
555576pub fn codegen_crate < B : ExtraBackendMethods > (
0 commit comments