Date: Tue, 5 Feb 2002 17:01:29 +1100 (EST) From: Bruce Evans <bde@zeta.org.au> To: Mike Silbersack <silby@silby.com> Cc: Michal Mertl <mime@traveller.cz>, <hackers@freebsd.org>, <greg@bogslab.ucdavis.edu> Subject: Re: stack alignment issues Message-ID: <20020205163210.G25358-100000@gamplex.bde.org> In-Reply-To: <20020204120547.B2144-100000@patrocles.silby.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 4 Feb 2002, Mike Silbersack wrote: > On Tue, 5 Feb 2002, Bruce Evans wrote: > > I haven't done anything to clean up the patch. I hope the problem > > will go away in future versions of gcc (align the stack at runtime in > > the few routines that actually need it). > > Well, if Linux aligns the initial stack, the chance that gcc will have > auto-alignment added sounds to be about zero. You might as well go ahead > with your patch when you get a chance. There is a nonzero probability that the pessimization of aligning in almost every routine will be fixed someday. Actually, the pessimization is worse -- the alignment is done before every call. Example: %%% foo.c: foo() { f1(1); f2(2); f3(3.0); } %%% gcc -O -S [-mpreferred-stack boundary] currently generates the following code for this: %%% .file "z.c" .version "01.01" gcc2_compiled.: .section .rodata .p2align 3 .LC0: .long 0x0,0x40080000 .text .p2align 2,0x90 .globl foo .type foo,@function foo: pushl %ebp movl %esp,%ebp subl $8,%esp # <- extra instruction for alignment (for foo) addl $-12,%esp # <- extra instruction for alignment (for f1) pushl $1 call f1 addl $-12,%esp # <- extra instruction for alignment (for f2) pushl $2 call f2 addl $32,%esp # <- extra instruction for alignment (for f3) addl $-8,%esp # <- extra instruction for alignment (another) pushl .LC0+4 pushl .LC0 call f3 leave ret .Lfe1: .size foo,.Lfe1-foo .ident "GCC: (c) 2.95.3 20010315 (release)" %%% It should generate something like: .file "z.c" .version "01.01" gcc2_compiled.: .section .rodata .p2align 3 .LC0: .long 0x0,0x40080000 .text .p2align 2,0x90 .globl foo .type foo,@function foo: pushl %ebp movl %esp,%ebp andl $~0x7,%esp # <- extra instruction for alignment (for foo) # Only needed since foo() uses FPU. # 8-byte alignment enough for doubles? # Adjust in prologue so that there are # hopefully no alloca()-like issues, except # we need a frame pointer to restore %esp. pushl $1 call f1 pushl $2 call f2 pushl .LC0+4 pushl .LC0 call f3 leave ret .Lfe1: .size foo,.Lfe1-foo .ident "GCC: (c) 2.95.3 20010315 (release)" %%% My patch is not suitable for committing verbatim. It has 2 or 3 XXX's. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020205163210.G25358-100000>