This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: initializing the .bss area

JJ <> writes:

> I'm writing a custom _start function in assembly. I'm using some old
> code as reference. It zeroes out the .bss area. I checked the
> disassembly of the generated binary and the bss area contains 0x0 by
> default. From what I read online, the bss area contains the
> uninitialized variables. If thats the case, isn't it fine to not
> explicitly initialize this in the _start?

The contents of the .bss section must contain zeroes when the program
starts to run.  Typically a binary does not actually include the .bss
section, it just specifies how large it is (in ELF this is done in the
program header by having p_memsz be larger than p_filesz).  If your
binary includes zeroes for the .bss section for some reason, then you
don't have to do anything further.  If your memory is guaranteed to be
zeroes for whatever reason, then you don't have to do anything
further.  In a typical embedded system neither is true, in which case
the startup code must explicitly zero the .bss section before jumping
to the program proper.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]