So we know that linker
(in my case ld
) adds the Program Headers
to the Relocatable file
while creating the actual Executable
.
Then these Headers are used to load the program into memory at run-time.
First of all how
ld
calculates and adds these headers to the file?And then if the
Program Headers
are used only to load the program into memory (correct me if I'm wrong), how come different executables have different number ofProgram Headers
?
For example a simple helloworld written in assembly has 2 Program headers:
readelf -h helloworld
...
Number of program headers: 2
...
But the bash
has 11 program headers:
readelf -h /bin/bash
...
Number of program headers: 11
...