Fix compile with -fomit-frame-pointer

Peter Chapman 9gfrye202 at sneakemail.com
Wed Dec 1 18:15:10 CST 2004


Hello everyone. This patch fixes up several inline assembler blocks so
that they produce correct code with the -fomit-frame-pointer gcc flag.

Currently, if an argument is passed as a memory location relative to
esp, and the asm code performs a push to the stack, then subsequent use
of that argument will reference the wrong memory location because esp
has changed.
This patch tightens the constraints on the arguments to inline asm
blocks, forcing the use of register variables in this situation. (In a
couple of places I had to name a specific register to avoid gcc
cunningly using esp as a pointer argument).

I believe this fixes the issue identified in
http://bugs.winehq.org/show_bug.cgi?id=2532

Any comments? Thanks...

Pete Chapman
-------------- next part --------------
Index: dlls/msvcrt/cppexcept.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/cppexcept.c,v
retrieving revision 1.12
diff -u -r1.12 cppexcept.c
--- dlls/msvcrt/cppexcept.c	19 Oct 2004 04:03:07 -0000	1.12
+++ dlls/msvcrt/cppexcept.c	1 Dec 2004 23:25:57 -0000
@@ -53,7 +53,7 @@
 {
     void *ret;
     __asm__ __volatile__ ("pushl %%ebp; movl %2,%%ebp; call *%%eax; popl %%ebp" \
-                          : "=a" (ret) : "0" (func), "g" (ebp) : "ecx", "edx", "memory" );
+                          : "=a" (ret) : "0" (func), "r" (ebp) : "ecx", "edx", "memory" );
     return ret;
 }
 
@@ -64,10 +64,10 @@
     if (has_vbase)
         /* in that case copy ctor takes an extra bool indicating whether to copy the base class */
         __asm__ __volatile__("pushl $1; pushl %2; call *%0"
-                             : : "r" (func), "c" (this), "g" (src) : "eax", "edx", "memory" );
+                             : : "r" (func), "c" (this), "r" (src) : "eax", "edx", "memory" );
     else
         __asm__ __volatile__("pushl %2; call *%0"
-                             : : "r" (func), "c" (this), "g" (src) : "eax", "edx", "memory" );
+                             : : "r" (func), "c" (this), "r" (src) : "eax", "edx", "memory" );
 }
 
 /* call the destructor of the exception object */
Index: dlls/msvcrt/except.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/except.c,v
retrieving revision 1.33
diff -u -r1.33 except.c
--- dlls/msvcrt/except.c	1 Sep 2004 04:58:21 -0000	1.33
+++ dlls/msvcrt/except.c	1 Dec 2004 23:25:57 -0000
@@ -76,7 +76,7 @@
     DWORD ret;
     __asm__ __volatile__ ("pushl %%ebp; pushl %3; movl %2,%%ebp; call *%%eax; popl %%ebp; popl %%ebp"
                           : "=a" (ret)
-                          : "0" (func), "g" (ebp), "g" (arg)
+                          : "0" (func), "r" (ebp), "r" (arg)
                           : "ecx", "edx", "memory" );
     return ret;
 }
Index: dlls/msvcrt/tests/cpp.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/tests/cpp.c,v
retrieving revision 1.3
diff -u -r1.3 cpp.c
--- dlls/msvcrt/tests/cpp.c	8 Nov 2004 22:11:05 -0000	1.3
+++ dlls/msvcrt/tests/cpp.c	1 Dec 2004 23:25:57 -0000
@@ -156,7 +156,7 @@
   void* ret;
   __asm__ __volatile__ ("pushl %%ecx;\n\tmovl %2, %%ecx;\n\tcall *%1;\n\tpopl %%ecx;"
                         : "=a" (ret)
-                        : "g" (func), "m" (_this)
+                        : "r" (func), "r" (_this)
                         : "memory" );
   return ret;
 }
@@ -166,7 +166,7 @@
   __asm__ __volatile__ ("pushl %%ecx;\n\tpushl %2;\n\t"
                         "movl %3, %%ecx;\n\tcall *%1;\n\tpopl %%ecx;"
                         : "=a" (ret)
-                        : "g" (func), "m" (arg), "m" (_this)
+                        : "r" (func), "r" (arg), "r" (_this)
                         : "memory" );
   return ret;
 }
