[MacPorts] #62306: glib2-devel @2.62.5: build fails on Lion with error: #error G_ATOMIC_LOCK_FREE defined, but incapable of lock-free atomics.
MacPorts
noreply at macports.org
Mon Feb 15 23:17:57 UTC 2021
#62306: glib2-devel @2.62.5: build fails on Lion with error: #error
G_ATOMIC_LOCK_FREE defined, but incapable of lock-free atomics.
--------------------+-------------------------
Reporter: kencu | Owner: ryandesign
Type: defect | Status: assigned
Priority: Normal | Milestone:
Component: ports | Version:
Keywords: lion | Port: glib2-devel
--------------------+-------------------------
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'
}}}
--
Ticket URL: <https://trac.macports.org/ticket/62306>
MacPorts <https://www.macports.org/>
Ports system for macOS
More information about the macports-tickets
mailing list