-fno-align-functions still adds padding on i386 on gcc3.1

John Baldwin jhb@FreeBSD.org
Thu May 9 21:51:00 GMT 2002


We are currently trying to change the system compiler in FreeBSD over
to gcc 3.1.x.  Some of the C code we compile is in the bootstrap where
space is a real premium, thus we want to avoid as much padding as
possible.  Since it's just boot code that isn't executed all that often
the performance hit from making the code more compact (i.e. if it's
misaligned) is much less important than the space taken up by padding.
The problem we are seeing is that -fno-align-functions doesn't seem to
actually be disabling function alignment (and possibly similar for the
other -fno-align-foo parameters).

Sample test program:

void foo(void);
void bar(void);

void
foo(void)
{
}

void
bar(void)
{
}

First this is what the current system compiler turns out:

> cc -v
Using builtin specs.
gcc version 2.95.4 20020320 [FreeBSD]
> cc -Os -malign-functions=0 test.c -c
> objdump -d test.o

test.o:     file format elf32-i386

Disassembly of section .text:

00000000 <foo>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   c9                      leave  
   4:   c3                      ret    

00000005 <bar>:
   5:   55                      push   %ebp
   6:   89 e5                   mov    %esp,%ebp
   8:   c9                      leave  
   9:   c3                      ret    
   a:   89 f6                   mov    %esi,%esi

Note <bar> starts at offset 05 right after <foo>.

This is what a CVS version of gcc 3.1 turns out:

> gcc31 -v
Reading specs from /usr/local/lib/gcc-lib/i386-portbld-freebsd5.0/3.1/specs
Configured with: ./..//gcc-20020429/configure --disable-nls --with-gnu-as
--with-gnu-ld
--with-gxx-include-dir=/usr/local/lib/gcc-lib/i386-portbld-freebsd5.0/3.1/includ
e/g++ --disable-libgcj --disable-shared --prefix=/usr/local
i386-portbld-freebsd5.0
Thread model: posix
gcc version 3.1 20020429 (prerelease) [FreeBSD]
> gcc31 -Os -malign-functions=0 -c test.c
cc1: warning: -malign-functions is obsolete, use -falign-functions
> objdump -d test.o

test.o:     file format elf32-i386

Disassembly of section .text:

00000000 <foo>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   c9                      leave  
   4:   c3                      ret    
   5:   90                      nop    

00000006 <bar>:
   6:   55                      push   %ebp
   7:   89 e5                   mov    %esp,%ebp
   9:   c9                      leave  
   a:   c3                      ret    
   b:   90                      nop    

Note the extra 'nop' after <foo> now to force <bar> to be
aligned.  If I use '-fno-align-functions' in place of
'-malign-functions=0' above, I get the same result.

Now a few extra nop's after each function isn't going to
add but so much "bloat" but we have seen a 7k program go from
128 bytes to spare to being 64 bytes too large, which is a
difference of 244 bytes.  As far as I can tell, the difference
in size is due to alignment padding for functions, labels, loops,
etc.

If you need more information I'll do my best to provide it.

-- 

John Baldwin <jhb@FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/



More information about the Gcc-bugs mailing list