@@ -487,6 +487,7 @@ case ${target} in
esac
tm_file="${tm_file} ${cpu_type}/darwin.h"
tm_p_file="${tm_p_file} darwin-protos.h"
+ libgcc_tm_file="${libgcc_tm_file} darwin-lib.h"
target_gtfiles="\$(srcdir)/config/darwin.c"
extra_options="${extra_options} darwin.opt"
c_target_objs="${c_target_objs} darwin-c.o"
@@ -648,6 +649,7 @@ case ${target} in
esac
;;
*-*-openbsd*)
+ libgcc_tm_file="${libgcc_tm_file} openbsd-lib.h"
tmake_file="t-libc-ok t-openbsd t-libgcc-pic"
case ${enable_threads} in
yes)
@@ -673,6 +675,7 @@ case ${target} in
tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC SINGLE_LIBC"
;;
*-*-solaris2*)
+ libgcc_tm_file="${libgcc_tm_file} sol2-lib.h"
extra_options="${extra_options} sol2.opt"
;;
*-*-*vms*)
@@ -730,6 +733,7 @@ alpha*-*-freebsd*)
;;
alpha*-*-netbsd*)
tm_file="${tm_file} netbsd.h alpha/elf.h netbsd-elf.h alpha/netbsd.h"
+ libgcc_tm_file="${libgcc_tm_file} netbsd-lib.h"
extra_options="${extra_options} netbsd.opt netbsd-elf.opt \
alpha/elf.opt"
target_cpu_default="MASK_GAS"
@@ -758,6 +762,7 @@ alpha*-dec-osf5.1*)
tmake_file="t-slibgcc-dummy"
tm_file="${tm_file} alpha/osf5.h"
tm_defines="${tm_defines} TARGET_SUPPORT_ARCH=1"
+ libgcc_tm_file="${libgcc_tm_file} alpha/osf5-lib.h"
extra_options="${extra_options} rpath.opt alpha/osf5.opt"
extra_headers=va_list.h
use_gcc_stdint=provide
@@ -1197,10 +1202,12 @@ x86_64-*-freebsd*)
;;
i[34567]86-*-netbsdelf*)
tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h netbsd.h netbsd-elf.h i386/netbsd-elf.h"
+ libgcc_tm_file="${libgcc_tm_file} netbsd-lib.h"
extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
;;
x86_64-*-netbsd*)
tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h netbsd.h netbsd-elf.h i386/x86-64.h i386/netbsd64.h"
+ libgcc_tm_file="${libgcc_tm_file} netbsd-lib.h"
extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
tmake_file="${tmake_file} i386/t-crtstuff"
;;
@@ -1447,6 +1454,7 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
tm_file="${tm_file} i386/mingw-pthread.h"
fi
tm_file="${tm_file} i386/mingw32.h"
+ libgcc_tm_file="${libgcc_tm_file} i386/mingw32-lib.h"
# This makes the logic if mingw's or the w64 feature set has to be used
case ${target} in
*-w64-*)
@@ -2462,6 +2470,7 @@ sparc-*-linux*)
;;
sparc-*-netbsdelf*)
tm_file="${tm_file} dbxelf.h elfos.h sparc/sysv4.h netbsd.h netbsd-elf.h sparc/netbsd-elf.h"
+ libgcc_tm_file="${libgcc_tm_file} netbsd-lib.h"
extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
extra_options="${extra_options} sparc/long-double-switch.opt"
;;
@@ -2527,6 +2536,7 @@ sparc64-*-linux*)
;;
sparc64-*-freebsd*|ultrasparc-*-freebsd*)
tm_file="${tm_file} ${fbsd_tm_file} dbxelf.h elfos.h sparc/sysv4.h sparc/freebsd.h"
+ libgcc_tm_file="${libgcc_tm_file} freebsd-lib.h"
extra_options="${extra_options} sparc/long-double-switch.opt"
tmake_file="${tmake_file} sparc/t-crtfm"
case "x$with_cpu" in
@@ -2538,6 +2548,7 @@ sparc64-*-freebsd*|ultrasparc-*-freebsd*
sparc64-*-netbsd*)
tm_file="sparc/biarch64.h ${tm_file}"
tm_file="${tm_file} dbxelf.h elfos.h sparc/sysv4.h netbsd.h netbsd-elf.h sparc/netbsd-elf.h"
+ libgcc_tm_file="${libgcc_tm_file} netbsd-lib.h"
extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
extra_options="${extra_options} sparc/long-double-switch.opt"
tmake_file="${tmake_file} sparc/t-netbsd64"
@@ -5395,7 +5395,7 @@ alpha_trampoline_init (rtx m_tramp, tree
if (TARGET_ABI_OSF)
{
emit_insn (gen_imb ());
-#ifdef ENABLE_EXECUTE_STACK
+#ifdef HAVE_ENABLE_EXECUTE_STACK
emit_library_call (init_one_libfunc ("__enable_execute_stack"),
LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
#endif
@@ -73,7 +73,4 @@ along with GCC; see the file COPYING3.
"%{Ofast|ffast-math|funsafe-math-optimizations:crtfm%O%s} \
%(netbsd_endfile_spec)"
-
-/* Attempt to enable execute permissions on the stack. */
-
-#define ENABLE_EXECUTE_STACK NETBSD_ENABLE_EXECUTE_STACK
+#define HAVE_ENABLE_EXECUTE_STACK
@@ -165,22 +165,7 @@ along with GCC; see the file COPYING3.
#define HAVE_STAMP_H 1
#endif
-/* Attempt to turn on access permissions for the stack. */
-
-#define ENABLE_EXECUTE_STACK \
-void \
-__enable_execute_stack (void *addr) \
-{ \
- extern int mprotect (const void *, size_t, int); \
- 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 HAVE_ENABLE_EXECUTE_STACK
/* Digital UNIX V4.0E (1091)/usr/include/sys/types.h 4.3.49.9 1997/08/14 */
#define SIZE_TYPE "long unsigned int"
@@ -923,43 +923,7 @@ void add_framework_path (char *);
#define TARGET_ASM_OUTPUT_ANCHOR NULL
#define DARWIN_SECTION_ANCHORS 0
-/* Attempt to turn on execute permission for the stack. This may be
- used by TARGET_TRAMPOLINE_INIT if 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
- we always issue the mprotect() call.
-
- Unfortunately it is not possible to make this namespace-clean.
-
- 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 ENABLE_EXECUTE_STACK \
-extern void __enable_execute_stack (void *); \
-void \
-__enable_execute_stack (void *addr) \
-{ \
- extern int mprotect (void *, size_t, int); \
- extern int getpagesize (void); \
- static int size; \
- static long mask; \
- \
- char *page, *end; \
- \
- if (size == 0) \
- { \
- size = getpagesize(); \
- mask = ~((long) size - 1); \
- } \
- \
- page = (char *) (((long) addr) & mask); \
- end = (char *) ((((long) (addr + (TARGET_64BIT ? 48 : 40))) & mask) + size); \
- \
- /* 7 == PROT_READ | PROT_WRITE | PROT_EXEC */ \
- (void) mprotect (page, end - page, 7); \
-}
+#define HAVE_ENABLE_EXECUTE_STACK
/* For Apple KEXTs, we make the constructors return this to match gcc
2.95. */
@@ -23399,7 +23399,7 @@ ix86_trampoline_init (rtx m_tramp, tree
gcc_assert (offset <= TRAMPOLINE_SIZE);
}
-#ifdef ENABLE_EXECUTE_STACK
+#ifdef HAVE_ENABLE_EXECUTE_STACK
#ifdef CHECK_EXECUTE_STACK_ENABLED
if (CHECK_EXECUTE_STACK_ENABLED)
#endif
@@ -219,21 +219,7 @@ do { \
/* Let defaults.h definition of TARGET_USE_JCR_SECTION apply. */
#undef TARGET_USE_JCR_SECTION
-#undef MINGW_ENABLE_EXECUTE_STACK
-#define MINGW_ENABLE_EXECUTE_STACK \
-extern void __enable_execute_stack (void *); \
-void \
-__enable_execute_stack (void *addr) \
-{ \
- MEMORY_BASIC_INFORMATION b; \
- if (!VirtualQuery (addr, &b, sizeof(b))) \
- abort (); \
- VirtualProtect (b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE, \
- &b.Protect); \
-}
-
-#undef ENABLE_EXECUTE_STACK
-#define ENABLE_EXECUTE_STACK MINGW_ENABLE_EXECUTE_STACK
+#define HAVE_ENABLE_EXECUTE_STACK
#undef CHECK_EXECUTE_STACK_ENABLED
#define CHECK_EXECUTE_STACK_ENABLED flag_setstackexecutable
@@ -118,5 +118,4 @@ along with GCC; see the file COPYING3.
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 ENABLE_EXECUTE_STACK NETBSD_ENABLE_EXECUTE_STACK
+#define HAVE_ENABLE_EXECUTE_STACK
@@ -66,5 +66,4 @@ along with GCC; see the file COPYING3.
fprintf (FILE, "\tcall __mcount\n"); \
}
-/* Attempt to enable execute permissions on the stack. */
-#define ENABLE_EXECUTE_STACK NETBSD_ENABLE_EXECUTE_STACK
+#define HAVE_ENABLE_EXECUTE_STACK
@@ -1,6 +1,6 @@
/* Base configuration file for all NetBSD targets.
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
- 2007, 2009, 2010 Free Software Foundation, Inc.
+ 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
This file is part of GCC.
@@ -173,50 +173,3 @@ along with GCC; see the file COPYING3.
#undef WINT_TYPE
#define WINT_TYPE "int"
-
-
-/* Attempt to turn on execute permission for the stack. This may be
- used by TARGET_TRAMPOLINE_INIT if 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
- we always issue the mprotect() call.
-
- Note that we go out of our way to use namespace-non-invasive calls
- here. Unfortunately, there is no libc-internal name for mprotect().
-
- 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 *); \
-void \
-__enable_execute_stack (void *addr) \
-{ \
- extern int mprotect (void *, size_t, int); \
- extern int __sysctl (int *, unsigned int, void *, size_t *, \
- void *, size_t); \
- \
- static int size; \
- static long mask; \
- \
- char *page, *end; \
- \
- if (size == 0) \
- { \
- int mib[2]; \
- size_t len; \
- \
- mib[0] = 6; /* CTL_HW */ \
- mib[1] = 7; /* HW_PAGESIZE */ \
- len = sizeof (size); \
- (void) __sysctl (mib, 2, &size, &len, NULL, 0); \
- mask = ~((long) size - 1); \
- } \
- \
- page = (char *) (((long) addr) & mask); \
- end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
- \
- /* 7 == PROT_READ | PROT_WRITE | PROT_EXEC */ \
- (void) mprotect (page, end - page, 7); \
-}
@@ -281,20 +281,4 @@ do { \
/* Storage layout. */
-/* Stack is explicitly denied execution rights on OpenBSD platforms. */
-#define ENABLE_EXECUTE_STACK \
-extern void __enable_execute_stack (void *); \
-void \
-__enable_execute_stack (void *addr) \
-{ \
- long size = getpagesize (); \
- long mask = ~(size-1); \
- char *page = (char *) (((long) addr) & mask); \
- char *end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
- \
- if (mprotect (page, end - page, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) \
- perror ("mprotect of trampoline code"); \
-}
-
-#include <sys/types.h>
-#include <sys/mman.h>
+#define HAVE_ENABLE_EXECUTE_STACK
@@ -207,52 +207,7 @@ along with GCC; see the file COPYING3.
#define STDC_0_IN_SYSTEM_HEADERS 1
-/*
- * Attempt to turn on access permissions for the stack.
- *
- * _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.
- *
- */
-
-/* sys/mman.h is not present on some non-Solaris configurations
- that use sol2.h, so ENABLE_EXECUTE_STACK must use a magic
- number instead of the appropriate PROT_* flags. */
-
-#define ENABLE_EXECUTE_STACK \
- \
-/* #define STACK_PROT_RWX (PROT_READ | PROT_WRITE | PROT_EXEC) */ \
- \
-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 /* STACK_PROT_RWX */) \
- need_enable_exec_stack = 1; \
-} \
- \
-extern void __enable_execute_stack (void *); \
-void \
-__enable_execute_stack (void *addr) \
-{ \
- extern int mprotect(void *, size_t, int); \
- 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); \
- \
- if (mprotect (page, end - page, 7 /* STACK_PROT_RWX */) < 0) \
- perror ("mprotect of trampoline code"); \
- } \
-}
+#define HAVE_ENABLE_EXECUTE_STACK
/* Support Solaris-specific format checking for cmn_err. */
#define TARGET_N_FORMAT_TYPES 1
@@ -98,31 +98,7 @@ along with GCC; see the file COPYING3.
#undef SPARC_DEFAULT_CMODEL
#define SPARC_DEFAULT_CMODEL CM_MEDLOW
-#define ENABLE_EXECUTE_STACK \
- static int need_enable_exec_stack; \
- static void check_enabling(void) __attribute__ ((constructor)); \
- static void check_enabling(void) \
- { \
- extern int sysctlbyname(const char *, void *, size_t *, void *, size_t);\
- int prot = 0; \
- size_t len = sizeof(prot); \
- \
- sysctlbyname ("kern.stackprot", &prot, &len, NULL, 0); \
- 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) \
- return; \
- else { \
- /* 7 is PROT_READ | PROT_WRITE | PROT_EXEC */ \
- if (mprotect (addr, TRAMPOLINE_SIZE, 7) < 0) \
- perror ("mprotect of trampoline code"); \
- } \
- }
-
+#define HAVE_ENABLE_EXECUTE_STACK
/************************[ Assembler stuff ]********************************/
@@ -74,8 +74,7 @@ along with GCC; see the file COPYING3.
#undef STDC_0_IN_SYSTEM_HEADERS
-/* Attempt to enable execute permissions on the stack. */
-#define ENABLE_EXECUTE_STACK NETBSD_ENABLE_EXECUTE_STACK
+#define HAVE_ENABLE_EXECUTE_STACK
/* Below here exists the merged NetBSD/sparc & NetBSD/sparc64 compiler
description, allowing one to build 32-bit or 64-bit applications
@@ -7998,7 +7998,7 @@ sparc32_initialize_trampoline (rtx m_tra
/* Call __enable_execute_stack after writing onto the stack to make sure
the stack address is accessible. */
-#ifdef ENABLE_EXECUTE_STACK
+#ifdef HAVE_ENABLE_EXECUTE_STACK
emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
#endif
@@ -8041,7 +8041,7 @@ sparc64_initialize_trampoline (rtx m_tra
/* Call __enable_execute_stack after writing onto the stack to make sure
the stack address is accessible. */
-#ifdef ENABLE_EXECUTE_STACK
+#ifdef HAVE_ENABLE_EXECUTE_STACK
emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
#endif
@@ -764,7 +764,7 @@ extern void fancy_abort (const char *, i
/* Target macros only used for code built for the target, that have
moved to libgcc-tm.h or have never been present elsewhere. */
#pragma GCC poison DECLARE_LIBRARY_RENAMES LIBGCC2_GNU_PREFIX \
- MD_UNWIND_SUPPORT
+ MD_UNWIND_SUPPORT ENABLE_EXECUTE_STACK
/* Other obsolete target macros, or macros that used to be in target
headers and were not used, and may be obsolete or may never have
new file mode 100644
@@ -0,0 +1,38 @@
+/* libgcc configuration file for Tru64 UNIX V5.1.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+/* Attempt to turn on access permissions for the stack. */
+
+#include <sys/mman.h>
+#include <unistd.h>
+
+#define STACK_PROT_RWX (PROT_READ | PROT_WRITE | PROT_EXEC)
+
+#define ENABLE_EXECUTE_STACK \
+void \
+__enable_execute_stack (void *addr) \
+{ \
+ long size = getpagesize (); \
+ long mask = ~(size-1); \
+ char *page = (char *) (((long) addr) & mask); \
+ char *end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
+ \
+ if (mprotect (page, end - page, STACK_PROT_RWX) < 0) \
+ perror ("mprotect of trampoline code"); \
+}
new file mode 100644
@@ -0,0 +1,56 @@
+/* libgcc configuration file for Darwin.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+/* Attempt to turn on execute permission for the stack. This may be
+ used by TARGET_TRAMPOLINE_INIT if 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
+ we always issue the mprotect() call.
+
+ Unfortunately it is not possible to make this namespace-clean.
+
+ 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 ENABLE_EXECUTE_STACK \
+extern void __enable_execute_stack (void *); \
+void \
+__enable_execute_stack (void *addr) \
+{ \
+ extern int mprotect (void *, size_t, int); \
+ extern int getpagesize (void); \
+ static int size; \
+ static long mask; \
+ \
+ char *page, *end; \
+ \
+ if (size == 0) \
+ { \
+ size = getpagesize(); \
+ mask = ~((long) size - 1); \
+ } \
+ \
+ page = (char *) (((long) addr) & mask); \
+ end = (char *) ((((long) (addr + (TARGET_64BIT ? 48 : 40))) & mask) + size); \
+ \
+ /* 7 == PROT_READ | PROT_WRITE | PROT_EXEC */ \
+ (void) mprotect (page, end - page, 7); \
+}
new file mode 100644
@@ -0,0 +1,43 @@
+/* libgcc configuration file for FreeBSD.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+#define ENABLE_EXECUTE_STACK \
+ static int need_enable_exec_stack; \
+ static void check_enabling(void) __attribute__ ((constructor)); \
+ static void check_enabling(void) \
+ { \
+ extern int sysctlbyname(const char *, void *, size_t *, void *, size_t);\
+ int prot = 0; \
+ size_t len = sizeof(prot); \
+ \
+ sysctlbyname ("kern.stackprot", &prot, &len, NULL, 0); \
+ 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) \
+ return; \
+ else { \
+ /* 7 is PROT_READ | PROT_WRITE | PROT_EXEC */ \
+ if (mprotect (addr, TRAMPOLINE_SIZE, 7) < 0) \
+ perror ("mprotect of trampoline code"); \
+ } \
+ }
new file mode 100644
@@ -0,0 +1,30 @@
+/* libgcc configuration file for Windows32.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+#define ENABLE_EXECUTE_STACK \
+extern void __enable_execute_stack (void *); \
+void \
+__enable_execute_stack (void *addr) \
+{ \
+ MEMORY_BASIC_INFORMATION b; \
+ if (!VirtualQuery (addr, &b, sizeof(b))) \
+ abort (); \
+ VirtualProtect (b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE, \
+ &b.Protect); \
+}
new file mode 100644
@@ -0,0 +1,64 @@
+/* libgcc configuration file for NetBSD.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+/* Attempt to turn on execute permission for the stack. This may be
+ used by TARGET_TRAMPOLINE_INIT if 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
+ we always issue the mprotect() call.
+
+ Note that we go out of our way to use namespace-non-invasive calls
+ here. Unfortunately, there is no libc-internal name for mprotect().
+
+ 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 ENABLE_EXECUTE_STACK \
+extern void __enable_execute_stack (void *); \
+void \
+__enable_execute_stack (void *addr) \
+{ \
+ extern int mprotect (void *, size_t, int); \
+ extern int __sysctl (int *, unsigned int, void *, size_t *, \
+ void *, size_t); \
+ \
+ static int size; \
+ static long mask; \
+ \
+ char *page, *end; \
+ \
+ if (size == 0) \
+ { \
+ int mib[2]; \
+ size_t len; \
+ \
+ mib[0] = 6; /* CTL_HW */ \
+ mib[1] = 7; /* HW_PAGESIZE */ \
+ len = sizeof (size); \
+ (void) __sysctl (mib, 2, &size, &len, NULL, 0); \
+ mask = ~((long) size - 1); \
+ } \
+ \
+ page = (char *) (((long) addr) & mask); \
+ end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
+ \
+ /* 7 == PROT_READ | PROT_WRITE | PROT_EXEC */ \
+ (void) mprotect (page, end - page, 7); \
+}
new file mode 100644
@@ -0,0 +1,36 @@
+/* libgcc configuration file for OpenBSD.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+/* Stack is explicitly denied execution rights on OpenBSD platforms. */
+#define ENABLE_EXECUTE_STACK \
+extern void __enable_execute_stack (void *); \
+void \
+__enable_execute_stack (void *addr) \
+{ \
+ long size = getpagesize (); \
+ long mask = ~(size-1); \
+ char *page = (char *) (((long) addr) & mask); \
+ char *end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
+ \
+ if (mprotect (page, end - page, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) \
+ perror ("mprotect of trampoline code"); \
+}
+
+#include <sys/types.h>
+#include <sys/mman.h>
new file mode 100644
@@ -0,0 +1,54 @@
+/* libgcc configuration file for Solaris 2.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+/* Attempt to turn on access permissions for the stack. */
+
+#include <sys/mman.h>
+#include <unistd.h>
+
+#define STACK_PROT_RWX (PROT_READ | PROT_WRITE | PROT_EXEC)
+
+#define ENABLE_EXECUTE_STACK \
+ \
+static int need_enable_exec_stack; \
+ \
+static void check_enabling(void) __attribute__ ((constructor)); \
+static void check_enabling(void) \
+{ \
+ int prot = (int) sysconf(_SC_STACK_PROT); \
+ if (prot != STACK_PROT_RWX) \
+ need_enable_exec_stack = 1; \
+} \
+ \
+extern void __enable_execute_stack (void *); \
+void \
+__enable_execute_stack (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); \
+ \
+ if (mprotect (page, end - page, STACK_PROT_RWX) < 0) \
+ perror ("mprotect of trampoline code"); \
+ } \
+}
----- Original Message ----- From: "Rainer Orth" <ro@CeBiTec.Uni-Bielefeld.DE> To: gcc-patches@gcc.gnu.org Cc: "Joseph S. Myers" <joseph@codesourcery.com>, "Paolo Bonzini" <bonzini@gnu.org>, "Ralf Wildenhues" <Ralf.Wildenhues@gmx.de>, "Mike Stump" <mikestump@comcast.net>, "Loren J. Rittle" <ljrittle@acm.org>, "Kai Tietz" <ktietz@redhat.com>, "Dave Korn" <dave.korn.cygwin@gmail.com>, "Jason Thorpe" <thorpej@netbsd.org>, "Krister Walfridsson" <krister.walfridsson@gmail.com>, "Uros Bizjak" <ubizjak@gmail.com>, "Richard Henderson" <rth@redhat.com>, "Eric Botcazou" <ebotcazou@adacore.com> Sent: Monday, May 30, 2011 5:59:10 PM Subject: [build] Move ENABLE_EXECUTE_STACK to toplevel libgcc This is my hopefully last patch for toplevel libgcc moves: it moves ENABLE_EXECUTE_STACK to $target-lib.h headers in libgcc/config. Since gcc/config/sol2.h is only used on Solaris targets anymore and Solaris 8 is the minimal supported version, I've removed both a Solaris 2.6 workaround and include <sys/mman.h> directly. Same thing in osf5-lib.h. Since the existance of the macro is used in alpha/alpha.c, i386/i386.c, and sparc/sparc.c to enable calls to __enable_execute_stack, I had to define HAVE_ENABLE_EXECUTE_STACK in the gcc/config headers to convey the necessary information. The new libgcc/config/$target-lib.h headers are added to libgcc_tm_file in gcc/config.gcc. I'd rather add them to libgcc/config.host instead so the information is kept local to libgcc. Bootstrapped without regressions on i386-pc-solaris2.11 and sparc-sun-solaris2.11. I've Cc'ed the OS port maintainers of the other affected targets and would appreciate testing/review. An OpenBSD maintainer isn't listed, unfortunately. Also included are the CPU port maintainers for the modified backends. Ok for mainline after a week if no problems occur in testing on the other targets? Thanks. Rainer 2011-05-29 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> gcc: * config/alpha/netbsd.h (ENABLE_EXECUTE_STACK): Remove. (HAVE_ENABLE_EXECUTE_STACK): Define. * config/alpha/osf5.h (ENABLE_EXECUTE_STACK): Remove. (HAVE_ENABLE_EXECUTE_STACK): Define. * config/darwin.h (ENABLE_EXECUTE_STACK): Remove. (HAVE_ENABLE_EXECUTE_STACK): Define. * config/i386/mingw32.h (MINGW_ENABLE_EXECUTE_STACK): Remove. (ENABLE_EXECUTE_STACK): Remove. (HAVE_ENABLE_EXECUTE_STACK): Define. * config/i386/netbsd-elf.h (ENABLE_EXECUTE_STACK): Remove. (HAVE_ENABLE_EXECUTE_STACK): Define. * config/i386/netbsd64.h (ENABLE_EXECUTE_STACK): Remove. (HAVE_ENABLE_EXECUTE_STACK): Define. * config/netbsd.h (NETBSD_ENABLE_EXECUTE_STACK): Remove. * config/openbsd.h (ENABLE_EXECUTE_STACK): Remove. (HAVE_ENABLE_EXECUTE_STACK): Define. * config/sol2.h (ENABLE_EXECUTE_STACK): Remove. (HAVE_ENABLE_EXECUTE_STACK): Define. * config/sparc/freebsd.h (ENABLE_EXECUTE_STACK): Remove. (HAVE_ENABLE_EXECUTE_STACK): Define. * config/sparc/netbsd-elf.h (ENABLE_EXECUTE_STACK): Remove. (HAVE_ENABLE_EXECUTE_STACK): Define. * config/alpha/alpha.c (alpha_trampoline_init): Test HAVE_ENABLE_EXECUTE_STACK. * config/i386/i386.c (ix86_trampoline_init): Likewise. * config/sparc/sparc.c (sparc32_initialize_trampoline): Likewise. (sparc64_initialize_trampoline): Likewise. * config.gcc (*-*-darwin*): Add darwin-lib.h to libgcc_tm_file. (*-*-openbsd*): Add openbsd-lib.h to libgcc_tm_file. (*-*-solaris2*): Add sol2-lib.h to libgcc_tm_file. (alpha*-*-netbsd*): Add netbsd-lib.h to libgcc_tm_file. (alpha*-dec-osf5.1): Add alpha/osf5-lib.h to libgcc_tm_file. (i[34567]86-*-mingw*): Add i386/mingw32-lib.h to libgcc_tm_file. (i[34567]86-*-netbsdelf*, x86_64-*-netbsd*): Add netbsd-lib.h to libgcc_tm_file. (sparc64-*-freebsd*): Add freebsd-lib.h to libgcc_tm_file. (sparc-*-netbsdelf*, sparc64-*-netbsd*): Add netbsd-lib.h to libgcc_tm_file. * system.h (ENABLE_EXECUTE_STACK): Poison. libgcc: * config/alpha/osf5-lib.h: New file. * config/darwin-lib.h: New file. * config/freebsd-lib.h: New file. * config/i386/mingw32-lib.h: New file. * config/netbsd-lib.h: New file. * config/openbsd-lib.h: New file. * config/sol2-lib.h: New file.