Bug 9350 - -fomit-frame-pointer does not work for main
Summary: -fomit-frame-pointer does not work for main
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.2.1
: P3 normal
Target Milestone: 4.1.0
Assignee: Richard Henderson
URL:
Keywords: documentation
Depends on:
Blocks:
 
Reported: 2003-01-17 05:26 UTC by ctm
Modified: 2005-11-03 01:43 UTC (History)
1 user (show)

See Also:
Host:
Target: i686-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-10-16 04:25:15


Attachments
gcc_bug.bz2 (522 bytes, application/octet-stream)
2003-05-21 15:17 UTC, ctm
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ctm 2003-01-17 05:26:01 UTC
When -fomit-frame-pointer is used, main still uses a frame pointer.  The -fomit-frame-pointer portion of the gcc info pages doesn't mention this special case.

Release:
gcc version 3.2.1 20021207 (Red Hat Linux 8.0 3.2.1-2)

Environment:
Linux canceled.ardi.com 2.4.20-2.2acpi #1 Thu Jan 2 16:31:33 MST 2003 i686 i686
i386 GNU/Linux

How-To-Repeat:
attached file includes tiny example.
Comment 1 Wolfgang Bangerth 2003-03-15 05:15:06 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Doc bug.
Comment 2 Andrew Pinski 2003-12-03 09:03:17 UTC
From the docs:
Don't keep the frame pointer in a register for functions that don't need one
Well main needs it to realign the stack.
Comment 3 ctm 2003-12-03 16:02:44 UTC
If you change main in my example program to xmain, you get the behavior one would expect 
without any apriori knowledge about what gcc is going to do.

If gcc wants to treat main specially, that's fine.  But if you don't document this special case, the 
documentation is incomplete.

