This directory contains the shared library compression tool that allows to reduce the shared library size by compressing non-performance critical code. The decompression is done on demand by a watcher thread that is set in a library constructor. This constructor (located in a single .c file) should be included in the library's build.
Additional information may be found in the tracking bug: https://crbug.com/998082
The tool consists of 2 parts:
This script does the compression part. It removes the specified range from the file and adds compressed version of it instead. It then sets decompression hook's smagic bytes to point at the cutted range and to the compressed version.
decompression_hook/ path and should be build together with the target library.
It decompresses data from compressed section, provided by compression script and populates the target range by setting a new library constructor which starts a watcher thread, handling page fault events.
Firstly, the library needs to be build with the tool's decompression hook. To do this add the following file to your build:
Additionally the library must be linked with
After the library build is complete, the compression script must be applied to it in the following way:
./compress_section.py -i lib.so -o patched_lib.so -l <begin> -r <end>
<end> are the file offsets of the part that you want to compress.
It is important to note that after running the script some of the common ELF tooling utilities, for example objcopy, may stop working because of the unusual (but legal) changes made to the library.
To run tests: