Hrmm, just did that test myself, it seems to do some stack alignment.Craze Frog wrote:No, main has a special meaning. It means, "this is where I want the program execution to start". Just read the C99 standard, section 5.1.2.2.1. The same standard also prohibits any function named main to have any other return type than int. Which is the reason for the warning in GCC.MessiahAndrw wrote:No it doesn't. main() is no different to any other function. It is usually the first C/C++ function called in your code, but you can easily edit your assembly stub to change that.Craze Frog wrote:main() has a special meaning in C. Just rename your function k_main() or something and the warning will go away.
Edit: JamesM got there before me, but unfortunately he isn't completely correct either.Source code:In implementation main() is no different...Asm generated by gcc 3.4.4 for cygwin:Code: Select all
int crudebox() { __asm__("#CODE START 2"); __asm__("#CODE END 2"); return 0; } int main() { __asm__("#CODE START"); __asm__("#CODE END"); return 0; }
I agree that it shouldn't be like that, the stack probing should be done in another function that calls main, but someone decided to do it like that.Code: Select all
... _crudebox: pushl %ebp movl %esp, %ebp /APP #CODE START 2 #CODE END 2 /NO_APP popl %ebp xorl %eax, %eax ret ... _main: pushl %ebp movl $16, %eax movl %esp, %ebp subl $8, %esp andl $-16, %esp call __alloca call ___main /APP #CODE START #CODE END /NO_APP leave xorl %eax, %eax ret
Code: Select all
#include <stdlib.h>
#include <stdio.h>
int func(char argc, char **argv)
{
return 0;
}
int main(char argc, char **argv)
{
return 0;
}
$ gcc -o test.o test.c -nostdlib
$ objdump -d test.o
test.o: file format elf32-i386
Disassembly of section .text:
08048094 <func>:
8048094: 55 push %ebp
8048095: 89 e5 mov %esp,%ebp
8048097: 83 ec 04 sub $0x4,%esp
804809a: 8b 45 08 mov 0x8(%ebp),%eax
804809d: 88 45 fc mov %al,0xfffffffc(%ebp)
80480a0: b8 00 00 00 00 mov $0x0,%eax
80480a5: c9 leave
80480a6: c3 ret
080480a7 <main>:
80480a7: 8d 4c 24 04 lea 0x4(%esp),%ecx
80480ab: 83 e4 f0 and $0xfffffff0,%esp
80480ae: ff 71 fc pushl 0xfffffffc(%ecx)
80480b1: 55 push %ebp
80480b2: 89 e5 mov %esp,%ebp
80480b4: 51 push %ecx
80480b5: 83 ec 04 sub $0x4,%esp
80480b8: 8b 01 mov (%ecx),%eax
80480ba: 88 45 f8 mov %al,0xfffffff8(%ebp)
80480bd: b8 00 00 00 00 mov $0x0,%eax
80480c2: 83 c4 04 add $0x4,%esp
80480c5: 59 pop %ecx
80480c6: 5d pop %ebp
80480c7: 8d 61 fc lea 0xfffffffc(%ecx),%esp
80480ca: c3 ret