Index: crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/i386-elf/crt1.c,v retrieving revision 1.12 diff -u -r1.12 crt1.c --- crt1.c 26 Jan 2003 23:14:47 -0000 1.12 +++ crt1.c 15 Apr 2004 20:41:11 -0000 @@ -101,7 +101,40 @@ monstartup(&eprol, &etext); #endif _init(); +#ifndef __GNUC__ exit( main(argc, argv, env) ); +#else + /* + * Some versions of gcc expect the stack frame to be aligned as + * follows after it is set up in main(): + * + * +--------------+ <--- aligned by PREFERRED_STACK_BOUNDARY + * +%ebp (if any) + + * +--------------+ + * |return address| + * +--------------+ + * | arguments | + * | : | + * | : | + * +--------------+ + * + * We implement the above to fix just the usual case. + * Alignment for main() is too compiler-dependent to handle correctly + * in all cases here (or in the kernel). E.g., a different alignment + * is required for at least gcc-2.95.4 even for the small variation + * of compiling main() with -fomit-frame-pointer. + */ + __asm__(" \ + andl $~0xf, %%esp; \ + subl $12+12, %%esp; \ + movl %0, 0(%%esp); \ + movl %1, 4(%%esp); \ + movl %2, 8(%%esp); \ + call main; \ + movl %%eax, 0(%%esp); \ + call exit \ + " : : "r" (argc), "r" (argv), "r" (env) : "ax", "cx", "dx", "memory"); +#endif } #ifdef GCRT