public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Export __enable_execute_stack
@ 2004-06-11 14:39 Eric Botcazou
  2004-06-11 22:17 ` Richard Henderson
  2004-06-14 13:13 ` Jakub Jelinek
  0 siblings, 2 replies; 15+ messages in thread
From: Eric Botcazou @ 2004-06-11 14:39 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2155 bytes --]

Hi,

This patch lets libgcc.so export __enable_execute_stack (the function is 
required for trampoline support on Solaris, NetBSD, FreeBSD/SPARC64 and OSF).  
I added a new target macro ENABLE_EXECUTE_STACK so as to uncouple it from 
TRANSFER_FROM_TRAMPOLINE.

Bootstrapped/regtested on sparc-sun-solaris2.8 and i586-redhat-linux-gnu 
(mainline).  I also built cross-compilers to

   alphaev56-dec-osf5.1
   alphaev56-unknown-netbsd
   i386-unknown-netbsd
   sparc-netbsd-elf
   sparc-sun-solaris2.8
   sparc64-unknown-freebsd5.1
   sparc64-sun-solaris2.9

and verified that the call to __enable_execute_stack is still present in the 
assembly file as needed.

OK for mainline?  Would it be feasible to add it to the 3.4 branch at some 
point?


2004-06-11  Eric Botcazou  <ebotcazou@act-europe.fr>

	* libgcc2.c (__enable_execute_stack): New symbol.
	* libgcc-std.ver (GCC_3.5): New version.  Inherit from GCC_3.4
	and declare __enable_execute_stack.
	* mklibgcc.in (lib2funcs): Add _enable_execute_stack.
	* doc/tm.texi (trampolines): Add ENABLE_EXECUTE_STACK macro.
	* config/netbsd.h (NETBSD_ENABLE_EXECUTE_STACK): Rename
	into ENABLE_EXECUTE_STACK.
	* config/sol2.h (TRANSFER_FROM_TRAMPOLINE): Likewise.
	* config/alpha/alpha.c (alpha_initialize_trampoline): Conditionalize
	on ENABLE_EXECUTE_STACK instead of TRANSFER_FROM_TRAMPOLINE.
	* config/alpha/netbsd.h (TRANSFER_FROM_TRAMPOLINE): Delete.
	* config/alpha/osf.h (TRANSFER_FROM_TRAMPOLINE): Rename into
	ENABLE_EXECUTE_STACK.
	* config/i386/i386.c (x86_initialize_trampoline): Conditionalize
	on ENABLE_EXECUTE_STACK instead of TRANSFER_FROM_TRAMPOLINE.
	* config/i386/netbsd-elf.h (TRANSFER_FROM_TRAMPOLINE): Delete.
	* config/i386/netbsd.h (TRANSFER_FROM_TRAMPOLINE): Likewise.
	* config/i386/netbsd64.h (TRANSFER_FROM_TRAMPOLINE): Likewise.
	* config/sparc/freebsd.h (TRANSFER_FROM_TRAMPOLINE): Rename into
	ENABLE_EXECUTE_STACK.
	* config/sparc/netbsd-elf.h (TRANSFER_FROM_TRAMPOLINE): Delete.
	* config/sparc/sparc.c (sparc_initialize_trampoline): Conditionalize
	on ENABLE_EXECUTE_STACK instead of TRANSFER_FROM_TRAMPOLINE.
	(sparc64_initialize_trampoline): Likewise.


-- 
Eric Botcazou

[-- Attachment #2: enable_execute_stack.diff --]
[-- Type: text/x-diff, Size: 12537 bytes --]

Index: libgcc2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/libgcc2.c,v
retrieving revision 1.171
diff -u -r1.171 libgcc2.c
--- libgcc2.c	19 May 2004 23:43:13 -0000	1.171
+++ libgcc2.c	10 Jun 2004 13:20:27 -0000
@@ -1487,6 +1487,19 @@
 
 #endif /* L_clear_cache */
 \f
+#ifdef L_enable_execute_stack
+/* Attempt to turn on execute permission for the stack.  */
+
+#ifdef ENABLE_EXECUTE_STACK
+  ENABLE_EXECUTE_STACK
+#else
+void
+__enable_execute_stack (void *addr __attribute__((__unused__)))
+{}
+#endif /* ENABLE_EXECUTE_STACK */
+
+#endif /* L_enable_execute_stack */
+\f
 #ifdef L_trampoline
 
 /* Jump to a trampoline, loading the static chain address.  */
Index: libgcc-std.ver
===================================================================
RCS file: /cvs/gcc/gcc/gcc/libgcc-std.ver,v
retrieving revision 1.23
diff -u -r1.23 libgcc-std.ver
--- libgcc-std.ver	4 Sep 2003 10:47:45 -0000	1.23
+++ libgcc-std.ver	10 Jun 2004 13:20:27 -0000
@@ -211,3 +211,9 @@
   __paritydi2
   __parityti2
 }
