Fix atomic builtins detection

Jérémie Courrèges-Anglas jca at wxcvbn.org
Tue Apr 26 10:46:59 UTC 2016


Ralph Boehme <slow at samba.org> writes:

> On Mon, Apr 25, 2016 at 11:15:42AM -0700, Jeremy Allison wrote:
>> On Mon, Apr 25, 2016 at 04:24:28PM +0200, Jeremie Courreges-Anglas wrote:
>> > 
>> > 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.
>> 
>> Looks good to me. Can I get a second Team reviewer ?
>
> lgtm. Can you push? Thanks!

Thanks you both.  Any chance to see this land in v4-3?

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



More information about the samba-technical mailing list