Using seh exceptions, win32 threads

Bug #1338043 reported by Tony Kelman
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
gcc-mingw-w64 (Debian)
Fix Released
Unknown
gcc-mingw-w64 (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Perhaps this question should go to Debian - I'm interested in using the MinGW-w64 cross-compiler package but my preference is for SEH exception handling on x86_64 (rather than sjlj), and win32 threading instead of posix to avoid the dependence on libwinpthread-1.dll. Other non-Debian distributions like Fedora and OpenSUSE provide this combination by default, though I recognize win32 threading does not work as well with std::thread so it's not ideal for all users. If there were a mechanism for providing multiple options through Debian/Ubuntu packaging, it would be a much more versatile platform for cross-compilation.

Maybe this would be good to do as a PPA? I'm experimenting now with doing dpkg-buildpackage with a couple small modifications to the debian/rules file where the appropriate configure flags are used.

Related branches

Revision history for this message
Stephen Kitt (steve-sk2) wrote :

I keep an eye on bugs filed here, so there's no need to push this to Debian (I'm the Debian packager for this).

Your question covers similar issues to those raised in http://bugs.debian.org/750741 so I'm linking the two.

With regards to a proper solution, I'd be interested in anything you can come up with. I'm working (slowly) on a way of providing both win32 and pthreads-based libraries simultaneously, using linker script switches to pick the right one. Switching between SJLJ and SEH will happen automatically at some point in the future, or rather SEH will become the default, since the patent has now expired.

Changed in gcc-mingw-w64 (Debian):
status: Unknown → New
Revision history for this message
Tony Kelman (tkelman) wrote :

Thanks Stephen, glad you saw this.

So it looks like I got a set of debs built okay from the source package without much trouble. I changed --enable-threads from posix to win32 in debian/rules, and deleted the line that said --enable-sjlj-exceptions. The gcc-mingw-w64-i686/usr/lib/gcc/i686-w64-mingw32/4.8 build result has an sjlj libgcc_s, and no libwinpthread. I also had to change debian/gcc-mingw-w64-x86-64.install to fix the 64 bit filename to now be libgcc_s_seh-1.dll.

I'll give these debs I just built a try. Will take a while to rebuild the library I'm interested in at the moment, it has a bunch of big dependencies.

You know better than I in terms of the best way to eventually set it up. But I'd be interested to see what it might look like from an end-user standpoint. Would alternatives be used to switch the default linker script between multiple options, possibly?

Revision history for this message
Stephen Kitt (steve-sk2) wrote :

Actually I was thinking of spec files, not linker scripts, sorry!

It would end up looking something like

x86_64-w64-mingw32-gcc -mwin32threads

to build with Win32 threads, etc. Or perhaps -mthreads=win32 (and -mthreads=posix), depending on what I can get the specs to do.

Revision history for this message
Tony Kelman (tkelman) wrote :

The cross-compile from my own set of SEH, win32-threading debs worked nicely.

There was one little hangup of strerror_s not existing in the msvcrt runtime when I try to run the cross-compiled binary on XP, but I think I can solve that with a configure flag in the library I'm building. Deciding to not support XP is an okay decision in my book, hopefully more people will agree with that over time.

Overall I was pleasantly surprised how painless and relatively quick (only about 20 minutes, on an old computer) it was to build the set of modified MinGW debs, it felt much faster than the last time I built GCC from source on a non-Debian distribution. Maybe just because cross-compilers don't go through the whole bootstrap process?

Anyway, in case it helps anyone who comes across this in the future, this was the set of steps I did to make it all work (reconstructed from my .bash_history):

mkdir ~/GCC
cd ~/GCC
apt-get source gcc-mingw-w64
sudo apt-get build-dep g++-mingw-w64
sudo apt-get build-dep gfortran-mingw-w64
cd gcc-mingw-w64-12
# change --enable-threads=posix to --enable-threads=win32
# and remove --enable-sjlj-exceptions from debian/rules
# change libgcc_s_sjlj-1.dll to libgcc_s_seh-1.dll in
# debian/gcc-mingw-w64-x86-64.install
dpkg-buildpackage -rfakeroot -uc -b
cd ..
sudo dpkg -i *.deb

This overwrites the existing SJLJ, posix-threading MinGW packages I had installed, but I'm okay with that for now and it should be easy to get them back if I need them.

Changed in gcc-mingw-w64 (Debian):
status: New → Fix Committed
Changed in gcc-mingw-w64 (Debian):
status: Fix Committed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package gcc-mingw-w64 - 14.1

---------------
gcc-mingw-w64 (14.1) unstable; urgency=medium

  * Take the threading model into account when stripping libraries.

 -- Stephen Kitt <email address hidden> Thu, 31 Jul 2014 07:27:45 +0200

Changed in gcc-mingw-w64 (Ubuntu):
status: New → Fix Released
Revision history for this message
Stephen Kitt (steve-sk2) wrote :

The changelog snippet given above doesn't explain how this bug was fixed: gcc-mingw-w64 now uses the upstream default exception handling (SJLJ for 32-bit Windows, SEH for 64-bit Windows), and provides two toolchains, one using Windows threads and one using POSIX threads. The required threading model can be selected using update-alternatives; the default is Windows threads to minimise the change since Debian's last stable release. A specific threading model can also be used for a given compilation by suffixing the compiler with either -posix or -win32, e.g. i686-w64-mingw32-gcc-posix to explicitly use POSIX threads.

Revision history for this message
Tony Kelman (tkelman) wrote :

That sounds perfect Stephen, thanks for the great work and the heads-up.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.