pub enum LinkMode {
Static,
StaticPie,
Dynamic,
DynamicNoPie,
Shared,
}Expand description
How the program is linked, which decides the first start file and the flags.
Five cases rather than two booleans for static and position independent, because the two are not independent and the start file is a different file in four of the five. A pair of flags would admit a sixth combination, a shared object that is not position independent, which is not a thing any of these linkers will produce.
Variants§
Static
Everything in the binary, no interpreter, no relocation at load. The default for musl, and
the mode spec/cross-compile/02-the-goal.md’s exit criterion names.
StaticPie
Static, and position independent, so the loader may place it anywhere. A different first
start file, because the program has to relocate itself before main and rcrt1.o is what
does that.
Dynamic
Against the shared libc, position independent, with the libc’s loader named in the program
header. What every distribution builds today and what -pie asks for.
DynamicNoPie
Against the shared libc, at a fixed address, which is -no-pie.
The same link as LinkMode::Dynamic with a different start file, because the reference to
main in crt1.o is an absolute one and the reference in Scrt1.o is not. Build systems
that pass -no-pie are usually doing it because something in them takes the address of a
function and compares it, and they get the file that matches.
A shared object rather than a program, which is -shared.
No start file at all, since nothing starts a shared object and it has no main to be
started at, and no loader named either: the program that loads this one carries that.