compiler – Is an OS compiled every time it boots?

Put simply, compilation is the process of turning human-readable source code into machine-readable binary instructions. Once you have those instructions in place, you generally want to reuse them as much as possible, because executing something is much, much faster than compiling it. That’s no different if the program you’re compiling is a game, a word processor, or the kernel of an operating system – except that the bigger the program, the bigger the cost of recompiling it.

There are basically two reasons to recompile something:

  • Because you’ve changed the source code to do something completely new.
  • To optimise the binary program for a new situation, such as a different CPU instruction set.

Occasionally, these two things go hand in hand, because to squeeze the most performance out of something, you want to remove all decisions while it’s running, and hard-code options in the source code before compiling.

This is probably where you’ve heard about kernels being recompiled: because the source code of the Linux kernel is freely available and designed in a particular way, you can recompile it with certain features that you don’t need switched off, or certain options hard-coded. But that’s something that will be done manually by expert users, not something that happens during the normal usage of a Linux system.

With Windows, the answer is even more clear cut: only Microsoft and a few people they’ve made specific arrangements with have the source code to their kernel, so only they can compile it. If you have a copy of Windows, what you have is the binaries they’ve compiled, and your PC just executes them.