[comp.unix.i386] Initialization of .BSS question.

joe@proto.COM (Joe Huffman) (06/28/90)

I am porting the runtime library from a MSDOS compiler to UNIX.  Under
SCO UNIX (first target) the .BSS segment is initialized to all 0's by
the OS (at least prior to the application code getting control).  Under
MSDOS this was the responsiblity of the startup code.  I currently have
it removed from the UNIX version but was a bit concerned that under some
versions of UNIX it may be necessary to include it.  As other discussions
have pointed out, it would be a security hole if it were to be left as
garbage from other programs.  But it could be initialized to something
other than 0, assuming that it was the runtime libraries responsibilty to
set it to 0.

The question is:  Are there existing/going-to-be any i386 UNIX's that do not 
initialize the .BSS section to 0?

Email is fine, I don't think this is of particularly wide interest...

Thanks.

-- 
joe@proto.com
uunet!proto!joe
FAX: 208-263-8772

cpcahil@virtech.uucp (Conor P. Cahill) (06/29/90)

In article <1319@proto.COM> joe@proto.COM (Joe Huffman) writes:
>I am porting the runtime library from a MSDOS compiler to UNIX.  Under
>SCO UNIX (first target) the .BSS segment is initialized to all 0's by
>the OS (at least prior to the application code getting control).  Under
>MSDOS this was the responsiblity of the startup code.  I currently have
>it removed from the UNIX version but was a bit concerned that under some
>versions of UNIX it may be necessary to include it.  As other discussions

ANY C compiler, when building an executable for a hosted environment, on any
machine under any OS that doesn't initialize all of non-initialized global
variables (.BSS) to all 0's is VERY BROKEN.

You will not have to add any initialization code to set this stuff to 
zero.  (And should not have to add it to your DOS compiler.  (However, 
you DOS compiler may have this stuff in it's setup code that is called
prior to your main() routine, but you should not have to be aware of this
mechanism)).


-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 

joe@proto.COM (Joe Huffman) (06/30/90)

In article <1990Jun29.014319.11970@virtech.uucp>, cpcahil@virtech.uucp (Conor P. Cahill) writes:
> In article <1319@proto.COM> joe@proto.COM (Joe Huffman) writes:
> >I am porting the runtime library from a MSDOS compiler to UNIX.  Under
> 
> ANY C compiler, when building an executable for a hosted environment, on any
> machine under any OS that doesn't initialize all of non-initialized global
> variables (.BSS) to all 0's is VERY BROKEN.
> 
> You will not have to add any initialization code to set this stuff to 
> zero.  (And should not have to add it to your DOS compiler.  (However, 
> you DOS compiler may have this stuff in it's setup code that is called
> prior to your main() routine, but you should not have to be aware of this
> mechanism)).

[FLAME ON!]
Was I so unclear on this??  Nearly all the respondents seemed to
misunderstand me.  I am porting (part of) the compiler!!  The setup code that 
calls main is what I was concerned about.  This is MY code that calls main() 
(among other things).  I know that .BSS MUST be set to zero (by somebodies 
code, OS or compiler) or else I wouldn't be worrying about it or have been 
assigned this task.  My concern was whether all UNIX's could be depended on 
for this.  Not whether all 'C' compilers could be counted on for this in your 
application code.  I am aware of that and that is why I was concerned, I did 
not want to ship a 'VERY BROKEN' C/C++ compiler.
[FLAME OFF!]

Thank you for your responses.  There were a couple of people who understood
my question and answered it adequately.

Sorry (well, some anyway) for spouting off.  Next time (coming up soon) I will
be a bit more explicit about what I'm asking about.


-- 
joe@proto.com
uunet!proto!joe
FAX: 208-263-8772