The linker is not technically part of the compiler, but it is needed to make a completed app. The purpose of the linker is to combine (link) all the various bits and pieces of machine code created by the compiler along with the necessary information to create a runnable app for the OS.
The Compiler series:
- Compilers 101 – Overview and Lexer
- Compilers 102 – Parser
- Compilers 103 – Semantic Analyzer
- Compilers 104 – IR Generation
- Compilers 105 – Back End Overview
- Compilers 106 - Optimizer
- Compilers 107 - Optimizer Loop Unrolling
- Compilers 108 - Code Generation
Each OS has a way to define an executable file so that it can run it. This typically involves some sort of header and a format that describes how the various machine code binary components are all combined. This is called an executable type, executable format or object file format.
This is what Xojo uses as the executable format when building 64-bit x86 and ARM apps using LLVM:
- For Linux, Xojo uses ELF (Executable and Linkable Format). This is a common standard used by many Unix-like systems.
- For macOS and iOS, Xojo uses Mach-O. This is the format that was introduced for Cocoa apps and dates all the way back to the NeXT days.
- For Windows, Xojo uses the PE (Portable Executable) format.
The Linker is responsible for combining all the machine code generated by the compiler for your project, adding libraries and generating the appropriate executable format. When the linker has finished, you have a native app that works on the operating system.
For 64-bit x86 and ARM apps using LLVM, Xojo uses the lld linker.
I hope you found the Compiler Series helpful. And when you need to easily create your own cross-platform and multi-platform apps for Windows, macOS, Linux, Raspberry Pi, iOS or the web be sure to check out Xojo!
Top comments (0)