as far as i know, the bss section of any program should be zeroed on initialization, however, when i try to do this in my code (usually just before calling my real main function) my code dies miserably. I'm using C++, so at first i thought i was perhaps trashing some vtables, but they wouldnt go into the bss section anyway..
any thoughts, anyone who has been using C++ in there kernel bother to do this?
proxy
C++ and bss section
Re:C++ and bss section
Well, it must be possible to zero the bss, otherwise nobody would do it.
The way I do it is to zero the bss from the assembly-language startup code, before any C code is run. This way the C code can't start writing values to the bss before it is zeroed. A simple REP STOSD is enough, along with symbols (defined in a linker script) for the start and end of the bss section.
The way I do it is to zero the bss from the assembly-language startup code, before any C code is run. This way the C code can't start writing values to the bss before it is zeroed. A simple REP STOSD is enough, along with symbols (defined in a linker script) for the start and end of the bss section.
Re:C++ and bss section
It shouldn't be necessary. actually. According to the as User Reference
HTH. Note tha the reason [tt]auto[/tt] variables need to cleared, even if the BSS and stack segments are cleared beforehand, is because they are allocated on the stack; if a function is called, and then returns, whatever arguments and local variables it used will still be there when the next called function sets up its own stack frame.When your program starts running, all the contents of the bss section are zeroed bytes.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:C++ and bss section
it IS necessary:Schol-R-LEA wrote: It shouldn't be necessary. actually.
is only true when you're in an existing execution environment. But if you're building your own environment (and if you're programming an OS, there are chances you are ...), you'll have to wipe the BSS so that it will fulfill the requirements of the usual programming environment.When your program starts running, all the contents of the bss section are zeroed bytes.
Re:C++ and bss section
i figured out why i was having a problem my stack is an array (like in multiiboot example) which ends up in the BSS section. And by the time I was trying to zero things out, the stack was in use. So I was trashing the stack data...no good.
Thanks for the input, I just added a short block of asm in my initial boot.S which zeros out the bss section.
proxy
Thanks for the input, I just added a short block of asm in my initial boot.S which zeros out the bss section.
proxy