Opened 12 years ago

Closed 11 years ago

Last modified 9 years ago

#4849 closed Bugs (fixed)

MinGW-64: detail/interlocked.hpp chooses wrong prototypes for InterlockedCompareExchange et al

Reported by: Jim Bell <jim@…> Owned by: Anthony Williams
Milestone: Boost 1.55.0 Component: thread
Version: Boost 1.54.0 Severity: Problem
Keywords: mingw64 InterlockedCompareExchange once.hpp thread.cpp Cc: jim@…, sam@…, phprus@…

Description

I see pdimov's name on detail/interlocked.hpp, so I'm filing this here...

MinGW-64/Win7 fails to compile thread.cpp, so all dependent regressions fail.

In file included from ../boost/thread/once.hpp:14,
                 from ..\libs\thread\src\win32\thread.cpp:17:
../boost/thread/win32/once.hpp: In function 'void boost::call_once(boost::once_flag&, Function)':
../boost/thread/win32/once.hpp:136: error: '_InterlockedCompareExchange' is not a member of 'boost::detail'
../boost/thread/win32/once.hpp:152: error: '_InterlockedIncrement' is not a member of 'boost::detail'
../boost/thread/win32/once.hpp:155: error: '_InterlockedExchange' is not a member of 'boost::detail'
../boost/thread/win32/once.hpp:169: error: '_InterlockedExchange' is not a member of 'boost::detail'
../boost/thread/win32/once.hpp:184: error: '_InterlockedIncrement' is not a member of 'boost::detail'

If I modify detail/interlocked.hpp to choose it as BOOST_USE_WINDOWS_H, thread.cpp builds and dependent tests pass. It seems BOOST_USE_WINDOWS_H is special-purpose, so I'm not sure if this is the final fix.

#if defined( BOOST_USE_WINDOWS_H ) || defined(_WIN64)

Presently it's choosing this section (line 107):

#elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )

This seems somewhat similar to Ticket #4217

Attachments (4)

mingw64-thread.patch (569 bytes ) - added by Jim Bell <jim@…> 12 years ago.
mingw64-thread-2.patch (3.4 KB ) - added by Jim Bell <jim@…> 12 years ago.
interlocked.diff (1.3 KB ) - added by bronf 9 years ago.
mingw64_iterlocked.patch (2.8 KB ) - added by Bobby Mihalca <bobbymihalca@…> 9 years ago.

Download all attachments as: .zip

Change History (28)

comment:1 by Peter Dimov, 12 years ago

BOOST_USE_WINDOWS_H is a user macro; it causes boost headers to include <windows.h>, which should never happen automatically.

comment:2 by Sam Morris <sam@…>, 12 years ago

Cc: sam@… added

comment:3 by Peter Dimov, 12 years ago

I see that the "Win7-x64 jc-bell.com" regression tester doesn't have the issue, but this may be caused by a different version of windows.h. Either way, this is not (in my opinion) an issue with interlocked.hpp, it's caused by thread.cpp including windows.h before once.hpp. windows.h then (I assume) defines Interlocked* as macros to _Interlocked*. Putting the windows.h include last should solve the problem.

comment:4 by Jim Bell <jim@…>, 12 years ago

"Win7-x64 jc-bell.com" is my platform (still experimental), and it this works because I have a fix for it. It #undef's Interlocked... stuff after #include <windows.h>

by Jim Bell <jim@…>, 12 years ago

Attachment: mingw64-thread.patch added

comment:5 by Jim Bell <jim@…>, 12 years ago

To clarify: the patch applies to boost/libs/thread/src/win32/thread.cpp

comment:6 by Peter Dimov, 12 years ago

Can you please try moving the <windows.h> include last instead?

comment:7 by anonymous, 12 years ago

Yes. Moving #include <windows.h> below all other includes DOES correct the above "_Interlocked..." errors above.

I'm attaching a patch that shows this, and also a couple other related MinGW-64 patches that might be helpful. Review it carefully.

by Jim Bell <jim@…>, 12 years ago

Attachment: mingw64-thread-2.patch added

comment:8 by Peter Dimov, 12 years ago

Component: smart_ptrthread
Owner: changed from Peter Dimov to Anthony Williams

I'll reassign this to Anthony for now, he can bounce it back to me later. :-)

comment:9 by anonymous, 12 years ago

