[Mesa-dev] [PATCH] disk cache: Link with -latomic if necessary

Thierry Reding thierry.reding at gmail.com
Tue Feb 27 10:32:39 UTC 2018


On Mon, Feb 26, 2018 at 11:28:23PM +0000, Mike Lothian wrote:
> On Fri, 23 Feb 2018 at 13:18 Thierry Reding <thierry.reding at gmail.com>
> wrote:
> 
> > From: Thierry Reding <treding at nvidia.com>
> >
> > The disk cache implementation uses 64-bit atomic operations. For some
> > architectures, such as 32-bit ARM, GCC will not be able to translate
> > these operations into lock-free instructions and will instead rely on
> > the external atomics library to provide these operations.
> >
> > Check at configuration time whether or not linking against libatomic
> > is necessary and if so, create a dependency that can be used while
> > linking the mesautil library.
> >
> > This is the meson equivalent of 2ef7f23820a6 ("configure: check if
> > -latomic is needed for __atomic_*").
> >
> > Signed-off-by: Thierry Reding <treding at nvidia.com>
> > ---
> >  meson.build          | 15 +++++++++++++++
> >  src/util/meson.build |  2 +-
> >  2 files changed, 16 insertions(+), 1 deletion(-)
> >
> > diff --git a/meson.build b/meson.build
> > index 121341a950c4..7c6f40573421 100644
> > --- a/meson.build
> > +++ b/meson.build
> > @@ -800,6 +800,21 @@ endif
> >  if cc.compiles('int main() { int n; return __atomic_load_n(&n,
> > __ATOMIC_ACQUIRE); }',
> >                 name : 'GCC atomic builtins')
> >    pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
> > +
> > +  # Not all atomic calls can be turned into lock-free instructions, in
> > which
> > +  # GCC will make calls into the libatomic library. Check whether we need
> > to
> > +  # link with -latomic.
> > +  #
> > +  # This can happen for 64-bit atomic operations on 32-bit architectures
> > such
> > +  # as ARM.
> > +  if not cc.links('''#include <stdint.h>
> > +                     int main() {
> > +                       uint64_t n;
> > +                       return (int)__atomic_load_n(&n, __ATOMIC_ACQUIRE);
> > +                     }''',
> > +                  name : 'GCC atomic builtins required -latomic')
> > +    dep_atomic = cc.find_library('atomic')
> > +  endif
> >  endif
> >  if not cc.links('''#include <stdint.h>
> >                     uint64_t v;
> > diff --git a/src/util/meson.build b/src/util/meson.build
> > index b23dba3a9851..eece1cefef6a 100644
> > --- a/src/util/meson.build
> > +++ b/src/util/meson.build
> > @@ -102,7 +102,7 @@ libmesa_util = static_library(
> >    'mesa_util',
> >    [files_mesa_util, format_srgb],
> >    include_directories : inc_common,
> > -  dependencies : [dep_zlib, dep_clock, dep_thread],
> > +  dependencies : [dep_zlib, dep_clock, dep_thread, dep_atomic],
> >    c_args : [c_msvc_compat_args, c_vis_args],
> >    build_by_default : false
> >  )
> > --
> > 2.16.2
> >
> >
> Hi
> 
> I had this issue when building a 32bit Mesa on x86-64 when using Clang,
> 64bit was fine.
> 
> Will this work for Clang too and if so can a similar change be made for
> autotools?

I think this should work for clang as well. I'm not overly familiar with
it, but Google suggests that clang supports these atomic operations and
will fallback to generating calls into libatomic for those that can't be
turned into lock-free operations.

My understanding is that this should already work for autotools. See my
note about the equivalent commit already in Mesa's master.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180227/bcd3c243/attachment.sig>


More information about the mesa-dev mailing list