On Thu, Aug 29, 2019 at 03:16:12PM +0200, Mark Wielaard wrote:
> From: Jonathon Anderson <jm...@rice.edu>
> 
> Uses the stdatomic.h provided by FreeBSD when GCC doesn't (ie. GCC < 4.9)
> 
> Signed-off-by: Jonathon Anderson <jm...@rice.edu>
> Signed-off-by: Srđan Milaković <sm...@rice.edu>
> ---
>  configure.ac         |  12 ++
>  lib/ChangeLog        |   6 +
>  lib/Makefile.am      |   3 +-
>  lib/atomics.h        |  37 ++++
>  lib/stdatomic-fbsd.h | 442 +++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 499 insertions(+), 1 deletion(-)
>  create mode 100644 lib/atomics.h
>  create mode 100644 lib/stdatomic-fbsd.h
> 
> diff --git a/configure.ac b/configure.ac
> index c443fa3b..b8aba460 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -226,6 +226,18 @@ LDFLAGS="$save_LDFLAGS"])
>  AS_IF([test "x$ac_cv_tls" != xyes],
>        AC_MSG_ERROR([__thread support required]))
>  
> +dnl Before 4.9 gcc doesn't ship stdatomic.h, but the nessesary atomics are
> +dnl available by (at least) 4.7. So if the system doesn't have a stdatomic.h 
> we
> +dnl fall back on one copied from FreeBSD that handles the difference.
> +AC_CACHE_CHECK([whether gcc provides stdatomic.h], ac_cv_has_stdatomic,
> +  [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <stdatomic.h>]])],
> +                  ac_cv_has_stdatomic=yes, ac_cv_has_stdatomic=no)])
> +AM_CONDITIONAL(HAVE_STDATOMIC_H, test "x$ac_cv_has_stdatomic" = xyes)
> +AS_IF([test "x$ac_cv_has_stdatomic" = xyes], [AC_DEFINE(HAVE_STDATOMIC_H)])
> +
> +AH_TEMPLATE([HAVE_STDATOMIC_H], [Define to 1 if `stdatomic.h` is provided by 
> the
> +                                 system, 0 otherwise.])
> +
>  dnl This test must come as early as possible after the compiler configuration
>  dnl tests, because the choice of the file model can (in principle) affect
>  dnl whether functions and headers are available, whether they work, etc.

Sorry, do you remember why stdatomic.h availability check had to be so
complicated instead of straightforward AC_CHECK_HEADERS([stdatomic.h])?

The reason why I'm interested is that I accidentally noticed that the
check doesn't work as expected because ...

> [...]
> diff --git a/lib/atomics.h b/lib/atomics.h
> new file mode 100644
> index 00000000..ffd12f87
> --- /dev/null
> +++ b/lib/atomics.h
> @@ -0,0 +1,37 @@
> +/* Conditional wrapper header for C11-style atomics.
> +   Copyright (C) 2019-2019 Red Hat, Inc.
> +   This file is part of elfutils.
> +
> +   This file is free software; you can redistribute it and/or modify
> +   it under the terms of either
> +
> +     * the GNU Lesser General Public License as published by the Free
> +       Software Foundation; either version 3 of the License, or (at
> +       your option) any later version
> +
> +   or
> +
> +     * the GNU General Public License as published by the Free
> +       Software Foundation; either version 2 of the License, or (at
> +       your option) any later version
> +
> +   or both in parallel, as here.
> +
> +   elfutils is distributed in the hope that it will be useful, but
> +   WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   General Public License for more details.
> +
> +   You should have received copies of the GNU General Public License and
> +   the GNU Lesser General Public License along with this program.  If
> +   not, see <http://www.gnu.org/licenses/>.  */
> +
> +#include "config.h"
> +
> +#if HAVE_STDATOMIC_H

... here it's assumed that HAVE_STDATOMIC_H is always defined
(to either 1 or 0) which is not the case:

  AS_IF([test "x$ac_cv_has_stdatomic" = xyes], [AC_DEFINE(HAVE_STDATOMIC_H)])

means that HAVE_STDATOMIC_H is defined only if $ac_cv_has_stdatomic == "yes".


-- 
ldv

Reply via email to