Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Hi,
This is my first question since I created an account
I have a tiny kernel which is a raw binary and it is converted from ELF format usinig linker script
I defined .text, .rodata, .data and .bss in my linker script.
As we know, .bss information is not present in binary/executable file.
Now, here is my question.
Then, how does the memory corresponding to the size of .bss are allocated when machine loads kernel???
This can be a basic knowledge for some of you guys.
The bss section contains read-write static data that doesn't require an initial value to be stored in file. Therefore, the ELF file just simply stores the location of the start of this section and its size. The loader (whether it be the boot-loader or an elf parser in your kernel) then allocates that space in memory, and zeros it, done.
Hoozim wrote:that doesn't require an initial value
.bss is used for uninitialized variables and variables initialized as zero or NULL. You'll have to zero the memory you allocate because of the latter case.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
BMW wrote:If you are using a flat binary, wouldn't the .bss be included in the binary executable file?
No. In that case there's still no initialised data in the .bss (and no point storing "nothing" in the file).
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
BMW wrote:
To allocate space for it, do I have to make symbols that point to the start/end of .bss?
If you're using GCC then you'll be able to get the start address of the BSS and the address just after the BSS from the linker. See the manual page for "end" on linux.
bwat wrote:If you're using GCC then you'll be able to get the start address of the BSS and the address just after the BSS from the linker. See the manual page for "end" on linux.
movl $_end,%eax
subl $_edata,%eax # eax = $_end - $_edata (size of BSS)
pushl %eax # number of bytes to clear
pushl $_edata # starting location
call bzero
Thanks.
So those _end and _edata symbols are defined by GCC? And your .bss is at the end of the file so you don't have to make a space in the middle of your binary?
BMW wrote:
So this (Boot Sequence) is not 100% correct?
It depends on what you want to load. The BSS as we know it today is just a space optimisation used in certain languages/development tool-chains. You could write assembly code that didn't have a BSS section and load it with a simple load & go bootsrap loader.
Every universe of discourse has its logical structure --- S. K. Langer.
BMW wrote:Thanks.
So those _end and _edata symbols are defined by GCC? And your .bss is at the end of the file so you don't have to make a space in the middle of your binary?
If you're on linux, type "man end" or go here http://man7.org/linux/man-pages/man3/end.3.html and see how the symbols are used.
You don't have to shift stuff around, you'll only have to clear the BSS section. Unless of course you're doing something I'm not - I just keep it simple.
Every universe of discourse has its logical structure --- S. K. Langer.
bwat wrote:If you're on linux, type "man end" or go here http://man7.org/linux/man-pages/man3/end.3.html and see how the symbols are used.
You don't have to shift stuff around, you'll only have to clear the BSS section. Unless of course you're doing something I'm not - I just keep it simple.
Hold on, is the .bss present in a flat binary but not initialised? So all I have to do is zero it?
i.e. could I zero the BSS in the file so I didn't have to do it upon loading the binary?
bwat wrote:If you're on linux, type "man end" or go here http://man7.org/linux/man-pages/man3/end.3.html and see how the symbols are used.
You don't have to shift stuff around, you'll only have to clear the BSS section. Unless of course you're doing something I'm not - I just keep it simple.
Hold on, is the .bss present in a flat binary but not initialised? So all I have to do is zero it?
I have a program that copies the ELF TEXT & DATA segments to an image file which my bootstrap loader reads from disk. I don't create the BSS part of the image so I have to clear it in memory after it has loaded. I could generate a block of zeroes in the image for the BSS if I wanted to but that would increase the size of the image.
By zeroing the BSS section after the OS has loaded, you'll have a method that works regardless of the format of the OS executable that is loaded.
Every universe of discourse has its logical structure --- S. K. Langer.