what is .bss segment, what saved in .bss segment?

what is .bss segment, what saved in .bss segment?

Post by Denis Pere » Thu, 07 Aug 2003 16:25:00



* hercules < XXXX@XXXXX.COM > [08-Tue-03 20:09 -0700]:
>

There are 3 (main?) segments/sections of the file produced
by a linker.

text - program text (and apparently const char arrays. maybe
other 'const' arrays, since those can not be changed
anyway). I am not 100% sure about the array part, maybe
someone will correct me.

data - initialized global data. see examples below.

bss - uninitialized global data.

Here are some examples
--------------------------------------------------------

int x = 1; /* goes into data */
int y; /* goes into bss */

/* i think this would also end up in text, but maybe data. I
* am not sure */
const int z = 1;

/* this, we've seen go into 'text',
* since can't be changed anyway,
* but can be protected */
const char array[] = {'a','b'....etc}

/* the rest goes into text */
int
main(void)
{
return EXIT_SUCCESS;
}

--------------------------------------------------------
Here is some more info on where name BSS might've come from.

*****
Block Started by Symbol

(BSS) The uninitialised data segment produced by Unix
linkers. The other segments are the "text" segment which
contains the program code and the "data" segment contains
initialised data. Objects in the bss segment have only a
name and a size but no value.
*****
BSS = "Block Started by Symbol"

Dennis Ritchie says:

Actually the acronym (in the sense we took it up; it may
have other credible etymologies) is "Block Started by
Symbol." It was a pseudo-op in FAP (Fortran Assembly [-er?]
Program), an assembler for the IBM 704-709-7090-7094
machines. It defined its label and set aside space for a
given number of words. There was another pseudo-op, BES,
"Block Ended by Symbol" that did the same except that the
label was defined by the last assigned word + 1. (On these
machines Fortran arrays were stored backwards in storage and
were 1-origin.)

The usage is reasonably appropriate, because just as with
standard Unix loaders, the space assigned didn't have to be
punched literally into the object deck but was represented
by a count somewhere.

****
The acronym BSS refers to the run-time uninitialized data
area and that the acronym has historical origins.

*****
from "Expert C Programming"
The BSS segment gets its name from abbrevbiating "Block
Started by Symbol" -- a pseudo-op from the old IBM 704
assembler, carried over into UNIX, and there ever since.
Some people like to remember it as "Better Save Space".
SInce the BSS segment only holds variables that don't have
any value yet, it doesn't actually need to store the image
of these variables. The size that BSS will require at
runtime is recorded in the object file, but BSS (unlike the
data segment) does not take up any actual space
--------------------------------------------------------

denis

--
'From' email address is used as a sink. Not read. Ever.
Instead, send to [p-o-s-t-i-n-g|o-v-e-r-w-h-e-l-m|n-e-t]
(remove dashes, replace the first vertical bar with @,
and second with a dot). Sorry for any inconvenience.