Closed Centrix14 closed 2 years ago
Every compiler working fine in my system, using those every day.
@Biswa96 Very interesting! Tell me, what OS do you use, what version of GCC do you have?
I'm using Windows 10 (whatever the latest version number is). All latest msys2 and mingw packages https://packages.msys2.org/search?q=gcc
Ok, the problem was solved after a complete reinstallation of MSYS2. Sorry for noise.
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, thefile
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?
int main(void) { puts("Hello, world!");
}