PE destructors create crashes in binutils itself
Mon Jun 3 11:27:00 GMT 2019
> In b0daac83, you fixed static constructors and destructors on
*sigh* No good deed goes unpunished.
> It turns out that binutils itself (ld.exe,
> windres.exe, etc) crashes if linked by a binutils >=2.31. Runtime
> execution works fine, but just before exiting, the program crashes and
> triggers the various Windows crash detector things and exits with a
> non-zero exit code.
Given the timing of the crash, the implication is that a destructor is
causing the problem. Presumably when linked with a pre 2.31 linker the
destructor is never run, and so the problem is not seen.
> Do you have any ideas why the destructor logic in binutils itself
> would be crashing on mingw/windows/PE? This is something we're running
> into with the toolchains over on musl.cc.
So my suggestion would be to run the linker inside GDB, and put a breakpoint
at the start of the destructor chain. Then watch each destructor in turn
to see which one breaks.
The most obvious candidate for being the cause of the problem is the
ld_cleanup() function in ld/ldmain.c. This is called at exit and I would
suspect that it closing something that was not opened. In fact you could
try a quick hack and just comment out the contents of that function to
see if that "solves" the problem. If you can narrow down the problem,
please file a binutils bug report so that we can investigate further.
(Note - I do not actually have access to a MinGw/PE development environment
so it would be really helpful if you could be as specific as possible in
describing what needs to be fixed).
More information about the Binutils