Skip to content

Commit

Permalink
gcc: use DWARF exception handling for i686-w64-mingw32
Browse files Browse the repository at this point in the history
This is the default used by MSYS2[^1], ArchLinux[^2] and probably everyone else.
This is required to compile Rust programs as it doesn't support SJLJ[^3].

[^1]: https://github.com/msys2/MINGW-packages/blob/725f262e9f6313e3ee04327a33c16614c970a110/mingw-w64-gcc/PKGBUILD#L185-L186
[^2]: https://gitlab.archlinux.org/archlinux/packaging/packages/mingw-w64-gcc/-/blob/14.2.0-3/PKGBUILD#L62
[^3]: rust-lang/rust#55444 (comment)
  • Loading branch information
js6pak committed Dec 23, 2024
1 parent d70bd19 commit 734f2cc
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions pkgs/development/compilers/gcc/common/configure-flags.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@

assert !enablePlugin -> disableGdbPlugin;

# Note [Windows Exception Handling]
# sjlj (short jump long jump) exception handling makes no sense on x86_64,
# it's forcably slowing programs down as it produces a constant overhead.
# On x86_64 we have SEH (Structured Exception Handling) and we should use
# that. On i686, we do not have SEH, and have to use sjlj with dwarf2.
# Hence it's now conditional on x86_32 (i686 is 32bit).
#
# ref: https://stackoverflow.com/questions/15670169/what-is-difference-between-sjlj-vs-dwarf-vs-seh


let
inherit (stdenv)
buildPlatform hostPlatform targetPlatform;
Expand All @@ -57,6 +47,10 @@ let
"--with-as=${if targetPackages.stdenv.cc.bintools.isLLVM then binutils else targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as"
"--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld"
]
++ lib.optionals (crossMingw && targetPlatform.isx86_32) [
"--disable-sjlj-exceptions"
"--with-dwarf2"
]
++ (if withoutTargetLibc then [
"--disable-libssp"
"--disable-nls"
Expand All @@ -80,10 +74,6 @@ let
"--disable-nls"
# To keep ABI compatibility with upstream mingw-w64
"--enable-fully-dynamic-string"
] ++ lib.optionals (crossMingw && targetPlatform.isx86_32) [
# See Note [Windows Exception Handling]
"--enable-sjlj-exceptions"
"--with-dwarf2"
] else [
(if crossDarwin then "--with-sysroot=${lib.getLib libcCross}/share/sysroot"
else "--with-headers=${lib.getDev libcCross}${libcCross.incdir or "/include"}")
Expand Down

0 comments on commit 734f2cc

Please sign in to comment.