This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Reduce size footprint of empty strings.


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.

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,

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.

jeff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]