Welcome to the chapter about the toolchain behind the Linux kernel. This chapter describes the tools which are used to build the kernel and the format of the binaries they produce - from the moment you execute make in the root of the kernel source tree, through linking of object files, to the resulting ELF binaries and the assembly code embedded in the kernel sources.
This chapter assumes you are comfortable with basic computer architecture and have a light familiarity with the C programming language and x86_64 assembly syntax. You do not need to be a kernel expert, but being able to read short code snippets and recognize hardware terms will help.
Each part of this chapter focuses on one tool or format. The parts build on each other, so read in order the first time, then revisit individual parts as references when you need to recall how a specific tool or format works. It is quite useful to have the source code of Linux kernel on your local computer to follow the details. You can obtain the source code using the following command:
git clone git@github.com:torvalds/linux.gitAlternatively, you can get the source code through the GitHub CLI:
gh repo clone torvalds/linuxWhen reading this and other chapters, you may encounter special notation:
makeandMakefile- refer to the build tool which drives the kernel compilation and its input filesvmlinuxandbzImage- the resident kernel image and the compressed bootable kernel image*.o- denotes object files produced by the compiler before linkingELF- is the Executable and Linkable Format, the standard binary format on Linux__asm__- marks inline assembly statements embedded inCcode0x...- denotes hexadecimal values
- What happens when you execute
makein the root directory of the Linux kernel source code and how thebzImageis produced - How the linker combines object files into an executable and how linker scripts control this process
- The structure of
ELFbinaries and how the Linux kernel describes them in its source code - How to read and write inline assembly statements in both their basic and extended forms
The topics in this chapter are independent of one another, so you can read the sections in any order. The chapter covers the following topics:
- How the kernel is compiled - from the
makeexecution to the building of thebzImage - Linkers - the linking process, object files and linker scripts
- Executable and Linkable Format - the structure of
ELFbinaries and their representation in the kernel - Inline assembly - basic and extended forms of inline assembly with examples