Hello everybody, I'm looking for a nice solution.
One of my programs has a lot of strings in it; about 20% of binary size, or something like that. Now most of them are rarely used - error messages like "Cannot write to file", "No space left while allocating memory", etc. I tried to compress just the help texts in the binary - and saved 11k without any other modification. Now I'd like to wrap that in some magic macro, so that it looks like that: char *text=C("text"); Then there could be #if USE_COMPRESSED_TEXT #define C(x) ... #else #define C(x) x #endif but that's where I'm stuck. It's easy to write a function that takes a pointer to some compressed space and returns a pointer to the uncompressed data (re-entry is no problem). I don't know how to get the transformation while compiling. - I could try #define C(x) uncompress(buffer##__LINE__) and write some script that looks for the C() calls and generates a C file with the buffer constants - which means parsing (some of) C. - Or these texts get put in some special segment, that gets compressed into another before linking, and the original segment gets removed. - Or, what I'd like best: Is there some way to tell GCC "whenever this macro is used, call program X, and substitute the macro value with the output"? That would be the easiest way for me. Now you might say that it isn't that interesting - just use a compressed filesystem, or whatever. But these are all different tradeoffs; I'd just like to reduce the storage (and typical memory) footprint of my application by storing rarely used data compressed. I'd imagine that other projects would use that too, if it's easily available - and then the space needed for a small installation would decrease by some non-trivial amount. And, not at least, allowing dynamic macro expansion would allow some neat hacks :-) Please keep me CC:ed; thank you for all ideas, tips and other feedback. Regards, Phil -- Versioning your /etc, /home or even your whole installation? Try fsvs (fsvs.tigris.org)!