This is the mail archive of the libc-hacker@sourceware.org mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix i?86 lll_futex_{,timed_}wait and lll_wait_tid


Hi!

All other arches except i?86 have "memory" clobber in lll_futex_wait
etc. (be it through INTERNAL_SYSCALL or explicitly).  These macros
are only used a handful time in generic code (and never in i?86 specific
code) and in a big portion of those places in tight loops, without
an explicit memory clobber anywhere.  The syscall itself I guess
servers as a CPU memory barrier, so all we need is a barrier to tell
GCC not to optimize things accross it.
At least 2 places are miscompiled because of this:
1) unregister_atfork (say with GCC 4.1.0pre current CVS glibc):
   d40c0:       f0 ff 48 14             lock decl 0x14(%eax)
   d40c4:       8b 50 14                mov    0x14(%eax),%edx
   d40c7:       85 d2                   test   %edx,%edx
   d40c9:       74 22                   je     d40ed <__unregister_atfork+0xed>
   d40cb:       8d 78 14                lea    0x14(%eax),%edi
   d40ce:       31 f6                   xor    %esi,%esi
   d40d0:       b8 f0 00 00 00          mov    $0xf0,%eax
   d40d5:       89 f1                   mov    %esi,%ecx
   d40d7:       87 fb                   xchg   %edi,%ebx
   d40d9:       65 ff 15 10 00 00 00    call   *%gs:0x10
   d40e0:       87 fb                   xchg   %edi,%ebx
   d40e2:       eb ec                   jmp    d40d0 <__unregister_atfork+0xd0>
(note the endless loop)
2) start_thread:
    52b8:       8b 45 b8                mov    0xffffffb8(%ebp),%eax
    52bb:       f6 40 5c 40             testb  $0x40,0x5c(%eax)
    52bf:       75 44                   jne    5305 <start_thread+0x123>
...
    5305:       31 d2                   xor    %edx,%edx
    5307:       89 c7                   mov    %eax,%edi
    5309:       81 c7 e8 01 00 00       add    $0x1e8,%edi
    530f:       31 f6                   xor    %esi,%esi
    5311:       b8 f0 00 00 00          mov    $0xf0,%eax
    5316:       89 f1                   mov    %esi,%ecx
    5318:       87 fb                   xchg   %edi,%ebx
    531a:       65 ff 15 10 00 00 00    call   *%gs:0x10
    5321:       87 fb                   xchg   %edi,%ebx
    5323:       eb ec                   jmp    5311 <start_thread+0x12f>
(likewise)

2006-02-08  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_futex_wait,
	lll_futex_timedwait, lll_wait_tid): Add "memory" clobber.

--- libc/nptl/sysdeps/unix/sysv/linux/i386/lowlevellock.h.jj	2006-01-06 06:01:25.000000000 +0100
+++ libc/nptl/sysdeps/unix/sysv/linux/i386/lowlevellock.h	2006-02-08 11:12:25.000000000 +0100
@@ -75,7 +75,8 @@
 		      : "=a" (__status)					      \
 		      : "0" (SYS_futex), LLL_EBX_REG (futex), "S" (0),	      \
 			"c" (FUTEX_WAIT), "d" (_val),			      \
-			"i" (offsetof (tcbhead_t, sysinfo)));		      \
+			"i" (offsetof (tcbhead_t, sysinfo))		      \
+		      : "memory");					      \
     __status;								      \
   })
 
@@ -90,7 +91,8 @@
 		      : "=a" (__status)					      \
 		      : "0" (SYS_futex), LLL_EBX_REG (futex), "S" (timeout),  \
 			"c" (FUTEX_WAIT), "d" (_val),			      \
-			"i" (offsetof (tcbhead_t, sysinfo)));		      \
+			"i" (offsetof (tcbhead_t, sysinfo))		      \
+		      : "memory");					      \
     __status;								      \
   })
 
@@ -346,7 +348,8 @@ extern int lll_unlock_wake_cb (int *__fu
 			: "=&a" (__ignore)				      \
 			: "i" (SYS_futex), LLL_EBX_REG (&tid), "S" (0),	      \
 			  "c" (FUTEX_WAIT), "d" (_tid),			      \
-			  "i" (offsetof (tcbhead_t, sysinfo)));		      \
+			  "i" (offsetof (tcbhead_t, sysinfo))		      \
+			: "memory");					      \
   } while (0)
 
 extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime)

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]