Index: dlls/ntdll/signal_i386.c
===================================================================
RCS file: /home/wine/wine/dlls/ntdll/signal_i386.c,v
retrieving revision 1.87
diff -u -r1.87 signal_i386.c
--- dlls/ntdll/signal_i386.c	24 Aug 2004 02:26:59 -0000	1.87
+++ dlls/ntdll/signal_i386.c	1 Dec 2004 23:25:57 -0000
@@ -111,7 +111,7 @@
                           "int $0x80\n\t"
                           "popl %%ebx"
                           : "=a" (sig)
-                          : "0" (SYS_sigaction), "r" (sig), "c" (new), "d" (old) );
+                          : "0" (SYS_sigaction), "S" (sig), "c" (new), "d" (old) );
     if (sig>=0) return 0;
     errno = -sig;
     return -1;
@@ -128,7 +128,7 @@
                           "int $0x80\n\t"
                           "popl %%ebx"
                           : "=a" (ret)
-                          : "0" (SYS_sigaltstack), "r" (new), "c" (old) );
+                          : "0" (SYS_sigaltstack), "q" (new), "c" (old) );
     if (ret >= 0) return 0;
     errno = -ret;
     return -1;
Index: dlls/ntdll/virtual.c
===================================================================
RCS file: /home/wine/wine/dlls/ntdll/virtual.c,v
retrieving revision 1.41
diff -u -r1.41 virtual.c
--- dlls/ntdll/virtual.c	11 Oct 2004 20:59:06 -0000	1.41
+++ dlls/ntdll/virtual.c	1 Dec 2004 23:25:58 -0000
@@ -672,7 +672,7 @@
                              "popl %%ebx"
                              : "=a" (ret)
                              : "0" (90), /* SYS_mmap */
-                               "g" (&args)
+                               "S" (&args)
                              : "memory" );
         if (ret < 0 && ret > -4096)
         {
Index: libs/wine/ldt.c
===================================================================
RCS file: /home/wine/wine/libs/wine/ldt.c,v
retrieving revision 1.5
diff -u -r1.5 ldt.c
--- libs/wine/ldt.c	13 Dec 2003 01:37:38 -0000	1.5
+++ libs/wine/ldt.c	1 Dec 2004 23:25:59 -0000
@@ -78,7 +78,7 @@
                           "popl %%ebx"
                           : "=a" (res)
                           : "0" (SYS_modify_ldt),
-                            "r" (func),
+                            "S" (func),
                             "c" (ptr),
                             "d" (count) );
     if (res >= 0) return res;
@@ -94,7 +94,7 @@
                           "int $0x80\n\t"
                           "popl %%ebx"
                           : "=a" (res)
-                          : "0" (243) /* SYS_set_thread_area */, "r" (ptr) );
+                          : "0" (243) /* SYS_set_thread_area */, "q" (ptr) );
     if (res >= 0) return res;
     errno = -res;
     return -1;
Index: loader/kthread.c
===================================================================
RCS file: /home/wine/wine/loader/kthread.c,v
retrieving revision 1.10
diff -u -r1.10 kthread.c
--- loader/kthread.c	19 Oct 2004 03:57:05 -0000	1.10
+++ loader/kthread.c	1 Dec 2004 23:25:59 -0000
@@ -272,7 +272,7 @@
             "ret;\n"
             "1:\n\t"                    /* parent -> caller thread */
             "addl $8,%%esp" :
-            : "r" (sp), "g" (SYS_rfork), "g" (RFPROC | RFMEM | RFTHREAD)
+            : "r" (sp), "r" (SYS_rfork), "r" (RFPROC | RFMEM | RFTHREAD)
             : "eax", "edx");
         return 0;
     }
