This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] Reduce size footprint of empty strings.
- From: Jeff Law <law at redhat dot com>
- To: Maxim Kuvyrkov <maxim at codesourcery dot com>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>, Mark Mitchell <mark at codesourcery dot com>
- Date: Thu, 25 Feb 2010 09:33:44 -0700
- Subject: Re: [PATCH] Reduce size footprint of empty strings.
- References: <4B8656D9.firstname.lastname@example.org>
On 02/25/10 03:54, Maxim Kuvyrkov wrote:
This patch reduces the on-disk size of binaries by placing zero-filled
string variables to .bss.I guess this officially ends the practice of allowing one to edit (via
adb or emacs) the binary's data section to provide a different
initializer for these objects. It was something I used to do with
regularity "way back when". I'm not objecting, just pointing out that
something that used to work isn't going to anymore.
Consider the following example:
static char filename1[MAXPATHNAME] = "";
static char filename2[MAXPATHNAME] = "";
static char filenameN[MAXPATHNAME] = "";
where MAXPATHNAME is a big number, 1024 or more is not uncommon.
Currently, GCC puts all these arrays into the .data section and
allocates chunks of zero-filled space for them. This is a shame
considering that the `""' initializers expand to '\0' and, thus, the
variables can be safely placed into .bss section instead. Data in the
.bss section is always zero-initialized before the program starts, so
there is no need to keep initialization image in the binary.
The tree.c:initializer_zerop() predicate is the one responsible for
identifying initializers that are sole zeroes at runtime.
This patch teaches GCC that `""', `"\0"', `"\0\0"', etc. are all
equivalent to zeroes.
The patch was bootstrapped and regtested on x86_64-linux-gnu (all
languages except ada) with no regressions.
OK for 4.6?
The patch is simple enough to be considered for 4.5, but this is RMs'