Fix atomic builtins detection
Jeremy Allison
jra at samba.org
Tue Apr 26 17:25:09 UTC 2016
On Tue, Apr 26, 2016 at 12:46:59PM +0200, Jérémie Courrèges-Anglas wrote:
> 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?
Yep - create a bug at bugzilla.samba.org and ask for
a back-port - will be a simple process.
More information about the samba-technical
mailing list