@@ -263,4 +263,7 @@
in i386 6 argument syscall issue). */
#define CAN_USE_REGISTER_ASM_EBP 0
+/* Build glibc with gcc -fstack-check. */
+#define BUILD_FSTACK_CHECK 0
+
#endif
@@ -1626,6 +1626,22 @@ for opt in -ffp-contract=off -mno-fused-madd; do
done])
AC_SUBST(libc_cv_cc_nofma)
+
+dnl Determine if -fstack-check is being used
+AC_CACHE_CHECK(for -fstack-check, libc_cv_fstack_check, [dnl
+cat > conftest.c << \EOF
+void foo (void) {};
+EOF
+dnl
+libc_cv_fstack_check=no
+if ${CC-cc} $CFLAGS -Q -v conftest.c -c 2>&1 | sed -e '/cc1/!d;s/(")|(^.* - )//g' | grep '\-fstack\-check' >/dev/null; then
+ libc_cv_fstack_check=yes
+fi
+rm -f conftest*])
+if test x"$libc_cv_fstack_check" = xyes; then
+ AC_DEFINE(BUILD_FSTACK_CHECK)
+fi
+
if test -n "$submachine"; then
AC_CACHE_CHECK([for compiler option for CPU variant],
libc_cv_cc_submachine, [dnl
@@ -317,8 +317,20 @@ __spawnix (pid_t * pid, const char *file,
| ((GL (dl_stack_flags) & PF_X) ? PROT_EXEC : 0));
/* Add a slack area for child's stack. */
+#if BUILD_FSTACK_CHECK
+/* The gcc -fstack-check internal docs state the default interval checking is
+ one page, which means we need two pages (the current one, and the next
+ probed). No target currently defines it larger. Further, it mentions that
+ the default minimum stack size needed to recover from an overflow is 4/8KiB
+ for sjlj or 8/12KiB for others. But some Linux targets (like mips and
+ ppc) go up to 16KiB (and some non-Linux targets go up to 24KiB). So
+ we allocate at least 4 pages for such cases*/
+# define MIN_PAGES 4
+#else
+# define MIn_PAGES 1
+#endif
size_t argv_size = (argc * sizeof (void *)) + 512;
- size_t stack_size = ALIGN_UP (argv_size, GLRO(dl_pagesize));
+ size_t stack_size = ALIGN_UP (argv_size, MIN_PAGES * GLRO(dl_pagesize));
void *stack = __mmap (NULL, stack_size, prot,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
if (__glibc_unlikely (stack == MAP_FAILED))