Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Mar 2011 12:31:53 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Roman Divacky <rdivacky@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r219452 - in head/sys/boot: common i386/boot2
Message-ID:  <20110311112515.M1003@besplex.bde.org>
In-Reply-To: <201103101640.p2AGeDe4049512@svn.freebsd.org>
References:  <201103101640.p2AGeDe4049512@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110311112515.M1003>