On Thu, 10 Mar 2011, Roman Divacky wrote:

Log:
 Some more shrinking.
...
    o    kname is explicitly initialized in main() as BSS
         in boot2 is not zeroed

Not zeroing the bss is very fragile and broken, and would save a negative
amount of space once other bugs are fixed:
- many other variables depend on the BSS being zeroed.  One is the critical
  `opts' variable -- this is only accessed by read-modify-write instructions
  which always read garbage unless the BSS is zeroed.
- -fno-zero-initialized-in-bss is missing in CFLAGS.  This confuses naive
  compilers into believing that the BSS actually works so that it is safe
  for them to translate bogus explicit initializations to zero like
  `char *kname = NULL;' from zero-data in the data section to
  implicitly-zeroed data in the BSS.
- fixing CFLAGS gives no change in boot2.o, except in the old version with
  "char *kname = NULL;" it moves kname from the BSS to the data section,
  thus expanding boot2.o by 4 bytes.
- initializing kname in main() takes a lot of code (10 bytes).  10 is
  because the code is pessimized for space.  It is "movl $0,kname".
  Good code in main() would take 7 bytes for the first zero-initialized
  variable and 5 bytes for each additional one
  ("xorl %eax,%eax; movl %eax,kname; movl %eax,opts; ...").  But this
  would still be bad code.  It takes 15 bytes for 2 variables and may miss
  many.  Initializing the whole BSS would takes at most 14 bytes for
  "movl $edata,%edi; movl $end-edata,%ecx; xorl %eax,%eax; rep stosb"
  (less if %eax is already 0 (only need %al) or the 0 in it or %ecx can
  be reused; less if the high word of %edi or %ecx is already 0 so that
  only the low word needs to be loaded).

Bruce
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to