Bug 599227

Summary: mingw <pthread.h> is broken
Product: [Fedora] Fedora Reporter: Eric Blake <eblake>
Component: mingw32-pthreadsAssignee: Kalev Lember <kalevlember>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: rawhideCC: berrange, drizt72, erik-fedora, fedora-mingw, kalevlember, lfarkas, rjones, rohara
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: mingw32-pthreads-2.8.0-15.20110511cvs.fc16 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-05-12 17:18:33 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Eric Blake 2010-06-02 21:40:19 UTC
Description of problem:
The cross-compilation header /usr/i686-pc-mingw32/sys-root/mingw/include/pthread.h, installed as part of the mingw32-pthreads package, has several coding bugs.

Version-Release number of selected component (if applicable):
mingw32-pthreads-2.8.0-10.fc13.noarch

How reproducible:
Always


Steps to Reproduce:
1. Try cross-compiling any code that uses localtime_r with a second argument with side effects, or try calling (localtime_r)(arg1,arg2).
2. Try cross-compiling any project that uses gnulib's <time.h> replacement header (libvirt is an example project; it includes a ./autobuild.sh script that will automatically try a mingw cross-compilation, if you have installed a mingw portablexdr library, although that library is not yet part of fedora).
  
Actual results:
The definition of localtime_r is broken, because it evaluates the second argument twice.  And, since POSIX allows one to #undef localtime_r, but there is no localtime_r function in the library, you get a link failure if you bypass the function-like macro.  Finally, the pthreads-win32 library made the mistake of installing <config.h>, which is asking for namespace collision with most other autotooled packages.

Expected results:
<pthread.h> should not define any *_r functions, nor should it interfere with a proper <time.h>.  Also, the library should not install <config.h>, but should instead modify its installed headers to be self-contained.

Additional info:
See this thread on bug-gnulib for more details:
http://lists.gnu.org/archive/html/bug-gnulib/2010-06/msg00007.html

Comment 1 Ryan O'Hara 2010-07-14 21:08:10 UTC
I recently came across this bug when trying to compile libcheck under mingw32, which choked on the localtime_r problem described in comment #1.

Comment 2 Erik van Pienbroek 2011-01-28 18:37:53 UTC
Do you happen to know if these issues have been resolved upstream already? There has been activity in upstreams CVS repo to add support for mingw-w64 and possibly other fixes. See http://sourceforge.net/apps/trac/mingw-w64/wiki/Compile%20pthreads for details.

On that link there also are patches to fix the config.h issue which you mentioned. For the new cross compiler framework which I mentioned in your other bugreport (bug 599567) I have those patches already applied.

If you want to test this new version of mingw32-pthreads you can use the testing repository for the new cross compiler framework. Details for that can be found at https://fedoraproject.org/wiki/MinGW/CrossCompilerFramework

Comment 3 Kalev Lember 2011-05-12 07:08:56 UTC
(In reply to comment #0)
[snip]
> Finally, the pthreads-win32 library made the mistake
> of installing <config.h>, which is asking for namespace collision with most
> other autotooled packages.
> 
> Expected results:
[snip]
> Also, the library should not install <config.h>, but should
> instead modify its installed headers to be self-contained.

I gave a stab at fixing the config.h issue. In rawhide pthreads.h no longer includes config.h and both config.h and its other private headers are no longer installed.

The fix is in mingw32-pthreads-2.8.0-14.fc16

http://pkgs.fedoraproject.org/gitweb/?p=mingw32-pthreads.git;a=blobdiff;f=mingw32-pthreads.spec;h=4b7aaff11c12bb7df614ea7f4d2a0af35aa66d76;hp=e6dbf82ceefe2a5b5ea4ca9164a1be94ae046c56;hb=7b7cbed7d5e5a0ec8c68a42e280e8bc74d01a734;hpb=dc57f4600486bd31e906493e4dcec1396d33e5a0

Comment 4 Kalev Lember 2011-05-12 07:56:28 UTC
It would also appear that in CVS HEAD localtime_r and other *_r definitions are gone from pthreads.h; perhaps we should consider packaging up a snapshot.

Anyone interested in talking to upstream and asking when they are going to make a new release?

Comment 5 Erik van Pienbroek 2011-05-12 16:56:32 UTC
After some discussion with Kalev on IRC I think it's a good idea to update the mingw32-pthreads package in Fedora to the latest CVS version. That way we should also be ready with a compatible version for when mingw-w64 will be introduced in Fedora 16

Comment 6 Kalev Lember 2011-05-12 17:18:33 UTC
I just built mingw32-pthreads-2.8.0-15.20110511cvs.fc16 for rawhide, which should fix both the config.h issue by removing the header, and also remove the possibly conflicting localtime_r definition. I did some basic testing, but it would be very awesome if someone else could try it with a real world test case.

Closing the ticket.