Fix atomic builtins detection

Jeremie Courreges-Anglas jca at wxcvbn.org
Mon Apr 25 14:24:28 UTC 2016


Hi,

lib/replace/wscript has this bunch of code:

    # Check for atomic builtins. */
    conf.CHECK_CODE('''
                    int main(void) {
                        int i;
                        (void)__sync_fetch_and_add(&i, 1);
                        return 0;
                    }
                    ''',
                    'HAVE___SYNC_FETCH_AND_ADD',
                    msg='Checking for __sync_fetch_and_add compiler builtin')


It is incorrect, since CHECK_CODE already wraps the code fragment in
main().  Here's what gets compiled:


[includes]
 int main(void) { 
                    int main(void) {
                        int i;
                        (void)__sync_fetch_and_add(&i, 1);
                        return 0;
                    }
                    ; return 0; }


Now the funny part is when you run this where __sync_fetch_and_add is
actually not available.  The inner main() function isn't called
anywhere, and at cc -O2 it is simply optimized out, thus the compile
test wrongly succeeds.  This can be seen for example on OpenBSD/hppa
(gcc-4.2.1).

Please find attached a patch to fix this issue for __sync_fetch_and_add
and atomic_add_32.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-CHECK_CODE-usage-in-atomics-builtin-detection.patch
Type: text/x-patch
Size: 2017 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160425/68aef93b/0001-Fix-CHECK_CODE-usage-in-atomics-builtin-detection.bin>
-------------- next part --------------

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE


More information about the samba-technical mailing list