Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why an executable program for a specific CPU does not work on Linux and Windows?

An executable problem like exe does not work on Linux (without wine). When compiling source code compiler produce object code which is specific to a particular cpu architecture. But same application does not work with on an another OS with same CPU. I know code may include instructions to specific to the OS that will prevent executable running. But what about a simple program 2+2 ? Confusing part is what the hell that machine code prevents working. Machine code specific to cpu right? If we strip executable file format could we see same machine code (like 2 + 2) for both operating systems?

One more question: What about assembly language? DO windows and Linux use different assembly language for same cpu?.

like image 750
Tony Cruise Avatar asked Jan 13 '10 19:01

Tony Cruise


1 Answers

There are many differences. Among them:

  1. Executable Format: Every OS requires the binaries to conform to a specific binary format. For Windows, this is Portable Executable (PE) format. For Linux, it's ELF most of the time (it supports other types too).

  2. Application Binary Interface: Each OS defines a set of primary system functions and the way a program calls them. This is fundamentally different between Linux and Windows. While the instructions that compute 2 + 2 are identical on Linux and Windows in x86 architecture, the way the application starts, the way it prints out the output, and the way it exits differs between the operating systems.

Yes, both Linux and Windows programs on x86 architecture use the instruction set that the CPU supports which is defined by Intel.

like image 93
mmx Avatar answered Jan 03 '23 06:01

mmx