[PATCH] Reduce file size for PT_GNU_RELRO segment

H.J. Lu hjl.tools@gmail.com
Fri Mar 27 20:00:00 GMT 2015


On Wed, Mar 25, 2015 at 7:22 PM, Alan Modra <amodra@gmail.com> wrote:
> On Thu, Mar 19, 2015 at 06:02:44AM -0700, H.J. Lu wrote:
>> When a padding in file is used to align PT_GNU_RELRO segment, the maximum
>> padding size is maximum page size minus 1.  This patch trades memory size
>> for file size by increasing memory size to avoid padding if file size
>> will be reduced by more than maximum page minus a page and memory size
>> will be increased by less than a page.
>
> Isn't this just re-inventing the commonpage adjustment done for
> DATA_SEGMENT_ALIGN?  Why didn't the existing code in ldexp.c work for
> you?

The existing code in  ldexp.c only deals with sections within PT_GNU_RELRO
segment.  It doesn't consider impact of the section just before PT_GNU_RELRO
segment on the file size due to the alignment requirement for PT_GNU_RELRO
segment.  In order to properly align PT_GNU_RELRO segment, we pad the first
section of PT_GNU_RELRO segment by

((sec->vma - (prev_sec->vma + prev_sec->size)) % common_pagesize

If we can reduce the padding significantly by increasing the address
of the first
section of PT_GNU_RELRO segment just a little bit, we limit the padding
to the minimum and generate a much smaller binary.  That is what my patch
does.


-- 
H.J.



More information about the Binutils mailing list