+
+%inherit GCC_3.5 GCC_3.4
+GCC_3.5 {
+  # Used to deal with trampoline initialization on some platforms
+  __enable_execute_stack
+}
Index: mklibgcc.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/mklibgcc.in,v
retrieving revision 1.68
diff -u -r1.68 mklibgcc.in
--- mklibgcc.in	19 Mar 2004 03:32:07 -0000	1.68
+++ mklibgcc.in	10 Jun 2004 13:20:28 -0000
@@ -48,8 +48,8 @@
 	_cmpdi2 _ucmpdi2 _floatdidf _floatdisf _fixunsdfsi _fixunssfsi
 	_fixunsdfdi _fixdfdi _fixunssfdi _fixsfdi _fixxfdi _fixunsxfdi
 	_floatdixf _fixunsxfsi _fixtfdi _fixunstfdi _floatditf _clear_cache
-	_trampoline __main _absvsi2 _absvdi2 _addvsi3 _addvdi3
-	_subvsi3 _subvdi3 _mulvsi3 _mulvdi3 _negvsi2 _negvdi2 _ctors
+	_enable_execute_stack _trampoline __main _absvsi2 _absvdi2 _addvsi3
+	_addvdi3 _subvsi3 _subvdi3 _mulvsi3 _mulvdi3 _negvsi2 _negvdi2 _ctors
 	_ffssi2 _ffsdi2 _clz _clzsi2 _clzdi2 _ctzsi2 _ctzdi2 _popcount_tab
 	_popcountsi2 _popcountdi2 _paritysi2 _paritydi2'
 
Index: doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.327
diff -u -r1.327 tm.texi
--- doc/tm.texi	3 Jun 2004 23:15:01 -0000	1.327
+++ doc/tm.texi	10 Jun 2004 13:21:05 -0000
@@ -4670,6 +4670,19 @@
 @var{end} are both pointer expressions.
 @end defmac
 
+The operating system may also require the stack to be made executable
+before calling the trampoline.  To implement this requirement, define
+the following macro.
+
+@defmac ENABLE_EXECUTE_STACK
+Define this macro if certain operations must be performed before executing
+code located on the stack.  The macro should expand to a series of C
+file-scope constructs (e.g. functions) and provide a unique entry point
+named @code{__enable_execute_stack}.  The target is responsible for
+emitting calls to the entry point in the code, for example in the
+@code{INITIALIZE_TRAMPOLINE} macro.
+@end defmac
+
 To use a standard subroutine, define the following macro.  In addition,
 you must make sure that the instructions in a trampoline fill an entire
 cache line with identical instructions, or else ensure that the
Index: config/netbsd.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/netbsd.h,v
retrieving revision 1.26
diff -u -r1.26 netbsd.h
--- config/netbsd.h	27 Sep 2003 04:48:11 -0000	1.26
+++ config/netbsd.h	10 Jun 2004 13:21:05 -0000
@@ -181,7 +181,7 @@
 \f
 
 /* Attempt to turn on execute permission for the stack.  This may be
-   used by TRANSFER_FROM_TRAMPOLINE of the target needs it (that is,
+   used by INITIALIZE_TRAMPOLINE of the target needs it (that is,
    if the target machine can change execute permissions on a page).
 
    There is no way to query the execute permission of the stack, so
@@ -193,11 +193,9 @@
    Also note that no errors should be emitted by this code; it is considered
    dangerous for library calls to send messages to stdout/stderr.  */
 
-#define NETBSD_ENABLE_EXECUTE_STACK					\
-extern void __enable_execute_stack (void *);				\
+#define ENABLE_EXECUTE_STACK						\
 void									\
