Fix CHECK_CODE usage in atomics builtin detection
authorJérémie Courrèges-Anglas <jca@wxcvbn.org>
Mon, 25 Apr 2016 14:10:03 +0000 (16:10 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 25 Apr 2016 23:19:40 +0000 (01:19 +0200)
CHECK_CODE already wraps the code with main().  Adding another layer
results in a nested function, eg

  int main(void) { int main(void) { __sync_fetch_and_add(); } }

Since the inner function isn't called it is optimized out at cc -O2,
thus the linker doesn't fail if __sync_fetch_and_add() isn't available.

Issue noticed on OpenBSD/hppa.

Signed-off-by: Jérémie Courrèges-Anglas <jca@wxcvbn.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Apr 26 01:19:40 CEST 2016 on sn-devel-144

lib/replace/wscript

index 37cbbb7dc2380fca57d66dfab02ad7882299e69f..5efd86cd232664cc9e9c1756e386484464c13c93 100644 (file)
@@ -202,23 +202,15 @@ def configure(conf):
 
     # Check for atomic builtins. */
     conf.CHECK_CODE('''
-                    int main(void) {
-                        int i;
-                        (void)__sync_fetch_and_add(&i, 1);
-                        return 0;
-                    }
+                    int i;
+                    (void)__sync_fetch_and_add(&i, 1);
                     ''',
                     'HAVE___SYNC_FETCH_AND_ADD',
                     msg='Checking for __sync_fetch_and_add compiler builtin')
 
     conf.CHECK_CODE('''
-                    #include <stdint.h>
-                    #include <sys/atomic.h>
-                    int main(void) {
-                        int32_t i;
-                        atomic_add_32(&i, 1);
-                        return 0;
-                    }
+                    int32_t i;
+                    atomic_add_32(&i, 1);
                     ''',
                     'HAVE_ATOMIC_ADD_32',
                     headers='stdint.h sys/atomic.h',