There are two operations which are performed in relocation.
One is section merging, where each section is merged into the final executable, the next one is section
placement.
So in section placement, uh, when you are assembling, when you are running assembler on your dot
exe file, each section is assumed to start from address zero, and then labels are assigned relative
to relative to start of the section.
But when you are creating the final executable, the sections are placed at some address x, and then
the labels are also, uh, updated according to the value of the x.
So the placement of the section at a particular location in memory, and patching of all the references
to the labels in the section is done by the linker.
I can update the this particular section placement location.
For example, if I want to update the text section, uh placement location instead of using zero zero,
I want to use the address 0100.
I can use something known as this option to LD and I can change it.
So I will show you.
Now we are explaining some of array program, so I will take the sum of array.
Uh, I'll copy the object files, which we have some sub s main dot s, uh, just will use a single
program.
Here is.
Amen.
So I'll copy it here.
I'll now say array some oh some dot s and I will say symbol table some dot array some dot o.
So here you have everything starting with the address.
Uh zero.
And then they have assigned the corresponding uh values have been assigned to the labels.
Now the text segment for all the text segment I can use a.
Text no and LD.
LD is a linker, so I'm asking the linker to assign.
Place this text section at the address.
Uh, 0100.
Now the when you do this, it will see how it happens.
Uh, show you the symbol table.
Now symbol table.
So now it started placing the text section starting at the address 100, and the label addresses are
updated accordingly because the starting address of the section is 100.
So this is about section placement.
So section placement is.
So we have seen uh section merging and section placement are two operations which are performed in relocation.
Section merging means it will combine all the sections of all the object files text section, data section,
all into a single one object file that is merging.
And this is section placement.
If I want to place the text section at a particular address, if I want to place the data section at
a particular address, I can do it.
So if I will show you just this one example for this relocation, what is happening?
The relocation.
And in relocation we have two steps section merging and section placement.
So consider we have two assembly files a dot s and b dot s a dot s as a function of strcpy it has a
label strcpy y and v dot s has a label s trillion.
Now if you are giving this to the assembler, assembler will create an object file and it will assign
addresses starting from zero zero.
And same is for b dot s.
So we have a dot zero and b dot o.
We have this as a text section.
Assume this is a text section where the code is present.
All are having like uh addresses starting from zero zero to this.
Both are having addresses starting from zero.
Now comes the linker.
Linker performs two operations in relocation.
One is merging the text section.
So it will take the strcpy.
It will keep it here.
It will take the strlen.
It will keep it after the Strcpy is text section and it will update the addresses.
Now in the section placement I can inform the and this is patched.
I mean Strcpy y address and strlen is patched.
They have got a new addresses.
I mean I did not get new address because it has placed the starting of the section, but strlen has
got the newer, uh, actual new address here.
It will see, you know, it is uh, for alien was zero.
It is like 14 here.
This section merging merging sections text sections from two files.
Now section placement.
Placement is like we can place this instead of if you if I do not want to keep it zero I want to keep
it 230 and four zero.
I can keep it by using this t text option.
So yeah.
So what we need to understand is relocation is uh two steps section merging and section placement.
Section merging is merging two text from two files.
All the sections from two files.
In this example you are merging text sections and section placement is placing the section at a particular
address.