Invoking atomic functions from a C++ shared lib (or should I force linking with -lgcc?)

Andrew Haley aph@redhat.com
Fri Nov 19 10:41:00 GMT 2010


On 11/19/2010 10:14 AM, Christophe Lyon wrote:
> 
>>
>> What I have found is that g++ (unlike gcc) links with -lgcc_s instead of
>> -lgcc and that the atomic functions are present in libgcc.a and not in
>> libgcc_s.so.
>>
> 
> Anyone knows the rationale for the absence of functions such as
> __sync_fetch_and_add (and more generally all __sunc* functions) from
> libgcc_s.so ?

It was to make them faster by avoiding a trip through the PLT.

> Is it a bug/feature specific to the ARM port? (on x86 for instance, such
> functions do not exist, the corresponding builtin is fully expanded and
> requires not lib call).

There are a couple of targets that use libcalls for atomics.

You should be able simply to link with

  -lgcc_s -lgcc

Andrew.



More information about the Gcc-help mailing list