开发者

Object files without ELF header or ways to reduce object file size with GCC?

开发者 https://www.devze.com 2023-01-31 10:12 出处:网络
I\'m using GCC to compile some C code. Is there a way to strip e.g. the ELF header from object file and make linker to add the header? Or, are there other possibilities to strip down the resulting obj

I'm using GCC to compile some C code. Is there a way to strip e.g. the ELF header from object file and make linker to add the header? Or, are there other possibilities to strip down the resulting object file size than the obvious -Os and -s flags?(-ffast-math, -fomit-frame-pointer, -fshort-doubles do help to reduce the code size but hexdumping the object file reveals huge amounts of zeroes which are "seemingly" useless).

Tools like strip/sst开发者_开发问答rip aren't really of much use as the object file has to preserve the symbols(it will be linked later on). (-strip-unneeded and -R .comment -R .gnu.version do their magic though).

What I'm doing is something which requires me to bundle (compressed) object file to the user and have a script embedded to link it at users-end. Every byte counts!


The ELF header can't be removed and restored later on, as valuable information is stored there and then lost forever (like file offsets for some tables, architecture, etc. IIRC). You've already listed almost everything that you can do to reduce the size, except maybe bzip'ing.


If you run the object files through a compression algorith, those "huge amounts of zeroes" should shrink by a large factor, since they have low information content. You might want to investigate a better compression algorithnm, perhaps it's possible to gain more there than by going to a modified/non-standard "hacked" object file format, if even possible.


You can try playing with -fdata-sections, -ffunction-sections and -Wl,--gc-sections, but this is not safe, so be sure to understand how they work before using them.

0

精彩评论

暂无评论...
验证码 换一张
取 消