-__enable_execute_stack (addr)						\
-     void *addr;							\
+__enable_execute_stack (void *addr)					\
 {									\
   extern int mprotect (void *, size_t, int);				\
   extern int __sysctl (int *, unsigned int, void *, size_t *,		\
Index: config/sol2.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/sol2.h,v
retrieving revision 1.10
diff -u -r1.10 sol2.h
--- config/sol2.h	31 May 2004 15:15:08 -0000	1.10
+++ config/sol2.h	10 Jun 2004 13:21:07 -0000
@@ -163,9 +163,6 @@
 /*
  * 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-bit 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.
@@ -173,10 +170,10 @@
  */
 
 /* sys/mman.h is not present on some non-Solaris configurations
-   that use sol2.h, so TRANSFER_FROM_TRAMPOLINE must use a magic
+   that use sol2.h, so ENABLE_EXECUTE_STACK must use a magic
    number instead of the appropriate PROT_* flags.  */
 
-#define TRANSFER_FROM_TRAMPOLINE					\
+#define ENABLE_EXECUTE_STACK						\
 									\
 /* #define STACK_PROT_RWX (PROT_READ | PROT_WRITE | PROT_EXEC) */	\
 									\
@@ -192,7 +189,6 @@
     need_enable_exec_stack = 1;						\
 }									\
 									\
-extern void __enable_execute_stack (void *);				\
 void									\
 __enable_execute_stack (void *addr)					\
 {									\
Index: config/alpha/alpha.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/alpha/alpha.c,v
retrieving revision 1.363
diff -u -r1.363 alpha.c
--- config/alpha/alpha.c	13 May 2004 06:39:54 -0000	1.363
+++ config/alpha/alpha.c	10 Jun 2004 13:21:29 -0000
@@ -5848,7 +5848,7 @@
       emit_move_insn (gen_rtx_MEM (SImode, addr), temp1);
     }
 
-#ifdef TRANSFER_FROM_TRAMPOLINE
+#ifdef ENABLE_EXECUTE_STACK
   emit_library_call (init_one_libfunc ("__enable_execute_stack"),
 		     0, VOIDmode, 1, tramp, Pmode);
 #endif
Index: config/alpha/netbsd.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/alpha/netbsd.h,v
retrieving revision 1.20
diff -u -r1.20 netbsd.h
--- config/alpha/netbsd.h	27 Sep 2003 04:48:12 -0000	1.20
+++ config/alpha/netbsd.h	10 Jun 2004 13:21:29 -0000
@@ -74,10 +74,5 @@
    %(netbsd_endfile_spec)"
 
 
-/* Attempt to enable execute permissions on the stack.  */
-
-#define TRANSFER_FROM_TRAMPOLINE NETBSD_ENABLE_EXECUTE_STACK
-
-
 #undef TARGET_VERSION
 #define TARGET_VERSION fprintf (stderr, " (NetBSD/alpha ELF)");
Index: config/alpha/osf.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/alpha/osf.h,v
retrieving revision 1.36
diff -u -r1.36 osf.h
--- config/alpha/osf.h	30 Apr 2004 20:09:51 -0000	1.36
+++ config/alpha/osf.h	10 Jun 2004 13:21:32 -0000
@@ -145,7 +145,7 @@
 
 /* Attempt to turn on access permissions for the stack.  */
 
-#define TRANSFER_FROM_TRAMPOLINE					\
+#define ENABLE_EXECUTE_STACK						\
 void									\
 __enable_execute_stack (void *addr)					\
 {									\
Index: config/i386/i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.671
diff -u -r1.671 i386.c
--- config/i386/i386.c	8 Jun 2004 13:26:04 -0000	1.671
+++ config/i386/i386.c	10 Jun 2004 13:22:06 -0000
@@ -12592,7 +12592,7 @@
 	abort ();
     }
 
-#ifdef TRANSFER_FROM_TRAMPOLINE
+#ifdef ENABLE_EXECUTE_STACK
   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
 		     LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
 #endif
Index: config/i386/netbsd-elf.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/netbsd-elf.h,v
retrieving revision 1.18
diff -u -r1.18 netbsd-elf.h
--- config/i386/netbsd-elf.h	26 Sep 2003 04:07:46 -0000	1.18
+++ config/i386/netbsd-elf.h	10 Jun 2004 13:22:06 -0000
@@ -119,7 +119,4 @@
    we don't care about compatibility with older gcc versions.  */
 #define DEFAULT_PCC_STRUCT_RETURN 1
 
-/* Attempt to enable execute permissions on the stack.  */
-#define TRANSFER_FROM_TRAMPOLINE NETBSD_ENABLE_EXECUTE_STACK
-
 #define TARGET_VERSION fprintf (stderr, " (NetBSD/i386 ELF)");
Index: config/i386/netbsd.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/netbsd.h,v
retrieving revision 1.26
diff -u -r1.26 netbsd.h
--- config/i386/netbsd.h	18 Oct 2002 23:10:35 -0000	1.26
+++ config/i386/netbsd.h	10 Jun 2004 13:22:06 -0000
@@ -67,6 +67,3 @@
    prefix is added.  */
 #undef GOT_SYMBOL_NAME
 #define GOT_SYMBOL_NAME "GLOBAL_OFFSET_TABLE_"
-
-/* Attempt to enable execute permissions on the stack.  */
-#define TRANSFER_FROM_TRAMPOLINE NETBSD_ENABLE_EXECUTE_STACK
Index: config/i386/netbsd64.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/netbsd64.h,v
retrieving revision 1.9
diff -u -r1.9 netbsd64.h
--- config/i386/netbsd64.h	26 Sep 2003 04:07:46 -0000	1.9
+++ config/i386/netbsd64.h	10 Jun 2004 13:22:06 -0000
@@ -67,7 +67,4 @@
     fprintf (FILE, "\tcall __mcount\n");				\
 }
 
