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]
Other format: [Raw text]

[PATCH] Fix Sparc `mprotect' trampoline problem


The patch below fixes problem with making Sparc Solaris trampolines
executable (I reported the problem as PR target/12865).
The patch applies to gcc-3.3-20031027 and gcc-3.4-20031029.

* config/sparc/sparc.c (sparc_initialize_trampoline, 
  sparc64_initialize_trampoline): generate call to `__enable_execute_stack'
  only after filling the trampiline.

--- gcc-3.3.1.orig/gcc/config/sparc/sparc.c	Wed Jul 16 07:19:33 2003
+++ gcc-3.3.1/gcc/config/sparc/sparc.c	Tue Oct 14 01:04:01 2003
@@ -6777,10 +6777,6 @@
     SETHI i,r  = 00rr rrr1 00ii iiii iiii iiii iiii iiii
     JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
    */
-#ifdef TRANSFER_FROM_TRAMPOLINE
-  emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
-                     LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
-#endif
 
   emit_move_insn
     (gen_rtx_MEM (SImode, plus_constant (tramp, 0)),
@@ -6811,6 +6807,13 @@
 		   expand_and (SImode, cxt, GEN_INT (0x3ff), NULL_RTX),
 		   GEN_INT (trunc_int_for_mode (0x8410a000, SImode)),
 		   NULL_RTX, 1, OPTAB_DIRECT));
+  
+  /* Call `__enable_execute_stack' after stack is extended, otherwise
+     `mprotect' may fail. (hebisch@math.uni.wroc.pl) */
+#ifdef TRANSFER_FROM_TRAMPOLINE
+  emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
+                     LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
+#endif
 
   /* On UltraSPARC a flush flushes an entire cache line.  The trampoline is
      aligned on a 16 byte boundary so one flush clears it all.  */
@@ -6829,11 +6832,6 @@
 sparc64_initialize_trampoline (tramp, fnaddr, cxt)
      rtx tramp, fnaddr, cxt;
 {
-#ifdef TRANSFER_FROM_TRAMPOLINE
-  emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
-                     LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
-#endif
-
   /*
 	rd	%pc, %g1
 	ldx	[%g1+24], %g5
@@ -6852,8 +6850,15 @@
 		  GEN_INT (trunc_int_for_mode (0xca586010, SImode)));
   emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 16)), cxt);
   emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 24)), fnaddr);
-  emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, tramp))));
 
+  /* Call `__enable_execute_stack' after stack is extended, otherwise
+     `mprotect' may fail. (hebisch@math.uni.wroc.pl) */
+#ifdef TRANSFER_FROM_TRAMPOLINE
+  emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
+                     LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
+#endif
+
+  emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, tramp))));
   if (sparc_cpu != PROCESSOR_ULTRASPARC
       && sparc_cpu != PROCESSOR_ULTRASPARC3)
     emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, plus_constant (tramp, 8)))));

-- 
                              Waldek Hebisch
hebisch@math.uni.wroc.pl 


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