This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
i386.md: restore PIC register after __builtin_longjmp
- To: gcc-patches at gcc dot gnu dot org
- Subject: i386.md: restore PIC register after __builtin_longjmp
- From: Anthony Green <green at cygnus dot com>
- Date: Sat, 1 Jan 2000 13:51:35 -0800
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