<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>GCC 3.4.3 is the default compiler which ships with Solaris 10 (SunOS 5.10).<div>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).</div><div><br></div><div>However, on sparc, the compilation fails because GCC 3.4.3 does not include the __sync_fetch_and_add() function (macro?).</div><div><br></div><div>On i86pc, the compilation passes because of this bit of code:</div><div><br></div><div><div>    // the below is necessary because __sync_fetch_and_add is not universally available on i386.. I 3> RHEL5.</div><div>    #if defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )</div><div>    static int atomic_exchange_and_add( unsigned int * pw, int dv )</div><div>    {</div><div>        // int r = *pw;</div><div>        // *pw += dv;</div><div>        // return r;</div><div><br></div><div>        int r;</div><div><br></div><div>        __asm__ __volatile__</div><div>        (</div><div>            "lock\n\t"</div><div>            "xadd %1, %0":</div><div>            "+m"( *pw ), "=r"( r ): // outputs (%0, %1)</div><div>            "1"( dv ): // inputs (%2 == %1)</div><div>            "memory", "cc" // clobbers</div><div>        );</div><div><br></div><div>        return r;</div><div>    }</div></div><div><br></div><div>Obviously, the x86 assembler bit cannot work on sparc, and since the __sync_fetch_and_add() is unavailable, it fails.</div><div><br></div><div>My "fix" for that was this:</div><div><br></div><div><div>    #else</div><div>    static int atomic_exchange_and_add( unsigned int * pw, int dv )</div><div>    {</div><div>      #if(((__GNUC__ == 3) && (__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ == 3)) && defined(__sparc__))</div><div>      int r = *pw;</div><div>      *pw += dv;</div><div>      return(r);</div><div>      #else</div><div>      return __sync_fetch_and_add(pw, dv);</div><div>      #endif</div><div>    }</div><div>    #endif</div></div><div><br></div><div>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?</div>                                      </div></body>
</html>