Windows-on-ARM-Experiments / mingw-woarm64-build

Workflows and build scripts for Windows on Arm64 GNU cross-compiler for `aarch64-w64-mingw32` target.
GNU General Public License v2.0
33 stars 4 forks source link

Bad return code before reaching `main` when `fprintf` is linked with `aarch64-w64-mingw32-g++` executable #198

Open Blackhex opened 2 months ago

Blackhex commented 2 months ago

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.

ZacWalk commented 2 months ago

Interesting: fprintf itself is part of the C standard library, using it in a C++ program might indirectly trigger the initialization of parts of the C++ standard library. Constructors etc.

@Blackhex it might be worth taking a look at .init_array or the ctors list in the c++ output. Looking at the disam, ctors looks the same for both but a little weird for c++


0000000140008d78 <__CTOR_LIST__>:
   140008d78:   ffffffff    .inst   0xffffffff ; undefined
   140008d7c:   ffffffff    .inst   0xffffffff ; undefined`