public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer
       [not found] <bug-11807-6667@http.gcc.gnu.org/bugzilla/>
@ 2006-04-21  2:11 ` acahalan at gmail dot com
  2006-08-10 21:48 ` Martin dot vGagern at gmx dot net
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: acahalan at gmail dot com @ 2006-04-21  2:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #24 from acahalan at gmail dot com  2006-04-21 02:11 -------
PIC register: while the user could save and restore this, the whole point of
this fancy assembly notation is so that gcc can do nice scheduling and register
allocation. The save and restore should thus be done by gcc. Perhaps the PIC
register won't soon be needed, so gcc could use it for something else until it
gets reloaded with the normal content. At the very least, gcc could pick a good
location for the save/restore operations.

Frame pointer register: this is the same as the PIC register. It's good to
schedule the save/restore nicely.

Stack pointer register: this one is special. For app code, signals may arrive.
For kernel code, interrupts might be delivered without a stack change. Not
supporting a clobbered stack pointer is definitely tolerable. Ideally this case
could be handled (making the code non-reentrant), but the resulting mess is
probably of very limited use. I could imagine abusing push/pop to iterate over
arrays, but that's insane.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer
       [not found] <bug-11807-6667@http.gcc.gnu.org/bugzilla/>
  2006-04-21  2:11 ` [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer acahalan at gmail dot com
@ 2006-08-10 21:48 ` Martin dot vGagern at gmx dot net
  2007-01-25  1:02 ` pinskia at gcc dot gnu dot org
  2007-01-30 18:20 ` dpm at danger dot com
  3 siblings, 0 replies; 12+ messages in thread
