This is the mail archive of the gcc@gcc.gnu.org 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]

Re[2]: bss section not getting zero-initialised vars


Mike Stump wrote:
> > etienne lorrain wrote:
> >  I am probably not getting something obvious, but in C (gcc-2.95.2
> >  or more, did not test before) my zero initialised variables are not
> >  set to the .bss section but to the .data section (as seen in
> >  assembler file).
>
> Yes, this is true.  gcc doesn't have the optimization where we move
> zero inited things into bss.

  That is the answer to my question, seems to be one "imperfection".

> >   Looked at deja.com, found "-fconserve-space" on a
> >  2 years + discussion on djgpp, it does not work here.
>
> Yes, it does work, you just are using the case where it works.

  I do not understand 100%: I am on Linux-i386 as I said, and retried
 yesterday; -fconserve-space or -fno-conserve-space does not change
 anything, are documented as obselete and only for C++.

> >   Does someone has a pointer to how to get
> > int my_variable = 0;
> >  onto .bss section automatically, without using "int my_variable
> > __attribute__((section("bss"))) = 0;" ?
>
> Sure, remove the = 0 on it.  Also, on my system (x86 linux) mine get
> placed into bss all by themselves, meaning -fconserve-space on my
> platform does nothing.

  If you remove the initialisation, and whatever attribute((section()))
 you supply, you get your variable in the ".common" section - look
 in the assembler file generated. The linker will map the ".common"
 and ".bss" sections together to produce one "BSS" section for
 the operating system.

  The only "imperfection" is that all zero initialised variable
 are mapped to the ".data" section, so the size of the executable
 file is bigger - it does only matter for me because I am reading
 this file from a floppy.

 Usually, I better like to keep variables (and structures) initialised
 when I am assuming it in the logic of the software; what would you
 think of someone writing:

unsigned global_variable;

void fct (void)
  {
  if (global_variable == 0)
      global_variable = init_global_variable();
  }

  Have a nice day,
  Etienne.
___________________________________________________________
Do You Yahoo!?
Achetez, vendez! À votre prix! Sur http://encheres.yahoo.fr

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