Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between two empty main{} programs with and without OS? [closed]

What is the difference between two empty programs main {} when compiled using a c/c++ compiler for target with OS (say linux) and without an OS (say for an embedded DSP target)? I am specifically interested to know what the compiler does differently when there is an OS and otherwise. How is the compiler/language runtime differ in two cases?

like image 268
Shan Avatar asked Dec 30 '12 13:12

Shan


1 Answers

It is actually the linker that does a different job when packaging a program to run on an operating system versus building a program that runs on the bare hardware alone. The compiler merely produces object files consisting of instructions targeted for the host architecture, and these chunks are later combined and packaged by the linker.

A program that is meant to run on an operating system has to have a certain binary structure -- this is where executable formats come into play. Such a format may dictate that the program should have a few header sections in the beginning and then the code should follow, for example. It is the job of the OS loader to interpret this structure and then feed the CPU with the stream of instructions that the code section contains.

In contrast, a program that is meant to run on the bare hardware usually doesn't have a special structure and can be fed directly to the CPU.

like image 132
Blagovest Buyukliev Avatar answered Nov 15 '22 21:11

Blagovest Buyukliev