msys2 / MSYS2-packages

Package scripts for MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
1.29k stars 485 forks source link

After the update the GCC compiler broke in the MSYS environment #2964

Closed Centrix14 closed 2 years ago

Centrix14 commented 2 years ago

It's going to be a long story, have a seat!

Today I decided to start developing my own little shell like bash. To begin with, I decided to write a program that runs something using fork and the exec family of functions. Here I came across a problem: there is no wait.h in the MINGW64 environment. After digging into the issue of the project, I realized that I would have to use the MSYS environment. Next, I updated gcc in MSYS, and found a strange thing: my test program compiles, but does not run. The shell returned the following: ./test: unable to run binary file: Exec format error. Very strange, I thought. To sweep away any doubts, I threw a simple hello-world and got the same thing - the compiled file does not run. After that I compiled the same file in MINGW64 environment. And everything worked. I have the same versions of GCC in MINGW and MSYS - 11.2.0 I didn't stop there, and decided to shove the non-working exe into the ldd utility, which got the expected result: Bad file descriptor. Then I decided to compare the files. And indeed, not only did the working version weigh 125 KB, and not only 61 working, but they also begin to differ from a byte with an offset of 0x86. In the working version, the number 0x13 is written at this address, and in the non-working version - 0x12. Further, the files are strikingly different. At the same time, the file utility considers that both files: PE32+ executable (console) x86-64, for MS Windows. The same situation is observed in the MINGW32 environment: GCC returns non-working code.

How to reproduce it?

  1. Update the GCC compiler in the MSYS environment to the latest version.
  2. Compile the simplest hello-world in C:
    
    #include <stdio.h>

int main(void) { puts("Hello, world!");

return 0;

}


4. Run the received file. Does not work.
5. Compile the same code in MINGW64. To run. Works!

## Context

- OS: Windows 8.1 x64
- GCC v11.2.0

Just in case, I attach the received executable files. test-mingw64 is an exe obtained in the MINGW64 environment, test-msys is the result of compilation in MSYS
[issue.zip](https://github.com/msys2/MSYS2-packages/files/8602733/issue.zip)
.
Biswa96 commented 2 years ago

Every compiler working fine in my system, using those every day.

Centrix14 commented 2 years ago

@Biswa96 Very interesting! Tell me, what OS do you use, what version of GCC do you have?

Biswa96 commented 2 years ago

I'm using Windows 10 (whatever the latest version number is). All latest msys2 and mingw packages https://packages.msys2.org/search?q=gcc

Centrix14 commented 2 years ago

Ok, the problem was solved after a complete reinstallation of MSYS2. Sorry for noise.