__sync_fetch_and_add_4 in libstdc++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello gcc-help,

When compiling gmp on Solaris 9 i386, using gcc (4.3.3 and 4.6.1),
I've come across a problem where the linking stage of the t-access.o
object would result in an error:

libtool: link: /opt/csw/bin/g++-4.6 -mtune=i686 -O2 -pipe -m32
-march=i386 -fexceptions -m32 -march=i386 -o .libs/t-assign t-assign.o
 -L/home/maciej/src/opencsw/pkg/libgmp/trunk/work/solaris9-i386/build-isa-i386/gmp-5.0.2/.libs
-L/opt/csw/lib/. -L/opt/csw/lib ../../tests/.libs/libtests.a
../../.libs/libgmpxx.so
/home/maciej/src/opencsw/pkg/libgmp/trunk/work/solaris9-i386/build-isa-i386/gmp-5.0.2/.libs/libgmp.so
/opt/csw/lib/libstdc++.so -lm ../../.libs/libgmp.so -Wl,-R
-Wl,/opt/csw/lib
ld: warning: file ../../.libs/libgmp.so: linked to
/home/maciej/src/opencsw/pkg/libgmp/trunk/work/solaris9-i386/build-isa-i386/gmp-5.0.2/.libs/libgmp.so:
attempted multiple inclusion of file
ld: warning: file /opt/csw/lib/./libstdc++.so: linked to
/opt/csw/lib/libstdc++.so: attempted multiple inclusion of file
Undefined                       first referenced
 symbol                             in file
__sync_fetch_and_add_4              t-assign.o
ld: fatal: Symbol referencing errors. No output written to .libs/t-assign

A similar problem was encountered in the past[1].

The porting FAQ at OpenCSW[2] contains information about a workaround
for this problem: disable optimization during compilation.  Other
workarounds found on the web suggest changing the target architecture
to i686.  Not satisfied with these workarounds, I've done some digging
with help from friends (kudos to Joerg Schilling!).

The GCC invocation used to compile this object was:

/opt/csw/bin/g++-4.6 -DHAVE_CONFIG_H -I. -I../.. -I../.. -I../../tests
 -fexceptions -I/opt/csw/include  -mtune=i686 -O2 -pipe -m32
-march=i386 -fexceptions -c -o t-assign.o t-assign.cc

I've generated the assembly file from t-assign.cc and found references
to __sync_fetch_and_add_4:

.L213:
        subl    $4, %edi
        movl    $-1, 4(%esp)
        movl    %edi, (%esp)
        call    __sync_fetch_and_add_4
        jmp     .L77

I've looked up the function name in the GCC documentation[3], and
found out that it's got to do with the capabilities of the target CPU
architecture.  If the target architecture doesn't have the opcode for
specific atomic operations, libstdc++ generates a compatibility
function, called __sync_fetch_and_add_4.  In my case, it looks like
during the libstdc++ compilation, this function was not generated.
Later on, when g++ is used with -march=i386, it knows that i386 has no
required opcode and creates a dangling reference to
__sync_fetch_and_add_4.

The fix would probably involve compiling libstdc++ in such a way, that
__sync_fetch_and_add_4 would be generated.  Do you have an idea how to
achieve this?

Regards,
Maciej

[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28671
[2] http://wiki.opencsw.org/porting-faq#toc6
[3] http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/doc/xml/manual/concurrency_extensions.xml?view=markup


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux