Date: 2 Dec 1999 12:02:12 -0000 From: Ville-Pertti Keinonen <will@iki.fi> To: marcel@scc.nl Cc: current@freebsd.org, dillon@apollo.backplane.com, bde@zeta.org.au Subject: Re: kernel: -mpreferred-stack-boundary=2 ?? Message-ID: <19991202120212.4618.qmail@ns.demophon.com> In-Reply-To: <384657E7.B3E461D5@scc.nl> (message from Marcel Moolenaar on Thu, 02 Dec 1999 12:28:39 %2B0100)
next in thread | previous in thread | raw e-mail | index | archive | help
> AFAICT, it's enough to just align the stack before doing anything else.
> In this case it means aligning the stack somewhere before
> (exit(main(...)). gcc maintains proper alignment on an aligned stack.
I wouldn't rely on that, gcc is free to assume that it can address
local variables relative to the stack. In practice, it uses %ebp
unless you use -fomit-frame-pointer, but I don't think that
manipulating the stack pointer without gcc knowing about it is
guaranteed to be safe (alloca is a special case, gcc detects that it
is used internally). Future improvements in code generation would
also be likely to break things.
However, an easy alternative would be to make the _start entry point
an assembly language stub that calls a C function:
That would look something like this if done in crt1.c:
asm(".text; .globl _start; _start:;"
"lea 4(%esp),%eax;"
"andl $~15,%esp;"
"subl $4,%esp;"
"pushl %eax;"
"call c_start");
static void
c_start(char **argv)
{
etc...
This of course assumes that static symbols have naming conventions
identical to global symbols. (It can easily be made more predictable
by assigning the function a specific symbol)
> Maybe alignment can even be done in the kernel...
It gets messy, it has to be done before putting the env and argv
pointers in place... On program entry, (%esp) is argc, %esp + 4 is
the beginning of the argv array and env array is located immediately
after the argv array.
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19991202120212.4618.qmail>
