Re: Memory initialization (not)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 30 September 2008, Jim Dougherty wrote:
> Mihai DonÈu wrote:
> >     On Tuesday 30 September 2008, Jim Dougherty wrote:
> >>  I have a section of memory that I do not want to be initialized with
> >>  zeros when my program starts.
> >>  Is there a way to achieve this?
> >
> > I think that zero initialization is a consequence of how the process
> > images is
> > created. For example:
> >
> > static char a[65536];
> >
> > will make the .bss section of size ~65536 bytes which is allocated by the
> > dynamic linker by means of mmap() which always provides zeroed-out pages.
> >
> > So to answer your question: global variables are likely to be always
> > initialized with zero (it's out of gcc-s hands). Stack variables, on the
> > other hand, are "initialized" with whatever is on the stack, which yeah,
> > if you don't explicitly initialize them, could be called uninitialized.
> > :)
>
> I think that you are wrong although I do not know what the answer is.

I might very well. :) I did not know you were referring to an embedded system 
so I just assumed a common GNU based os.

> I am writing firmware for an embedded system that contains conventional
> general purpose RAM but it also contains a small amount of battery
> backed up RAM.  We store data in the battery backed up RAM that is
> basically permanent, the data is not lost when power is turned off and
> on.  In the case of this battery backed up RAM, we do not want the
> compiler writing over our good data at powerup.

I'm assuming (again) that the program will be created withing the same address 
boundaries and you want it's data sections to be mapped over an already 
initialized memory.

I am not aware of gcc generating initializer code without it being requested. 
Could you give us more details about the environment you are using to build 
your program?

> I have to believe that there is a way to do this but I do not know what
> it is?

-- 
Mihai DonÈu (unices.bitdefender.com)

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux