From: sdw@meaddata.com (Stephen Williams) Subject: Re: IMPORTANT [BUG in 0.99] Re: [ANNOUNCE]: linux version 0.99 Date: 29 Dec 1992 15:54:04 GMT
Lars Wirzenius (wirzeniu@klaava.Helsinki.FI) wrote:
: >Just curious - I haven't got the .99 sources yet, but why is an explicit
: >initialiser needed here. A static pointer ought to be initialised to
: >NULL in the executable already?
NOT!
:
: In normal C programs, yes, but the kernel is a bit special. Like, for
NOT!
: instance, who is going to do the initialization? Normally it is the
: kernel (which zeroes out all memory before it is given to a user
: process), the linker (which loads the pre-initialized variables from a
: file, i.e. those variables which are given an explicit initializer),
: and possbily the C startup code. Trouble is, none of these are active
: when the kernel is booting...
Statics are either explicitly initialized or they are not.
If they are not, their contents are UNDEFINED until set.
This is per ANSI C.
There is NO requirement of the compiler or system to zero
un-initialized statics (or auto's).
The fact that some systems waste time doing so is no reason rely on it
as a feature. This was already debated and tossed out as something to
rely on.
If you wanted to clear the bss segment, as an explicit optimization
over having nulls in your executable, link a dummy module first (ok,
after crt0.o) and last that each have a dummy bss variable.
Then, asap in main, do: memset(dum_beg, 0, dum_end-dum_beg);
This will only definitely work for 32 bit (non-segment) code.
You could also use the sbrk function's variable for the end of memory
(the sbrk() function uses this to remember where memory ended before a
new brk() sys call) and something at the beginning. (Doesn't crt0.o
have a bss variable for environp that it sets?)
And, yes, it would be nice if the nulling were garunteed. The problem
I think is the overhead incurred for a program that has a huge bss and
doesn't need it initialized. A better solution would be (if it
weren't for the headache..) to have bss and bsz segments.
sdw