public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/52813] New: %rsp in clobber list is silently ignored
@ 2012-03-31 22:53 jhaberman at gmail dot com
  2012-04-01  9:21 ` [Bug inline-asm/52813] " ubizjak at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: jhaberman at gmail dot com @ 2012-03-31 22:53 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52813
           Summary: %rsp in clobber list is silently ignored
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jhaberman@gmail.com


The following test program crashes even though I correctly listed %rsp as
clobbered:

--

int main() {
  asm volatile ("movq $0, %%rsp" : : : "%rsp");
  return 0;
}

--

I would prefer gcc to error out in this case instead of silently ignoring my
instruction.


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

* [Bug inline-asm/52813] %rsp in clobber list is silently ignored
  2012-03-31 22:53 [Bug inline-asm/52813] New: %rsp in clobber list is silently ignored jhaberman at gmail dot com
@ 2012-04-01  9:21 ` ubizjak at gmail dot com
  2012-04-01 15:54 ` jhaberman at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ubizjak at gmail dot com @ 2012-04-01  9:21 UTC (permalink / raw)
  To: gcc-bugs

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

Uros Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Uros Bizjak <ubizjak at gmail dot com> 2012-04-01 09:21:09 UTC ---
The compiler doesn't analyse asm string.


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

* [Bug inline-asm/52813] %rsp in clobber list is silently ignored
  2012-03-31 22:53 [Bug inline-asm/52813] New: %rsp in clobber list is silently ignored jhaberman at gmail dot com
  2012-04-01  9:21 ` [Bug inline-asm/52813] " ubizjak at gmail dot com
@ 2012-04-01 15:54 ` jhaberman at gmail dot com
  2012-04-01 18:58 ` ubizjak at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jhaberman at gmail dot com @ 2012-04-01 15:54 UTC (permalink / raw)
  To: gcc-bugs

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

Josh Haberman <jhaberman at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |

--- Comment #2 from Josh Haberman <jhaberman at gmail dot com> 2012-04-01 15:54:27 UTC ---
I don't expect the compiler to analyze the asm string.  I expect the compiler
to respect my clobber list.

I told GCC that I would clobber %rsp.  Any other register that I put in the
clobber list causes GCC to save that register to the stack or to another
register before the asm and restore it from the stack/register after the asm. 
For example:

--

#include <stdlib.h>
int main() {
  int x = rand();
  asm volatile ("movq $0, %%rax" : : : "%rax");
  return x;
}

$ gcc -Wall -O3 -fomit-frame-pointer -c -o test.o test.c
$ objdump -d -r -M intel test.o
test.o:     file format elf64-x86-64


Disassembly of section .text.startup:

0000000000000000 <main>:
   0:    48 83 ec 08              sub    rsp,0x8
   4:    e8 00 00 00 00           call   9 <main+0x9>
            5: R_X86_64_PC32    rand-0x4
   9:    89 c2                    mov    edx,eax
   b:    48 c7 c0 00 00 00 00     mov    rax,0x0
  12:    89 d0                    mov    eax,edx
  14:    48 83 c4 08              add    rsp,0x8
  18:    c3                       ret

--

Notice that it saved eax to edx before my asm and restored it afterwards.  This
works for every register except %rsp, which is silently ignored if you try to
list it in the clobber list.  This is a bug.


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

* [Bug inline-asm/52813] %rsp in clobber list is silently ignored
  2012-03-31 22:53 [Bug inline-asm/52813] New: %rsp in clobber list is silently ignored jhaberman at gmail dot com
  2012-04-01  9:21 ` [Bug inline-asm/52813] " ubizjak at gmail dot com
  2012-04-01 15:54 ` jhaberman at gmail dot com
@ 2012-04-01 18:58 ` ubizjak at gmail dot com
  2012-04-01 19:23 ` jhaberman at gmail dot com
  2012-05-28 23:10 ` ralph-gccbugzilla at inputplus dot co.uk
  4 siblings, 0 replies; 6+ messages in thread
From: ubizjak at gmail dot com @ 2012-04-01 18:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Uros Bizjak <ubizjak at gmail dot com> 2012-04-01 18:58:27 UTC ---
(In reply to comment #2)
> I don't expect the compiler to analyze the asm string.  I expect the compiler
> to respect my clobber list.
> 
> I told GCC that I would clobber %rsp.  Any other register that I put in the
> clobber list causes GCC to save that register to the stack or to another
> register before the asm and restore it from the stack/register after the asm. 
> For example:

%rsp is considered a "fixed" register, used for fixed purposes all throughout
the compiled code and are therefore not available for general allocation.

So, save %rsp at the beginning of your asm code and restore it at the end.


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

* [Bug inline-asm/52813] %rsp in clobber list is silently ignored
  2012-03-31 22:53 [Bug inline-asm/52813] New: %rsp in clobber list is silently ignored jhaberman at gmail dot com
                   ` (2 preceding siblings ...)
  2012-04-01 18:58 ` ubizjak at gmail dot com
@ 2012-04-01 19:23 ` jhaberman at gmail dot com
  2012-05-28 23:10 ` ralph-gccbugzilla at inputplus dot co.uk
  4 siblings, 0 replies; 6+ messages in thread
From: jhaberman at gmail dot com @ 2012-04-01 19:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Josh Haberman <jhaberman at gmail dot com> 2012-04-01 19:23:14 UTC ---
I understand that GCC may not be able to save/restore %rsp like it does other
registers.  But if that's the case, GCC should throw an error if the user puts
%rsp in the clobber list, instead of silently ignoring it.  Otherwise how is
the user supposed to know that %rsp will not be saved except through trial and
error?


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

* [Bug inline-asm/52813] %rsp in clobber list is silently ignored
  2012-03-31 22:53 [Bug inline-asm/52813] New: %rsp in clobber list is silently ignored jhaberman at gmail dot com
                   ` (3 preceding siblings ...)
  2012-04-01 19:23 ` jhaberman at gmail dot com
@ 2012-05-28 23:10 ` ralph-gccbugzilla at inputplus dot co.uk
  4 siblings, 0 replies; 6+ messages in thread
From: ralph-gccbugzilla at inputplus dot co.uk @ 2012-05-28 23:10 UTC (permalink / raw)
  To: gcc-bugs

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

Ralph Corderoy <ralph-gccbugzilla at inputplus dot co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ralph-gccbugzilla at
                   |                            |inputplus dot co.uk

--- Comment #5 from Ralph Corderoy <ralph-gccbugzilla at inputplus dot co.uk> 2012-05-28 23:06:51 UTC ---
The examples clearly show the problem and it bites me here.  Please change the
status to confirmed.


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

end of thread, other threads:[~2012-05-28 23:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-31 22:53 [Bug inline-asm/52813] New: %rsp in clobber list is silently ignored jhaberman at gmail dot com
2012-04-01  9:21 ` [Bug inline-asm/52813] " ubizjak at gmail dot com
2012-04-01 15:54 ` jhaberman at gmail dot com
2012-04-01 18:58 ` ubizjak at gmail dot com
2012-04-01 19:23 ` jhaberman at gmail dot com
2012-05-28 23:10 ` ralph-gccbugzilla at inputplus dot co.uk

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