public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/39078]  New: Registers in on clober list are cloberred when compiled with optimization  (x86_64) ?
@ 2009-02-02 16:54 valery_reznic at yahoo dot com
  2009-02-06  1:43 ` [Bug inline-asm/39078] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: valery_reznic at yahoo dot com @ 2009-02-02 16:54 UTC (permalink / raw)
  To: gcc-bugs

Source file:


file test.c
=======================================================
#define __NR_close 2
#define CLOBBER_LIST "memory", "cc", "r11", "r12", "r13", "r14", "r15", "rbx"
#define MY_SYSCALL_1(ARG)                                                      
      \
        __extension__ ((                                                       
      \
                {                                                              
      \
                        register unsigned long result;                         
      \
                        register unsigned long _arg1 asm("rdi") = (unsigned
long)ARG; \
                        asm volatile (                                         
      \
                                "call my_syscall\n\t"                          
      \
                                : "=a" (result)                                
      \
                                : "0" (__NR_close), "r" (_arg1)                
      \
                                : CLOBBER_LIST                                 
      \
                        );                                                     
      \
                        result;                                                
      \
                } ))                                                           
      \

void func_1(int arg)
{
        MY_SYSCALL_1(arg);
}
================================================================================

Compilation command:

gcc  -O2 -S -o test.S test.c

Output file (test.S)
=====================================================================
        .file   "bb.c"
        .text
        .p2align 4,,15
.globl func_1
        .type   func_1, @function
func_1:
.LFB2:
        movq    %rbx, -40(%rsp)
.LCFI0:
        movq    %r12, -32(%rsp)
.LCFI1:
        movslq  %edi,%rdi
        movq    %r13, -24(%rsp)
.LCFI2:
        movq    %r14, -16(%rsp)
.LCFI3:
        movl    $2, %eax
        movq    %r15, -8(%rsp)
.LCFI4:
#APP
        call my_syscall

#NO_APP
        movq    -40(%rsp), %rbx
        movq    -32(%rsp), %r12
        movq    -24(%rsp), %r13
        movq    -16(%rsp), %r14
        movq    -8(%rsp), %r15
        ret
=====================================================================
All registers mentioned in the CLOBERR_LIST (but r11) are moved to the stack.
Stack pointer doesn't adjusted !!!
Than 'call my_syscall' overwrite on the stack saved value of 'r15'.
Than, future instructions in the 'my_syscall' can overwrite other saved
registers.
After return from 'my_syscall' overwritten values copied to registers.

I.e while compiler tried to save CLOBER_LIST registers' content it failed to do
it.

I tried to compile code both with gcc-3.4.2 (FedoraCore 3) and gcc-4.1.2
(Fedora 8) - results are same.

Result are same when compile with any of -O1,-O2 or -O3.

When compile without optimization, stack pointer is adjusted, i.e generated
code is OK.


-- 
           Summary: Registers in on clober list are cloberred when compiled
                    with optimization  (x86_64) ?
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: valery_reznic at yahoo dot com
  GCC host triplet: file bb.c
                    =====================================================
GCC target triplet: x86_64-redhat-linux


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


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

end of thread, other threads:[~2009-02-11 15:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-02 16:54 [Bug inline-asm/39078] New: Registers in on clober list are cloberred when compiled with optimization (x86_64) ? valery_reznic at yahoo dot com
2009-02-06  1:43 ` [Bug inline-asm/39078] " pinskia at gcc dot gnu dot org
2009-02-06  7:12 ` valery_reznic at yahoo dot com
2009-02-06 11:51 ` ubizjak at gmail dot com
2009-02-06 12:08 ` jakub at gcc dot gnu dot org
2009-02-09 16:08 ` valery_reznic at yahoo dot com
2009-02-09 16:09 ` valery_reznic at yahoo dot com
2009-02-11  7:50 ` ubizjak at gmail dot com
2009-02-11 14:26 ` valery_reznic at yahoo dot com
2009-02-11 15:32 ` ubizjak at gmail dot com
2009-02-11 15:56 ` valery_reznic at yahoo dot com

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