This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Reduce size footprint of empty strings.
- From: Maxim Kuvyrkov <maxim at codesourcery dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Cc: Mark Mitchell <mark at codesourcery dot com>
- Date: Thu, 25 Feb 2010 13:54:17 +0300
- Subject: [PATCH] Reduce size footprint of empty strings.
This patch reduces the on-disk size of binaries by placing zero-filled
string variables to .bss.
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' call.
Thank you,
--
Maxim Kuvyrkov
CodeSourcery
maxim@codesourcery.com
(650) 331-3385 x724
Attachment:
fsf-gcc-string_cst.ChangeLog
Description: Text document
Attachment:
fsf-gcc-string_cst.patch
Description: Text document