[Pdns-dev] GCC 3.4.3, __sync_fetch_and_add on SunOS 5.10 sparc

Peter van Dijk peter.van.dijk at netherlabs.nl
Mon Nov 18 13:39:58 CET 2013


Hello,

On Oct 2, 2013, at 19:16 , a b wrote:

> However, on sparc, the compilation fails because GCC 3.4.3 does not include the __sync_fetch_and_add() function (macro?).
> 
> On i86pc, the compilation passes because of this bit of code:
> 
>     // the below is necessary because __sync_fetch_and_add is not universally available on i386.. I 3> RHEL5.
>     #if defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
>     static int atomic_exchange_and_add( unsigned int * pw, int dv )
>     {
>         // int r = *pw;
>         // *pw += dv;
>         // return r;
> 
>         int r;
> 
>         __asm__ __volatile__
>         (
>             "lock\n\t"
>             "xadd %1, %0":
>             "+m"( *pw ), "=r"( r ): // outputs (%0, %1)
>             "1"( dv ): // inputs (%2 == %1)
>             "memory", "cc" // clobbers
>         );
> 
>         return r;
>     }
> 
> Obviously, the x86 assembler bit cannot work on sparc, and since the __sync_fetch_and_add() is unavailable, it fails.
> 
> My "fix" for that was this:
> 
>     #else
>     static int atomic_exchange_and_add( unsigned int * pw, int dv )
>     {
>       #if(((__GNUC__ == 3) && (__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ == 3)) && defined(__sparc__))
>       int r = *pw;
>       *pw += dv;
>       return(r);
>       #else
>       return __sync_fetch_and_add(pw, dv);
>       #endif
>     }
>     #endif
> 
> But I do not trust myself to have fully understood the code and the intent. Can someone who has worked on this code confirm or deny that this is a sane fix?

Apologies for my late response; I was triggered by your report of a recursor crash (which I presume is unrelated as it happened on x86).

This fix is not right - it lacks the synchronous aspect of the original. I'm not sure how to fix this portably - if we knew, we would have done so..

We do strongly advise using a more recent gcc if at all possible.

Kind regards,
-- 
Peter van Dijk
Netherlabs Computer Consulting BV - http://www.netherlabs.nl/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mailman.powerdns.com/pipermail/pdns-dev/attachments/20131118/8f9fd64a/attachment.pgp>


More information about the Pdns-dev mailing list