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: Sat, 28 Mar 2015 15:46:49 -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> <CAMe9rOrVpthhMfZEXcMkKzmHcxymfQHKuTuZPi_y36=s6KJ9iA at mail dot gmail dot com> <20150328041540 dot GE26234 at bubble dot grove dot modra dot org> <CAMe9rOoVzbOvdE1_apgUbHtm0gG89d3_9qbnA8=Y3Qu9MznUPA at mail dot gmail dot com>
On Sat, Mar 28, 2015 at 11:30 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Mar 27, 2015 at 9:15 PM, Alan Modra <amodra@gmail.com> wrote:
>> On Fri, Mar 27, 2015 at 01:00:20PM -0700, H.J. Lu wrote:
>>> On Wed, Mar 25, 2015 at 7:22 PM, Alan Modra <amodra@gmail.com> wrote:
>>> > 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?
>>>
>>> segment. In order to properly align PT_GNU_RELRO segmnet, we pad the first
>>> section of PT_GNU_RELRO segment by
>>
>> Adjusting the start of the first section of the PT_GNU_RELRO segment
>> is exactly what DATA_SEGMENT_ALIGN is supposed to do. You are
>> patching the wrong place. Any adjustment to the start of the relro
>> segment belongs in ldexp.c code evaluating DATA_SEGMENT_ALIGN.
>>
>
> Since output_section_statement isn't passed to ldexp.c, I don't see how
> DATA_SEGMENT_ALIGN in ldexp.c can check the section address and size.
>
>
lang_size_sections aligns expld.dataseg.base:
5422 /* Aligning the adjusted base guarantees the padding
5423 between sections won't change. This is better than
5424 simply subtracting 1 << max_alignment_power which is
5425 what we used to do here. */
5426 expld.dataseg.base &= ~((1 << max_alignment_power) - 1);
5427 lang_reset_memory_regions ();
5428 one_lang_size_sections_pass (relax, check_regions);
5429 }
5430 }
5431 link_info.relro_start = expld.dataseg.base;
(gdb) p/x expld.dataseg
$290 = {phase = 0x4, base = 0x24bd00, min_base = 0x4bcc7,
relro_end = 0x24f000, end = 0x64eae0, pagesize = 0x1000,
maxpagesize = 0x200000, relro = 0x0, relro_start_stat = 0x8203e0,
relro_end_stat = 0x822b20}
(gdb)
and calls lang_size_sections_1 to align the first section of
PT_GNU_RELRO segmnet:
(gdb) bt
#0 lang_size_sections_1 (prev=0x81f258, output_section_statement=0x8135b0,
fill=0x0, dot=2407680, relax=0x0, check_regions=1)
at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:4919
#1 0x0000000000415219 in one_lang_size_sections_pass (relax=0x0,
check_regions=1)
at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:5368
#2 0x000000000041541d in lang_size_sections (relax=0x0, check_regions=1)
at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:5428
#3 0x0000000000417758 in lang_process ()
at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:6766
#4 0x000000000041b588 in main (argc=74, argv=0x7fffffffd328)
at /export/gnu/import/git/sources/binutils-gdb/ld/ldmain.c:419
(gdb) list
4914 if (section_alignment > 0)
4915 {
4916 bfd_vma savedot = newdot;
4917 newdot = align_power (newdot, section_alignment);
4918
4919 dotdelta = newdot - savedot;
4920 if (dotdelta != 0
4921 && (config.warn_section_align
4922 || os->addr_tree != NULL)
4923 && expld.phase != lang_mark_phase_enum)
(gdb)
After that, DATA_SEGMENT_ALIGN is processed:
(gdb) bt
#0 fold_binary (tree=0x820380)
at /export/gnu/import/git/sources/binutils-gdb/ld/ldexp.c:570
#1 0x000000000042065d in exp_fold_tree_1 (tree=0x820380)
at /export/gnu/import/git/sources/binutils-gdb/ld/ldexp.c:989
#2 0x00000000004206f2 in exp_fold_tree_1 (tree=0x8203b0)
at /export/gnu/import/git/sources/binutils-gdb/ld/ldexp.c:1008
#3 0x0000000000420bef in exp_fold_tree (tree=0x8203b0,
current_section=0x8078b0 <_bfd_std_section+560>, dotp=0x7fffffffcf68)
at /export/gnu/import/git/sources/binutils-gdb/ld/ldexp.c:1166
#4 0x0000000000414e36 in lang_size_sections_1 (prev=0x820300,
output_section_statement=0x8135b0, fill=0x0, dot=310471, relax=0x0,
check_regions=1)
at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:5211
#5 0x0000000000415219 in one_lang_size_sections_pass (relax=0x0,
check_regions=1)
at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:5368
#6 0x000000000041524f in lang_size_sections (relax=0x0, check_regions=1)
at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:5378
#7 0x000000000041724a in lang_relax_sections (need_layout=1)
at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:6529
#8 0x0000000000427d83 in gldelf_x86_64_map_segments (need_layout=1)
at eelf_x86_64.c:68
#9 0x000000000042ae3f in gldelf_x86_64_after_allocation ()
---Type <return> to continue, or q <return> to quit---
at eelf_x86_64.c:1787
#10 0x0000000000421899 in ldemul_after_allocation ()
at /export/gnu/import/git/sources/binutils-gdb/ld/ldemul.c:70
#11 0x000000000041775d in lang_process ()
at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:6770
#12 0x000000000041b588 in main (argc=74, argv=0x7fffffffd328)
at /export/gnu/import/git/sources/binutils-gdb/ld/ldmain.c:419
(gdb) list
565 else if (expld.dataseg.phase == exp_dataseg_none)
566 {
567 expld.dataseg.phase = exp_dataseg_align_seen;
568 expld.dataseg.min_base = expld.dot;
569 expld.dataseg.base = expld.result.value;
570 expld.dataseg.pagesize = commonpage;
571 expld.dataseg.maxpagesize = maxpage;
572 expld.dataseg.relro_end = 0;
573 }
574 else
(gdb) f 11
#11 0x000000000041775d in lang_process ()
at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:6770
6770 ldemul_after_allocation ();
(gdb) list
6765 /* Size up the sections. */
6766 lang_size_sections (NULL, ! RELAXATION_ENABLED);
6767
6768 /* See if anything special should be done now we know how big
6769 everything is. This is where relaxation is done. */
6770 ldemul_after_allocation ();
6771
6772 /* Fix any .startof. or .sizeof. symbols. */
6773 lang_set_startof ();
6774
(gdb)
I don't see DATA_SEGMENT_ALIGN changes section address.
--
H.J.