| Author |
Message |
Utkarsh
Guest
|
Posted:
Sun Dec 11, 2005 5:15 pm Post subject:
what for .bss segment? |
|
|
Hello Guys,
I am new to this group and embedded domain.
Can anyone please tell me the utility of .bss section. (stores
uninitialised data)..but why can't it be stored in Data segment
(together with other initialised data)?
what is the advantage/ need of .bss segment?
Regards,
Utkarsh. |
|
| Back to top |
|
 |
MetalHead
Guest
|
Posted:
Sun Dec 11, 2005 5:15 pm Post subject:
Re: what for .bss segment? |
|
|
Utkarsh wrote:
| Quote: | Hello Guys,
I am new to this group and embedded domain.
Can anyone please tell me the utility of .bss section. (stores
uninitialised data)..but why can't it be stored in Data segment
(together with other initialised data)?
what is the advantage/ need of .bss segment?
|
In a ROM based system, when you put a variable in the Data (initialized
data) segment, it requires rom storage for the initialization value and
address. It also requires the C startup code to take the time to
initialize the RAM location. For scratch buffers and maybe the heap (if
used) this can be a lot of wasted space and time.
In a disk based system, it still effects the image size and startup time
of a program.
Normally the un-initialized storage still gets set to 0 by the startup
code, but that can be removed by the person writing the startup code
(crt0.s or crt0.c).
Good Luck,
Bob |
|
| Back to top |
|
 |
Hans-Bernhard Broeker
Guest
|
Posted:
Mon Dec 12, 2005 3:37 pm Post subject:
Re: what for .bss segment? |
|
|
Utkarsh <u4karsh@gmail.com> wrote:
| Quote: | Can anyone please tell me the utility of .bss section. (stores
uninitialised data)..
|
It doesn't. It stores variables that don't have an explict
initializer given by your code, but which are nevertheless initialized
(to all-bits-zero). It may even hold those that do have an explicit
initializer --- if that initializer is zero, your platform a sane one,
and your compiler a clever little bastard.
| Quote: | but why can't it be stored in Data segment (together with other
initialised data)?
|
It could. But that would be rather spectacularly wasteful. There's
no good reason to a store lots of zero-bytes as part of the program,
when you can just have the startup code to the equivalent of a
memset(start_bss, 0, length_bss)
instead.
Basically, the .bss segment is a poor man's initialiser data
compression algorithm.
--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain. |
|
| Back to top |
|
 |
#define
Guest
|
Posted:
Mon Dec 12, 2005 5:15 pm Post subject:
Re: what for .bss segment? |
|
|
Hello,
But from my C (DOS) programming exp. all the static and global
variables (that take DS or .bss) are by default initialised to 0.
So from where the case of having "uninitialised data" come from? This
really beats me.....
Also, "They" say that it allows effective usage of memory (EEPROM/ RAM
etc). Does it make any sense?
Regards,
#define (trying my new nickname :-)) |
|
| Back to top |
|
 |
Meindert Sprang
Guest
|
Posted:
Tue Dec 13, 2005 12:32 am Post subject:
Re: what for .bss segment? |
|
|
"#define" <u4karsh@gmail.com> wrote in message
news:1134405307.741196.302540@g14g2000cwa.googlegroups.com...
| Quote: | Hello,
But from my C (DOS) programming exp. all the static and global
variables (that take DS or .bss) are by default initialised to 0.
So from where the case of having "uninitialised data" come from? This
really beats me.....
|
const int test = 10;
is initialized and
int test;
isn't.
| Quote: | Also, "They" say that it allows effective usage of memory (EEPROM/ RAM
etc). Does it make any sense?
|
The former uses ROM to store 10 and the latter doesn't.
Meindert |
|
| Back to top |
|
 |
