Patchwork [ObjC] fix objc.dg/exceptions2.m linkage error.

login
register
mail settings
Submitter IainS
Date Dec. 17, 2010, 2:34 p.m.
Message ID <CDE2122D-3A5B-4DE6-84E2-AE152A68F42C@sandoe-acoustics.co.uk>
Download mbox | patch
Permalink /patch/75902/
State New
Headers show

Comments

IainS - Dec. 17, 2010, 2:34 p.m.
The NeXT runtime library names its m64 personality routine  
"___objc_personality_v0"

So, in addition to the change to switch off sjlj exceptions (which  
causes linkage errors for the absent sjlj routines),
we also need to generate the right name for the eh personality...

OK?
Iain

objc:

	* objc/objc-act.c (objc_eh_personality): Select personality name on  
runtime.
	(objc_init_exceptions): New.
	(objc_begin_try_stmt): Use objc_init_exceptions.
	(objc_build_throw_stmt): Likewise.
Nicola Pero - Dec. 17, 2010, 6:01 p.m.
+  /* We could arrange for only one warning - by moving this before the check.  */

Yes, excellent idea - don't be shy - why don't you just update the patch to do it ? ;-)

I love your idea of printing the error

  "-fobjc-exceptions is required to enable Objective-C exception syntax"

only once per compilation unit instead of a lot of times. :-)

The main problem, I guess, would be updating the tests in the testsuite as
fobjc-exceptions.m would need to be broken down into multiple tests.

But it seems worth it.  It's distracting when the same error is printed lots of times.

Anyway, just a suggestion for making the patch even better; there's nothing wrong with it as it is.

Thanks

-----Original Message-----
From: "IainS" <developer@sandoe-acoustics.co.uk>
Sent: Friday, 17 December, 2010 15:34
To: "GCC Patches" <gcc-patches@gcc.gnu.org>
Cc: "Mike Stump" <mrs@gcc.gnu.org>, "Nicola Pero" <nicola.pero@meta-innovation.com>
Subject: [Patch ObjC] fix objc.dg/exceptions2.m linkage error.

The NeXT runtime library names its m64 personality routine  
"___objc_personality_v0"

So, in addition to the change to switch off sjlj exceptions (which  
causes linkage errors for the absent sjlj routines),
we also need to generate the right name for the eh personality...

OK?
Iain

objc:

	* objc/objc-act.c (objc_eh_personality): Select personality name on  
runtime.
	(objc_init_exceptions): New.
	(objc_begin_try_stmt): Use objc_init_exceptions.
	(objc_build_throw_stmt): Likewise.
Mike Stump - Dec. 17, 2010, 8:53 p.m.
On Dec 17, 2010, at 6:34 AM, IainS <developer@sandoe-acoustics.co.uk> wrote:
> The NeXT runtime library names its m64 personality routine "___objc_personality_v0"
> 
> So, in addition to the change to switch off sjlj exceptions (which causes linkage errors for the absent sjlj routines),
> we also need to generate the right name for the eh personality...
> 
> OK?

Ok.  If you want to do once per unit, that's fine too.

Patch

Index: gcc/objc/objc-act.c
===================================================================
--- gcc/objc/objc-act.c	(revision 167976)
+++ gcc/objc/objc-act.c	(working copy)
@@ -5028,11 +5028,41 @@  tree
 objc_eh_personality (void)
 {
   if (!flag_objc_sjlj_exceptions && !objc_eh_personality_decl)
-    objc_eh_personality_decl = build_personality_function ("gnu_objc");
+    objc_eh_personality_decl = build_personality_function 
+				(flag_next_runtime
+						? "objc"
+						: "gnu_objc");
   return objc_eh_personality_decl;
 }
 #endif
 
+static void
+objc_init_exceptions (location_t loc)
+{
+  static bool done = false;
+
+  /* -fobjc-exceptions is required to enable Objective-C exceptions.
+     For example, on Darwin, ObjC exceptions require a sufficiently
+     recent version of the runtime, so the user must ask for them
+     explicitly.  On other platforms, at the moment -fobjc-exceptions
+     triggers -fexceptions which again is required for exceptions to
+     work.
+  */
+  if (!flag_objc_exceptions)
+    {
+      error_at (loc, "%<-fobjc-exceptions%> is required to enable Objective-C exception syntax");
+    }
+
+  /* We could arrange for only one warning - by moving this before the check.  */
+  if (done)
+    return;
+  done = true;
+
+#ifndef OBJCPLUS
+  using_eh_for_cleanups ();
+#endif
+}
+
 /* Build __builtin_eh_pointer, or the moral equivalent.  In the case
    of Darwin, we'll arrange for it to be initialized (and associated
    with a binding) later.  */
@@ -5334,17 +5364,7 @@  objc_begin_try_stmt (location_t try_locus, tree bo
   c->end_try_locus = input_location;
   cur_try_context = c;
 
-  /* -fobjc-exceptions is required to enable Objective-C exceptions.
-     For example, on Darwin, ObjC exceptions require a sufficiently
-     recent version of the runtime, so the user must ask for them
-     explicitly.  On other platforms, at the moment -fobjc-exceptions
-     triggers -fexceptions which again is required for exceptions to
-     work.
-  */
-  if (!flag_objc_exceptions)
-    {
-      error_at (try_locus, "%<-fobjc-exceptions%> is required to enable Objective-C exception syntax");
-    }
+  objc_init_exceptions (try_locus);
 
   /* Collect the list of local variables.  We'll mark them as volatile
      at the end of compilation of this function to prevent them being
@@ -5552,10 +5572,7 @@  objc_build_throw_stmt (location_t loc, tree throw_
 {
   tree args;
 
-  if (!flag_objc_exceptions)
-    {
-      error_at (loc, "%<-fobjc-exceptions%> is required to enable Objective-C exception syntax");
-    }
+  objc_init_exceptions (loc);
 
   if (throw_expr == NULL)
     {