We have seen about Elf headers, and we know Elf is divided into mainly four parts.
Elf header.
Elf sections.
Section header and sections.
Program headers and segments, and then the object code.
So we have seen about elf header.
Now let's look into sections and segments.
So to understand section and segments we need to know who is using Elf file.
There are two tools which are using Elf files.
One is the linker.
Linker comes when you are compiling your code.
So linker comes after the assembler generates the object file.
So linker it combines multiple Elf files, the multiple object files finally into an executable or a
library the shared library or static shared library.
So this is when after uh after you have compiled your assembly code into object code, linker comes
into picture.
It performs merging of the text section.
It needs merge.
It needs to know where the text section in the object file is.
Data section is bsis.
It will merge them with all the other object files, and any relocations needs to be performed to do
that.
You know what is the functionality of linker section, placement section merging, relocation symbol
resolution.
So all this are performed by linker.
So elf.
So linker needs to know all the details for performing those operations.
It needs to know where the text section is.
And the data section is where the BSS is.
After the executable is generated.
Now comes the part of the loader.
Loader loads this executable file in the memory of the process.
So in the.
As bare metal programming we have seen about the startup code, it places the perform some operation
where it places the data section in the Ram.
And.
All right.
So that is a loader loader require also needs to know about some uh needs to know which parts of the
file are code, which parts of the file are the data, which is read only data, where I need to keep
the BSS in the memory of process, all those needs to be known by the loader.
So for this two tools linker and loader.
Elf file contains two tables.
One is section header table which points with which has pointers to sections to be used by the linker,
and the other is a program header table, which has pointers to segments to be used by the loader.
So important point is your linker and loader are the two tools which uses Elf files.
Each of them have some tables where for linker has section header tables table which has pointers to
sections.
Loader has program header table with pointer to the segments, and both tables are simply arrays of
entries that contains information about each part of the Elf file.
For section header table.
It contains information about where the section are which is used by the linker, and for program header
table, it will have pointers to the section segments which is used by the loader.
So this is a basic Elf file.
You have Elf header.
Then you have program header which is pointing to the segments, uh entries of segments.
And then you have finally at the bottom you have section header which is pointing to the getting giving
you the linker the information about sections.