-/* Attempt to enable execute permissions on the stack.  */
-#define TRANSFER_FROM_TRAMPOLINE NETBSD_ENABLE_EXECUTE_STACK
-
 #define TARGET_VERSION fprintf (stderr, " (NetBSD/x86_64 ELF)");
Index: config/sparc/freebsd.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/sparc/freebsd.h,v
retrieving revision 1.27
diff -u -r1.27 freebsd.h
--- config/sparc/freebsd.h	7 May 2004 03:45:03 -0000	1.27
+++ config/sparc/freebsd.h	10 Jun 2004 13:22:10 -0000
@@ -96,7 +96,7 @@
 #undef  SPARC_DEFAULT_CMODEL
 #define SPARC_DEFAULT_CMODEL	CM_MEDLOW
 
-#define TRANSFER_FROM_TRAMPOLINE					\
+#define ENABLE_EXECUTE_STACK						\
   static int need_enable_exec_stack;					\
   static void check_enabling(void) __attribute__ ((constructor));	\
   static void check_enabling(void)					\
@@ -109,7 +109,6 @@
     if (prot != 7)							\
       need_enable_exec_stack = 1;					\
   }									\
-  extern void __enable_execute_stack (void *);				\
   void __enable_execute_stack (void *addr)				\
   {									\
     if (!need_enable_exec_stack)					\
Index: config/sparc/netbsd-elf.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/sparc/netbsd-elf.h,v
retrieving revision 1.23
diff -u -r1.23 netbsd-elf.h
--- config/sparc/netbsd-elf.h	7 Feb 2004 17:06:25 -0000	1.23
+++ config/sparc/netbsd-elf.h	10 Jun 2004 13:22:10 -0000
@@ -88,9 +88,6 @@
 
 #undef STDC_0_IN_SYSTEM_HEADERS
 
-/* Attempt to enable execute permissions on the stack.  */
-#define TRANSFER_FROM_TRAMPOLINE NETBSD_ENABLE_EXECUTE_STACK
-
 #undef TARGET_VERSION
 #define TARGET_VERSION fprintf (stderr, " (%s)", TARGET_NAME);
 
Index: config/sparc/sparc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/sparc/sparc.c,v
retrieving revision 1.302
diff -u -r1.302 sparc.c
--- config/sparc/sparc.c	7 Jun 2004 20:58:27 -0000	1.302
+++ config/sparc/sparc.c	10 Jun 2004 13:22:27 -0000
@@ -7465,7 +7465,7 @@
 
   /* Call __enable_execute_stack after writing onto the stack to make sure
      the stack address is accessible.  */
-#ifdef TRANSFER_FROM_TRAMPOLINE
+#ifdef ENABLE_EXECUTE_STACK
   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
                      LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
 #endif
@@ -7506,7 +7506,7 @@
 
   /* Call __enable_execute_stack after writing onto the stack to make sure
      the stack address is accessible.  */
-#ifdef TRANSFER_FROM_TRAMPOLINE
+#ifdef ENABLE_EXECUTE_STACK
   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
                      LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
 #endif

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: [PATCH] Export __enable_execute_stack
@ 2004-06-13 18:18 Richard Kenner
  0 siblings, 0 replies; 15+ messages in thread
From: Richard Kenner @ 2004-06-13 18:18 UTC (permalink / raw)
  To: jakub; +Cc: gcc-patches

    2) during 3.4.x build with 3.4.x as bootstrap compiler (unlike 3.3.x
    bootstrap compiler + 3.4.x build) I get:
    ./xnmake -b ../nmake.adb
    Segmentation fault

Indeed, I've seen problems with the various "make" programs on 64-bit
machines for quite a while, but have never the the ambition to debug them.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2004-06-14 11:23 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-11 14:39 [PATCH] Export __enable_execute_stack Eric Botcazou
2004-06-11 22:17 ` Richard Henderson
2004-06-11 22:45   ` Eric Botcazou
2004-06-11 22:55     ` Richard Henderson
2004-06-11 23:08       ` Eric Botcazou
2004-06-11 23:42         ` Richard Henderson
2004-06-12 11:39           ` Eric Botcazou
2004-06-12 12:14             ` Jakub Jelinek
2004-06-12 16:39               ` Eric Botcazou
2004-06-13  8:26                 ` Richard Henderson
2004-06-13 17:09               ` Arnaud Charlet
2004-06-13 17:54                 ` Jakub Jelinek
2004-06-13 18:19                   ` Arnaud Charlet
2004-06-14 13:13 ` Jakub Jelinek
2004-06-13 18:18 Richard Kenner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).