From owner-svn-src-all@FreeBSD.ORG Fri Mar 11 01:31:58 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4CE4B1065672; Fri, 11 Mar 2011 01:31:58 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail08.syd.optusnet.com.au (mail08.syd.optusnet.com.au [211.29.132.189]) by mx1.freebsd.org (Postfix) with ESMTP id DBBA08FC0A; Fri, 11 Mar 2011 01:31:57 +0000 (UTC) Received: from c122-107-125-80.carlnfd1.nsw.optusnet.com.au (c122-107-125-80.carlnfd1.nsw.optusnet.com.au [122.107.125.80]) by mail08.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id p2B1VrO5007662 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 11 Mar 2011 12:31:55 +1100 Date: Fri, 11 Mar 2011 12:31:53 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Roman Divacky In-Reply-To: <201103101640.p2AGeDe4049512@svn.freebsd.org> Message-ID: <20110311112515.M1003@besplex.bde.org> References: <201103101640.p2AGeDe4049512@svn.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed 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 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Mar 2011 01:31:58 -0000 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