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]

3.0 PATCH: Avoid SIGBUS in libobjc on sparcv9-sun-solaris2.8


Re-running the objc testsuite after the patches reported in

	http://gcc.gnu.org/ml/gcc-patches/2001-06/msg00038.html

I noticed that (both on v7-bi-m64 and v9-bi-m64) all objc tests compiled,
but failed to run.  All crashed with a SIGBUS and stack traces like the
following:

=>[1] __gthread_objc_thread_id(0x10011f660, 0x80, 0x0, 0x10000831c, 0x0, 0x0), at 0x10000e5d4
  [2] __objc_thread_id(0x10011f660, 0x0, 0x0, 0xffffffffffffffff, 0xfffffffffffffff8, 0x10011fa60), at 0x10000e058
  [3] objc_thread_id(0x10011bc10, 0x10000b49c, 0x10011f540, 0x100119f98, 0x1, 0x4), at 0x10000d874
  [4] objc_mutex_lock(0x10011bc10, 0x119000, 0x10011d4a0, 0xb400, 0x0, 0x1), at 0x10000d9cc
  [5] __objc_init_class_tables(0x100119298, 0x119000, 0x10011bc10, 0xffffffff7f71ce50, 0xffffffff7f200be8, 0xffffffff7efaffe0), at 0x1000045c4
  [6] __objc_exec_class(0x100119dd8, 0x119c00, 0x1, 0xffffffff7ee26014, 0x0, 0x1), at 0x100006bbc
  [7] mECZUBA(0x100009964, 0xffffffff7efbab68, 0x20, 0xffffffff7efbab78, 0xffffffffffffffff, 0x1), at 0x100009980
  [8] __do_global_ctors_aux(0x0, 0xffffffff7efb34e0, 0xffffffff7efb34e8, 0x1000042c4, 0x0, 0xffffffff7f600000), at 0x100017064
  [9] _init(0x0, 0xffffffff7efaeef8, 0x1, 0x0, 0x0, 0x0), at 0x1000170a0

Some digging around revealed that this happens here:

gcc/gthr-posix.h has this:

static __inline__ objc_thread_t
__gthread_objc_thread_id(void)
{
  if (__gthread_active_p ())
    {
      pthread_t self = pthread_self();

      return *(objc_thread_t *)&self;
    }
  else
    return (objc_thread_t)1;
}

On Solaris 2, pthread_t is and unsigned int, while objc_thread_t is a void *.
pthread_t * and objc_thread_t * have different alignment requirements, thus
the SIGBUS.

The patch below allows me to successfully recompile both m32 and m64
libobjc (with 32x64 and 64x32 gcc) and run the objc testsuite with very few
remaining testsuite differences:

* both bi-arch sparc-sun-solaris2.8 and sparcv9-sun-solaris2.8: m32 -> m64

-Running target unix/-m32
+Running target unix

-PASS: objc/execute/bycopy-3.m execution,  -O 
+FAIL: objc/execute/bycopy-3.m execution,  -O 

-PASS: objc/execute/formal_protocol-5.m execution,  -O 
+FAIL: objc/execute/formal_protocol-5.m execution,  -O 

I haven't investigated those yet.

There's one problem with the patch below: compiling libobjc/thr-objc.c now
gives two compiler warnings (maybe the reason for the construct used
before):

gcc/gthr-posix.h: In function `__gthread_objc_thread_detach':
gcc/gthr-posix.h:161: warning: cast to pointer from integer of different size
gcc/gthr-posix.h: In function `__gthread_objc_thread_id':
gcc/gthr-posix.h:249: warning: cast to pointer from integer of different size

I don't know why objc_thread_t is a void * right now, using a long instead
should be able to avoid this warning, independent of the type of the
underlying thread identification.  If this is ok, I can provide a separate
patch to implement this.

Ok for branch and mainline?

	Rainer

-----------------------------------------------------------------------------
Rainer Orth, Faculty of Technology, Bielefeld University

Email: ro@TechFak.Uni-Bielefeld.DE


Sat Jun  2 00:54:40 2001  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>

	* gthr-posix.h (__gthread_objc_thread_detach): Simply cast
	pthread_t to objc_thread_t.
	(__gthread_objc_thread_id): Likewise.

Index: gcc/gthr-posix.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gthr-posix.h,v
retrieving revision 1.11.6.2
diff -u -p -r1.11.6.2 gthr-posix.h
--- gthr-posix.h	2001/05/30 22:39:08	1.11.6.2
+++ gthr-posix.h	2001/06/01 23:18:09
@@ -158,7 +158,7 @@ __gthread_objc_thread_detach(void (*func
     return NULL;
  
   if ( !(pthread_create(&new_thread_handle, NULL, (void *)func, arg)) )
-    thread_id = *(objc_thread_t *)&new_thread_handle;
+    thread_id = (objc_thread_t) new_thread_handle;
   else
     thread_id = NULL;
   
@@ -246,13 +246,9 @@ static inline objc_thread_t
 __gthread_objc_thread_id(void)
 {
   if (__gthread_active_p ())
-    {
-      pthread_t self = pthread_self();
-
-      return *(objc_thread_t *)&self;
-    }
+    return (objc_thread_t) pthread_self();
   else
-    return (objc_thread_t)1;
+    return (objc_thread_t) 1;
 }
 
 /* Sets the thread's local storage pointer. */


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