stacks: fix default C stack size

The ifdef in config-internal.h was buggy since RLIMIT_STACK is only defined after
sys/resource.h has been included which it wasn't. This lead to the stack size always being
increased to at least the default of 1 MB. To fix this, we move the check for RLIMIT_STACK
to the configure script.
This commit is contained in:
Marius Gerbershagen 2020-06-11 15:04:22 +02:00
parent 3b39f2332f
commit 90043d205c
6 changed files with 45 additions and 7 deletions

15
src/aclocal.m4 vendored
View file

@ -665,6 +665,21 @@ case "${ECL_STACK_DIR}" in
up|UP) AC_MSG_RESULT(no) ;;
*) AC_MSG_ERROR(Unable to determine stack growth direction)
esac])
dnl
dnl --------------------------------------------------------------
dnl Check if we can determine the stack size at runtime
dnl
AC_DEFUN(ECL_STACK_SIZE,[
AC_CHECK_HEADER([sys/resource.h],
[AC_DEFINE([HAVE_SYS_RESOURCE_H], [], [Define to 1 if you have the <sys/resource.h> header file.])
AC_CHECK_DECL([RLIMIT_STACK],
[AC_DEFINE([ECL_CAN_SET_STACK_SIZE], [], [Define to 1 if we can set the stack size at runtime.])],
[],
[#include <sys/resource.h>])],
[],[])
])
dnl
dnl ------------------------------------------------------------
dnl Find out a setjmp() that does not save signals. It is called

View file

@ -29,7 +29,7 @@ cs_set_size(cl_env_ptr env, cl_index new_size)
{
volatile char foo = 0;
cl_index margin = ecl_option_values[ECL_OPT_C_STACK_SAFETY_AREA];
#if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_STACK) && !defined(NACL)
#if defined(ECL_CAN_SET_STACK_SIZE)
{
struct rlimit rl;

22
src/configure vendored
View file

@ -7125,7 +7125,7 @@ fi
done
for ac_header in sys/resource.h sys/utsname.h float.h pwd.h dlfcn.h link.h \
for ac_header in sys/utsname.h float.h pwd.h dlfcn.h link.h \
mach-o/dyld.h dirent.h sys/ioctl.h sys/select.h \
sys/wait.h semaphore.h
do :
@ -8345,6 +8345,24 @@ $as_echo "no" >&6; } ;;
*) as_fn_error $? "Unable to determine stack growth direction" "$LINENO" 5
esac
ac_fn_c_check_header_mongrel "$LINENO" "sys/resource.h" "ac_cv_header_sys_resource_h" "$ac_includes_default"
if test "x$ac_cv_header_sys_resource_h" = xyes; then :
$as_echo "#define HAVE_SYS_RESOURCE_H /**/" >>confdefs.h
ac_fn_c_check_decl "$LINENO" "RLIMIT_STACK" "ac_cv_have_decl_RLIMIT_STACK" "#include <sys/resource.h>
"
if test "x$ac_cv_have_decl_RLIMIT_STACK" = xyes; then :
$as_echo "#define ECL_CAN_SET_STACK_SIZE /**/" >>confdefs.h
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether closedir returns void" >&5
$as_echo_n "checking whether closedir returns void... " >&6; }
@ -8997,8 +9015,6 @@ main ()
if (*(data + i) != *(data3 + i))
return 14;
close (fd);
free (data);
free (data3);
return 0;
}
_ACEOF

View file

@ -658,7 +658,7 @@ AC_CHECK_HEADERS( [fcntl.h limits.h netdb.h netinet/in.h] \
[sched.h] )
dnl !!! end autoscan
AC_CHECK_HEADERS( [sys/resource.h sys/utsname.h float.h pwd.h dlfcn.h link.h] \
AC_CHECK_HEADERS( [sys/utsname.h float.h pwd.h dlfcn.h link.h] \
[mach-o/dyld.h dirent.h sys/ioctl.h sys/select.h] \
[sys/wait.h semaphore.h] )
@ -711,8 +711,9 @@ ECL_SSE
ECL_COMPLEX_C99
dnl -----------------------------------------------------------------------
dnl Study the call conventions
dnl Stack size and growth direction
ECL_STACK_DIRECTION
ECL_STACK_SIZE
dnl =====================================================================
dnl Checks for library functions

View file

@ -9,6 +9,9 @@
/* ECL_AVOID_FPE_H */
#undef ECL_AVOID_FPE_H
/* Define to 1 if we can set the stack size at runtime. */
#undef ECL_CAN_SET_STACK_SIZE
/* Allow STREAM operations to work on arbitrary objects */
#undef ECL_CLOS_STREAMS

View file

@ -240,7 +240,10 @@
#include "@ECL_LIBFFI_HEADER@"
#endif
#if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_STACK) && !defined(NACL)
/* Can we determine and set the stack size at runtime? */
#undef ECL_CAN_SET_STACK_SIZE
#if defined(ECL_CAN_SET_STACK_SIZE)
#define ECL_DEFAULT_C_STACK_SIZE 0 /* Use the stack size provided by the OS */
#else
#define ECL_DEFAULT_C_STACK_SIZE @ECL_DEFAULT_C_STACK_SIZE@