Skip to content

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

Open
@Blackhex

Description

@Blackhex

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 and aarch64-w64-mingw32-g++ they are identical and when then they are linked with aarch64-w64-mingw32-g++ it fails while with aarch64-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 by aarch64-w64-mingw32-gcc good-exe.txt linkers are showing some differences.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions