Menu

#152 undefined reference to __sync_sub_and_fetch_4 compiling with mingw

v1.1.x
closed
5
2013-01-07
2012-12-26
z8a
No

log4cplus release: v1.1.1-rc1
compiler: mingw32 gcc 4.7.1
OS: Windows 7 64 bit
error: undefined reference to __sync_sub_and_fetch_4 in pointer.cxx

The compilation is successful if I change
destroy = __sync_sub_and_fetch (&count, 1) == 0;

in

__sync_sub_and_fetch (&count, 1);
destroy = (count==0);

Could be OK?

Discussion

  • Václav Haisman

    Václav Haisman - 2012-12-26

    The sugested change is not ok. Fetching the count variable must be atomic.

    What Mingw distribution are you using? What GCC version?

     
  • Václav Haisman

    Václav Haisman - 2013-01-01
    • assigned_to: Václav Zeman
     
  • Václav Haisman

    Václav Haisman - 2013-01-01

    I still cannot reproduce it. I am surprised that there exists a version of GCC that would not have those built-in functions available. Please try to report this as a compiler bug.

     
  • Václav Haisman

    Václav Haisman - 2013-01-04

    So I have been able to reproduce this by using -march=i386 in CXXFLAGS. You could have saved me some time by following the Bug Reporting Instruction.

    As long as you do not actually require executables that actually run on the actual Intel (and compatible) i386 SX/DX CPUs, you can work around it by using -march=i486 (or higher) flag.

    I have fixed the breakage in log4cplus using the attached patch. However, GCC's libstdc++ is still broken as it relies on the __sync* routines internally as well:

    Creating library file: .libs/liblog4cplus.dll.asrc/.libs/liblog4cplus_la-appenderattachableimpl.o:/usr/lib/gcc/i686-pc-mingw32/4.5.2/include/c++/ext/atomicity.h:46: undefined reference to `___sync_fetch_and_add_4'
    src/.libs/liblog4cplus_la-appender.o:/usr/lib/gcc/i686-pc-mingw32/4.5.2/include/c++/ext/atomicity.h:46: undefined reference to `___sync_fetch_and_add_4'
    src/.libs/liblog4cplus_la-asyncappender.o:/usr/lib/gcc/i686-pc-mingw32/4.5.2/include/c++/ext/atomicity.h:46: undefined reference to `___sync_fetch_and_add_4'
    src/.libs/liblog4cplus_la-clogger.o:/usr/lib/gcc/i686-pc-mingw32/4.5.2/include/c++/ext/atomicity.h:46: undefined reference to `___sync_fetch_and_add_4'
    src/.libs/liblog4cplus_la-configurator.o:/usr/lib/gcc/i686-pc-mingw32/4.5.2/include/c++/ext/atomicity.h:46: undefined reference to `___sync_fetch_and_add_4'
    src/.libs/liblog4cplus_la-consoleappender.o:/usr/lib/gcc/i686-pc-mingw32/4.5.2/include/c++/ext/atomicity.h:46: more undefined references to `___sync_fetch_and_add_4' follow
    collect2: ld returned 1 exit status
    
     

    Last edit: Václav Haisman 2013-01-04
  • Václav Haisman

    Václav Haisman - 2013-01-04
    • labels: --> mingw
    • status: open --> pending
     
  • Václav Haisman

    Václav Haisman - 2013-01-07

    I have reproduced this with Ruby's DevKit-tdm-32-4.5.2-20111229-1559-sfx as well. It seems that this specific TDM's GCC build is not given a '--with-arch=' switch and it defaults to i386 (on x86 platform). I am mainly using Linug-x-MinGW64 cross compiler and that has different configuration, thus this has not turned up on my builds.

    I have one more patch to push. I had to add it to make things work with this DevKit (different error). I will push it later today to trunk.

    I am closing this as fixed now.

     
  • Václav Haisman

    Václav Haisman - 2013-01-07
    • labels: mingw --> mingw, fixed
    • status: pending --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.