Bug 20421 – Exceptions don't work when linking through lld-link

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2019-11-27T07:11:52Z
Last change time
2020-02-27T20:12:10Z
Keywords
pull
Assigned to
No Owner
Creator
Rainer Schuetze

Comments

Comment #0 by r.sagitario — 2019-11-27T07:11:52Z
import std.stdio; void main(){ try { throw new Exception("first"); } catch (Exception e) { writeln("catch ", e.msg); } writeln("done"); } Building this with against the mingw libs with > dmd.exe -m32mscoff test.d -mscrtlib=msvcrt100 generates an executable that doesn't produce any output, but silently crashes. When run in a debugger, it reports: Unhandled exception at 0x004010EF in x.exe: 0xC00001A5: An invalid exception handler routine has been detected (parameters: 0x00000001). This seems to happen when lld is used instead of the Microsoft linker. Using lld from LLVM 9 spits out errors "not compatible with SEH", but links using /SAFESEH:NO. The resulting executable then works.
Comment #1 by kinke — 2019-11-27T16:34:23Z
I've had my share of related issues as well; even had to fork LLVM's compiler-rt to make their assembly files SAFESEH compatible. - This is almost certainly already fixed in the new (but so far unused by DMD) MinGW-based libs; e.g., see https://github.com/ldc-developers/mingw-w64-libs/blob/8d930c129daa798379b3d563617847f8e895f43e/buildsdk.d#L379.
Comment #2 by r.sagitario — 2019-11-27T18:07:40Z
It works out of the box by using the MS linker (still using the mingw libraries that come with dmd). Making the libs SAFESEH compatible would be nice, but I don't think dmd generates appropriate object files anyway. So passing /SAFESEH:NO to lld v9 might be an option.
Comment #3 by dlang-bot — 2020-02-09T13:05:53Z
@rainers created dlang/installer pull request #433 "fix Issue 20421 - Exceptions don't work when linking through lld-link" fixing this issue: - fix Issue 20421 - Exceptions don't work when linking through lld-link patch LLD to not set IMAGE_DLL_CHARACTERISTICS_NO_SEH, the MS linker also doesn't do this. https://github.com/dlang/installer/pull/433
Comment #4 by dlang-bot — 2020-02-10T00:50:29Z
dlang/installer pull request #433 "fix Issue 20421 - Exceptions don't work when linking through lld-link" was merged into master: - 7f990228948520366d4ccf0c79c2f2407ffc2e1f by Rainer Schuetze: fix Issue 20421 - Exceptions don't work when linking through lld-link patch LLD to not set IMAGE_DLL_CHARACTERISTICS_NO_SEH, the MS linker also doesn't do this. https://github.com/dlang/installer/pull/433
Comment #5 by dlang-bot — 2020-02-27T20:12:10Z
dlang/dmd pull request #10814 "fix issue 20421 - Exceptions don't work when linking through lld-link" was merged into stable: - e8b41b36b35dacbb7fd9cce4342cac2787ecfda3 by Rainer Schuetze: fix issue 20421 - Exceptions don't work when linking through lld-link when linking through lld-link, add /SAFESEH:NO to linker command line add build on azure that uses lld and mingw import libraries use run.d instead of gmake to run tests d_do_test: remove legacy command line "-map nul.map" update to build with LDC 1.20.0 https://github.com/dlang/dmd/pull/10814