This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Reduce file size for PT_GNU_RELRO segment
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Fri, 27 Mar 2015 13:00:20 -0700
- Subject: Re: [PATCH] Reduce file size for PT_GNU_RELRO segment
- Authentication-results: sourceware.org; auth=none
- References: <20150319130244 dot GA22592 at intel dot com> <20150326022246 dot GU26234 at bubble dot grove dot modra dot org>
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.