Just because main might be used as the entry point to a program doesn't mean that gcc users are 
going to guess that this means that main needs a frame pointer.  Without special knowledge (e.g. 
documentation, examination of the gcc source code, examination of gcc's behavior) a 
knowledgable person would assume that whether a function needs a frame pointer or not is a 
question that can be resolved without knowing the function's name.
Comment 4 Andrew Pinski 2005-09-26 15:24:22 UTC
The note in the documention should be expanded to say approximately "-fomit-frame-pointer does 
nothing for the function main as it is the entry point and the need for realigning the stack is needed".
Comment 5 Richard Henderson 2005-11-03 01:40:38 UTC
Subject: Bug 9350

Author: rth
Date: Thu Nov  3 01:40:33 2005
New Revision: 106420

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106420
Log:
        PR target/9350
        PR target/24374
        * dwarf2out.c (dwarf2out_reg_save_reg): New.
        (dwarf2out_frame_debug_expr): Return after dwarf_handle_frame_unspec.
        * function.c (assign_parms): Use calls.internal_arg_pointer.
        (expand_main_function): Remove FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
        code.
        * target-def.h (TARGET_INTERNAL_ARG_POINTER): New.
        (TARGET_CALLS): Add it.
        * target.h (struct gcc_target): Add calls.internal_arg_pointer.
        * targhooks.c (default_internal_arg_pointer): New.
        * targhooks.h (default_internal_arg_pointer): Declare.
        * tree.h (dwarf2out_reg_save_reg): Declare.
        * doc/tm.texi (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN): Remove.
        * config/i386/i386.c (dbx_register_map): Add return column.
        (dbx64_register_map, svr4_dbx_register_map): Likewise.
        (TARGET_INTERNAL_ARG_POINTER, ix86_internal_arg_pointer): New.
        (TARGET_DWARF_HANDLE_FRAME_UNSPEC, ix86_dwarf_handle_frame_unspec): New.        (ix86_function_ok_for_sibcall): Disable if force_align_arg_pointer.
        (ix86_save_reg): Save force_align_arg_pointer.
        (ix86_emit_save_regs): Make regno unsigned.
        (ix86_emit_save_regs_using_mov): Likewise.
        (ix86_expand_prologue): Handle force_align_arg_pointer.
        (ix86_expand_epilogue): Likewise.
        * config/i386/i386.h: (dbx_register_map): Update.
        (dbx64_register_map, svr4_dbx_register_map): Update.
        (struct machine_function): Add force_align_arg_pointer.
        * config/i386/i386.md (UNSPEC_REG_SAVE, UNSPEC_DEF_CFA): New.
        (UNSPEC_TP, UNSPEC_TLS_GD, UNSPEC_TLS_LD_BASE): Renumber.
        (TARGET_PUSH_MEMORY peepholes): Disable if RTX_FRAME_RELATED_P.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/config/i386/i386.h
    trunk/gcc/config/i386/i386.md
    trunk/gcc/doc/tm.texi
    trunk/gcc/dwarf2out.c
    trunk/gcc/function.c
    trunk/gcc/target-def.h
    trunk/gcc/target.h
    trunk/gcc/targhooks.c
    trunk/gcc/targhooks.h
    trunk/gcc/tree.h

Comment 6 Richard Henderson 2005-11-03 01:43:44 UTC
Fixed.
Comment 7 stuart@gcc.gnu.org 2006-02-28 01:47:22 UTC
Subject: Bug 9350

Author: stuart
Date: Tue Feb 28 01:47:16 2006
New Revision: 111503

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=111503
Log:
2006-02-17  Stuart Hastings  <stuart@apple.com>

	* Radar 4356747
	(marked APPLE LOCAL "4356747 stack realign")
	doc/extend.texi (force_align_arg_pointer): Document.
	doc/invoke.texi (-mstackrealign): Document.
	config/i386/i386.h (TARGET_OPTIONS): Add -mstackrealgin.
	config/i386/i386.c (ix86_force_align_arg_pointer): New.
	(ix86_force_align_arg_pointer_string): New.
	(ix86_attribute_table): Add "force_align_arg_pointer" attribute.
	(ix86_function_regparm): Compensate for new attribute.
	(ix86_internal_arg_pointer): Check for new attribute.

2005-11-02  Richard Henderson  <rth@redhat.com>

	(marked APPLE LOCAL "mainline 2006-02-17 4356747 stack realign")
	PR target/9350
	PR target/24374
	* dwarf2out.c (dwarf2out_reg_save_reg): New.
	(dwarf2out_frame_debug_expr): Return after dwarf_handle_frame_unspec.
	* function.c (assign_parms): Use calls.internal_arg_pointer.
	(expand_main_function): Remove FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
	code.
	* target-def.h (TARGET_INTERNAL_ARG_POINTER): New.
	(TARGET_CALLS): Add it.
	* target.h (struct gcc_target): Add calls.internal_arg_pointer.
	* targhooks.c (default_internal_arg_pointer): New.
	* targhooks.h (default_internal_arg_pointer): Declare.
	* tree.h (dwarf2out_reg_save_reg): Declare.
	* doc/tm.texi (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN): Remove.
	* config/i386/i386.c (dbx_register_map): Add return column.
	(dbx64_register_map, svr4_dbx_register_map): Likewise.
	(TARGET_INTERNAL_ARG_POINTER, ix86_internal_arg_pointer): New.
	(TARGET_DWARF_HANDLE_FRAME_UNSPEC, ix86_dwarf_handle_frame_unspec): New.
	(ix86_function_ok_for_sibcall): Disable if force_align_arg_pointer.
	(ix86_save_reg): Save force_align_arg_pointer.
	(ix86_emit_save_regs): Make regno unsigned.
	(ix86_emit_save_regs_using_mov): Likewise.
	(ix86_expand_prologue): Handle force_align_arg_pointer.
	(ix86_expand_epilogue): Likewise.
	* config/i386/i386.h: (dbx_register_map): Update.
	(dbx64_register_map, svr4_dbx_register_map): Update.
	(struct machine_function): Add force_align_arg_pointer.
	* config/i386/i386.md (UNSPEC_REG_SAVE, UNSPEC_DEF_CFA): New.
	(UNSPEC_TP, UNSPEC_TLS_GD, UNSPEC_TLS_LD_BASE): Renumber.
	(TARGET_PUSH_MEMORY peepholes): Disable if RTX_FRAME_RELATED_P.

2006-02-27  Stuart Hastings  <stuart@apple.com>

	Radar 4448096
	* testsuite/gcc.target/i386/4448096-1.c: New.
	* testsuite/g++.dg/4448096-2.C: New.

Added:
    branches/apple-local-200502-branch/gcc/testsuite/gcc.target/i386/20060210-1.c
    branches/apple-local-200502-branch/gcc/testsuite/gcc.target/i386/20060210-2.c
    branches/apple-local-200502-branch/gcc/testsuite/gcc.target/i386/20060210-3.c
    branches/apple-local-200502-branch/gcc/testsuite/gcc.target/i386/20060210-4.c
Modified:
    branches/apple-local-200502-branch/gcc/ChangeLog.apple-ppc
    branches/apple-local-200502-branch/gcc/config/i386/i386-protos.h
    branches/apple-local-200502-branch/gcc/config/i386/i386.c
    branches/apple-local-200502-branch/gcc/config/i386/i386.h
    branches/apple-local-200502-branch/gcc/config/i386/i386.md
    branches/apple-local-200502-branch/gcc/doc/extend.texi
    branches/apple-local-200502-branch/gcc/doc/invoke.texi
    branches/apple-local-200502-branch/gcc/dwarf2out.c
    branches/apple-local-200502-branch/gcc/emit-rtl.c
    branches/apple-local-200502-branch/gcc/function.c
    branches/apple-local-200502-branch/gcc/rtl.h
    branches/apple-local-200502-branch/gcc/target-def.h
    branches/apple-local-200502-branch/gcc/target.h
    branches/apple-local-200502-branch/gcc/targhooks.c
    branches/apple-local-200502-branch/gcc/targhooks.h
    branches/apple-local-200502-branch/gcc/testsuite/ChangeLog.apple-ppc
    branches/apple-local-200502-branch/gcc/tree.h