An elf is seen as a collection of segments by the loader and collection of sections by the linker.
Program header table provides segment view of the binary segment.
View is used during loading the Elf in memory to create process layout, whereas section header table
provides a section view of the binary and this is used during linking.
Program headers are essential while running the executable because they inform the OS all it needs to
know how to put the executable into memory.
So kernel needs takes the Elf as an argument from system call Execve.
So we run uh execve.
In elf it goes to the kernel kernel.
What it does is it loads the Elf header and the program header table into memory.
And then whatever is specified in the load uh, type, that is also it loads the content into.
So first it is loading the elf header and then the program header table.
And then it checks the type whether the type is load.
Then if yes it will load into the memory that particular segment is loaded into the memory.
So if you see this first it checks the header.
It takes this header.
It reads this header.
Uh it reads uh the program header.
And then whatever is of type load uh it will take that from this particular file size and the offset
and will load it into the memory.
And also to check if interpreter is needed.
If this particular type is there, then it will also give the control to this.
Either it will give the control to this to load the dependencies, or it will give the control to the
executable.
So if you go into the Elf, you will have uh, a lot of code.
Uh, you have like thousands of lines of code, uh, like bin format.
Elf handler is there.
It is responsible for parsing out details of Elf file and using them.
Like if I go to the code, if I say.
Kernel.
Linux.
If I go ss I have I think this is present in bin format lf.
So there are different formats.
One is clef is the one format dot c.
Uh so you load clef binary.
Different things are here.
And if you see this this is almost 2000 lines of code okay.
And should have you can see read parameters.
All this information is there.
So it does not have uh it performs loading of parameters.
Should also see load or something.
Right.
So it leads.
You can read through this code.
It loads L parameters and all this.
So this is the file which is responsible for uh reading the l f headers and parameters.
And again copying the data into the memory.
And then finally giving back to the control to the our user space code.
So load l f binary is the function.
Uh which is responsible.
So load elf binary.
This is the function which is responsible.
It is checking first is checking whether it has e ident field.
It is of exact type or not.
It is reading the program headers and it is checking the interpreter type it interpreter type.
Right.
And it's doing a lot of things right.
It should also really read the PD type load I think.
Let me check whether we have pretty load.
So here also it is using PD load and all all those it is doing.
So if knowing about elf header then you can also understand this code because it is using the same.
I think it will use Elf should use.
And e.l.f.
Dot h header file as well.
So they also it is also using e.l.f dot h.