build-sys: Fix atomic support detection

Attempting to use atomics operations on an architecture that does not
support them generally results in a link error:

ld: /tmp/ccjYcMPP.o: in function `func':
testfile.c:(.text+0x1c): undefined reference to `__sync_bool_compare_and_swap_4'

The current build system uses cc.compiles() to check if atomic ops are
supported, but cc.compiles() does not attempt to link, so the test fails
to enable libatomics_opts.

Fix this by using cc.links() instead of cc.compiles().

Signed-off-by: Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/732>
This commit is contained in:
Nicolas Cavallari 2022-07-01 14:03:44 +02:00 committed by PulseAudio Marge Bot
parent 81a051089f
commit fd81201f28

View file

@ -498,22 +498,24 @@ endif
need_libatomic_ops = false
atomictest = '''void func() {
atomictest = '''int main() {
volatile int atomic = 2;
__sync_bool_compare_and_swap (&atomic, 2, 3);
return 0;
}
'''
if cc.compiles(atomictest)
if cc.links(atomictest)
cdata.set('HAVE_ATOMIC_BUILTINS', 1)
newatomictest = '''void func() {
newatomictest = '''int main() {
int c = 0;
__atomic_store_n(&c, 4, __ATOMIC_SEQ_CST);
return 0;
}
'''
if(cc.compiles(newatomictest))
if(cc.links(newatomictest))
cdata.set('HAVE_ATOMIC_BUILTINS_MEMORY_MODEL', 1)
endif