From: Martin dot vGagern at gmx dot net @ 2006-08-10 21:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #25 from Martin dot vGagern at gmx dot net  2006-08-10 21:48 -------
(In reply to comment #8)
> 1. No way we can support clobbering both SP and FP.

You could in theory by storing one of them to some fixed memory location. But
here things get really ugly, so this is more of a philosophical answer.

> 2. We could support clobbering the FP by pushing it onto the stack and
>    restoring it. Doesn't seem worth the trouble, though, since people can
>    do this themselves in the asm.

Not necessarily. For x86 with -fomit-frame-pointer, local variables are usually
adressed relative to SP. If you push FP onto the stack, you modify SP, and
operands are prehaps no longer accessible. If gcc would store FP on the stack,
it could take the offset into account and make things work.

By the way, the same is imo true for the x86 PIC register ebx, which I would
like to see clobberable and stored by gcc as well. Saving and restoring ebx in
asm can be a real pain for the above reason. It would be great if the compiler
additionaly would ensure that no other operand is an address relative to ebx.

> 3. We could support clobbering the SP by introducing a FP and being very
>    careful. I cannot see any useful application though, so it doesn't seem
>    worth the trouble.

One useful application would be in the sense of "no clobber register may
overlap with any of the other operands". You could place the SP on the clobber
list to indicate that you are going to modify it, and gcc could then try to
avoid emitting SP-relative operands, e.g. by making them FP-relative or
shouting if this is not possible.

You might even think of this in the sense of "a clobbered register may contain
any data at the end of the asm". That would be asm code that uses the stack,
but  does not clean up afterwards. You could in many cases restore the SP as a
fixed offset from the FP, to allow such asm code.

BTW: The test case I just wrote for bug 28686 exhibits this problem here as
well, along with two other issues.


-- 

Martin dot vGagern at gmx dot net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Martin dot vGagern at gmx
                   |                            |dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer
       [not found] <bug-11807-6667@http.gcc.gnu.org/bugzilla/>
  2006-04-21  2:11 ` [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer acahalan at gmail dot com
  2006-08-10 21:48 ` Martin dot vGagern at gmx dot net
@ 2007-01-25  1:02 ` pinskia at gcc dot gnu dot org
  2007-01-30 18:20 ` dpm at danger dot com
  3 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-01-25  1:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #26 from pinskia at gcc dot gnu dot org  2007-01-25 01:02 -------
*** Bug 30579 has been marked as a duplicate of this bug. ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dpm at danger dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer
       [not found] <bug-11807-6667@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2007-01-25  1:02 ` pinskia at gcc dot gnu dot org
@ 2007-01-30 18:20 ` dpm at danger dot com
  3 siblings, 0 replies; 12+ messages in thread
From: dpm at danger dot com @ 2007-01-30 18:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #27 from dpm at danger dot com  2007-01-30 18:20 -------
Bug 30579 was marked as a duplicate of this bug. If I compile the test case
from that bug with -fomit-frame-pointer, gcc still generates invalid code. (We
don't use frame pointers in our system at all). Is this already known? It seems
like gcc should support clobbering of fp if you've disabled frame pointers.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer
  2003-08-05 12:45 [Bug c++/11807] New: Wrong usage of registers on ARM aw11 at os dot inf dot tu-dresden dot de
                   ` (6 preceding siblings ...)
  2005-08-23 11:42 ` ncunningham at cyclades dot com
@ 2005-08-26  9:34 ` aw11 at os dot inf dot tu-dresden dot de
  7 siblings, 0 replies; 12+ messages in thread
From: aw11 at os dot inf dot tu-dresden dot de @ 2005-08-26  9:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From aw11 at os dot inf dot tu-dresden dot de  2005-08-26 09:13 -------
GCC must error out when clobbering the frame pointer register because it is
likely to generate faulty code when the frame pointer is clobbered. You have to
save and restore the frame pointer on your own with (x86 push ebp; pop ebp). The
you need not to clobber it.

The only exception could possibly be the compiler option -fno-frame-pointer.
However at the moment GCC for arm generates faulty code even with this option,
if the frame pointer is clobbered.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer
  2003-08-05 12:45 [Bug c++/11807] New: Wrong usage of registers on ARM aw11 at os dot inf dot tu-dresden dot de
                   ` (5 preceding siblings ...)
  2005-08-23 11:41 ` pinskia at gcc dot gnu dot org
@ 2005-08-23 11:42 ` ncunningham at cyclades dot com
  2005-08-26  9:34 ` aw11 at os dot inf dot tu-dresden dot de
  7 siblings, 0 replies; 12+ messages in thread
From: ncunningham at cyclades dot com @ 2005-08-23 11:42 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ncunningham at cyclades dot com  2005-08-23 11:41 -------
Subject: Re:  GCC should error out when clobbering
	the stack pointer and frame pointer

The function needs to be inlined - the return value especially is
pivotal in the transition from the booted kernel context to the
suspended one. That said, I'm no x86 assembly guru, so there might be a
way around it.

Regards,

Nigel

On Tue, 2005-08-23 at 21:34, pinskia at gcc dot gnu dot org wrote:
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-23 11:34 -------
> (In reply to comment #20)
> > gcc shouldn't always error out in this situation. For suspend to disk, we
> > clobber all registers when restoring the original cpu context after copying back
> > the original kernel context. We could lie to gcc and say we don't clobber the
> > register, but I'd prefer to be honest :>
> 
> You know you can use a function to do that and a .s file for that right?  You don't need to use an inline-
> asm, right?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer
  2003-08-05 12:45 [Bug c++/11807] New: Wrong usage of registers on ARM aw11 at os dot inf dot tu-dresden dot de
                   ` (4 preceding siblings ...)
  2005-08-23 11:31 ` nigel at suspend2 dot net
@ 2005-08-23 11:41 ` pinskia at gcc dot gnu dot org
  2005-08-23 11:42 ` ncunningham at cyclades dot com
  2005-08-26  9:34 ` aw11 at os dot inf dot tu-dresden dot de
  7 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-23 11:41 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-23 11:34 -------
(In reply to comment #20)
> gcc shouldn't always error out in this situation. For suspend to disk, we
> clobber all registers when restoring the original cpu context after copying back
> the original kernel context. We could lie to gcc and say we don't clobber the
> register, but I'd prefer to be honest :>

You know you can use a function to do that and a .s file for that right?  You don't need to use an inline-
asm, right?

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer
  2003-08-05 12:45 [Bug c++/11807] New: Wrong usage of registers on ARM aw11 at os dot inf dot tu-dresden dot de
                   ` (3 preceding siblings ...)
  2005-08-10 11:29 ` pinskia at gcc dot gnu dot org
@ 2005-08-23 11:31 ` nigel at suspend2 dot net
  2005-08-23 11:41 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: nigel at suspend2 dot net @ 2005-08-23 11:31 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From nigel at suspend2 dot net  2005-08-23 11:31 -------
gcc shouldn't always error out in this situation. For suspend to disk, we
clobber all registers when restoring the original cpu context after copying back
the original kernel context. We could lie to gcc and say we don't clobber the
register, but I'd prefer to be honest :>

Nigel

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer
  2003-08-05 12:45 [Bug c++/11807] New: Wrong usage of registers on ARM aw11 at os dot inf dot tu-dresden dot de
                   ` (2 preceding siblings ...)
  2005-08-10 11:25 ` giovannibajo at libero dot it
@ 2005-08-10 11:29 ` pinskia at gcc dot gnu dot org
  2005-08-23 11:31 ` nigel at suspend2 dot net
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-10 11:29 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-10 11:28 -------
(In reply to comment #18)
> Small testcase from PR 23313, showing ICE on invalid:
the code does not ICE but creates "wrong code" at runtime.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor
           Keywords|ice-on-invalid-code         |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer
  2003-08-05 12:45 [Bug c++/11807] New: Wrong usage of registers on ARM aw11 at os dot inf dot tu-dresden dot de
  2005-08-10 10:46 ` [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer pinskia at gcc dot gnu dot org
  2005-08-10 10:47 ` pinskia at gcc dot gnu dot org
@ 2005-08-10 11:25 ` giovannibajo at libero dot it
  2005-08-10 11:29 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: giovannibajo at libero dot it @ 2005-08-10 11:25 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2005-08-10 11:25 -------
Small testcase from PR 23313, showing ICE on invalid:

-----------------------------------------
int main(){
    int i;

    asm (
        "xorl %%ebp, %%ebp\n\t"
        "movl %0, %%ebp\n\t"
        :: "m" (i)
        : "%ebp"
    );
    return 0;
}
-----------------------------------------

This makes this PR a bug, not simply an enhancement.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |normal
           Keywords|                            |ice-on-invalid-code


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer
  2003-08-05 12:45 [Bug c++/11807] New: Wrong usage of registers on ARM aw11 at os dot inf dot tu-dresden dot de
  2005-08-10 10:46 ` [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer pinskia at gcc dot gnu dot org
@ 2005-08-10 10:47 ` pinskia at gcc dot gnu dot org
  2005-08-10 11:25 ` giovannibajo at libero dot it
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-10 10:47 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-10 10:47 -------
*** Bug 23313 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |michaelni at gmx dot at


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer
  2003-08-05 12:45 [Bug c++/11807] New: Wrong usage of registers on ARM aw11 at os dot inf dot tu-dresden dot de
@ 2005-08-10 10:46 ` pinskia at gcc dot gnu dot org
  2005-08-10 10:47 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-10 10:46 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-10 10:46 -------
Frame pointer is still not fixed at -O0.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2007-01-30 18:20 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-11807-6667@http.gcc.gnu.org/bugzilla/>
2006-04-21  2:11 ` [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer acahalan at gmail dot com
2006-08-10 21:48 ` Martin dot vGagern at gmx dot net
2007-01-25  1:02 ` pinskia at gcc dot gnu dot org
2007-01-30 18:20 ` dpm at danger dot com
2003-08-05 12:45 [Bug c++/11807] New: Wrong usage of registers on ARM aw11 at os dot inf dot tu-dresden dot de
2005-08-10 10:46 ` [Bug inline-asm/11807] GCC should error out when clobbering the stack pointer and frame pointer pinskia at gcc dot gnu dot org
2005-08-10 10:47 ` pinskia at gcc dot gnu dot org
2005-08-10 11:25 ` giovannibajo at libero dot it
2005-08-10 11:29 ` pinskia at gcc dot gnu dot org
2005-08-23 11:31 ` nigel at suspend2 dot net
2005-08-23 11:41 ` pinskia at gcc dot gnu dot org
2005-08-23 11:42 ` ncunningham at cyclades dot com
2005-08-26  9:34 ` aw11 at os dot inf dot tu-dresden dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).