Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Jun 2002 15:40:23 +1000 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Matthew Dillon <dillon@apollo.backplane.com>
Cc:        current@FreeBSD.ORG, <obrien@FreeBSD.ORG>
Subject:   Re: fixes for gcc -falign-foo
Message-ID:  <20020606152514.H10454-100000@gamplex.bde.org>
In-Reply-To: <200206060428.g564SY1c011166@apollo.backplane.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 5 Jun 2002, Matthew Dillon wrote:

>     Hey Bruce or David... has GCC3 by any chance fixed the stack alignment
>     eyesore or is that still the default?  If so could we by any chance fix
>     it in our version?  It creates massive bloat when you have lots of tiny
>     functions and as far as I can tell there is no advantage at all except
>     for the occassional floating point intensive app.  I really hate having
>     to specify -mpreferred-stack-boundary=2 in my builds.

Apparently not.  It seems to have even added an extra stack alignment
instruction:

%%%
$ cat z.c
main()
{
	foo();
	bar(1, 2);
}
$ cc -O -S z.c
$ cat z.s
	.file	"z.c"
	.text
	.p2align 2,,3
.globl main
	.type	main,@function
main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	andl	$-16, %esp	<---
	call	foo
	subl	$8, %esp
	pushl	$2
	pushl	$1
	call	bar
	leave
	ret
.Lfe1:
	.size	main,.Lfe1-main
	.ident	"GCC: (GNU) 3.1 [FreeBSD] 20020509 (prerelease)"
%%%

This andl is precisely what is needed to get the stack to a known alignment
starting from an unknown one, but I think it should only be done if the
function has any local variables that need more than 4-byte alignment
(and/or if the cpu arch cares).  But in the above it is just an extra
instruction if the caller has already aligned the stack.

The alignment and the extra alignment is even down when it is obviously
just wasted:

%%%
$ cat z.c
main()
{
}
$ cc -O3 -S z.c
$ cat z.s
	.file	"z.c"
	.text
	.p2align 2,,3
.globl main
	.type	main,@function
main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp	<-- old alignment
	andl	$-16, %esp	<-- new alignment
	leave			<-- alignment not actually used
	ret
.Lfe1:
	.size	main,.Lfe1-main
	.ident	"GCC: (GNU) 3.1 [FreeBSD] 20020509 (prerelease)"
%%%

I use the default for this except for compiling gcc itself.

Bruce


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?20020606152514.H10454-100000>