Skip to content

Commit

Permalink
Call apr__atomic_generic64_init() if needed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ylavic committed May 19, 2023
1 parent 325fed9 commit 5a82970
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 29 deletions.
2 changes: 1 addition & 1 deletion atomic/netware/apr_atomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion atomic/os390/atomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions atomic/unix/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion atomic/unix/ia32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion atomic/unix/mutex64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdlib.h>

Expand Down
2 changes: 1 addition & 1 deletion atomic/unix/ppc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion atomic/unix/s390.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion atomic/unix/solaris.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions atomic/win32/apr_atomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 25 additions & 7 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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 <atomic.h>],
Expand All @@ -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)
Expand Down
20 changes: 9 additions & 11 deletions include/arch/unix/apr_arch_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5a82970

Please sign in to comment.