[Pdns-dev] GCC 3.4.3, __sync_fetch_and_add on SunOS 5.10 sparc
a b
tripivceta at hotmail.com
Wed Oct 2 19:16:06 CEST 2013
GCC 3.4.3 is the default compiler which ships with Solaris 10 (SunOS 5.10).This compiler compiles pdns-3.1 with a couple of patches here and there more or less fine on the i86pc platform (32- and 64-bit x86).
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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.powerdns.com/pipermail/pdns-dev/attachments/20131002/95c92a33/attachment.html>
More information about the Pdns-dev
mailing list