Bug 6627 - -fno-align-functions regression from 2.95
Summary: -fno-align-functions regression from 2.95
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2002-05-10 11:46 UTC by David O'Brien
Modified: 2003-07-25 17:33 UTC (History)
5 users (show)

See Also:
Host: i386-portbld-freebsd5.0
Target: i386-portbld-freebsd5.0
Build: i386-portbld-freebsd5.0
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David O'Brien 2002-05-10 11:46:01 UTC
 from http://gcc.gnu.org/ml/gcc-bugs/2002-05/msg00372.html

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).

Using the program below, this is what the current system compiler (2.95.4
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.

Release:
3.1 20020509 (prerelease) [FreeBSD]

Environment:
System: FreeBSD dragon.nuxi.com 5.0-CURRENT FreeBSD 5.0-CURRENT #261: Mon May 6 11:39:49 PDT 2002 rootk@dragon.nuxi.com:/FBSD/src/sys/i386/compile/DRAGON i386


 
host: i386-portbld-freebsd5.0
build: i386-portbld-freebsd5.0
target: i386-portbld-freebsd5.0
configured with: ./..//gcc-20020429/configure --disable-nls --with-gnu-as --with-gnu-ld --with-gxx-include-dir=/opt/gcc31.2002-04-29/lib/gcc-lib/i386-portbld-freebsd5.0/3.1/include/g++ --disable-libgcj --disable-shared --prefix=/opt/gcc31.2002-04-29 i386-portbld-freebsd5.0

How-To-Repeat:
void foo(void);
void bar(void);

void
foo(void)
{
}

void
bar(void)
{
}

gcc295 -Os -malign-functions=0 -c test.c
gcc31 -Os -malign-functions=0 -c test.c
Comment 1 Richard Henderson 2002-05-13 16:52:40 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: http://gcc.gnu.org/ml/gcc/2002-05/msg00989.html
Comment 2 David O'Brien 2002-06-27 13:12:08 UTC
From: obrien@freebsd.org
To: audit@freebsd.org, obrien@freebsd.org, gcc-gnats@gcc.gnu.org,
   gcc-prs@gcc.gnu.org, current@freebsd.org, jhb@freebsd.org,
   gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org
Cc:  
Subject: Re: optimization/6627: -fno-align-functions regression from 2.95
Date: Thu, 27 Jun 2002 13:12:08 -0700 (PDT)

 rth said at http://gcc.gnu.org/ml/gcc/2002-05/msg00989.html he would not
 raise the priority for 3.1.1.  But this is a regression and I hope maybe
 something can be done about it.  Maybe a fix based on a #define one must
 explicitly turn on when building GCC.
 
 I do not see why a fix cannot go in (in some form).  If a C++ user asks for
 an alignment of `1' then give it to them -- since when has C/C++ been about
 not letting the user shoot their foot off?  Or, can't the fix take into
 account that I am compiling C and not C++?
 
 This regression is still causing us problems in FreeBSD's boot code due to
 the larger size the code produces.  I'm sure this could be an issue for
 some embedded users.

Comment 3 Gerald Pfeifer 2002-06-27 22:28:10 UTC
From: Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>
To: gcc-gnats@gcc.gnu.org, <gcc-prs@gcc.gnu.org>
Cc: "David O'Brien" <obrien@freebsd.org>, <jhb@freebsd.org>,
   <current@freebsd.org>, <audit@freebsd.org>
Subject: Re: optimization/6627: -fno-align-functions regression from 2.95
Date: Thu, 27 Jun 2002 22:28:10 +0200 (CEST)

 This *is* a regression (even if it may be hard to fix on the release
 branch), so I'm raising it's priority.
 
 Gerald
 

Comment 4 Roger Sayle 2002-10-02 18:46:46 UTC
From: sayle@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/6627
Date: 2 Oct 2002 18:46:46 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	sayle@gcc.gnu.org	2002-10-02 11:46:46
 
 Modified files:
 	gcc            : ChangeLog toplev.c flags.h varasm.c tree.h 
 	gcc/config/i386: i386.h 
 	gcc/cp         : ChangeLog cp-tree.h decl.c 
 	gcc/java       : ChangeLog lang.c 
 
 Log message:
 	PR optimization/6627
 	* toplev.c (force_align_functions_log): New global variable.
 	* flags.h (force_align_functions_log): Add extern prototype.
 	* varasm.c (assemble_start_function): Use it to force minimum
 	function alignment.
 	* config/i386/i386.h (FUNCTION_BOUNDARY): Set the correct
 	minimum function alignment to one byte.
 	(TARGET_PTRMEMFUNC_VBIT_LOCATION): Store the virtual bit in
 	the least significant bit of vtable member function pointers.
 	* tree.h (enum ptrmemfunc_vbit_where_t): Move definition to
 	here from cp/cp-tree.h.
 	
 	* cp/cp-tree.h (enum ptrmemfunc_vbit_where_t): Delete definition
 	from here, and move it to tree.h.
 	* cp/decl.c (cxx_init_decl_processing): If storing the vbit
 	in function pointers, ensure that force_align_functions_log
 	is atleast one.
 	
 	* java/lang.c (java_init): If storing the vbit in function
 	pointers, ensure that force_align_functions_log is atleast
 	one to aid compatability with g++ vtables.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.15601&r2=1.15602
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/toplev.c.diff?cvsroot=gcc&r1=1.677&r2=1.678
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/flags.h.diff?cvsroot=gcc&r1=1.90&r2=1.91
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&r1=1.313&r2=1.314
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree.h.diff?cvsroot=gcc&r1=1.357&r2=1.358
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.h.diff?cvsroot=gcc&r1=1.291&r2=1.292
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.2977&r2=1.2978
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.754&r2=1.755
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.941&r2=1.942
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1061&r2=1.1062
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/lang.c.diff?cvsroot=gcc&r1=1.110&r2=1.111
 
Comment 5 Roger Sayle 2002-10-02 19:45:09 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: This has just been fixed on mainline CVS by the following patch:
    
    2002-10-02  Roger Sayle  <roger@eyesopen.com>
    
            PR optimization/6627
            * toplev.c (force_align_functions_log): New global variable.
            * flags.h (force_align_functions_log): Add extern prototype.
            * varasm.c (assemble_start_function): Use it to force minimum
            function alignment.
            * config/i386/i386.h (FUNCTION_BOUNDARY): Set the correct
            minimum function alignment to one byte.
            (TARGET_PTRMEMFUNC_VBIT_LOCATION): Store the virtual bit in
            the least significant bit of vtable member function pointers.
            * tree.h (enum ptrmemfunc_vbit_where_t): Move definition to
            here from cp/cp-tree.h.
Comment 6 Roger Sayle 2002-10-06 23:02:12 UTC
From: sayle@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/6627
Date: 6 Oct 2002 23:02:12 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	sayle@gcc.gnu.org	2002-10-06 16:02:12
 
 Modified files:
 	gcc            : ChangeLog toplev.c flags.h varasm.c tree.h 
 	gcc/config/i386: i386.h 
 	gcc/cp         : ChangeLog cp-tree.h decl.c 
 	gcc/java       : ChangeLog lang.c 
 
 Log message:
 	PR optimization/6627
 	* toplev.c (force_align_functions_log): New global variable.
 	* flags.h (force_align_functions_log): Add extern prototype.
 	* varasm.c (assemble_start_function): Use it to force minimum
 	function alignment.
 	* config/i386/i386.h (FUNCTION_BOUNDARY): Set the correct
 	minimum function alignment to one byte.
 	(TARGET_PTRMEMFUNC_VBIT_LOCATION): Store the virtual bit in
 	the least significant bit of vtable member function pointers.
 	* tree.h (enum ptrmemfunc_vbit_where_t): Move definition to
 	here from cp/cp-tree.h.
 	
 	* cp/cp-tree.h (enum ptrmemfunc_vbit_where_t): Delete definition
 	from here, and move it to tree.h.
 	* cp/decl.c (cxx_init_decl_processing): If storing the vbit
 	in function pointers, ensure that force_align_functions_log
 	is atleast one.
 	
 	* java/lang.c (java_init): If storing the vbit in function
 	pointers, ensure that force_align_functions_log is atleast
 	one to aid compatability with g++ vtables.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.13152.2.657.2.72&r2=1.13152.2.657.2.73
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/toplev.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.574.2.16.2.1&r2=1.574.2.16.2.2
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/flags.h.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.76.4.1&r2=1.76.4.1.4.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.250.2.14&r2=1.250.2.14.2.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.308.2.2&r2=1.308.2.2.4.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.h.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.243.2.8.2.1&r2=1.243.2.8.2.2
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.2685.2.114.2.12&r2=1.2685.2.114.2.13
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.681.2.12.2.3&r2=1.681.2.12.2.4
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.866.2.36.2.1&r2=1.866.2.36.2.2
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.925.2.59.2.2&r2=1.925.2.59.2.3
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/lang.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.85.2.4&r2=1.85.2.4.2.1