i386.md: restore PIC register after __builtin_longjmp

Anthony Green green@cygnus.com
Mon Jan 3 22:14:00 GMT 2000


rth has approved this patch - although he pointed problems in the test
code.

I am committing the patch.

-- 
Anthony Green                                               Cygnus Solutions
                                                       Sunnyvale, California
------- Start of forwarded message -------
From: Anthony Green <green@cygnus.com>
Newsgroups: cygnus.egcs.patches
Subject: i386.md: restore PIC register after __builtin_longjmp
Date: Sat, 1 Jan 2000 13:51:35 -0800
Organization: None provided
Message-ID: < 200001012151.NAA02479@rtl.cygnus.com >
To: gcc-patches@gcc.gnu.org


The PIC register should be restored after __builtin_longjmp.  There
will be trouble otherwise.

The test code below should probably be adapted to support other
architectures.

Ok to check in?


2000-01-01  Anthony Green  <green@cygnus.com>
	
	* config/i386/i386.md (builtin_setjmp_receiver): New pattern.
	Restore the pic register if required.


Index: gcc/config/i386/i386.md
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386.md,v
retrieving revision 1.122
diff -u -r1.122 i386.md
--- i386.md	1999/12/17 00:45:03	1.122
+++ i386.md	2000/01/01 21:31:49
@@ -8335,6 +8335,15 @@
   load_pic_register ();
   DONE;
 }")
+
+(define_expand "builtin_setjmp_receiver"
+  [(label_ref (match_operand 0 "" ""))]
+  "flag_pic"
+  "
+{
+  load_pic_register ();
+  DONE;
+}")
 
 ;; Avoid redundant prefixes by splitting HImode arithmetic to SImode.
 
Index: gcc/testsuite/gcc.dg/000101-1.c
===================================================================
RCS file: 000101-1.c
diff -N 000101-1.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ 000101-1.c	Sat Jan  1 13:31:49 2000
@@ -0,0 +1,29 @@
+/* { dg-do run { target i?86-*-linux* } } */
+/* { dg-options "-fPIC" } */
+
+/* The System V PIC register on IA-32 is %ebx.  It should always
+   be restored after a __builtin_longjmp.  */
+
+int
+main ()
+{
+  register void *pic_register asm ("%ebx");
+  
+  /* More than enough space.  No need to include a header.  */
+  int jmp_buf[100]; 
+
+  void *saved_value = pic_register;
+
+  if (__builtin_setjmp (jmp_buf) != 0)
+    {
+      if (pic_register != saved_value)
+	abort ();
+    }
+  else
+    {
+      pic_register = (void *) ! pic_register;
+      __builtin_longjmp (jmp_buf, 1);
+    }
+
+  return 0;
+}



-- 
Anthony Green                                               Cygnus Solutions
                                                       Sunnyvale, California
------- End of forwarded message -------


More information about the Gcc-patches mailing list