sol2-sld-64.h (TRANSFER_FROM_TRAMPOLINE): Rework for efficiency by checking whether...
authorDavid S. Miller <davem@pierdol.cobaltmicro.com>
Wed, 7 Oct 1998 02:17:57 +0000 (02:17 +0000)
committerDavid S. Miller <davem@gcc.gnu.org>
Wed, 7 Oct 1998 02:17:57 +0000 (19:17 -0700)
* config/sparc/sol2-sld-64.h (TRANSFER_FROM_TRAMPOLINE): Rework
for efficiency by checking whether we need to modify the current
stack permission at all.
(ASM_OUTPUT_CONSTRUCTOR, ASM_OUTPUT_DESTRUCTOR): Define.
* config/sparc/sparc.c (sparc_initialize_trampoline): Emit
__enable_execute_stack libcall here too if
TRANSFER_FROM_TRAMPOLINE is defined.
* config/sparc/sparc.h: Set TARGET_ARCH32 to a constant if
IN_LIBGCC2.

From-SVN: r22880

gcc/ChangeLog
gcc/config/sparc/sol2-sld-64.h
gcc/config/sparc/sparc.c
gcc/config/sparc/sparc.h

index 384005961f3a8a277cf57333527e4021dd854866..4d2c2c973df72710608f17b72d9b1125aceba5ce 100644 (file)
@@ -1,3 +1,15 @@
+Wed Oct  7 02:05:20 1998  David S. Miller  <davem@pierdol.cobaltmicro.com>
+
+       * config/sparc/sol2-sld-64.h (TRANSFER_FROM_TRAMPOLINE): Rework
+       for efficiency by checking whether we need to modify the current
+       stack permission at all.
+       (ASM_OUTPUT_CONSTRUCTOR, ASM_OUTPUT_DESTRUCTOR): Define.
+       * config/sparc/sparc.c (sparc_initialize_trampoline): Emit
+       __enable_execute_stack libcall here too if
+       TRANSFER_FROM_TRAMPOLINE is defined.
+       * config/sparc/sparc.h: Set TARGET_ARCH32 to a constant if
+       IN_LIBGCC2.
+
 Wed Oct  7 02:27:52 1998  Jeffrey A Law  (law@cygnus.com)
 
        * Makefile.in (DRIVER_DEFINES): Remove last change.
index 7364cbb84e8377e370fff8746f14489f8ddc152b..13b0fe32cfe1bfc5719747e8fbf48f795815851d 100644 (file)
    
 #undef MD_STARTFILE_PREFIX
 #define MD_STARTFILE_PREFIX "/usr/lib/sparcv9/"
+#endif /* ! SPARC_BI_ARCH */
+
+/*
+ * Attempt to turn on access permissions for the stack.
+ *
+ * This code must be defined when compiling gcc but not when compiling
+ * libgcc2.a, unless we're generating code for 64 bits SPARC
+ *
+ * _SC_STACK_PROT is only defined for post 2.6, but we want this code
+ * to run always.  2.6 can change the stack protection but has no way to
+ * query it.
+ *
+ */
 
-/* Attempt to turn on access permissions for the stack.  */
-
-#define TRANSFER_FROM_TRAMPOLINE                                       \
-void                                                                   \
-__enable_execute_stack (addr)                                          \
-     void *addr;                                                       \
-{                                                                      \
-  long size = getpagesize ();                                          \
-  long mask = ~(size-1);                                               \
-  char *page = (char *) (((long) addr) & mask);                               \
-  char *end  = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
-                                                                       \
-  /* 7 is PROT_READ | PROT_WRITE | PROT_EXEC */                               \
-  if (mprotect (page, end - page, 7) < 0)                              \
-    perror ("mprotect of trampoline code");                            \
+#define TRANSFER_FROM_TRAMPOLINE                                       \
+static int need_enable_exec_stack;                                     \
+                                                                       \
+static void check_enabling(void) __attribute__ ((constructor));                \
+static void check_enabling(void)                                       \
+{                                                                      \
+  extern long sysconf(int);                                            \
+                                                                       \
+  int prot = (int) sysconf(515 /*_SC_STACK_PROT */);                   \
+  if (prot != 7)                                                       \
+    need_enable_exec_stack = 1;                                                \
+}                                                                      \
+                                                                       \
+void                                                                   \
+__enable_execute_stack (addr)                                          \
+     void *addr;                                                       \
+{                                                                      \
+  if (!need_enable_exec_stack)                                         \
+    return;                                                            \
+  else {                                                               \
+    long size = getpagesize ();                                                \
+    long mask = ~(size-1);                                             \
+    char *page = (char *) (((long) addr) & mask);                      \
+    char *end  = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
+                                                                       \
+    /* 7 is PROT_READ | PROT_WRITE | PROT_EXEC */                      \
+    if (mprotect (page, end - page, 7) < 0)                            \
+      perror ("mprotect of trampoline code");                          \
+  }                                                                    \
 }
-   
-#endif /* ! SPARC_BI_ARCH */
+
+/* A C statement (sans semicolon) to output an element in the table of
+   global constructors.  */
+#undef ASM_OUTPUT_CONSTRUCTOR
+#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME)                              \
+  do {                                                                 \
+    ctors_section ();                                                  \
+    fprintf (FILE, "\t%s\t ", TARGET_ARCH64 ? ASM_LONGLONG : INT_ASM_OP); \
+    assemble_name (FILE, NAME);                                                \
+    fprintf (FILE, "\n");                                              \
+  } while (0)
+
+/* A C statement (sans semicolon) to output an element in the table of
+   global destructors.  */
+#undef ASM_OUTPUT_DESTRUCTOR
+#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME)                                       \
+  do {                                                                 \
+    dtors_section ();                                                  \
+    fprintf (FILE, "\t%s\t ", TARGET_ARCH64 ? ASM_LONGLONG : INT_ASM_OP); \
+    assemble_name (FILE, NAME);                                        \
+    fprintf (FILE, "\n");                                              \
+  } while (0)
+
index 16fd6b7ba9d013da5c095dfff05f237a318a2f91..ae207027b0fa0539b5971865978082e6d030f599 100644 (file)
@@ -5438,6 +5438,10 @@ sparc_initialize_trampoline (tramp, fnaddr, cxt)
     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"),
+                     0, VOIDmode, 1, tramp, Pmode);
+#endif
 
   emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 0)),
                  expand_binop (SImode, ior_optab,
index e09e964f92de7cf8f28983206bbc7d078c858216..177c3327adba07e9c5e82215ba0ee14da0f984a0 100644 (file)
@@ -34,10 +34,18 @@ Boston, MA 02111-1307, USA.  */
    architectures to compile for.  We allow targets to choose compile time or
    runtime selection.  */
 #ifdef SPARC_BI_ARCH
+#ifdef IN_LIBGCC2
+#if defined(__sparcv9) || defined(__sparcv_v9) || defined(__arch64__)
+#define TARGET_ARCH32 0
+#else
+#define TARGET_ARCH32 1
+#endif /* V9 sparc */
+#else
 #define TARGET_ARCH32 (! TARGET_64BIT)
+#endif /* IN_LIBGCC2 */
 #else
 #define TARGET_ARCH32 (DEFAULT_ARCH32_P)
-#endif
+#endif /* SPARC_BI_ARCH */
 #define TARGET_ARCH64 (! TARGET_ARCH32)
 
 /* Code model selection.