-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't add argc
and argv
arguments to main
on WASI.
#65576
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -414,8 +414,11 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &' | |||||
rust_main_def_id: DefId, | ||||||
use_start_lang_item: bool, | ||||||
) { | ||||||
let llfty = | ||||||
cx.type_func(&[cx.type_int(), cx.type_ptr_to(cx.type_i8p())], cx.type_int()); | ||||||
let llfty = if cx.sess().target.target.options.main_needs_argc_argv { | ||||||
cx.type_func(&[cx.type_int(), cx.type_ptr_to(cx.type_i8p())], cx.type_int()) | ||||||
} else { | ||||||
cx.type_func(&[], cx.type_int()) | ||||||
}; | ||||||
|
||||||
let main_ret_ty = cx.tcx().fn_sig(rust_main_def_id).output(); | ||||||
// Given that `main()` has no arguments, | ||||||
|
@@ -445,11 +448,19 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &' | |||||
|
||||||
bx.insert_reference_to_gdb_debug_scripts_section_global(); | ||||||
|
||||||
// Params from native main() used as args for rust start function | ||||||
let param_argc = bx.get_param(0); | ||||||
let param_argv = bx.get_param(1); | ||||||
let arg_argc = bx.intcast(param_argc, cx.type_isize(), true); | ||||||
let arg_argv = param_argv; | ||||||
let (arg_argc, arg_argv) = if cx.sess().target.target.options.main_needs_argc_argv { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function is already large; this bit could be extracted into its own (+ appropriate doc comment). |
||||||
// Params from native main() used as args for rust start function | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
let param_argc = bx.get_param(0); | ||||||
let param_argv = bx.get_param(1); | ||||||
let arg_argc = bx.intcast(param_argc, cx.type_isize(), true); | ||||||
let arg_argv = param_argv; | ||||||
(arg_argc, arg_argv) | ||||||
} else { | ||||||
// The Rust start function doesn't need argc and argv, so just pass zeros. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
let arg_argc = bx.const_int(cx.type_int(), 0); | ||||||
let arg_argv = bx.const_null(cx.type_ptr_to(cx.type_i8p())); | ||||||
(arg_argc, arg_argv) | ||||||
}; | ||||||
|
||||||
let (start_fn, args) = if use_start_lang_item { | ||||||
let start_def_id = cx.tcx().require_lang_item(StartFnLangItem, None); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this wants a comment.