Are the programs actually compiled in true binary?

For example, when I compile a C application, is the output file read as binary, or does the OS interpret the compilation? Is "machine language" pure binary?

EDIT: Yes, everything on the computer is pure binary. Im asking if the handler directly processes the file issued by the compiler, or does the OS process it first?

+8
compiler-construction operating-system
source share
6 answers

A compiled program usually contains a header followed by valid CPU instructions (what you can call "binary") + various other data.

When you try to tell the OS to load your program, the header will be read by the OS, and it will be used to verify that the executable is a really executable file for that OS and this architecture. That is, so that you do not accidentally run a Linux program on Windows or similar.

The header also contains various other bits of information about where the actual processor instructions are in the exeutable file, where the data segments are located (text, lines, graphics), etc.

Once the OS is happy that the executable is what it should be, then the OS will load the different segments from the executable into memory and instruct the CPU to run the “binary” code segment. This code is "clean" in a sense that it is direct processor assembly code.

However, the operating system may interrupt the processor (for example, switch to another program or simply kill the program from memory, etc.). Thus, there are a lot of things in this running program, and the kind of OS “controls” it and ensures that it behaves like a good boy, but the code itself, when it is running, executes clean processor instructions as quickly as possible .. without using the OS to interpret the code between them.

Also note that a running program can call the OS differently while it is running. For example, to request the OS to open a window on the display, open a network connection, allocate memory, etc. All that actually happens is that the processor simply proceeds to execute the code elsewhere (i.e., it jumps from running the code in the executable file, runs part of the code in the OS, and then jumps back).

What is this in a nutshell. However, there are many other ways to run programs. There are virtual machines, interpreted languages ​​(e.g. Java or Ruby), etc. And they all run programs differently from traditional “pure binary” languages ​​like C / C ++, but hopefully this helps you understand how this works a little better.

+16
source share

I think that you are really asking if compiled programs work on bare metal (they run independently of the OS). Very short answer: no. Although the program itself executes its own processor instructions, the OS is able to limit it and control its behavior. In addition, some external (dll) characters must be allowed during the boot phase. Finally, most programs rely on various abstractions of the operating system (access to memory, for example, recording your own swap functions is extremely complicated and pointless). In this sense, no binaries are standalone keyless machine code.

However, they are pure binary. Everything is on the computer.

EDIT

Another way to interpret your question is: - compiled programs - actually your own CPU instructions. The answer is yes (in addition to downloading the binary file with which the OS should help). Compilers output assembly language in which each line corresponds to exactly one CPU command. This is still text. The assembly is compiled by the assembler into the actual binary.

+3
source share

What does true binary mean? All data on the computer is 1 s and 0, although the CPU "interprets" the operation codes in accordance with the location of the internal gate and transistors. There is no platonic ideal of a binary language.

+2
source share

Applications like this are usually compiled into machine code, instructions directly executed by the processor:

http://en.wikipedia.org/wiki/Machine_code

x86 ASM is one of the most common. Think about it as your code is compiled to a very low level. This is a layer above 1 and 0, which is sent directly along the metal, if that’s what you have in mind, and the OS is still in control. But yes, in the end it all comes down to binary - everything on the PC will do!

0
source share

It should also be noted that interpreted languages ​​have virtual machine code. (It is still in binary format.) They are converted to machine code using a virtual machine, a software class. (Also a binary file.)

0
source share

I wonder why no one mentioned the linker concept.

Basically, the compiler output is actually a binary file, but there is a trick. This compiled binary is often called an object file that contains the code for the object . Now do not confuse yourself here. An object code is nothing more than machine code or binary code, as you call it, but only part of it. The compiler usually outputs several such object files from the source of one program. In fact, each of these object files contains part of the complete executable machine code for this program. This is the place the linker is in. It basically associates all of these object files with a full executable that the machine can run as a program.

0
source share

All Articles