ruby-changes:66061
From: Peter <ko1@a...>
Date: Thu, 6 May 2021 04:31:48 +0900 (JST)
Subject: [ruby-changes:66061] 23a98237df (master): Fix PAGE_SIZE macro detection in autoconf
https://git.ruby-lang.org/ruby.git/commit/?id=23a98237df From 23a98237df28ad01d17b163eb650dfbd321b13ba Mon Sep 17 00:00:00 2001 From: Peter Zhu <peter@p...> Date: Wed, 5 May 2021 16:20:40 +0000 Subject: Fix PAGE_SIZE macro detection in autoconf The current fix for PAGE_SIZE macro detection in autoconf does not work correctly. I see the following output with running configure on Linux: ``` checking PAGE_SIZE is defined... no ``` Linux has PAGE_SIZE macro. This is happening because the macro exists in sys/user.h and not in the malloc headers. --- configure.ac | 19 +++++++++++-------- gc.c | 37 ++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/configure.ac b/configure.ac index 1eb4be4..e49c128 100644 --- a/configure.ac +++ b/configure.ac @@ -2727,23 +2727,26 @@ main(int argc, char *argv[]) https://github.com/ruby/ruby/blob/trunk/configure.ac#L2727 test x$rb_cv_fork_with_pthread = xyes || AC_DEFINE(CANNOT_FORK_WITH_PTHREAD) ]) -AS_IF([test "x$ac_cv_func_mmap" = xyes], [ - malloc_headers=`sed -n '/MALLOC_HEADERS_BEGIN/,/MALLOC_HEADERS_END/p' ${srcdir}/gc.c` +AC_CHECK_HEADERS([sys/user.h]) +AS_IF([test "x$ac_cv_func_mmap:$ac_cv_header_sys_user_h" = xyes:yes], [ AC_CACHE_CHECK([PAGE_SIZE is defined], rb_cv_page_size, - [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[${malloc_headers} + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + @%:@include <sys/user.h> typedef char conftest_page[PAGE_SIZE]; ]], [[]])], [rb_cv_page_size=const], - [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[${malloc_headers}]], [[ + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + @%:@include <sys/user.h> + ]], [[ int page_size = (int)PAGE_SIZE; (void)page_size; ]])], [rb_cv_page_size=variable], [rb_cv_page_size=no])])]) - AS_CASE([$rb_cv_page_size], - [const], [AC_DEFINE(USE_MMAP_ALIGNED_ALLOC, [(PAGE_SIZE <= HEAP_PAGE_SIZE)])], - [no], [AC_DEFINE(USE_MMAP_ALIGNED_ALLOC, 1)], + AS_IF([test "x$rb_cv_page_size" = xconst], + [AC_DEFINE(HAVE_CONST_PAGE_SIZE, 1)], + [AC_DEFINE(HAVE_CONST_PAGE_SIZE, 0)] ) -], [AC_DEFINE(USE_MMAP_ALIGNED_ALLOC, 0)]) +], [AC_DEFINE(HAVE_CONST_PAGE_SIZE, 0)]) } : "runtime section" && { diff --git a/gc.c b/gc.c index c899228..721e244 100644 --- a/gc.c +++ b/gc.c @@ -32,7 +32,6 @@ https://github.com/ruby/ruby/blob/trunk/gc.c#L32 #include <stdarg.h> #include <stdio.h> -/* MALLOC_HEADERS_BEGIN */ #ifndef HAVE_MALLOC_USABLE_SIZE # ifdef _WIN32 # define HAVE_MALLOC_USABLE_SIZE @@ -54,7 +53,6 @@ https://github.com/ruby/ruby/blob/trunk/gc.c#L53 # include <malloc/malloc.h> # endif #endif -/* MALLOC_HEADERS_END */ #ifdef HAVE_SYS_TIME_H # include <sys/time.h> @@ -73,6 +71,10 @@ https://github.com/ruby/ruby/blob/trunk/gc.c#L71 #include <sys/types.h> +#ifdef HAVE_SYS_USER_H +# include <sys/user.h> +#endif + #ifdef __EMSCRIPTEN__ #include <emscripten.h> #endif @@ -832,23 +834,17 @@ enum { https://github.com/ruby/ruby/blob/trunk/gc.c#L834 }; #define HEAP_PAGE_ALIGN (1 << HEAP_PAGE_ALIGN_LOG) #define HEAP_PAGE_SIZE HEAP_PAGE_ALIGN -#ifdef USE_MMAP_ALIGNED_ALLOC -# define Init_use_mmap_aligned_alloc() (void)0 -#elif !defined(HAVE_MMAP) -# define USE_MMAP_ALIGNED_ALLOC 0 -# define Init_use_mmap_aligned_alloc() (void)0 -#elif defined(PAGE_MAX_SIZE) && (PAGE_MAX_SIZE <= HEAP_PAGE_SIZE) -/* PAGE_SIZE <= HEAP_PAGE_SIZE */ -# define USE_MMAP_ALIGNED_ALLOC 1 -# define Init_use_mmap_aligned_alloc() (void)0 -#else -# define USE_MMAP_ALIGNED_ALLOC (use_mmap_aligned_alloc != false) + +#if defined(HAVE_MMAP) && defined(PAGE_SIZE) +# if HAVE_CONST_PAGE_SIZE +# define USE_MMAP_ALIGNED_ALLOC (PAGE_SIZE <= HEAP_PAGE_SIZE) +# else +# define USE_MMAP_ALIGNED_ALLOC (use_mmap_aligned_alloc != false) + static bool use_mmap_aligned_alloc; -static inline void -Init_use_mmap_aligned_alloc(void) -{ - use_mmap_aligned_alloc = (PAGE_SIZE <= HEAP_PAGE_SIZE); -} +# endif +#else +# define USE_MMAP_ALIGNED_ALLOC 0 #endif struct heap_page { @@ -3212,7 +3208,10 @@ Init_heap(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L3208 { rb_objspace_t *objspace = &rb_objspace; - Init_use_mmap_aligned_alloc(); +#if defined(HAVE_MMAP) && defined(PAGE_SIZE) && !HAVE_CONST_PAGE_SIZE + use_mmap_aligned_alloc = PAGE_SIZE <= HEAP_PAGE_SIZE; +#endif + #if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE) /* If Ruby's heap pages are not a multiple of the system page size, we * cannot use mprotect for the read barrier, so we must disable automatic -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/