Index: loader/preloader.c
===================================================================
RCS file: /home/wine/wine/loader/preloader.c,v
retrieving revision 1.10
diff -u -r1.10 preloader.c
--- loader/preloader.c	24 Sep 2004 00:25:32 -0000	1.10
+++ loader/preloader.c	1 Dec 2004 23:25:59 -0000
@@ -174,14 +174,14 @@
 {
     for (;;)  /* avoid warning */
         __asm__ __volatile__( "pushl %%ebx; movl %1,%%ebx; int $0x80; popl %%ebx"
-                              : : "a" (SYS_exit), "g" (code) );
+                              : : "a" (SYS_exit), "r" (code) );
 }
 
 static inline int wld_open( const char *name, int flags )
 {
     int ret;
     __asm__ __volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
-                          : "=a" (ret) : "0" (SYS_open), "g" (name), "c" (flags) );
+                          : "=a" (ret) : "0" (SYS_open), "r" (name), "c" (flags) );
     return SYSCALL_RET(ret);
 }
 
@@ -189,7 +189,7 @@
 {
     int ret;
     __asm__ __volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
-                          : "=a" (ret) : "0" (SYS_close), "g" (fd) );
+                          : "=a" (ret) : "0" (SYS_close), "r" (fd) );
     return SYSCALL_RET(ret);
 }
 
@@ -198,7 +198,7 @@
     int ret;
     __asm__ __volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
                           : "=a" (ret)
-                          : "0" (SYS_read), "g" (fd), "c" (buffer), "d" (len)
+                          : "0" (SYS_read), "r" (fd), "c" (buffer), "d" (len)
                           : "memory" );
     return SYSCALL_RET(ret);
 }
@@ -207,7 +207,7 @@
 {
     int ret;
     __asm__ __volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
-                          : "=a" (ret) : "0" (SYS_write), "g" (fd), "c" (buffer), "d" (len) );
+                          : "=a" (ret) : "0" (SYS_write), "r" (fd), "c" (buffer), "d" (len) );
     return SYSCALL_RET(ret);
 }
 
@@ -215,7 +215,7 @@
 {
     int ret;
     __asm__ __volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
-                          : "=a" (ret) : "0" (SYS_mprotect), "g" (addr), "c" (len), "d" (prot) );
+                          : "=a" (ret) : "0" (SYS_mprotect), "r" (addr), "c" (len), "d" (prot) );
     return SYSCALL_RET(ret);
 }
 
@@ -240,7 +240,7 @@
     args.fd     = fd;
     args.offset = offset;
     __asm__ __volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
-                          : "=a" (ret) : "0" (SYS_mmap), "g" (&args) : "memory" );
+                          : "=a" (ret) : "0" (SYS_mmap), "S" (&args) : "memory" );
     return (void *)SYSCALL_RET(ret);
 }
 
Index: server/fd.c
===================================================================
RCS file: /home/wine/wine/server/fd.c,v
retrieving revision 1.28
diff -u -r1.28 fd.c
--- server/fd.c	27 Oct 2004 01:03:30 -0000	1.28
+++ server/fd.c	1 Dec 2004 23:26:00 -0000
@@ -87,7 +87,7 @@
 {
     int ret;
     __asm__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
-             : "=a" (ret) : "0" (254 /*NR_epoll_create*/), "g" (size) );
+             : "=a" (ret) : "0" (254 /*NR_epoll_create*/), "r" (size) );
     SYSCALL_RET(ret);
 }
 
@@ -96,7 +96,7 @@
     int ret;
     __asm__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
              : "=a" (ret)
-             : "0" (255 /*NR_epoll_ctl*/), "g" (epfd), "c" (op), "d" (fd), "S" (event), "m" (*event) );
+             : "0" (255 /*NR_epoll_ctl*/), "r" (epfd), "c" (op), "d" (fd), "S" (event), "m" (*event) );
     SYSCALL_RET(ret);
 }
 
@@ -105,7 +105,7 @@
     int ret;
     __asm__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
              : "=a" (ret)
-             : "0" (256 /*NR_epoll_wait*/), "g" (epfd), "c" (events), "d" (maxevents), "S" (timeout)
+             : "0" (256 /*NR_epoll_wait*/), "r" (epfd), "c" (events), "d" (maxevents), "S" (timeout)
              : "memory" );
     SYSCALL_RET(ret);
 }


More information about the wine-patches mailing list