Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#62306 closed defect (fixed)

glib2-devel @2.62.5: build fails on Lion with error: #error G_ATOMIC_LOCK_FREE defined, but incapable of lock-free atomics.

Reported by: kencu (Ken) Owned by: ryandesign (Ryan Carsten Schmidt)
Priority: Normal Milestone:
Component: ports Version:
Keywords: lion Cc: kencu (Ken)
Port: glib2-devel

Description

building glib2-devel on Lions fails with the system clang:

<https://ports.macports.org/port/glib2-devel/summary>

(build.macports.org is down so I can't give you the exact link to broken build on the buildbot right now).

The error is generated by glib/gatomic.c because there is a missing define:

#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)

That define is defined by newer clangs, eg on Mojave:

$  /usr/bin/clang  -dM -E - < /dev/null | grep SWAP
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1

but not by the system clang on Lion:

$ /usr/bin/clang  -dM -E - < /dev/null | grep SWAP
-- nothing --

It was added to clang here <https://reviews.llvm.org/D621>.

The meson.build file for glib2 knows that older gcc versions sometims have atomic swap, but don't set that define, and they work around it like this, in meson.build for glib2(-devel):

atomicdefine = '''
#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
#error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
#endif
'''

# We know that we can always use real ("lock free") atomic operations with MSVC
if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl' or cc.links(atomictest, name : 'atomic ops')
  have_atomic_lock_free = true
  if cc.get_id() == 'gcc' and not cc.compiles(atomicdefine, name : 'atomic ops define')
    # Old gcc release may provide
    # __sync_bool_compare_and_swap but doesn't define
    # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
    glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
  endif

They didn't cover the case where clang also didn't set the define.

A simple patch to include clang as well as gcc in the fix:

-  if cc.get_id() == 'gcc' and not cc.compiles(atomicdefine, name : 'atomic ops define')
-    # Old gcc release may provide
+  if cc.get_id() == 'gcc' or cc.get_id() == 'clang' and not cc.compiles(atomicdefine, name : 'atomic ops define')
+    # Old gcc and clang releases may provide

and the old system clang on Lion can compile glib2-devel without any trouble:

$ port -v installed glib2-devel
The following ports are currently installed:
  glib2-devel @2.62.5_0+x11 (active) platform='darwin 11' archs='x86_64' date='2021-02-15T15:07:46-0800'

Change History (3)

comment:1 Changed 3 years ago by kencu (Ken)

Resolution: fixed
Status: assignedclosed

In 73c06f6ab7351d6f02e3128b99b118e9d6864c8f/macports-ports (master):

glib2-devel: fix build on Lion

closes: #62306

comment:2 Changed 3 years ago by ryandesign (Ryan Carsten Schmidt)

Link to upstream commit or bug report?

comment:3 Changed 3 years ago by kencu (Ken)

This in fact does remain in the current glib2 2.67.3, which I am just working on now.

I may upstream it, as it does look upstreamable.

Last edited 3 years ago by kencu (Ken) (previous) (diff)
Note: See TracTickets for help on using tickets.