Hi Dmitry,

On Thu, 2025-04-03 at 19:09 +0300, Dmitry V. Levin wrote:
> 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>
[...]
> > 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])?

I am afraid I don't remember.

Note that 5 years later we just require C11 + stdatomic:
https://sourceware.org/cgit/elfutils/commit/?id=d5fe635875628a9de431c883c0e5037dec0f85f3
The check for stdatomic.h is still the same though. But it doesn't set
HAVE_STDATOMIC_H anymore and the fallback lib/atomics.h has been
removed.

I think that means your issue/worry cannot happen anymore.
But maybe we should just use AC_CHECK_HEADERS([stdatomic.h]) and drop
the AC_COMPILE_IFELSE trick?

Cheers,

Mark

Reply via email to