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
32 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 1 month ago

Blackhex commented 1 month 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 1 month 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`