From 5a82970dc28bfce93fe83012b134bab516144de1 Mon Sep 17 00:00:00 2001 From: Yann Ylavic Date: Fri, 19 May 2023 10:32:01 +0000 Subject: [PATCH] Call apr__atomic_generic64_init() if needed Otherwise we get a segfault. Seen on Debian on powerpc with /* Define if compiler provides 32bit atomic builtins */ #define HAVE_ATOMIC_BUILTINS 1 /* Define if compiler provides 64bit atomic builtins */ /* #undef HAVE_ATOMIC_BUILTINS64 */ /* Define if compiler provides 32bit __atomic builtins */ #define HAVE__ATOMIC_BUILTINS 1 /* Define if compiler provides 64bit __atomic builtins */ /* #undef HAVE__ATOMIC_BUILTINS64 */ /* Define if use of generic atomics is requested */ /* #undef USE_ATOMICS_GENERIC */ configure: atomic builtins might be implemented for i586 and i686. atomics: Disentangle 32bit and 64bit atomics configuration. Regardless of --enable-nonportable-atomics setting, 64bit atomic builtins are disabled for 32bit CPUs/systems (using the generic/mutex implementation), until we figure out how to properly align apr_uint64_t (at least i[56]86 CPUs which could work with 64bit builtins actually don't if the data is not 64bit aligned, assuming the same for other 32bit CPUs is safer). One can --enable-nonportable-atomics=upto32bit to explicitely enable 32 bit builtins only (if available in the first place). Using --enable-nonportable-atomics=no still disables both 64bit and 32bit builtins, while =yes enables the ones known to exist AND work only (i.e. both, 32bit or none). Rename NEED_ATOMICS_GENERIC64 to USE_ATOMICS_GENERIC64 for consitency with 32bit atomics. atomics: Follow up to r1909321: remaining NEED_ATOMICS_GENERIC64. atomics: Follow up to r1909321: Windows does not use 64bit generic atomics. Merges r1909929 1.8.x. Merges r1907442, r1907988, r1909321, r1909323, r1909324 from trunk Submitted by: sf, ylavic, ylavic, ylavic, ylavic git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1909930 13f79535-47bb-0310-9956-ffa450edef68 --- atomic/netware/apr_atomic.c | 2 +- atomic/os390/atomic.c | 2 +- atomic/unix/builtins.c | 4 ++++ atomic/unix/ia32.c | 2 +- atomic/unix/mutex64.c | 2 +- atomic/unix/ppc.c | 2 +- atomic/unix/s390.c | 2 +- atomic/unix/solaris.c | 2 +- atomic/win32/apr_atomic.c | 4 ---- configure.in | 32 ++++++++++++++++++++++------- include/arch/unix/apr_arch_atomic.h | 20 ++++++++---------- 11 files changed, 45 insertions(+), 29 deletions(-) diff --git a/atomic/netware/apr_atomic.c b/atomic/netware/apr_atomic.c index 9c3df803997..daee00d3b96 100644 --- a/atomic/netware/apr_atomic.c +++ b/atomic/netware/apr_atomic.c @@ -20,7 +20,7 @@ APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *pool) { -#if defined (NEED_ATOMICS_GENERIC64) +#if defined(USE_ATOMICS_GENERIC64) return apr__atomic_generic64_init(p); #else return APR_SUCCESS; diff --git a/atomic/os390/atomic.c b/atomic/os390/atomic.c index e6a1693c452..f526e3473b3 100644 --- a/atomic/os390/atomic.c +++ b/atomic/os390/atomic.c @@ -20,7 +20,7 @@ apr_status_t apr_atomic_init(apr_pool_t *p) { -#if defined (NEED_ATOMICS_GENERIC64) +#if defined(USE_ATOMICS_GENERIC64) return apr__atomic_generic64_init(p); #else return APR_SUCCESS; diff --git a/atomic/unix/builtins.c b/atomic/unix/builtins.c index e7b117c7122..c8cd11c7647 100644 --- a/atomic/unix/builtins.c +++ b/atomic/unix/builtins.c @@ -27,7 +27,11 @@ APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p) { +#if defined (USE_ATOMICS_GENERIC64) + return apr__atomic_generic64_init(p); +#else return APR_SUCCESS; +#endif } APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem) diff --git a/atomic/unix/ia32.c b/atomic/unix/ia32.c index cdb7a528962..ce92c2208b9 100644 --- a/atomic/unix/ia32.c +++ b/atomic/unix/ia32.c @@ -20,7 +20,7 @@ APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p) { -#if defined (NEED_ATOMICS_GENERIC64) +#if defined(USE_ATOMICS_GENERIC64) return apr__atomic_generic64_init(p); #else return APR_SUCCESS; diff --git a/atomic/unix/mutex64.c b/atomic/unix/mutex64.c index a6a7ceb0b31..4ea4d8fc88f 100644 --- a/atomic/unix/mutex64.c +++ b/atomic/unix/mutex64.c @@ -17,7 +17,7 @@ #include "apr_arch_atomic.h" #include "apr_thread_mutex.h" -#if defined(USE_ATOMICS_GENERIC) || defined (NEED_ATOMICS_GENERIC64) +#if defined(USE_ATOMICS_GENERIC64) #include diff --git a/atomic/unix/ppc.c b/atomic/unix/ppc.c index 46554af5416..1ae727f0ef8 100644 --- a/atomic/unix/ppc.c +++ b/atomic/unix/ppc.c @@ -26,7 +26,7 @@ APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p) { -#if defined (NEED_ATOMICS_GENERIC64) +#if defined(USE_ATOMICS_GENERIC64) return apr__atomic_generic64_init(p); #else return APR_SUCCESS; diff --git a/atomic/unix/s390.c b/atomic/unix/s390.c index ae5d04082c3..c036128f36c 100644 --- a/atomic/unix/s390.c +++ b/atomic/unix/s390.c @@ -20,7 +20,7 @@ APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p) { -#if defined (NEED_ATOMICS_GENERIC64) +#if defined(USE_ATOMICS_GENERIC64) return apr__atomic_generic64_init(p); #else return APR_SUCCESS; diff --git a/atomic/unix/solaris.c b/atomic/unix/solaris.c index 9bc2de29a74..994354e668f 100644 --- a/atomic/unix/solaris.c +++ b/atomic/unix/solaris.c @@ -22,7 +22,7 @@ APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p) { -#if defined (NEED_ATOMICS_GENERIC64) +#if defined(USE_ATOMICS_GENERIC64) return apr__atomic_generic64_init(p); #else return APR_SUCCESS; diff --git a/atomic/win32/apr_atomic.c b/atomic/win32/apr_atomic.c index b29ea5956eb..5c2a8703282 100644 --- a/atomic/win32/apr_atomic.c +++ b/atomic/win32/apr_atomic.c @@ -18,11 +18,7 @@ APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p) { -#if defined (NEED_ATOMICS_GENERIC64) - return apr__atomic_generic64_init(p); -#else return APR_SUCCESS; -#endif } APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val) diff --git a/configure.in b/configure.in index 95dd0dfb5f8..7d3b1e61bd3 100644 --- a/configure.in +++ b/configure.in @@ -558,6 +558,9 @@ if test "$ap_cv_atomic_builtins" = "yes" -o "$ap_cv__atomic_builtins" = "yes"; t if test "$ap_cv__atomic_builtins" = "yes"; then AC_DEFINE(HAVE__ATOMIC_BUILTINS, 1, [Define if compiler provides 32bit __atomic builtins]) fi + has_atomic_builtins=yes +else + has_atomic_builtins=no fi AC_CACHE_CHECK([whether the compiler provides 64bit atomic builtins], [ap_cv_atomic_builtins64], @@ -802,18 +805,30 @@ void main(void) fi fi +force_generic_atomics=no +force_generic_atomics64=no +AC_CHECK_SIZEOF(void*, 4) +if test "x$ac_cv_sizeof_voidp" = "x"; then + force_generic_atomics64=yes +elif test $ac_cv_sizeof_voidp -lt 8; then + force_generic_atomics64=yes +fi AC_ARG_ENABLE(nonportable-atomics, [ --enable-nonportable-atomics Use optimized atomic code which may produce nonportable binaries], -[if test $enableval = yes; then - force_generic_atomics=no - else +[if test "$enableval" = "upto32bit"; then + force_generic_atomics64=yes + elif test "$enableval" != "yes"; then force_generic_atomics=yes fi ], [case $host_cpu in - i[[456]]86) force_generic_atomics=yes ;; - *) force_generic_atomics=no - case $host in + i[[34]]86) + force_generic_atomics=yes + ;; + i[[56]]86) + force_generic_atomics64=yes + ;; + *) case $host in *solaris2.10*) AC_TRY_COMPILE( [#include ], @@ -828,11 +843,14 @@ AC_ARG_ENABLE(nonportable-atomics, ;; esac ]) - if test $force_generic_atomics = yes; then AC_DEFINE([USE_ATOMICS_GENERIC], 1, [Define if use of generic atomics is requested]) fi +if test $force_generic_atomics = yes -o $force_generic_atomics64 = yes; then + AC_DEFINE([USE_ATOMICS_GENERIC64], 1, + [Define if use of 64bit generic atomics is requested]) +fi AC_SUBST(proc_mutex_is_global) AC_SUBST(eolstr) diff --git a/include/arch/unix/apr_arch_atomic.h b/include/arch/unix/apr_arch_atomic.h index ce771ad9c7c..a443b9dd11c 100644 --- a/include/arch/unix/apr_arch_atomic.h +++ b/include/arch/unix/apr_arch_atomic.h @@ -23,37 +23,35 @@ #include "apr_atomic.h" #if defined(USE_ATOMICS_GENERIC) -/* noop */ + /* noop */ #elif HAVE_ATOMIC_BUILTINS # define USE_ATOMICS_BUILTINS -# if HAVE_ATOMIC_BUILTINS64 -# define USE_ATOMICS_BUILTINS64 -# else -# define NEED_ATOMICS_GENERIC64 -# endif #elif defined(SOLARIS2) && SOLARIS2 >= 10 # define USE_ATOMICS_SOLARIS -# define NEED_ATOMICS_GENERIC64 #elif defined(__GNUC__) && defined(__STRICT_ANSI__) /* force use of generic atomics if building e.g. with -std=c89, which * doesn't allow inline asm */ # define USE_ATOMICS_GENERIC #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) # define USE_ATOMICS_IA32 -# define NEED_ATOMICS_GENERIC64 #elif defined(__GNUC__) && (defined(__powerpc__) \ || defined(__PPC__) \ || defined(__ppc__)) # define USE_ATOMICS_PPC -# define NEED_ATOMICS_GENERIC64 #elif defined(__GNUC__) && (defined(__s390__) || defined(__s390x__)) # define USE_ATOMICS_S390 -# define NEED_ATOMICS_GENERIC64 #else # define USE_ATOMICS_GENERIC #endif -#if defined(USE_ATOMICS_GENERIC) || defined (NEED_ATOMICS_GENERIC64) +#if defined(USE_ATOMICS_GENERIC64) + /* noop */ +#elif HAVE_ATOMIC_BUILTINS64 +# define USE_ATOMICS_BUILTINS64 +#else +# define USE_ATOMICS_GENERIC64 +#endif +#if defined(USE_ATOMICS_GENERIC64) apr_status_t apr__atomic_generic64_init(apr_pool_t *p); #endif