Align the stack suitably for the version of gcc in FreeBSD-4 (provided
-fomit-frame-pointer is not used). This is mostly moot for -current because gcc-3 does the alignment (slightly incorrectly) in main(). This patch is intended for easy MFC'ing and should be backed out in -current soon since it causes compiler warnings and better fixes are possible in -current. The best fix is to do nothing here and wait for gcc to do stack alignment right. gcc-3 aligns the stack in main(), but does it too late for main()'s local variables and too late for anything called before main(). A misaligned stack is now more than an efficiency problem, since some SSE instructions in some or all (hardware) implementations trap on misaligned operands even if alignment checking is not enabled. PR: 41528: Submitted by: NIIMI Satoshi <sa2c@sa2c.net> (original version) MFC after: 3 days
This commit is contained in:
parent
7698537b29
commit
fb0be37ded
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=104143
@ -100,7 +100,40 @@ _start(char *ap, ...)
|
||||
monstartup(&eprol, &etext);
|
||||
#endif
|
||||
_init();
|
||||
#ifndef __GNUC__
|
||||
exit( main(argc, argv, env) );
|
||||
#else
|
||||
/*
|
||||
* Some versions of gcc-2 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 in FreeBSD-4.
|
||||
* 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 # align stack to 16-byte boundary
|
||||
subl $12+12, %%esp # space for args and padding
|
||||
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
|
||||
|
@ -100,7 +100,40 @@ _start(char *ap, ...)
|
||||
monstartup(&eprol, &etext);
|
||||
#endif
|
||||
_init();
|
||||
#ifndef __GNUC__
|
||||
exit( main(argc, argv, env) );
|
||||
#else
|
||||
/*
|
||||
* Some versions of gcc-2 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 in FreeBSD-4.
|
||||
* 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 # align stack to 16-byte boundary
|
||||
subl $12+12, %%esp # space for args and padding
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user