This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fix builtin_setjmp on Darwin
- From: Geoffrey Keating <gkeating at apple dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 20 Sep 2002 11:38:41 -0700 (PDT)
- Subject: fix builtin_setjmp on Darwin
On Darwin, we need to restore the PIC register always. Unlike on AIX
or SVR4, the PIC register is per-function and so needs to be restored
for every reciever. It turns out the assembler can deal with the
expression required, so I chose to recompute the register at the
destination rather than save it with the setjmp.
Bootstrapped & tested on powerpc-darwin.
--
- Geoffrey Keating <geoffk@apple.com>
===File ~/patches/darwin-builtinsetjmpfix.patch=============
2002-09-20 Geoffrey Keating <geoffk@apple.com>
* config/rs6000/rs6000.c (rs6000_emit_prologue): Update for change
to load_macho_picbase.
* config/rs6000/rs6000.md: Document Darwin-specific unspec IDs.
(load_macho_picbase): Take the symbol to use as a parameter.
(macho_correct_pic): New insn.
(builtin_setjmp_reciever): On Darwin, restore the PIC register.
Index: config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.381
diff -u -p -r1.381 rs6000.c
--- config/rs6000/rs6000.c 16 Sep 2002 19:48:19 -0000 1.381
+++ config/rs6000/rs6000.c 20 Sep 2002 18:30:35 -0000
@@ -10457,8 +10457,12 @@ rs6000_emit_prologue ()
&& flag_pic && current_function_uses_pic_offset_table)
{
rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
+#if TARGET_MACHO
+ char *picbase = machopic_function_base_name ();
+ rtx src = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (picbase, -1));
- rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest)));
+ rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
+#endif
rs6000_maybe_dead (
emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
Index: config/rs6000/rs6000.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.md,v
retrieving revision 1.206
diff -u -p -r1.206 rs6000.md
--- config/rs6000/rs6000.md 13 Sep 2002 01:40:44 -0000 1.206
+++ config/rs6000/rs6000.md 20 Sep 2002 18:30:37 -0000
@@ -1,6 +1,6 @@
;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
;; Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-;; 1999, 2000, 2001 Free Software Foundation, Inc.
+;; 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
;; This file is part of GNU CC.
@@ -32,6 +32,8 @@
;; 8 movsi_got
;; 9/v eh_reg_restore
;; 10 fctiwz
+;; 15 load_macho_picbase
+;; 16 macho_correct_pic
;; 19 movesi_from_cr
;; 20 movesi_to_cr
@@ -10176,30 +10178,51 @@
(define_insn "load_macho_picbase"
[(set (match_operand:SI 0 "register_operand" "=l")
- (unspec:SI [(const_int 0)] 15))]
+ (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")] 15))]
"(DEFAULT_ABI == ABI_DARWIN) && flag_pic"
- "*
-{
-#if TARGET_MACHO
- char *picbase = machopic_function_base_name ();
- operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (picbase, -1));
-#endif
- return \"bcl 20,31,%1\\n%1:\";
-}"
+ "bcl 20,31,%1\\n%1:"
[(set_attr "type" "branch")
(set_attr "length" "4")])
+(define_insn "macho_correct_pic"
+ [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
+ (plus:SI (match_operand:SI 1 "gpc_reg_operand" "=r")
+ (unspec:SI [(match_operand:SI 2 "immediate_operand" "s")
+ (match_operand:SI 3 "immediate_operand" "s")]
+ 16)))]
+ "DEFAULT_ABI == ABI_DARWIN"
+ "addis %0,%1,ha16(%2-%3)\n\taddi %1,%1,lo16(%2-%3)"
+ [(set_attr "length" "8")])
+
;; If the TOC is shared over a translation unit, as happens with all
;; the kinds of PIC that we support, we need to restore the TOC
;; pointer only when jumping over units of translation.
+;; On Darwin, we need to reload the picbase.
(define_expand "builtin_setjmp_receiver"
[(use (label_ref (match_operand 0 "" "")))]
"(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
- || (TARGET_TOC && TARGET_MINIMAL_TOC)"
+ || (TARGET_TOC && TARGET_MINIMAL_TOC)
+ || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
"
{
- rs6000_emit_load_toc_table (FALSE);
+ if (DEFAULT_ABI == ABI_DARWIN)
+ {
+ char *picbase = machopic_function_base_name ();
+ rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (picbase, -1));
+ rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
+ rtx tmplabrtx;
+ char tmplab[20];
+
+ ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
+ CODE_LABEL_NUMBER (operands[0]));
+ tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (tmplab, -1));
+
+ emit_insn (gen_load_macho_picbase (picreg, tmplabrtx));
+ emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
+ }
+ else
+ rs6000_emit_load_toc_table (FALSE);
DONE;
}")
============================================================