So, the main function is the first thing that is executed when the program starts, but what is the initial value of esp when the main launch starts? i) what is on top of the stack when starting the main launch, are they command line arguments?
mainIt is called as a normal function, therefore (with a cdeclconvention call) the top elements are an up-down (optional) environment pointer, then a pointer to a pointer to a string argument argument is an array, then argc, then a return address main.
If I want to create local variables inside main, should I save the esp value in ebp and then increase esp by how much data I need, how do I do it inside a user-defined function?
main . crt0.o ( ) :
void
_start(void)
{
int rv = main(newargc, newargv, environ);
do_global_dtors();
exit(rv);
}
, tl; dr: .
( , _start , , syscall exit.)