mingw-woarm64-build
mingw-woarm64-build copied to clipboard
Bad return code before reaching `main` when `fprintf` is linked with `aarch64-w64-mingw32-g++` executable
Issue
When the following C/C++ code:
#include <stdio.h>
int main () {
FILE *f = fopen ("test.txt", "w");
fprintf (f, "%d\n", 10);
return 0;
}
is compiled with aarch64-w64-mingw32-g++
the control flow does not reach main
and return code 127 or 123 is returned.
- When the same code is compiled with
aarch64-w64-mingw32-gcc
, it works fine. - When
fprintf
line is removed, it works fine. - Other functions like
printf
work fine. - When object files are produced from this source code first, both with
aarch64-w64-mingw32-gcc
andaarch64-w64-mingw32-g++
they are identical and when then they are linked withaarch64-w64-mingw32-g++
it fails while withaarch64-w64-mingw32-gcc
it works. - The issue happens only when shared runtime libraries are linked, with
-static
the binary works fine. - It seems that the C++ linked binaries are not loading
libgcc_s_seh-1.dll
correctly while C linked ones does. - Disassembled EXE produced by
aarch64-w64-mingw32-g++
bad-exe.txt and byaarch64-w64-mingw32-gcc
good-exe.txt linkers are showing some differences.