michael@0: Elfhack is a program to optimize ELF binaries for size and cold startup michael@0: speed. michael@0: michael@0: Presently, it is quite experimental, though it works well for the target michael@0: it was created for: Firefox's libxul.so. michael@0: michael@0: Elfhack currently only does one thing: packing dynamic relocations ; michael@0: which ends up being a quite complex task, that can be summarized this michael@0: way: michael@0: - Remove RELATIVE relocations from the .rel.dyn/.rela.dyn section. michael@0: - Inject a small code able to apply relative relocations "by hand" michael@0: after the .rel.dyn/.rela.dyn section. michael@0: - Inject a section containing relocative relocations in a different michael@0: and more packed format, after the small code. michael@0: - Register the small code as DT_INIT function. Make the small code call michael@0: what was initially the DT_INIT function, if there was one. michael@0: - Remove the hole between the new section containing relative michael@0: relocations and the following sections, adjusting offsets and base michael@0: addresses accordingly. michael@0: - Adjust PT_LOAD entries to fit new offsets, and add an additional michael@0: PT_LOAD entry when that is necessary to handle the discrepancy between michael@0: offsets and base addresses, meaning the section offsets may yet again michael@0: need adjustments. michael@0: - Adjust various DT_* dynamic tags to fit the new ELF layout. michael@0: - Adjust section headers. michael@0: - Adjust ELF headers. michael@0: michael@0: See http://glandium.org/blog/?p=1177#relocations for some figures.