Miscompilation of m68k syscall wrappers with gcc 4.x

Richard Sandiford richard at codesourcery.com
Wed Mar 22 03:05:32 PST 2006


Hi,

This patch fixes a miscompilation of mmap() for Coldfire with gcc 4.x.
The problem was that the syscall was being invoked before any part of
the argument structure (buffer[]) had been initialised.

The outcome of gcc PR 19341 is that volatile asms don't implicitly
use or clobber memory, and that "memory" must be explicitly listed
in the clobber list:

    http://gcc.gnu.org/PR19341

All syscalls can potentially use or clobber memory, so this patch
adds a "memory" clobber to all the m68k syscall wrappers that I
could find.

Tested on m68k-uclinux for a coldfire target.  Please install if OK.

Richard


-------------- next part --------------
Index: libc/sysdeps/linux/m68k/syscall.c
===================================================================
--- libc/sysdeps/linux/m68k/syscall.c	(revision 14586)
+++ libc/sysdeps/linux/m68k/syscall.c	(working copy)
@@ -41,6 +41,7 @@ long syscall(long sysnum, long a, long b
 		: "g" (sysnum),
 		  "g" ((long)a), "g" ((long)b), "g" ((long)c),
 		  "g" ((long)d), "g" ((long)e), "g" ((long)f)
-		: "cc", "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%a0");
+		: "memory", "cc", "%d0", "%d1", "%d2", "%d3",
+		  "%d4", "%d5", "%a0");
 	__syscall_return(long,__res);
 }
Index: libc/sysdeps/linux/m68k/bits/syscalls.h
===================================================================
--- libc/sysdeps/linux/m68k/bits/syscalls.h	(revision 14586)
+++ libc/sysdeps/linux/m68k/bits/syscalls.h	(working copy)
@@ -67,7 +67,7 @@ type name(void) \
 		"movel	%%d0, %0" \
 		: "=g" (__res) \
 		: "i" (__NR_##name) \
-		: "cc", "%d0"); \
+		: "memory", "cc", "%d0"); \
 	__syscall_return(type, __res); \
 }
 
@@ -83,7 +83,7 @@ type name(atype a) \
 		: "=g" (__res) \
 		: "i" (__NR_##name), \
 		  "g" ((long)a) \
-		: "cc", "%d0", "%d1"); \
+		: "memory", "cc", "%d0", "%d1"); \
 	__syscall_return(type, __res); \
 }
 
@@ -101,7 +101,7 @@ type name(atype a, btype b) \
 		: "i" (__NR_##name), \
 		  "a" ((long)a), \
 		  "g" ((long)b) \
-		: "cc", "%d0", "%d1", "%d2"); \
+		: "memory", "cc", "%d0", "%d1", "%d2"); \
 	__syscall_return(type, __res); \
 }
 
@@ -121,7 +121,7 @@ type name(atype a, btype b, ctype c) \
 		  "a" ((long)a), \
 		  "a" ((long)b), \
 		  "g" ((long)c) \
-		: "cc", "%d0", "%d1", "%d2", "%d3"); \
+		: "memory", "cc", "%d0", "%d1", "%d2", "%d3"); \
 	__syscall_return(type, __res); \
 }
 
@@ -143,7 +143,7 @@ type name(atype a, btype b, ctype c, dty
 		  "a" ((long)b), \
 		  "a" ((long)c), \
 		  "g" ((long)d) \
-		: "cc", "%d0", "%d1", "%d2", "%d3", \
+		: "memory", "cc", "%d0", "%d1", "%d2", "%d3", \
 		  "%d4"); \
 	__syscall_return(type, __res); \
 }
@@ -168,7 +168,7 @@ type name(atype a, btype b, ctype c, dty
 		  "a" ((long)c), \
 		  "a" ((long)d), \
 		  "g" ((long)e) \
-		: "cc", "%d0", "%d1", "%d2", "%d3", \
+		: "memory", "cc", "%d0", "%d1", "%d2", "%d3", \
 		  "%d4", "%d5"); \
 	__syscall_return(type, __res); \
 }
@@ -195,7 +195,7 @@ type name(atype a, btype b, ctype c, dty
 		  "a" ((long)d), \
 		  "g" ((long)e), \
 		  "g" ((long)f) \
-		: "cc", "%d0", "%d1", "%d2", "%d3", \
+		: "memory", "cc", "%d0", "%d1", "%d2", "%d3", \
 		  "%d4", "%d5", "%a0"); \
 	__syscall_return(type, __res); \
 }


More information about the uClibc mailing list