This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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 (as applied to mainline): Fix a multiprocessor sparc bug (more rarely, might also affect single-processor, multithreaded code)


Fixes test case found in libstdc++/5037 which was the first report
with a reproducible test case of a long-standing rumored bug with the
sparc port.  Bootstrapped against 3.0.X on sparc-sun-solaris2.7 with
no regressions.  In general, it is a no-no to test against the branch
yet install on mainline.  However, the contents of this file are used
only by sparc ports and is identical between mainline and branch with
the small exception of a patch which removed an unused function.  I
had to punt since this is an important patch yet I couldn't build
mainline on solaris last I tried.

This patch was designed to be fully backwards compatible with how the
past code operates, i.e. exact same data structure is visible to
client code that may be bound in user applications compiled against
3.0, 3.0.1 or 3.0.2.  Of course, multithreaded applications will need
to be fully recompiled to get the fix since this stuff may have been
inlined in old objects that are name-mangle ABI compatible.

I almost hate to ask: Is this patch appropriate for the 3.0.X branch
before the 3.0.3 release?

2001-12-07  Nathan Myers  <ncm@cantrip.org>
            Loren Rittle <ljrittle@acm.org>

        libstdc++/5037
        * config/cpu/sparc/sparc32/bits/atomicity.h
        (struct __Atomicity_lock<__inst>): Add.
        (__Atomicity_lock<__inst>::_S_atomicity_lock): Add.
        (__exchange_and_add): Use __Atomicity_lock<0>::_S_atomicity_lock
        instead of lock local to static function.
        (__atomic_add): Likewise.

Index: libstdc++-v3/config/cpu/sparc/sparc32/bits/atomicity.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/cpu/sparc/sparc32/bits/atomicity.h,v
retrieving revision 1.4
diff -c -r1.4 atomicity.h
*** atomicity.h	2001/10/05 18:43:43	1.4
--- atomicity.h	2001/12/08 00:42:28
***************
*** 32,42 ****
  
  typedef int _Atomic_word;
  
  static int
  __attribute__ ((__unused__))
  __exchange_and_add (volatile _Atomic_word* __mem, int __val)
  {
-   static unsigned char __lock;
    _Atomic_word __result, __tmp;
  
    __asm__ __volatile__("1:	ldstub	[%1], %0\n\t"
--- 32,50 ----
  
  typedef int _Atomic_word;
  
+ template <int __inst>
+ struct __Atomicity_lock
+ {
+   static unsigned char _S_atomicity_lock;
+ };
+ 
+ template <int __inst>
+ unsigned char __Atomicity_lock<__inst>::_S_atomicity_lock = 0;
+ 
  static int
  __attribute__ ((__unused__))
  __exchange_and_add (volatile _Atomic_word* __mem, int __val)
  {
    _Atomic_word __result, __tmp;
  
    __asm__ __volatile__("1:	ldstub	[%1], %0\n\t"
***************
*** 44,56 ****
  		       "	bne	1b\n\t"
  		       "	 nop"
  		       : "=&r" (__tmp)
! 		       : "r" (&__lock)
  		       : "memory");
    __result = *__mem;
    *__mem += __val;
    __asm__ __volatile__("stb	%%g0, [%0]"
  		       : /* no outputs */
! 		       : "r" (&__lock)
  		       : "memory");
    return __result;
  }
--- 52,64 ----
  		       "	bne	1b\n\t"
  		       "	 nop"
  		       : "=&r" (__tmp)
! 		       : "r" (&__Atomicity_lock<0>::_S_atomicity_lock)
  		       : "memory");
    __result = *__mem;
    *__mem += __val;
    __asm__ __volatile__("stb	%%g0, [%0]"
  		       : /* no outputs */
! 		       : "r" (&__Atomicity_lock<0>::_S_atomicity_lock)
  		       : "memory");
    return __result;
  }
***************
*** 59,65 ****
  __attribute__ ((__unused__))
  __atomic_add (volatile _Atomic_word* __mem, int __val)
  {
-   static unsigned char __lock;
    _Atomic_word __tmp;
  
    __asm__ __volatile__("1:	ldstub	[%1], %0\n\t"
--- 67,72 ----
***************
*** 67,78 ****
  		       "	bne	1b\n\t"
  		       "	 nop"
  		       : "=&r" (__tmp)
! 		       : "r" (&__lock)
  		       : "memory");
    *__mem += __val;
    __asm__ __volatile__("stb	%%g0, [%0]"
  		       : /* no outputs */
! 		       : "r" (&__lock)
  		       : "memory");
  }
  
--- 74,85 ----
  		       "	bne	1b\n\t"
  		       "	 nop"
  		       : "=&r" (__tmp)
! 		       : "r" (&__Atomicity_lock<0>::_S_atomicity_lock)
  		       : "memory");
    *__mem += __val;
    __asm__ __volatile__("stb	%%g0, [%0]"
  		       : /* no outputs */
! 		       : "r" (&__Atomicity_lock<0>::_S_atomicity_lock)
  		       : "memory");
  }
  


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