He left sections.
The code and the data in an Elf binary are logically divided into contiguous, non-overlapping chunks
called sections.
We have already seen the section sections, right?
Uh, we have seen the bare metal programming.
We have seen the text section, the data section, the BSS section and all.
Already we have seen what are those?
What is the use of text section.
So why we are dividing into sections to provide a convenient organization for use by the linker.
So when you when you use a space code is compiled.
When when a program is compiled, different things are generated of the compilation.
All your code is going into the text section.
All the initialized variables are going to the data section.
All uninitialized variables are going to the BSS section.
This is on the local not local.
So global uninitialized variables.
All strings constant strings are grouped into this particular section such as STR assets.
Start AB.
All variable so all constant strings are grouped into not this section.
It is uh grouped into the row data section.
This row data section will go there.
We have uh assets section header string table as well.
But that is a different use.
We have row data section.
And you have something all the variables and function names which we see in when you do an enum command
goes into the sim tape sim tab section sim symbol table section.
All the debug information is grouped into the debug section.
So what we are seeing is sections provide uh divide sections.
Logically divide the code and data in an Elf binary into contiguous non-overlapping chunks, so into
different sections.
So all your yellow file is divided into different sections.
So how do we view the sections.
We have seen the command for uh we have seen the command for reading the headers.
Hyphen h.
So really hyphen h we view the elf header and the elf hyphen s capital S will give you the sections.
So let's see from a simple understanding of a simple code.
So I have a very simple code here which where I have a message hello elf, a string, constant string,
and I have a global variable.
Then I have a uninitialized global variable.
So this value should be initialized by the zero.
Okay.
Let me compile this code.
I'll only generate an object file okay.
So.
Now I have only generated an object file and I will also generate an executable.
So now I have this simple two files.
Now I can do a file and.
I have a object file and I have an executable file.
Now I do an elf hyphen h on user space dot o.
And this is what you were doing till now using elf.
Uh, the commands you are doing this all operations.
Now we now know that we have sections in the Elf file.
To view the sections, we have a command known as elf s user space dot oth.
So if you see this we have different sections.
And this is having uh a name type address of set size.
All this and this is not properly printed on the screen I can use an option plus w or I can say wide.
Now this will print in a wide format.
And this is easily understandable.
Here you need to see it.
Prints in a two line and header is also in two line.
So this wide option is very useful.
So you can see uh a normal object file is nearly having 15 sections zero based indexing which is based
indexed.
So 15 sections are present where you have text section, data section, base section.
Uh, this we already have seen in the bare metal they were having this section.
But in a Linux user space code you have lot of other sections.
Newcom's.
Let's see into executable file.
It has more than that.
So a normal object file uh which which was generated by an assembler only has 15 sections.
But when it, when the linker takes this object file and generates an executable file, it has 28 sections,
29 sections.
Okay.
We'll see what we have.
We know like text section contains the code.
We know R0 data contains the constants.
We know data section contains the global variables.
We know the BSS section contains the uninitialized global variables.
Okay.
Now let's see from this example I will say I'll print the code.
Of the.
I want to read.
I want to read the code section.
Okay.
There is no code section, right?
I want to read the text section from the this object.
So text section is very simple here.
It does not have anything in the code.
So if I see the user space code I'm just returning zero okay.
So the text section does not have much information.
But if you see the text section of the executable, it has a lot of information because C library comes
into picture.
Right?
Now let's look into the data section of user space.
Object file and data section contains 123456 right in a little endian format.
If you see this is what we have stored in the global variable okay.
Global variable is uh data section stored in the data section.
And we can easily observe that this is a 32 bit uh value.
And this is the same.
So we have uh in the data section, the global variables or the global variables are stored in the data
section.
Local variables will be stored in the stack not in the data section.
So now we have this.
We have seen the global variables are stored in the data section.
And then comes the message.
Message will be stored in the row data section.
So hello elf is a constant string which is a constant which will be stored in the row data section.
And you can see hello elf is stored in the.
Rotate a section.
You can also find this.
So you have auto data section with the.
Constant strings are stored, then we have BS.
BS is not a BS.
BS section is there?
But it does not have data to dump.
And we have this code which has BS.
I mean this is a value which is uninitialized and it has to go to the BS.
Okay.
Now we'll and we have the command saying it has no data to dump.
Why it is like that.
So if you see readelf uh headers it has a wide.
And it has BCIs.
And if you see size is zero.
We'll see why obstruction is zero.
But still we will be having the values assigned to of this variables to zero in our upcoming videos.