Experiment and learn how compilers, linkers and C runtime work cooperatively
A statically linked executable is one which does not depend on any dynamically
loaded libraries. Traditionally, a statically linked executable is also not a
PIE. Hence, the ELF file of a statically linked executable will not
have a .dynamic
section. Further, since the executable is not a PIE, it will
not require any dynamic relocations to be applied. Consequently, the ELF file
of a statically linked executable will also not have a .dyn.rel[a]
sections.
Since a statically linked executable is not a PIE, one can do an experiment
using gdb: For different runs of the executable, after enabling
load address randomization in gdb, print the address of the main
function.
The address should be the same for the different runs. In contrast with a
dynamically linked executable, the address will change for every run if
address randomization is enabled.
NOTE: To enable load address randomization in gdb, do this:
(gdb) set disable-randomization off