I'll just want to bump this since it wasn't fixed in the latest 1.46.1 release... if bumping is not usual in such bug-trackers I apologize for the inconvenience. ;)

comment:10 by anonymous, 12 years ago

Same. I met the issue on my build today. What would be the next delivery in an official build ?

comment:11 by Jim Bell <jim@…>, 12 years ago

One problem is that boost doesn't have a reliable mingw64 regression test for trunk and release. Mine's experimental, trunk-only, and doesn't get run often (to say the least). So the maintainer probably isn't going to take a chance on it.

Anyone want to run trunk and release regressions until this change gets shepherded through trunk and release branches? If so, we can at least try to get the maintainer's attention: I'll send him a polite e-mail about it. (No guarantee it'll get fixed even then.)

Until then, look at the attached patches and patch your distribution. Hate to say it, but that's the expedient fix.

comment:12 by Anthony Williams, 12 years ago

Status: newassigned

I've applied the patch to trunk (revision 70383). If it doesn't cause any problems it can be merged to release.

comment:13 by anonymous, 12 years ago

Thank you very much for your affords :)

comment:14 by Vladislav <phprus@…>, 11 years ago

Cc: phprus@… added

Tell please, this patch will get into release 1.47.0?

comment:15 by mayburn11, 11 years ago

i lost few days on investigate why mingw64 chokes compiling my code then i saw this

i patched my boost release to it and it works well

it be very nice if it can be merged to release branch

thank you mayburn11

comment:16 by Jim Bell <jim@…>, 11 years ago

This will be released in boost 1.47.0. See http://lists.boost.org/Archives/boost/2011/06/182834.php.

comment:17 by viboes, 11 years ago

Resolution: fixed
Status: assignedclosed

Closed as for the comments it seems this was committed in release branch.

comment:18 by mattyclarkson@…, 9 years ago

Just hit this same issue building 1.54.0 with MinGW-builds-x64-4.8.1-posix-seh on Windows 7 x64:

C:\Users\Matt\Documents\git\tool-chain\third_party\source\http\boost_1_54_0>b2 t
oolset=gcc variant=release link=shared threading=multi runtime-link=shared --pre
fix=C:\boost-1.54.0 --with-thread -d+2

Building the Boost C++ Libraries.



Component configuration:

    - atomic                   : not building
    - chrono                   : not building
    - context                  : not building
    - coroutine                : not building
    - date_time                : not building
    - exception                : not building
    - filesystem               : not building
    - graph                    : not building
    - graph_parallel           : not building
    - iostreams                : not building
    - locale                   : not building
    - log                      : not building
    - math                     : not building
    - mpi                      : not building
    - program_options          : not building
    - python                   : not building
    - random                   : not building
    - regex                    : not building
    - serialization            : not building
    - signals                  : not building
    - system                   : not building
    - test                     : not building
    - thread                   : building
    - timer                    : not building
    - wave                     : not building

gcc.link.dll bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\li
bboost_thread-mgw48-mt-1_54.dll.a

    "g++"   "-Wl,--out-implib,bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\t
hreading-multi\libboost_thread-mgw48-mt-1_54.dll.a" -o "bin.v2\libs\thread\build
\gcc-mingw-4.8.1\release\threading-multi\libboost_thread-mgw48-mt-1_54.dll"  -sh
ared -Wl,--start-group "bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threadi
ng-multi\win32\thread.o" "bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threa
ding-multi\win32\tss_dll.o" "bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\th
reading-multi\win32\tss_pe.o" "bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\
threading-multi\future.o" "bin.v2\libs\chrono\build\gcc-mingw-4.8.1\release\thre
ading-multi\libboost_chrono-mgw48-mt-1_54.dll.a" "bin.v2\libs\system\build\gcc-m
ingw-4.8.1\release\threading-multi\libboost_system-mgw48-mt-1_54.dll.a"  -Wl,-Bs
tatic  -Wl,-Bdynamic  -Wl,--end-group -mthreads

bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x387): undefined reference to `InterlockedCompareExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x3a4): undefined reference to `InterlockedCompareExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x400): undefined reference to `InterlockedExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x47e): undefined reference to `InterlockedIncrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x494): undefined reference to `InterlockedCompareExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x781): undefined reference to `InterlockedIncrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x79c): undefined reference to `InterlockedCompareExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x9a0): undefined reference to `InterlockedCompareExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x9bd): undefined reference to `InterlockedCompareExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0xa19): undefined reference to `InterlockedExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0xa9f): undefined reference to `InterlockedIncrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0xab5): undefined reference to `InterlockedCompareExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0xee2): undefined reference to `InterlockedIncrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0xefd): undefined reference to `InterlockedCompareExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1026): undefined reference to `InterlockedIncrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x10d9): undefined reference to `InterlockedIncrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1159): undefined reference to `InterlockedDecrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x11e8): undefined reference to `InterlockedIncrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1227): undefined reference to `InterlockedDecrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1293): undefined reference to `InterlockedDecrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1310): undefined reference to `InterlockedDecrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x13a9): undefined reference to `InterlockedDecrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1445): undefined reference to `InterlockedDecrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1a3d): undefined reference to `InterlockedCompareExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1a5a): undefined reference to `InterlockedCompareExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1ab6): undefined reference to `InterlockedExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1b21): undefined reference to `InterlockedIncrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1b37): undefined reference to `InterlockedCompareExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1df1): undefined reference to `InterlockedIncrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1e0c): undefined reference to `InterlockedCompareExchange'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x3212): undefined reference to `InterlockedDecrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x3328): undefined reference to `InterlockedDecrement'
bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\win32\thread.o:
thread.cpp:(.text+0x1130): undefined reference to `InterlockedIncrement'
c:/users/matt/documents/git/tool-chain/third_party/mingw-builds/4.8.1/x64/posix/
seh/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw
32/bin/ld.exe: bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\
win32\thread.o: bad reloc address 0x8 in section `.data'
collect2.exe: error: ld returned 1 exit status
...removing bin.v2\libs\thread\build\gcc-mingw-4.8.1\release\threading-multi\lib
boost_thread-mgw48-mt-1_54.dll.a
...skipped <pstage\lib>libboost_thread-mgw48-mt-1_54.dll.a for lack of <pbin.v2\
libs\thread\build\gcc-mingw-4.8.1\release\threading-multi>libboost_thread-mgw48-
mt-1_54.dll.a...
...skipped <pstage\lib>libboost_thread-mgw48-mt-1_54.dll for lack of <pbin.v2\li
bs\thread\build\gcc-mingw-4.8.1\release\threading-multi>libboost_thread-mgw48-mt
-1_54.dll...
...failed updating 2 targets...

I'm trying to figure out why the macros are not set to the correct symbols, if anyone has any pointers for me, I welcome a hint :)

comment:19 by Jim Bell <jim@…>, 9 years ago

@mattyclarkson: Have you studied/applied the patches in this ticket?

comment:20 by Matt Clarkson <mattyclarkson@…>, 9 years ago

@jim: I solved this by adding define=BOOST_USE_WINDOWS_H to fix the build. That forces the inclusion of windows.h pulling in the correct definitions for the symbols. I went over the patches, they all seem to be in the trunk now, so was a little lost but found some more information around on Google about building Boost with MinGW x64.

comment:21 by viboes, 9 years ago

It seems that there is a regression on mingw 64

See http://sourceforge.net/mailarchive/message.php?msg_id=31189847.

comment:22 by bronf, 9 years ago

I have eventually fixed this issue without having to define BOOST_USE_WINDOWS_H (which causes issues when compiling with wxWidgets for example). The patch (https://svn.boost.org/trac/boost/attachment/ticket/4849/interlocked.diff) works with mingw-w64 targeting both i686 and x86_64. Hope this can be included in 1.55.0.

by bronf, 9 years ago

Attachment: interlocked.diff added

comment:23 by Bobby Mihalca <bobbymihalca@…>, 9 years ago

Milestone: Boost 1.46.0Boost 1.55.0
Version: Boost Development TrunkBoost 1.54.0

Have the same problem and made a patch. It deals with mingw64 in its own #elif and undoes BOOST_INTERLOCKED_IMPORT from mingw64-thread-2.patch Tested with mingw64 4.8.1 64 and 32 bits and threads compile and work.

by Bobby Mihalca <bobbymihalca@…>, 9 years ago

Attachment: mingw64_iterlocked.patch added

comment:24 by Peter Dimov, 9 years ago

This should have been fixed by revision [85865].

Note: See TracTickets for help on using tickets.