From: "H.J. Lu" <hjl.tools@gmail.com>
To: Binutils <binutils@sourceware.org>
Subject: Re: [PATCH] Reduce file size for PT_GNU_RELRO segment
Date: Sat, 28 Mar 2015 22:46:00 -0000 [thread overview]
Message-ID: <CAMe9rOp8sdCbOp0eVzRmwMhe_3c2K0EJ6fmnMMWyA01KYamzLw@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOoVzbOvdE1_apgUbHtm0gG89d3_9qbnA8=Y3Qu9MznUPA@mail.gmail.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.
next prev parent reply other threads:[~2015-03-28 22:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-19 13:02 H.J. Lu
2015-03-26 2:22 ` Alan Modra
2015-03-27 20:00 ` H.J. Lu
2015-03-28 4:15 ` Alan Modra
2015-03-28 18:30 ` H.J. Lu
2015-03-28 22:46 ` H.J. Lu [this message]
2015-03-29 3:49 ` Alan Modra
2015-03-29 13:58 ` H.J. Lu
2015-03-30 12:39 ` Alan Modra
2015-03-30 13:00 ` H.J. Lu
2015-03-30 14:14 ` Alan Modra
2015-03-30 16:12 ` H.J. Lu
2015-04-01 9:12 ` Start of relro segment adjustment Alan Modra
2015-04-01 11:26 ` H.J. Lu
2015-03-29 3:19 ` [PATCH] Reduce file size for PT_GNU_RELRO segment H.J. Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMe9rOp8sdCbOp0eVzRmwMhe_3c2K0EJ6fmnMMWyA01KYamzLw@mail.gmail.com \
--to=hjl.tools@gmail.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).