Meindert Sprang
Guest
|
Posted:
Tue Dec 13, 2005 1:15 am Post subject:
Re: what for .bss segment? |
|
|
"#define" <u4karsh@gmail.com> wrote in message
news:1134415661.398433.62210@z14g2000cwz.googlegroups.com...
| Quote: | But....
int test;
"test" will be either static or global (to be stored in .bss) with
default value 0!!
Is it not initialised with value 0???? if not, then it's fine...but if
yes, then i've not got the ans. of my question :-(
i think .bss lands in on-chip EEPROM/ FLASH.
|
The difference is that a const is initialized with a specified value, which
is stored in ROM. So the ROM contains a copy of every const variable. This
takes up space. A non inilialized variable is simply cleared on startup.
There is no copy in ROM for that, the startup code simply clears all the
variables in the .bss segment to 0 in a loop. That is, when you do not
modify this behaviour by changing the startup code. In many embedded
systems, this clearing is skipped because such a system would have to
recover from a reset without clearing the entire state of the device. You as
the programmer are then responsible for clearing these variables, if
necessary.
Meindert |
|
| Back to top |
|
 |
Grant Edwards
Guest
|
Posted:
Tue Dec 13, 2005 1:15 am Post subject:
Re: what for .bss segment? |
|
|
On 2005-12-12, #define <u4karsh@gmail.com> wrote:
| Quote: | int test;
"test" will be either static or global (to be stored in .bss) with
default value 0!!
|
Right.
| Quote: | Is it not initialised with value 0????
|
Yes it is.
| Quote: | if not, then it's fine...but if
yes, then i've not got the ans. of my question :-(
|
Everything in the .bss section is usually initialized to 0 by
startup code.
| Quote: | i think .bss lands in on-chip EEPROM/ FLASH.
|
You think wrong.
Lame.
--
Grant Edwards grante Yow! .. I'll make you
at an ASHTRAY!!
visi.com |
|
| Back to top |
|
 |
#define
Guest
|
Posted:
Tue Dec 13, 2005 1:15 am Post subject:
Re: what for .bss segment? |
|
|
But....
int test;
"test" will be either static or global (to be stored in .bss) with
default value 0!!
Is it not initialised with value 0???? if not, then it's fine...but if
yes, then i've not got the ans. of my question :-(
i think .bss lands in on-chip EEPROM/ FLASH.
#define |
|
| Back to top |
|
 |
Paul Keinanen
Guest
|
Posted:
Tue Dec 13, 2005 9:15 am Post subject:
Re: what for .bss segment? |
|
|
On 12 Dec 2005 08:35:07 -0800, "#define" <u4karsh@gmail.com> wrote:
| Quote: | But from my C (DOS) programming exp. all the static and global
variables (that take DS or .bss) are by default initialised to 0.
|
That is just a peculiarity of the C-language standard that require
such initialisation, however, many languages do not make any
assumption about the initial value. A proper linker input (object)
file specification should be source language independent.
It is up to the C-compiler to assign addresses into the data segment
and the C-language initialisation code to clear the data segment at
startup, move any non-zero initial values to the data segment before
starting the main() function.
Paul |
|
| Back to top |
|
 |
Hans-Bernhard Broeker
Guest
|
Posted:
Tue Dec 13, 2005 5:15 pm Post subject:
Re: what for .bss segment? |
|
|
Meindert Sprang <mhsprang@nocustomspamware.nl> wrote:
| Quote: | The difference is that a const is initialized
|
'const' has nothing to do with the issue at hand.
| Quote: | with a specified value, which is stored in ROM. So the ROM contains
a copy of every const variable. This takes up space. A
non-inilialized variable is simply cleared on startup.
^^^^^^^^^^^^^^^ ^^^^^^^ |
That's contradictory. A variable of static storage duration is
*always* initialized, regardless of whether it came with an explicit
initializer in its definition or not.
So the difference is not whether it's initialized or not, it's what
the initial value is. Sometimes the initialization can be done by a
simple clearing of all bits to zero, sometimes it can't. If it can,
it's advantageous to do so.
--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain. |
|
| Back to top |
|
 |
|
|
|
|