[Bug target/62109] __gthr_i486_lock_cmp_xchg missing clobber

gccbugzilla at limegreensocks dot com gcc-bugzilla@gcc.gnu.org
Tue Mar 17 23:10:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62109

--- Comment #6 from David <gccbugzilla at limegreensocks dot com> ---
Actually, the code already uses InterlockedCompareExchange.  UNLESS users
explicitly tell it not to:

#ifdef __GTHREAD_I486_INLINE_LOCK_PRIMITIVES
static inline long
__gthr_i486_lock_cmp_xchg(long *__dest, long __xchg, long __comperand)
{
  long result;
  __asm__ __volatile__ ("\n\
    lock\n\
    cmpxchg{l} {%4, %1|%1, %4}\n"
    : "=a" (result), "=m" (*__dest)
    : "0" (__comperand), "m" (*__dest), "r" (__xchg)
    : "cc");
  return result;
}
#define __GTHR_W32_InterlockedCompareExchange __gthr_i486_lock_cmp_xchg
#else  /* __GTHREAD_I486_INLINE_LOCK_PRIMITIVES */
#define __GTHR_W32_InterlockedCompareExchange InterlockedCompareExchange
#endif /* __GTHREAD_I486_INLINE_LOCK_PRIMITIVES */

Since we are talking about postponing this to stage 1 (which I do not object
to), what if we change this to something like:

#ifdef __GTHREAD_I486_INLINE_LOCK_PRIMITIVES
#error "__GTHREAD_I486_INLINE_LOCK_PRIMITIVES is no longer supported. Remove
this definition to use system calls for Win98 and above."
#else  /* __GTHREAD_I486_INLINE_LOCK_PRIMITIVES */
#define __GTHR_W32_InterlockedCompareExchange InterlockedCompareExchange
#endif /* __GTHREAD_I486_INLINE_LOCK_PRIMITIVES */

Then wait to see if anyone cares.

I am ok with either fixing it (by adding the "memory" clobber) or removing it
(since the problem it was intended to fix only happens on OSs that aren't
supported anymore).  But leaving it "as-is" leaves open the possibility that
people are using this without even knowing it (and getting
nearly-impossible-to-track-down timing problems).  Or that someone might
copy/paste this code into their own projects.



More information about the Gcc-bugs mailing list